ld_syscall.h 3.3 KB

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