]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/ldso/include/dl-syscall.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / ldso / include / dl-syscall.h
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
8 #ifndef _DL_SYSCALL_H
9 #define _DL_SYSCALL_H
10
11 /* We can't use the real errno in ldso, since it has not yet
12  * been dynamicly linked in yet. */
13 #include "sys/syscall.h"
14 extern int _dl_errno;
15 #undef __set_errno
16 #define __set_errno(X) {(_dl_errno) = (X);}
17
18 /* Pull in the arch specific syscall implementation */
19 #include <dl-syscalls.h>
20 #ifdef NOT_FOR_L4
21 /*  For MAP_ANONYMOUS -- differs between platforms */
22 #define _SYS_MMAN_H 1
23 #include <bits/mman.h>
24
25 #ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
26 /* Pull in whatever this particular arch's kernel thinks the kernel version of
27  * struct stat should look like.  It turns out that each arch has a different
28  * opinion on the subject, and different kernel revs use different names... */
29 #if defined(__sparc_v9__) && (__WORDSIZE == 64)
30 #define kernel_stat64 stat
31 #else
32 #define kernel_stat stat
33 #endif
34 #include <bits/kernel_stat.h>
35 #include <bits/kernel_types.h>
36
37 /* Protection bits.  */
38 #define S_ISUID         04000   /* Set user ID on execution.  */
39 #define S_ISGID         02000   /* Set group ID on execution.  */
40
41 #else
42 /* 1. common-generic ABI doesn't need kernel_stat translation
43  * 3. S_IS?ID already provided by stat.h
44  */
45 #include <sys/stat.h>
46 #endif
47
48
49 /* Here are the definitions for some syscalls that are used
50    by the dynamic linker.  The idea is that we want to be able
51    to call these before the errno symbol is dynamicly linked, so
52    we use our own version here.  Note that we cannot assume any
53    dynamic linking at all, so we cannot return any error codes.
54    We just punt if there is an error. */
55 #define __NR__dl_exit __NR_exit
56 static __always_inline _syscall1(void, _dl_exit, int, status)
57
58 #define __NR__dl_close __NR_close
59 static __always_inline _syscall1(int, _dl_close, int, fd)
60
61 #if defined __NR_openat && !defined __NR_open
62 static __always_inline int _dl_open(const char *fn,
63                                                 int flags, __kernel_mode_t mode)
64 {
65         return INLINE_SYSCALL(openat, 4, AT_FDCWD, fn, flags, mode);
66 }
67
68 #elif defined __NR_open
69 # define __NR__dl_open __NR_open
70 static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
71                         __kernel_mode_t, mode)
72 #endif
73
74 #define __NR__dl_write __NR_write
75 static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
76                         const void *, buf, unsigned long, count)
77
78 #define __NR__dl_read __NR_read
79 static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
80                         const void *, buf, unsigned long, count)
81
82 #define __NR__dl_mprotect __NR_mprotect
83 static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
84                         unsigned long, len, int, prot)
85
86 #if defined __NR_fstatat64 && !defined __NR_stat
87 # define __NR__dl_fstatat64 __NR_fstatat64
88 static __always_inline _syscall4(int, _dl_fstatat64, int, fd, const char *,
89                                  fn, struct stat *, stat, int, flags)
90
91 static __always_inline int _dl_stat(const char *file_name,
92                         struct stat *buf)
93 {
94         return _dl_fstatat64(AT_FDCWD, file_name, buf, 0);
95 }
96 #elif defined __NR_stat
97 # define __NR__dl_stat __NR_stat
98 static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
99                         struct stat *, buf)
100 #endif
101
102 #if defined __NR_fstat64 && !defined __NR_fstat
103 # define __NR__dl_fstat __NR_fstat64
104 #elif defined __NR_fstat
105 # define __NR__dl_fstat __NR_fstat
106 #endif
107 static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf)
108
109 #define __NR__dl_munmap __NR_munmap
110 static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length)
111
112 #ifdef __NR_getxuid
113 # define __NR_getuid __NR_getxuid
114 #endif
115 #define __NR__dl_getuid __NR_getuid
116 static __always_inline _syscall0(uid_t, _dl_getuid)
117
118 #ifndef __NR_geteuid
119 # define __NR_geteuid __NR_getuid
120 #endif
121 #define __NR__dl_geteuid __NR_geteuid
122 static __always_inline _syscall0(uid_t, _dl_geteuid)
123
124 #ifdef __NR_getxgid
125 # define __NR_getgid __NR_getxgid
126 #endif
127 #define __NR__dl_getgid __NR_getgid
128 static __always_inline _syscall0(gid_t, _dl_getgid)
129
130 #ifndef __NR_getegid
131 # define __NR_getegid __NR_getgid
132 #endif
133 #define __NR__dl_getegid __NR_getegid
134 static __always_inline _syscall0(gid_t, _dl_getegid)
135
136 #ifdef __NR_getxpid
137 # define __NR_getpid __NR_getxpid
138 #endif
139 #define __NR__dl_getpid __NR_getpid
140 static __always_inline _syscall0(gid_t, _dl_getpid)
141
142 #if defined __NR_readlinkat && !defined __NR_readlink
143 # define __NR__dl_readlink __NR_readlinkat
144 static __always_inline _syscall4(int, _dl_readlink, int, id, const char *, path,
145                                                 char *, buf, size_t, bufsiz)
146 #elif defined __NR_readlink
147 # define __NR__dl_readlink __NR_readlink
148 static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
149                         size_t, bufsiz)
150 #endif
151
152 #ifdef __NR_pread64
153 #define __NR___syscall_pread __NR_pread64
154 static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
155                         size_t, count, off_t, offset_hi, off_t, offset_lo)
156
157 static __always_inline ssize_t
158 _dl_pread(int fd, void *buf, size_t count, off_t offset)
159 {
160         return __syscall_pread(fd, buf, count, offset, offset >> 31);
161 }
162 #elif defined __NR_pread
163 #define __NR___syscall_pread __NR_pread
164 static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
165                         size_t, count, off_t, offset_hi, off_t, offset_lo)
166
167 static __always_inline ssize_t
168 _dl_pread(int fd, void *buf, size_t count, off_t offset)
169 {
170         return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
171 }
172 #endif
173
174 #ifdef __UCLIBC_HAS_SSP__
175 # include <sys/time.h>
176 # define __NR__dl_gettimeofday __NR_gettimeofday
177 static __always_inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
178 # ifdef __USE_BSD
179                         struct timezone *
180 # else
181                         void *
182 # endif
183                                                 , tz)
184 #endif
185
186 /* Some architectures always use 12 as page shift for mmap2() eventhough the
187  * real PAGE_SHIFT != 12.  Other architectures use the same value as
188  * PAGE_SHIFT...
189  */
190 #ifndef MMAP2_PAGE_SHIFT
191 # define MMAP2_PAGE_SHIFT 12
192 #endif
193
194 #define MAP_FAILED ((void *) -1)
195 #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
196
197 static __always_inline
198 void *_dl_mmap(void *addr, unsigned long size, int prot,
199                int flags, int fd, unsigned long offset)
200 {
201 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
202         /* first try mmap(), syscall6() style */
203         return (void *)INLINE_SYSCALL(mmap, 6, addr, size, prot, flags, fd, offset);
204
205 #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
206         /* then try mmap2() */
207         unsigned long shifted;
208
209         if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
210                 return MAP_FAILED;
211
212         /* gcc needs help with putting things onto the stack */
213         shifted = offset >> MMAP2_PAGE_SHIFT;
214         return (void *)INLINE_SYSCALL(mmap2, 6, addr, size, prot, flags, fd, shifted);
215
216 #elif defined(__NR_mmap)
217         /* finally, fall back to mmap(), syscall1() style */
218         unsigned long buffer[6];
219         buffer[0] = (unsigned long) addr;
220         buffer[1] = (unsigned long) size;
221         buffer[2] = (unsigned long) prot;
222         buffer[3] = (unsigned long) flags;
223         buffer[4] = (unsigned long) fd;
224         buffer[5] = (unsigned long) offset;
225         return (void *)INLINE_SYSCALL(mmap, 1, buffer);
226 #else
227 # error "Your architecture doesn't seem to provide mmap() !?"
228 #endif
229 }
230
231 #endif /* not for L4 */
232 #endif /* _DL_SYSCALL_H */