2 * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
4 * GNU Lesser General Public License version 2.1 or later.
10 /* We can't use the real errno in ldso, since it has not yet
11 * been dynamicly linked in yet. */
12 #include "sys/syscall.h"
15 #define __set_errno(X) {(_dl_errno) = (X);}
17 /* Pull in the arch specific syscall implementation */
18 #include <dl-syscalls.h>
19 /* For MAP_ANONYMOUS -- differs between platforms */
21 #include <bits/mman.h>
23 #ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
24 /* Pull in whatever this particular arch's kernel thinks the kernel version of
25 * struct stat should look like. It turns out that each arch has a different
26 * opinion on the subject, and different kernel revs use different names... */
27 #define kernel_stat stat
28 #include <bits/kernel_stat.h>
29 #include <bits/kernel_types.h>
31 /* Protection bits. */
32 #define S_ISUID 04000 /* Set user ID on execution. */
33 #define S_ISGID 02000 /* Set group ID on execution. */
36 /* 1. common-generic ABI doesn't need kernel_stat translation
37 * 3. S_IS?ID already provided by stat.h
43 /* Here are the definitions for some syscalls that are used
44 by the dynamic linker. The idea is that we want to be able
45 to call these before the errno symbol is dynamicly linked, so
46 we use our own version here. Note that we cannot assume any
47 dynamic linking at all, so we cannot return any error codes.
48 We just punt if there is an error. */
49 #define __NR__dl_exit __NR_exit
50 static __always_inline attribute_noreturn __cold
void _dl_exit(int status
)
52 INLINE_SYSCALL(_dl_exit
, 1, status
);
53 #if __GNUC_PREREQ(4, 5)
54 __builtin_unreachable(); /* shut up warning: 'noreturn' function does return*/
60 #define __NR__dl_close __NR_close
61 static __always_inline
_syscall1(int, _dl_close
, int, fd
)
63 #if defined __NR_openat && !defined __NR_open
64 static __always_inline
int _dl_open(const char *fn
,
65 int flags
, __kernel_mode_t mode
)
67 return INLINE_SYSCALL(openat
, 4, AT_FDCWD
, fn
, flags
, mode
);
70 #elif defined __NR_open
71 # define __NR__dl_open __NR_open
72 static __always_inline
_syscall3(int, _dl_open
, const char *, fn
, int, flags
,
73 __kernel_mode_t
, mode
)
76 #define __NR__dl_write __NR_write
77 static __always_inline
_syscall3(unsigned long, _dl_write
, int, fd
,
78 const void *, buf
, unsigned long, count
)
80 #define __NR__dl_read __NR_read
81 static __always_inline
_syscall3(unsigned long, _dl_read
, int, fd
,
82 const void *, buf
, unsigned long, count
)
84 #define __NR__dl_mprotect __NR_mprotect
85 static __always_inline
_syscall3(int, _dl_mprotect
, const void *, addr
,
86 unsigned long, len
, int, prot
)
88 #if defined __NR_fstatat64 && !defined __NR_stat
89 # define __NR__dl_fstatat64 __NR_fstatat64
90 static __always_inline
_syscall4(int, _dl_fstatat64
, int, fd
, const char *,
91 fn
, struct stat
*, stat
, int, flags
)
93 static __always_inline
int _dl_stat(const char *file_name
,
96 return _dl_fstatat64(AT_FDCWD
, file_name
, buf
, 0);
98 #elif defined __NR_newfstatat && !defined __NR_stat
99 # define __NR__dl_newfstatat __NR_newfstatat
100 static __always_inline
_syscall4(int, _dl_newfstatat
, int, fd
, const char *,
101 fn
, struct stat
*, stat
, int, flags
)
103 static __always_inline
int _dl_stat(const char *file_name
,
106 return _dl_newfstatat(AT_FDCWD
, file_name
, buf
, 0);
108 #elif defined __NR_stat
109 # define __NR__dl_stat __NR_stat
110 static __always_inline
_syscall2(int, _dl_stat
, const char *, file_name
,
114 #if defined __NR_fstat64 && !defined __NR_fstat
115 # define __NR__dl_fstat __NR_fstat64
116 #elif defined __NR_fstat
117 # define __NR__dl_fstat __NR_fstat
119 static __always_inline
_syscall2(int, _dl_fstat
, int, fd
, struct stat
*, buf
)
121 #define __NR__dl_munmap __NR_munmap
122 static __always_inline
_syscall2(int, _dl_munmap
, void *, start
, unsigned long, length
)
125 # define __NR_getuid __NR_getxuid
127 #define __NR__dl_getuid __NR_getuid
128 static __always_inline
_syscall0(uid_t
, _dl_getuid
)
131 # define __NR_geteuid __NR_getuid
133 #define __NR__dl_geteuid __NR_geteuid
134 static __always_inline
_syscall0(uid_t
, _dl_geteuid
)
137 # define __NR_getgid __NR_getxgid
139 #define __NR__dl_getgid __NR_getgid
140 static __always_inline
_syscall0(gid_t
, _dl_getgid
)
143 # define __NR_getegid __NR_getgid
145 #define __NR__dl_getegid __NR_getegid
146 static __always_inline
_syscall0(gid_t
, _dl_getegid
)
149 # define __NR_getpid __NR_getxpid
151 #define __NR__dl_getpid __NR_getpid
152 static __always_inline
_syscall0(gid_t
, _dl_getpid
)
154 #if defined __NR_readlinkat
155 # define __NR__dl_readlink __NR_readlinkat
156 static __always_inline
_syscall4(int, _dl_readlink
, int, id
, const char *, path
,
157 char *, buf
, size_t, bufsiz
)
161 #define __NR___syscall_pread __NR_pread64
162 static __always_inline
_syscall5(ssize_t
, __syscall_pread
, int, fd
, void *, buf
,
163 size_t, count
, off_t
, offset_hi
, off_t
, offset_lo
)
165 static __always_inline ssize_t
166 _dl_pread(int fd
, void *buf
, size_t count
, off_t offset
)
168 return __syscall_pread(fd
, buf
, count
, offset
, offset
>> 31);
170 #elif defined __NR_pread
171 #define __NR___syscall_pread __NR_pread
172 static __always_inline
_syscall5(ssize_t
, __syscall_pread
, int, fd
, void *, buf
,
173 size_t, count
, off_t
, offset_hi
, off_t
, offset_lo
)
175 static __always_inline ssize_t
176 _dl_pread(int fd
, void *buf
, size_t count
, off_t offset
)
178 return __syscall_pread(fd
, buf
, count
, __LONG_LONG_PAIR(offset
>> 31, offset
));
182 #ifdef __UCLIBC_HAS_SSP__
183 # include <sys/time.h>
184 # define __NR__dl_gettimeofday __NR_gettimeofday
185 static __always_inline
_syscall2(int, _dl_gettimeofday
, struct timeval
*, tv
,
194 /* Some architectures always use 12 as page shift for mmap2() eventhough the
195 * real PAGE_SHIFT != 12. Other architectures use the same value as
198 #ifndef MMAP2_PAGE_SHIFT
199 # define MMAP2_PAGE_SHIFT 12
202 #define MAP_FAILED ((void *) -1)
203 #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
205 static __always_inline
206 void *_dl_mmap(void *addr
, unsigned long size
, int prot
,
207 int flags
, int fd
, unsigned long offset
)
209 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
210 /* first try mmap(), syscall6() style */
211 return (void *)INLINE_SYSCALL(mmap
, 6, addr
, size
, prot
, flags
, fd
, offset
);
213 #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
214 /* then try mmap2() */
215 unsigned long shifted
;
217 if (offset
& ((1 << MMAP2_PAGE_SHIFT
) - 1))
220 /* gcc needs help with putting things onto the stack */
221 shifted
= offset
>> MMAP2_PAGE_SHIFT
;
222 return (void *)INLINE_SYSCALL(mmap2
, 6, addr
, size
, prot
, flags
, fd
, shifted
);
224 #elif defined(__NR_mmap)
225 /* finally, fall back to mmap(), syscall1() style */
226 unsigned long buffer
[6];
227 buffer
[0] = (unsigned long) addr
;
228 buffer
[1] = (unsigned long) size
;
229 buffer
[2] = (unsigned long) prot
;
230 buffer
[3] = (unsigned long) flags
;
231 buffer
[4] = (unsigned long) fd
;
232 buffer
[5] = (unsigned long) offset
;
233 return (void *)INLINE_SYSCALL(mmap
, 1, buffer
);
235 # error "Your architecture doesn't seem to provide mmap() !?"
239 #endif /* _DL_SYSCALL_H */