2 use std
::os
::raw
::c_int
;
7 use crate::lxcseccomp
::ProxyMessageBuffer
;
10 const AUDIT_ARCH_X86_64
: u32 = 0xc000_003e;
11 const AUDIT_ARCH_I386
: u32 = 0x4000_0003;
13 pub enum SyscallStatus
{
18 impl From
<Errno
> for SyscallStatus
{
19 fn from(errno
: Errno
) -> Self {
20 SyscallStatus
::Err(errno
as i32)
31 pub struct SyscallArch
{
38 const SYSCALL_TABLE
: &[SyscallArch
] = &[
40 arch
: AUDIT_ARCH_X86_64
,
46 arch
: AUDIT_ARCH_I386
,
53 pub fn translate_syscall(arch
: u32, nr
: c_int
) -> Option
<Syscall
> {
55 // so we don't hit a -1 in SYSCALL_TABLE by accident...
59 for sc
in SYSCALL_TABLE
{
62 return Some(Syscall
::Mknod
);
63 } else if nr
== sc
.mknodat
{
64 return Some(Syscall
::MknodAt
);
65 } else if nr
== sc
.quotactl
{
66 return Some(Syscall
::Quotactl
);
73 pub fn get_c_string(msg
: &ProxyMessageBuffer
, offset
: u64) -> Result
<CString
, Error
> {
74 let mut data
= unsafe { vec::uninitialized(4096) }
;
75 let got
= msg
.mem_fd().read_at(&mut data
, offset
)?
;
77 let len
= unsafe { libc::strnlen(data.as_ptr() as *const _, got) }
;
79 Err(nix
::Error
::Sys(Errno
::EINVAL
).into())
84 // We used strlen, so the only Error in CString::new() cannot happen at this point:
85 Ok(CString
::new(data
).unwrap())
90 macro_rules
! sc_libc_try
{
94 return Ok($
crate::syscall
::SyscallStatus
::Err(
95 ::nix
::errno
::errno() as _