ld_syscall.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Pull in the arch specific type information */
  2. #include <sys/types.h>
  3. /* Pull in the arch specific syscall implementation */
  4. #include "ld_syscalls.h"
  5. /* For MAP_ANONYMOUS -- differs between platforms */
  6. #include <sys/mman.h>
  7. /* Pull in whatever this particular arch's kernel thinks the kernel version of
  8. * struct stat should look like. It turns out that each arch has a different
  9. * opinion on the subject, and different kernel revs use different names... */
  10. #include <sys/stat.h>
  11. /* Here are the definitions for some syscalls that are used
  12. by the dynamic linker. The idea is that we want to be able
  13. to call these before the errno symbol is dynamicly linked, so
  14. we use our own version here. Note that we cannot assume any
  15. dynamic linking at all, so we cannot return any error codes.
  16. We just punt if there is an error. */
  17. #define __NR__dl_exit __NR_exit
  18. static inline _syscall1(void, _dl_exit, int, status);
  19. #define __NR__dl_close __NR_close
  20. static inline _syscall1(int, _dl_close, int, fd);
  21. #ifdef __powerpc__
  22. /* PowerPC has a different calling convention for mmap(). */
  23. #define __NR__dl_mmap __NR_mmap
  24. static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
  25. int, prot, int, flags, int, fd, off_t, offset);
  26. #else
  27. #define __NR__dl_mmap_real __NR_mmap
  28. static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
  29. static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
  30. int flags, int fd, unsigned long offset)
  31. {
  32. unsigned long buffer[6];
  33. buffer[0] = (unsigned long) addr;
  34. buffer[1] = (unsigned long) size;
  35. buffer[2] = (unsigned long) prot;
  36. buffer[3] = (unsigned long) flags;
  37. buffer[4] = (unsigned long) fd;
  38. buffer[5] = (unsigned long) offset;
  39. return (void *) _dl_mmap_real(buffer);
  40. }
  41. #endif
  42. #ifndef _dl_MAX_ERRNO
  43. #define _dl_MAX_ERRNO 4096
  44. #endif
  45. #define _dl_mmap_check_error(__res) \
  46. (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO)
  47. #ifndef MAP_ANONYMOUS
  48. #ifdef __sparc__
  49. #define MAP_ANONYMOUS 0x20
  50. #else
  51. #error MAP_ANONYMOUS not defined and suplementary value not known
  52. #endif
  53. #endif
  54. #define __NR__dl_open __NR_open
  55. #define O_RDONLY 0x0000
  56. static inline _syscall2(int, _dl_open, const char *, fn, int, flags);
  57. #define __NR__dl_write __NR_write
  58. static inline _syscall3(unsigned long, _dl_write, int, fd,
  59. const void *, buf, unsigned long, count);
  60. #define __NR__dl_read __NR_read
  61. static inline _syscall3(unsigned long, _dl_read, int, fd,
  62. const void *, buf, unsigned long, count);
  63. #define __NR__dl_mprotect __NR_mprotect
  64. static inline _syscall3(int, _dl_mprotect, const void *, addr, unsigned long, len, int, prot);
  65. #define __NR__dl_stat __NR_stat
  66. static inline _syscall2(int, _dl_stat, const char *, file_name, struct stat *, buf);
  67. #define __NR__dl_munmap __NR_munmap
  68. static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
  69. #define __NR__dl_getuid __NR_getuid
  70. static inline _syscall0(uid_t, _dl_getuid);
  71. #define __NR__dl_geteuid __NR_geteuid
  72. static inline _syscall0(uid_t, _dl_geteuid);
  73. #define __NR__dl_getgid __NR_getgid
  74. static inline _syscall0(gid_t, _dl_getgid);
  75. #define __NR__dl_getegid __NR_getegid
  76. static inline _syscall0(gid_t, _dl_getegid);
  77. /*
  78. * Not an actual syscall, but we need something in assembly to say whether
  79. * this is OK or not.
  80. */
  81. static inline int _dl_suid_ok(void)
  82. {
  83. uid_t uid, euid, gid, egid;
  84. uid = _dl_getuid();
  85. euid = _dl_geteuid();
  86. gid = _dl_getgid();
  87. egid = _dl_getegid();
  88. if(uid == euid && gid == egid)
  89. return 1;
  90. else
  91. return 0;
  92. }