ld_syscall.h 3.2 KB

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