#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "sandbox/linux/seccomp-bpf/syscall.h"
#include <errno.h>
#include <stdint.h>
#include <ostream>
#include "base/check_op.h"
#include "build/build_config.h"
#include "sandbox/linux/bpf_dsl/seccomp_macros.h"
namespace sandbox {
namespace {
#if defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARM_FAMILY) || \
defined(ARCH_CPU_MIPS_FAMILY)
const int kInvalidSyscallNumber = …;
#else
#error Unrecognized architecture
#endif
asm …;
#if defined(__x86_64__)
extern "C" {
intptr_t SyscallAsm(intptr_t nr, const intptr_t args[6]);
}
#elif defined(__mips__)
extern "C" {
intptr_t SyscallAsm(intptr_t nr, const intptr_t args[8]);
}
#endif
}
intptr_t Syscall::InvalidCall() { … }
intptr_t Syscall::Call(int nr,
intptr_t p0,
intptr_t p1,
intptr_t p2,
intptr_t p3,
intptr_t p4,
intptr_t p5,
intptr_t p6,
intptr_t p7) { … }
void Syscall::PutValueInUcontext(intptr_t ret_val, ucontext_t* ctx) { … }
#if defined(__mips__)
intptr_t Syscall::SandboxSyscallRaw(int nr,
const intptr_t* args,
intptr_t* err_ret) {
register intptr_t ret __asm__("v0") = nr;
register intptr_t syscallasm __asm__("t9") = (intptr_t) &SyscallAsm;
register intptr_t err_stat __asm__("a3") = 0;
{
register const intptr_t* data __asm__("a0") = args;
asm volatile(
"jalr $t9\n"
" nop\n"
: "=r"(ret), "=r"(err_stat)
: "0"(ret),
"r"(data),
"r"(syscallasm)
: "memory", "ra", "a2");
}
*err_ret = err_stat;
return ret;
}
#endif
}