pal_linux.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <sys/syscall.h>
  21. #ifdef __x86_64__
  22. # include "sysdep-x86_64.h"
  23. #endif
  24. #define IS_ERR INTERNAL_SYSCALL_ERROR
  25. #define IS_ERR_P INTERNAL_SYSCALL_ERROR_P
  26. #define ERRNO INTERNAL_SYSCALL_ERRNO
  27. #define ERRNO_P INTERNAL_SYSCALL_ERRNO_P
  28. extern struct pal_linux_config {
  29. unsigned int pid, uid, gid;
  30. __sigset_t sigset;
  31. bool noexec;
  32. } pal_linux_config;
  33. #include <asm/mman.h>
  34. #ifdef INLINE_SYSCALL
  35. # ifdef __i386__
  36. # define ARCH_MMAP(addr, len, prot, flags, fd, offset) \
  37. ({ \
  38. struct mmap_arg_struct { \
  39. unsigned long addr; \
  40. unsigned long len; \
  41. unsigned long prot; \
  42. unsigned long flags; \
  43. unsigned long fd; \
  44. unsigned long offset; \
  45. } args = { .addr = (unsigned long) (addr), \
  46. .len = (unsigned long) (len), \
  47. .prot = (unsigned long) (prot), \
  48. .flags = (unsigned long) (flags), \
  49. .fd = (unsigned long) (fd), \
  50. .offset = (unsigned long) (offset), }; \
  51. INLINE_SYSCALL(mmap, 1, &args); \
  52. })
  53. # else
  54. # define ARCH_MMAP(addr, len, prot, flags, fd, offset) \
  55. INLINE_SYSCALL(mmap, 6, (addr), (len), (prot), (flags), (fd), (offset))
  56. # endif
  57. #else
  58. # error "INLINE_SYSCALL not supported"
  59. #endif
  60. #define ARCH_FORK() INLINE_SYSCALL(clone, 4, CLONE_CHILD_SETTID, 0, \
  61. NULL, &pal_linux_config.pid)
  62. #define ARCH_VFORK() INLINE_SYSCALL(clone, 4, CLONE_VM|CLONE_VFORK, 0, \
  63. NULL, NULL)
  64. #define PRESET_PAGESIZE (1 << 12)
  65. #define DEFAULT_BACKLOG 2048
  66. static inline int HOST_FLAGS (int alloc_type, int prot)
  67. {
  68. return ((alloc_type & PAL_ALLOC_32BIT) ? MAP_32BIT : 0) |
  69. ((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE|MAP_UNINITIALIZED : 0) |
  70. ((prot & PAL_PROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED);
  71. }
  72. static inline int HOST_PROT (int prot)
  73. {
  74. return prot & (PAL_PROT_READ|PAL_PROT_WRITE|PAL_PROT_EXEC);
  75. }
  76. int __clone (int (*__fn) (void * __arg), void * __child_stack,
  77. int __flags, const void * __arg, ...);
  78. #define ACCESS_R 4
  79. #define ACCESS_W 2
  80. #define ACCESS_X 1
  81. struct stat;
  82. bool stataccess (struct stat * stats, int acc);
  83. #if USE_VDSO_GETTIME == 1
  84. # if USE_CLOCK_GETTIME == 1
  85. struct timespec;
  86. long int (*__vdso_clock_gettime) (long int clk, struct timespec * tp);
  87. # else
  88. struct timeval;
  89. long int (*__vdso_gettimeofday) (struct timeval *, void *);
  90. # endif
  91. #endif
  92. #endif /* PAL_LINUX_H */