#ifndef Syscall_h
#define Syscall_h
#if ENABLE(SECCOMP_FILTERS)
#if CPU(X86_64)
#define REG_SYSCALL REG_RAX
#define REG_ARG0 REG_RDI
#define REG_ARG1 REG_RSI
#define REG_ARG2 REG_RDX
#define REG_ARG3 REG_R10
#elif CPU(X86)
#define REG_SYSCALL REG_EAX
#define REG_ARG0 REG_EBX
#define REG_ARG1 REG_ECX
#define REG_ARG2 REG_EDX
#define REG_ARG3 REG_ESI
#else
#error "CPU not supported."
#endif
#include <signal.h>
#include <sys/types.h>
#include <wtf/Noncopyable.h>
#include <wtf/StdLibExtras.h>
namespace IPC {
class ArgumentDecoder;
class ArgumentEncoder;
}
namespace WebKit {
class SyscallResult;
class SyscallPolicy;
class Syscall {
WTF_MAKE_NONCOPYABLE(Syscall);
public:
virtual ~Syscall() { }
static std::unique_ptr<Syscall> createFromContext(ucontext_t*);
static std::unique_ptr<Syscall> createFromDecoder(IPC::ArgumentDecoder*);
int type() const { return m_type; }
void setContext(mcontext_t* context) { m_context = context; }
mcontext_t* context() const { return m_context; }
virtual void setResult(const SyscallResult*) = 0;
virtual std::unique_ptr<SyscallResult> execute(const SyscallPolicy&) = 0;
virtual void encode(IPC::ArgumentEncoder&) const = 0;
virtual bool decode(IPC::ArgumentDecoder*) = 0;
protected:
Syscall(int type, mcontext_t*);
private:
int m_type;
mcontext_t* m_context;
};
class SyscallResult {
WTF_MAKE_NONCOPYABLE(SyscallResult);
public:
virtual ~SyscallResult() { }
static std::unique_ptr<SyscallResult> createFromDecoder(IPC::ArgumentDecoder*, int fd);
int type() const { return m_type; }
virtual void encode(IPC::ArgumentEncoder&) const = 0;
virtual bool decode(IPC::ArgumentDecoder*, int fd=-1) = 0;
protected:
SyscallResult(int type);
private:
int m_type;
};
}
#endif // ENABLE(SECCOMP_FILTERS)
#endif // Syscall_h