pal_linux.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. /* Copyright (C) 2014 OSCAR lab, Stony Brook University
  4. This file is part of Graphene Library OS.
  5. Graphene Library OS is free software: you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation, either version 3 of the
  8. License, or (at your option) any later version.
  9. Graphene Library OS is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef PAL_LINUX_H
  16. #define PAL_LINUX_H
  17. #include "pal_defs.h"
  18. #include "pal_linux_defs.h"
  19. #include "pal.h"
  20. #include "pal_internal.h"
  21. #define PAL_LOADER XSTRINGIFY(PAL_LOADER_PATH)
  22. #include <sys/syscall.h>
  23. #ifdef __x86_64__
  24. # include "sysdep-x86_64.h"
  25. #endif
  26. #define IS_ERR INTERNAL_SYSCALL_ERROR
  27. #define IS_ERR_P INTERNAL_SYSCALL_ERROR_P
  28. #define ERRNO INTERNAL_SYSCALL_ERRNO
  29. #define ERRNO_P INTERNAL_SYSCALL_ERRNO_P
  30. extern struct pal_linux_config {
  31. unsigned int pid, uid, gid;
  32. __sigset_t sigset;
  33. bool noexec;
  34. } pal_linux_config;
  35. #include <asm/mman.h>
  36. #ifdef INLINE_SYSCALL
  37. # ifdef __i386__
  38. # define ARCH_MMAP(addr, len, prot, flags, fd, offset) \
  39. ({ \
  40. struct mmap_arg_struct { \
  41. unsigned long addr; \
  42. unsigned long len; \
  43. unsigned long prot; \
  44. unsigned long flags; \
  45. unsigned long fd; \
  46. unsigned long offset; \
  47. } args = { .addr = (unsigned long) (addr), \
  48. .len = (unsigned long) (len), \
  49. .prot = (unsigned long) (prot), \
  50. .flags = (unsigned long) (flags), \
  51. .fd = (unsigned long) (fd), \
  52. .offset = (unsigned long) (offset), }; \
  53. INLINE_SYSCALL(mmap, 1, &args); \
  54. })
  55. # else
  56. # define ARCH_MMAP(addr, len, prot, flags, fd, offset) \
  57. INLINE_SYSCALL(mmap, 6, (addr), (len), (prot), (flags), (fd), (offset))
  58. # endif
  59. #else
  60. # error "INLINE_SYSCALL not supported"
  61. #endif
  62. #define ARCH_FORK() INLINE_SYSCALL(clone, 4, CLONE_CHILD_SETTID, 0, \
  63. NULL, &pal_linux_config.pid)
  64. #define ARCH_VFORK() INLINE_SYSCALL(clone, 4, CLONE_VM|CLONE_VFORK, 0, \
  65. NULL, NULL)
  66. #define PRESET_PAGESIZE (1 << 12)
  67. #define DEFAULT_BACKLOG 2048
  68. static inline int HOST_FLAGS (int alloc_type, int prot)
  69. {
  70. return ((alloc_type & PAL_ALLOC_32BIT) ? MAP_32BIT : 0) |
  71. ((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE|MAP_UNINITIALIZED : 0) |
  72. ((prot & PAL_PROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED);
  73. }
  74. static inline int HOST_PROT (int prot)
  75. {
  76. return prot & (PAL_PROT_READ|PAL_PROT_WRITE|PAL_PROT_EXEC);
  77. }
  78. int __clone (int (*__fn) (void * __arg), void * __child_stack,
  79. int __flags, const void * __arg, ...);
  80. #define ACCESS_R 4
  81. #define ACCESS_W 2
  82. #define ACCESS_X 1
  83. struct stat;
  84. bool stataccess (struct stat * stats, int acc);
  85. /* Locking and unlocking of Mutexes */
  86. int _DkMutexLock (struct mutex_handle * mut);
  87. int _DkMutexLockTimeout (struct mutex_handle * mut, int timeout);
  88. int _DkMutexUnlock (struct mutex_handle * mut);
  89. #include "pal_security.h"
  90. struct pal_proc_args {
  91. struct pal_sec_info pal_sec_info;
  92. PAL_IDX proc_fds[3];
  93. unsigned int parent_pid;
  94. PAL_IDX exec_fd;
  95. unsigned short exec_uri_offset;
  96. bool noexec;
  97. PAL_IDX manifest_fd;
  98. unsigned short manifest_uri_offset;
  99. unsigned short data_size;
  100. };
  101. int init_child_process (struct pal_proc_args * proc_args, void * proc_data);
  102. int signal_setup (void);
  103. #if USE_VDSO_GETTIME == 1
  104. # if USE_CLOCK_GETTIME == 1
  105. struct timespec;
  106. long int (*__vdso_clock_gettime) (long int clk, struct timespec * tp);
  107. # else
  108. struct timeval;
  109. long int (*__vdso_gettimeofday) (struct timeval *, void *);
  110. # endif
  111. #endif
  112. #endif /* PAL_LINUX_H */