sandbox.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef SANDBOX_H__
  2. # define SANDBOX_H__
  3. #define _GNU_SOURCE
  4. # include <sys/syscall.h>
  5. # include <sys/user.h>
  6. # include <unistd.h>
  7. # include "sllist.h"
  8. # ifndef NR_syscalls
  9. # define NR_syscalls 386
  10. # endif
  11. # ifdef __x86_64__
  12. # define REGISTER_TYPE unsigned long long int
  13. # else
  14. # define REGISTER_TYPE long int
  15. # endif
  16. typedef struct {
  17. const char **cmd;
  18. const char *tmpdir;
  19. char *cmdpath;
  20. char *tmppath;
  21. } t_param;
  22. struct s_sandboxenv;
  23. typedef int(* t_syscall_fnc)(struct s_sandboxenv *);
  24. struct s_sandboxenv {
  25. const t_param *params;
  26. t_syscall_fnc functions[NR_syscalls];
  27. int child_pid;
  28. struct user_regs_struct registers;
  29. REGISTER_TYPE syscall_args[6];
  30. };
  31. /* params.c */
  32. void print_help(const char *progname, int exit_status);
  33. t_param *parse_argv(const char **av);
  34. /* sandbox.c */
  35. int launch_program(const t_param *params);
  36. int manageSyscall(struct s_sandboxenv *env);
  37. void doTrace(int pid, const t_param *params);
  38. /* exec.c */
  39. void doExec(int pid_parent, const t_param *params);
  40. /* mem.c */
  41. /**
  42. * Get memory segment from addr ptr to first nullbyte
  43. * The returned addr is allocated with malloc and should be freed
  44. * readlen indicate successfully read bytes (nullable)
  45. **/
  46. void *getMem(const struct s_sandboxenv *env, size_t ptr, int *readlen);
  47. /* environment.c */
  48. int init_env(t_param *);
  49. void release_env(t_param *);
  50. # include "sandbox_syscall.h"
  51. #endif /* SANDBOX_H__ */