time.h: Add CLOCK_TAI
[uclibc-ng.git] / ldso / include / dl-syscall.h
blob9d80c6a26c54c26a518e630c03e65a3da5ee9681
1 /*
2 * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
4 * GNU Lesser General Public License version 2.1 or later.
5 */
7 #ifndef _DL_SYSCALL_H
8 #define _DL_SYSCALL_H
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"
13 extern int _dl_errno;
14 #undef __set_errno
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 */
20 #define _SYS_MMAN_H 1
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. */
35 #else
36 /* 1. common-generic ABI doesn't need kernel_stat translation
37 * 3. S_IS?ID already provided by stat.h
39 #include <sys/stat.h>
40 #endif
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*/
55 #else
56 while (1);
57 #endif
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)
74 #endif
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,
94 struct stat *buf)
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,
104 struct stat *buf)
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,
111 struct stat *, buf)
112 #endif
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
118 #endif
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)
124 #ifdef __NR_getxuid
125 # define __NR_getuid __NR_getxuid
126 #endif
127 #define __NR__dl_getuid __NR_getuid
128 static __always_inline _syscall0(uid_t, _dl_getuid)
130 #ifndef __NR_geteuid
131 # define __NR_geteuid __NR_getuid
132 #endif
133 #define __NR__dl_geteuid __NR_geteuid
134 static __always_inline _syscall0(uid_t, _dl_geteuid)
136 #ifdef __NR_getxgid
137 # define __NR_getgid __NR_getxgid
138 #endif
139 #define __NR__dl_getgid __NR_getgid
140 static __always_inline _syscall0(gid_t, _dl_getgid)
142 #ifndef __NR_getegid
143 # define __NR_getegid __NR_getgid
144 #endif
145 #define __NR__dl_getegid __NR_getegid
146 static __always_inline _syscall0(gid_t, _dl_getegid)
148 #ifdef __NR_getxpid
149 # define __NR_getpid __NR_getxpid
150 #endif
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)
158 #endif
160 #ifdef __NR_pread64
161 #define __NR___syscall_pread __NR_pread64
162 #ifdef __UCLIBC_SYSCALL_ALIGN_64BIT__
163 static __always_inline _syscall6(ssize_t, __syscall_pread, int, fd, void *, buf, size_t, dummy,
164 size_t, count, off_t, offset_hi, off_t, offset_lo)
166 static __always_inline ssize_t
167 _dl_pread(int fd, void *buf, size_t count, off_t offset)
169 return __syscall_pread(fd, buf, count, 0, __LONG_LONG_PAIR((offset >> 32), (offset & 0xffffffff)));
171 #else
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));
180 #endif
181 #elif defined __NR_pread
182 #define __NR___syscall_pread __NR_pread
183 static __always_inline _syscall5(ssize_t, __syscall_pread, int, fd, void *, buf,
184 size_t, count, off_t, offset_hi, off_t, offset_lo)
186 static __always_inline ssize_t
187 _dl_pread(int fd, void *buf, size_t count, off_t offset)
189 return __syscall_pread(fd, buf, count, __LONG_LONG_PAIR(offset >> 31, offset));
191 #endif
193 #ifdef __UCLIBC_HAS_SSP__
194 # include <sys/time.h>
195 # define __NR__dl_gettimeofday __NR_gettimeofday
196 static __always_inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
197 # ifdef __USE_BSD
198 struct timezone *
199 # else
200 void *
201 # endif
202 , tz)
203 #endif
205 /* Some architectures always use 12 as page shift for mmap2() eventhough the
206 * real PAGE_SHIFT != 12. Other architectures use the same value as
207 * PAGE_SHIFT...
209 #ifndef MMAP2_PAGE_SHIFT
210 # define MMAP2_PAGE_SHIFT 12
211 #endif
213 #define MAP_FAILED ((void *) -1)
214 #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
216 static __always_inline
217 void *_dl_mmap(void *addr, unsigned long size, int prot,
218 int flags, int fd, unsigned long offset)
220 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
221 /* first try mmap(), syscall6() style */
222 return (void *)INLINE_SYSCALL(mmap, 6, addr, size, prot, flags, fd, offset);
224 #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
225 /* then try mmap2() */
226 unsigned long shifted;
228 if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
229 return MAP_FAILED;
231 /* gcc needs help with putting things onto the stack */
232 shifted = offset >> MMAP2_PAGE_SHIFT;
233 return (void *)INLINE_SYSCALL(mmap2, 6, addr, size, prot, flags, fd, shifted);
235 #elif defined(__NR_mmap)
236 /* finally, fall back to mmap(), syscall1() style */
237 unsigned long buffer[6];
238 buffer[0] = (unsigned long) addr;
239 buffer[1] = (unsigned long) size;
240 buffer[2] = (unsigned long) prot;
241 buffer[3] = (unsigned long) flags;
242 buffer[4] = (unsigned long) fd;
243 buffer[5] = (unsigned long) offset;
244 return (void *)INLINE_SYSCALL(mmap, 1, buffer);
245 #else
246 # error "Your architecture doesn't seem to provide mmap() !?"
247 #endif
250 #endif /* _DL_SYSCALL_H */