OSDN Git Service

Jakub Bogusz from pld-linux dot org writes:
[uclinux-h8/uClibc.git] / ldso / include / dl-syscall.h
1 #ifndef _LD_SYSCALL_H_
2 #define _LD_SYSCALL_H_
3
4 /* Pull in the arch specific syscall implementation */
5 #include <dl-syscalls.h>
6 /*  For MAP_ANONYMOUS -- differs between platforms */
7 #include <asm/mman.h>
8 /* Pull in whatever this particular arch's kernel thinks the kernel version of
9  * struct stat should look like.  It turns out that each arch has a different
10  * opinion on the subject, and different kernel revs use different names... */
11 #define kernel_stat stat
12 #include <bits/kernel_stat.h>
13 #include <bits/kernel_types.h>
14
15
16 /* _dl_open() parameters */
17 #define O_RDONLY        0x0000
18 #define O_WRONLY             01
19 #define O_RDWR               02
20 #define O_CREAT            0100
21
22 /* Encoding of the file mode.  */
23 #define S_IFMT          0170000 /* These bits determine file type.  */
24
25 /* File types.  */
26 #define S_IFDIR         0040000 /* Directory.  */
27 #define S_IFCHR         0020000 /* Character device.  */
28 #define S_IFBLK         0060000 /* Block device.  */
29 #define S_IFREG         0100000 /* Regular file.  */
30 #define S_IFIFO         0010000 /* FIFO.  */
31 #define S_IFLNK         0120000 /* Symbolic link.  */
32 #define S_IFSOCK        0140000 /* Socket.  */
33
34 /* Protection bits.  */
35 #define S_ISUID         04000   /* Set user ID on execution.  */
36 #define S_ISGID         02000   /* Set group ID on execution.  */
37 #define S_ISVTX         01000   /* Save swapped text after use (sticky).  */
38 #define S_IREAD         0400    /* Read by owner.  */
39 #define S_IWRITE        0200    /* Write by owner.  */
40 #define S_IEXEC         0100    /* Execute by owner.  */
41
42 /* Stuff for _dl_mmap */
43 #if 0
44 #define MAP_FAILED      ((void *) -1)
45 #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
46 #else
47 #ifndef _dl_MAX_ERRNO
48 #define _dl_MAX_ERRNO 4096
49 #endif
50 #define _dl_mmap_check_error(__res)     \
51         (((int)__res) < 0 && ((int)__res) >= -_dl_MAX_ERRNO)
52 #endif
53
54
55
56 /* Here are the definitions for some syscalls that are used
57    by the dynamic linker.  The idea is that we want to be able
58    to call these before the errno symbol is dynamicly linked, so
59    we use our own version here.  Note that we cannot assume any
60    dynamic linking at all, so we cannot return any error codes.
61    We just punt if there is an error. */
62 #define __NR__dl_exit __NR_exit
63 static inline _syscall1(void, _dl_exit, int, status);
64
65 #define __NR__dl_close __NR_close
66 static inline _syscall1(int, _dl_close, int, fd);
67
68 #define __NR__dl_open __NR_open
69 static inline _syscall3(int, _dl_open, const char *, fn, int, flags, __kernel_mode_t, mode);
70
71 #define __NR__dl_write __NR_write
72 static inline _syscall3(unsigned long, _dl_write, int, fd,
73             const void *, buf, unsigned long, count);
74
75 #define __NR__dl_read __NR_read
76 static inline _syscall3(unsigned long, _dl_read, int, fd,
77             const void *, buf, unsigned long, count);
78
79 #define __NR__dl_mprotect __NR_mprotect
80 static inline _syscall3(int, _dl_mprotect, const void *, addr, unsigned long, len, int, prot);
81
82 #define __NR__dl_stat __NR_stat
83 static inline _syscall2(int, _dl_stat, const char *, file_name, struct stat *, buf);
84
85 #define __NR__dl_munmap __NR_munmap
86 static inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length);
87
88 #define __NR__dl_getuid __NR_getuid
89 static inline _syscall0(uid_t, _dl_getuid);
90
91 #define __NR__dl_geteuid __NR_geteuid
92 static inline _syscall0(uid_t, _dl_geteuid);
93
94 #define __NR__dl_getgid __NR_getgid
95 static inline _syscall0(gid_t, _dl_getgid);
96
97 #define __NR__dl_getegid __NR_getegid
98 static inline _syscall0(gid_t, _dl_getegid);
99
100 #define __NR__dl_getpid __NR_getpid
101 static inline _syscall0(gid_t, _dl_getpid);
102
103 #define __NR__dl_readlink __NR_readlink
104 static inline _syscall3(int, _dl_readlink, const char *, path, char *, buf, size_t, bufsiz);
105
106 #ifdef __NR_mmap
107 #if defined(__powerpc__) || defined(__mips__) || defined(__sh__) || defined(__sparc__)
108 /* PowerPC, MIPS and SuperH have a different calling convention for mmap(). */
109 #define __NR__dl_mmap __NR_mmap
110 static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,
111                 int, prot, int, flags, int, fd, off_t, offset);
112 #else
113 #define __NR__dl_mmap_real __NR_mmap
114 static inline _syscall1(void *, _dl_mmap_real, unsigned long *, buffer);
115
116 static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
117                 int flags, int fd, unsigned long offset)
118 {
119         unsigned long buffer[6];
120
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 *) _dl_mmap_real(buffer);
128 }
129 #endif
130 #elif defined __NR_mmap2
131 #define __NR___syscall_mmap2       __NR_mmap2
132 static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
133                 size_t, len, int, prot, int, flags, int, fd, off_t, offset);
134 /*always 12, even on architectures where PAGE_SHIFT != 12 */
135 #define MMAP2_PAGE_SHIFT 12
136 static inline void * _dl_mmap(void * addr, unsigned long size, int prot,
137                 int flags, int fd, unsigned long offset)
138 {
139     if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
140         return MAP_FAILED;
141     return(__syscall_mmap2(addr, size, prot, flags,
142                 fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
143 }
144 #endif
145
146 #endif /* _LD_SYSCALL_H_ */
147