#ifndef SANDBOX_H__ # define SANDBOX_H__ #define _GNU_SOURCE # include # include # include # include "sllist.h" # ifndef NR_syscalls # define NR_syscalls 386 # endif # ifdef __x86_64__ # define REGISTER_TYPE unsigned long long int # else # define REGISTER_TYPE long int # endif typedef struct { const char **cmd; const char *tmpdir; char *cmdpath; char *tmppath; } t_param; struct s_sandboxenv; typedef int(* t_syscall_fnc)(struct s_sandboxenv *); struct s_sandboxenv { const t_param *params; t_syscall_fnc functions[NR_syscalls]; int child_pid; struct user_regs_struct registers; REGISTER_TYPE syscall_args[6]; }; /* params.c */ void print_help(const char *progname, int exit_status); t_param *parse_argv(const char **av); /* sandbox.c */ int launch_program(const t_param *params); int manageSyscall(struct s_sandboxenv *env); void doTrace(int pid, const t_param *params); /* exec.c */ void doExec(int pid_parent, const t_param *params); /* mem.c */ /** * Get memory segment from addr ptr to first nullbyte * The returned addr is allocated with malloc and should be freed * readlen indicate successfully read bytes (nullable) **/ void *getMem(const struct s_sandboxenv *env, size_t ptr, int *readlen); /* environment.c */ int init_env(t_param *); void release_env(t_param *); # include "sandbox_syscall.h" #endif /* SANDBOX_H__ */