dl-syscall.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
  4. *
  5. * GNU Lesser General Public License version 2.1 or later.
  6. */
  7. #ifndef _DL_SYSCALL_H
  8. #define _DL_SYSCALL_H
  9. /* We can't use the real errno in ldso, since it has not yet
  10. * been dynamicly linked in yet. */
  11. #include "sys/syscall.h"
  12. extern int _dl_errno;
  13. #undef __set_errno
  14. #define __set_errno(X) {(_dl_errno) = (X);}
  15. /* Pull in the arch specific syscall implementation */
  16. #include <dl-syscalls.h>
  17. /* For MAP_ANONYMOUS -- differs between platforms */
  18. #define _SYS_MMAN_H 1
  19. #include <bits/mman.h>
  20. #ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
  21. /* Pull in whatever this particular arch's kernel thinks the kernel version of
  22. * struct stat should look like. It turns out that each arch has a different
  23. * opinion on the subject, and different kernel revs use different names... */
  24. #define kernel_stat stat
  25. #include <bits/kernel_stat.h>
  26. #include <bits/kernel_types.h>
  27. /* Protection bits. */
  28. #define S_ISUID 04000 /* Set user ID on execution. */
  29. #define S_ISGID 02000 /* Set group ID on execution. */
  30. #else
  31. /* 1. common-generic ABI doesn't need kernel_stat translation
  32. * 3. S_IS?ID already provided by stat.h
  33. */
  34. #include <sys/stat.h>
  35. #endif
  36. /* Here are the definitions for some syscalls that are used
  37. by the dynamic linker. The idea is that we want to be able
  38. to call these before the errno symbol is dynamicly linked, so
  39. we use our own version here. Note that we cannot assume any
  40. dynamic linking at all, so we cannot return any error codes.
  41. We just punt if there is an error. */
  42. #define __NR__dl_exit __NR_exit
  43. static __always_inline _syscall1(void, _dl_exit, int, status)
  44. #define __NR__dl_close __NR_close
  45. static __always_inline _syscall1(int, _dl_close, int, fd)
  46. #if defined __NR_openat && !defined __NR_open
  47. static __always_inline int _dl_open(const char *fn,
  48. int flags, __kernel_mode_t mode)
  49. {
  50. return INLINE_SYSCALL(openat, 4, AT_FDCWD, fn, flags, mode);
  51. }
  52. #elif defined __NR_open
  53. # define __NR__dl_open __NR_open
  54. static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
  55. __kernel_mode_t, mode)
  56. #endif
  57. #define __NR__dl_write __NR_write
  58. static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
  59. const void *, buf, unsigned long, count)
  60. #define __NR__dl_read __NR_read
  61. static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
  62. const void *, buf, unsigned long, count)
  63. #define __NR__dl_mprotect __NR_mprotect
  64. static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
  65. unsigned long, len, int, prot)
  66. #if defined __NR_fstatat64 && !defined __NR_stat
  67. # define __NR__dl_fstatat64 __NR_fstatat64
  68. static __always_inline _syscall4(int, _dl_fstatat64, int, fd, const char *,
  69. fn, struct stat *, stat, int, flags)
  70. static __always_inline int _dl_stat(const char *file_name,
  71. struct stat *buf)
  72. {
  73. return _dl_fstatat64(AT_FDCWD, file_name, buf, 0);
  74. }
  75. #elif defined __NR_stat
  76. # define __NR__dl_stat __NR_stat
  77. static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
  78. struct stat *, buf)
  79. #endif
  80. #if defined __NR_fstat64 && !defined __NR_fstat
  81. # define __NR__dl_fstat __NR_fstat64
  82. #elif defined __NR_fstat
  83. # define __NR__dl_fstat __NR_fstat
  84. #endif
  85. static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf)
  86. #define __NR__dl_munmap __NR_munmap
  87. static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length)
  88. #ifdef __NR_getxuid
  89. # define __NR_getuid __NR_getxuid
  90. #endif
  91. #define __NR__dl_getuid __NR_getuid
  92. static __always_inline _syscall0(uid_t, _dl_getuid)
  93. #ifndef __NR_geteuid
  94. # define __NR_geteuid __NR_getuid
  95. #endif
  96. #define __NR__dl_geteuid __NR_geteuid
  97. static __always_inline _syscall0(uid_t, _dl_geteuid)
  98. #ifdef __NR_getxgid
  99. # define __NR_getgid __NR_getxgid
  100. #endif
  101. #define __NR__dl_getgid __NR_getgid
  102. static __always_inline _syscall0(gid_t, _dl_getgid)
  103. #ifndef __NR_getegid
  104. # define __NR_getegid __NR_getgid
  105. #endif
  106. #define __NR__dl_getegid __NR_getegid
  107. static __always_inline _syscall0(gid_t, _dl_getegid)
  108. #ifdef __NR_getxpid
  109. # define __NR_getpid __NR_getxpid
  110. #endif
  111. #define __NR__dl_getpid __NR_getpid
  112. static __always_inline _syscall0(gid_t, _dl_getpid)
  113. #if defined __NR_readlinkat && !defined __NR_readlink
  114. # define __NR__dl_readlink __NR_readlinkat
  115. static __always_inline _syscall4(int, _dl_readlink, int, id, const char *, path,
  116. char *, buf, size_t, bufsiz)
  117. #elif defined __NR_readlink
  118. # define __NR__dl_readlink __NR_readlink
  119. static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
  120. size_t, bufsiz)
  121. #endif
  122. #ifdef __NR_pread64
  123. #define __NR___syscall_pread __NR_pread64
  124. static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
  125. size_t, count, off_t, offset_hi, off_t, offset_lo)
  126. static __always_inline ssize_t
  127. _dl_pread(int fd, void *buf, size_t count, off_t offset)
  128. {
  129. return __syscall_pread(fd, buf, count, offset, offset >> 31);
  130. }
  131. #elif defined __NR_pread
  132. #define __NR___syscall_pread __NR_pread
  133. static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
  134. size_t, count, off_t, offset_hi, off_t, offset_lo)
  135. static __always_inline ssize_t
  136. _dl_pread(int fd, void *buf, size_t count, off_t offset)
  137. {
  138. return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
  139. }
  140. #endif
  141. #ifdef __UCLIBC_HAS_SSP__
  142. # include <sys/time.h>
  143. # define __NR__dl_gettimeofday __NR_gettimeofday
  144. static __always_inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
  145. # ifdef __USE_BSD
  146. struct timezone *
  147. # else
  148. void *
  149. # endif
  150. , tz)
  151. #endif
  152. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  153. * real PAGE_SHIFT != 12. Other architectures use the same value as
  154. * PAGE_SHIFT...
  155. */
  156. #ifndef MMAP2_PAGE_SHIFT
  157. # define MMAP2_PAGE_SHIFT 12
  158. #endif
  159. #define MAP_FAILED ((void *) -1)
  160. #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
  161. static __always_inline
  162. void *_dl_mmap(void *addr, unsigned long size, int prot,
  163. int flags, int fd, unsigned long offset)
  164. {
  165. #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
  166. /* first try mmap(), syscall6() style */
  167. return (void *)INLINE_SYSCALL(mmap, 6, addr, size, prot, flags, fd, offset);
  168. #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
  169. /* then try mmap2() */
  170. unsigned long shifted;
  171. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
  172. return MAP_FAILED;
  173. /* gcc needs help with putting things onto the stack */
  174. shifted = offset >> MMAP2_PAGE_SHIFT;
  175. return (void *)INLINE_SYSCALL(mmap2, 6, addr, size, prot, flags, fd, shifted);
  176. #elif defined(__NR_mmap)
  177. /* finally, fall back to mmap(), syscall1() style */
  178. unsigned long buffer[6];
  179. buffer[0] = (unsigned long) addr;
  180. buffer[1] = (unsigned long) size;
  181. buffer[2] = (unsigned long) prot;
  182. buffer[3] = (unsigned long) flags;
  183. buffer[4] = (unsigned long) fd;
  184. buffer[5] = (unsigned long) offset;
  185. return (void *)INLINE_SYSCALL(mmap, 1, buffer);
  186. #else
  187. # error "Your architecture doesn't seem to provide mmap() !?"
  188. #endif
  189. }
  190. #endif /* _DL_SYSCALL_H */