| 1 |
.TH "seccomp_precompute" 3 "19 September 2022" "[email protected]" "libseccomp Documentation" |
| 2 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 3 |
.SH NAME |
| 4 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 5 |
seccomp_precompute \- Precompute the current seccomp filter |
| 6 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 7 |
.SH SYNOPSIS |
| 8 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 9 |
.nf |
| 10 |
.B #include <seccomp.h> |
| 11 |
.sp |
| 12 |
.B typedef void * scmp_filter_ctx; |
| 13 |
.sp |
| 14 |
.BI "int seccomp_precompute(scmp_filter_ctx " ctx ");" |
| 15 |
.sp |
| 16 |
Link with \fI\-lseccomp\fP. |
| 17 |
.fi |
| 18 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 19 |
.SH DESCRIPTION |
| 20 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 21 |
.P |
| 22 |
Precomputes the seccomp filter for later use by |
| 23 |
.BR seccomp_load () |
| 24 |
and similar functions. Not only does this improve performance of |
| 25 |
.BR seccomp_load () |
| 26 |
it also ensures that the seccomp filter can be loaded in an async-signal-safe |
| 27 |
manner if no changes have been made to the filter since it was precomputed. |
| 28 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 29 |
.SH RETURN VALUE |
| 30 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 31 |
Returns zero on success or one of the following error codes on failure: |
| 32 |
.TP |
| 33 |
.B -ECANCELED |
| 34 |
There was a system failure beyond the control of the library. |
| 35 |
.TP |
| 36 |
.B -EFAULT |
| 37 |
Internal libseccomp failure. |
| 38 |
.TP |
| 39 |
.B -EINVAL |
| 40 |
Invalid input, either the context or architecture token is invalid. |
| 41 |
.TP |
| 42 |
.B -ENOMEM |
| 43 |
The library was unable to allocate enough memory. |
| 44 |
.P |
| 45 |
If the \fISCMP_FLTATR_API_SYSRAWRC\fP filter attribute is non-zero then |
| 46 |
additional error codes may be returned to the caller; these additional error |
| 47 |
codes are the negative \fIerrno\fP values returned by the system. Unfortunately |
| 48 |
libseccomp can make no guarantees about these return values. |
| 49 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 50 |
.SH EXAMPLES |
| 51 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 52 |
.nf |
| 53 |
#include <seccomp.h> |
| 54 |
|
| 55 |
int main(int argc, char *argv[]) |
| 56 |
{ |
| 57 |
int rc = \-1; |
| 58 |
scmp_filter_ctx ctx; |
| 59 |
|
| 60 |
ctx = seccomp_init(SCMP_ACT_KILL); |
| 61 |
if (ctx == NULL) |
| 62 |
goto out; |
| 63 |
|
| 64 |
/* ... */ |
| 65 |
|
| 66 |
rc = seccomp_precompute(ctx); |
| 67 |
if (rc < 0) |
| 68 |
goto out; |
| 69 |
|
| 70 |
/* ... */ |
| 71 |
|
| 72 |
rc = seccomp_load(ctx); |
| 73 |
if (rc < 0) |
| 74 |
goto out; |
| 75 |
|
| 76 |
/* ... */ |
| 77 |
|
| 78 |
out: |
| 79 |
seccomp_release(ctx); |
| 80 |
return \-rc; |
| 81 |
} |
| 82 |
.fi |
| 83 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 84 |
.SH NOTES |
| 85 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 86 |
.P |
| 87 |
While the seccomp filter can be generated independent of the kernel, kernel |
| 88 |
support is required to load and enforce the seccomp filter generated by |
| 89 |
libseccomp. |
| 90 |
.P |
| 91 |
The libseccomp project site, with more information and the source code |
| 92 |
repository, can be found at https://github.com/seccomp/libseccomp. This tool, |
| 93 |
as well as the libseccomp library, is currently under development, please |
| 94 |
report any bugs at the project site or directly to the author. |
| 95 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 96 |
.SH AUTHOR |
| 97 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 98 |
Paul Moore <[email protected]> |
| 99 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 100 |
.SH SEE ALSO |
| 101 |
.\" ////////////////////////////////////////////////////////////////////////// |
| 102 |
.BR seccomp_load (3) |
| 103 |
.BR signal-safety (7) |