dl-syscall.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 _LD_SYSCALL_H_
  8. #define _LD_SYSCALL_H_
  9. /* Pull in the arch specific syscall implementation */
  10. #include <dl-syscalls.h>
  11. /* For MAP_ANONYMOUS -- differs between platforms */
  12. #define _SYS_MMAN_H 1
  13. #include <bits/mman.h>
  14. /* Pull in whatever this particular arch's kernel thinks the kernel version of
  15. * struct stat should look like. It turns out that each arch has a different
  16. * opinion on the subject, and different kernel revs use different names... */
  17. #if defined(__sparc_v9__) && (__WORDSIZE == 64)
  18. #define kernel_stat64 stat
  19. #else
  20. #define kernel_stat stat
  21. #endif
  22. #include <bits/kernel_stat.h>
  23. #include <bits/kernel_types.h>
  24. /* Protection bits. */
  25. #define S_ISUID 04000 /* Set user ID on execution. */
  26. #define S_ISGID 02000 /* Set group ID on execution. */
  27. /* Here are the definitions for some syscalls that are used
  28. by the dynamic linker. The idea is that we want to be able
  29. to call these before the errno symbol is dynamicly linked, so
  30. we use our own version here. Note that we cannot assume any
  31. dynamic linking at all, so we cannot return any error codes.
  32. We just punt if there is an error. */
  33. #define __NR__dl_exit __NR_exit
  34. static __always_inline _syscall1(void, _dl_exit, int, status);
  35. #define __NR__dl_close __NR_close
  36. static __always_inline _syscall1(int, _dl_close, int, fd);
  37. #define __NR__dl_open __NR_open
  38. static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
  39. __kernel_mode_t, mode);
  40. #define __NR__dl_write __NR_write
  41. static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
  42. const void *, buf, unsigned long, count);
  43. #define __NR__dl_read __NR_read
  44. static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
  45. const void *, buf, unsigned long, count);
  46. #define __NR__dl_mprotect __NR_mprotect
  47. static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
  48. unsigned long, len, int, prot);
  49. #define __NR__dl_stat __NR_stat
  50. static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
  51. struct stat *, buf);
  52. #define __NR__dl_fstat __NR_fstat
  53. static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf);
  54. #define __NR__dl_munmap __NR_munmap
  55. static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
  56. #ifdef __NR_getxuid
  57. # define __NR_getuid __NR_getxuid
  58. #endif
  59. #define __NR__dl_getuid __NR_getuid
  60. static __always_inline _syscall0(uid_t, _dl_getuid);
  61. #ifndef __NR_geteuid
  62. # define __NR_geteuid __NR_getuid
  63. #endif
  64. #define __NR__dl_geteuid __NR_geteuid
  65. static __always_inline _syscall0(uid_t, _dl_geteuid);
  66. #ifdef __NR_getxgid
  67. # define __NR_getgid __NR_getxgid
  68. #endif
  69. #define __NR__dl_getgid __NR_getgid
  70. static __always_inline _syscall0(gid_t, _dl_getgid);
  71. #ifndef __NR_getegid
  72. # define __NR_getegid __NR_getgid
  73. #endif
  74. #define __NR__dl_getegid __NR_getegid
  75. static __always_inline _syscall0(gid_t, _dl_getegid);
  76. #ifdef __NR_getxpid
  77. # define __NR_getpid __NR_getxpid
  78. #endif
  79. #define __NR__dl_getpid __NR_getpid
  80. static __always_inline _syscall0(gid_t, _dl_getpid);
  81. #define __NR__dl_readlink __NR_readlink
  82. static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
  83. size_t, bufsiz);
  84. #ifdef __UCLIBC_HAS_SSP__
  85. # include <sys/time.h>
  86. # define __NR__dl_gettimeofday __NR_gettimeofday
  87. static __always_inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
  88. # ifdef __USE_BSD
  89. struct timezone *, tz);
  90. # else
  91. void *, tz);
  92. # endif
  93. #endif
  94. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  95. * real PAGE_SHIFT != 12. Other architectures use the same value as
  96. * PAGE_SHIFT...
  97. */
  98. #ifndef MMAP2_PAGE_SHIFT
  99. # define MMAP2_PAGE_SHIFT 12
  100. #endif
  101. #define MAP_FAILED ((void *) -1)
  102. #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
  103. static __always_inline
  104. void *_dl_mmap(void *addr, unsigned long size, int prot,
  105. int flags, int fd, unsigned long offset)
  106. {
  107. #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
  108. /* first try mmap(), syscall6() style */
  109. return (void *)INLINE_SYSCALL(mmap, 6, addr, size, prot, flags, fd, offset);
  110. #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
  111. /* then try mmap2() */
  112. unsigned long shifted;
  113. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
  114. return MAP_FAILED;
  115. /* gcc needs help with putting things onto the stack */
  116. shifted = offset >> MMAP2_PAGE_SHIFT;
  117. return (void *)INLINE_SYSCALL(mmap2, 6, addr, size, prot, flags, fd, shifted);
  118. #elif defined(__NR_mmap)
  119. /* finally, fall back to mmap(), syscall1() style */
  120. unsigned long buffer[6];
  121. buffer[0] = (unsigned long) addr;
  122. buffer[1] = (unsigned long) size;
  123. buffer[2] = (unsigned long) prot;
  124. buffer[3] = (unsigned long) flags;
  125. buffer[4] = (unsigned long) fd;
  126. buffer[5] = (unsigned long) offset;
  127. return (void *)INLINE_SYSCALL(mmap, 1, buffer);
  128. #else
  129. # error "Your architecture doesn't seem to provide mmap() !?"
  130. #endif
  131. }
  132. #endif /* _LD_SYSCALL_H_ */