1 /* vi: set sw=4 ts=4: */
3 * Copyright (C) 2000-2005 by Erik Andersen <andersen@codepoet.org>
5 * GNU Lesser General Public License version 2.1 or later.
11 /* Pull in the arch specific syscall implementation */
12 #include <dl-syscalls.h>
14 /* For MAP_ANONYMOUS -- differs between platforms */
16 #include <bits/mman.h>
17 /* Pull in whatever this particular arch's kernel thinks the kernel version of
18 * struct stat should look like. It turns out that each arch has a different
19 * opinion on the subject, and different kernel revs use different names... */
20 #if defined(__sparc_v9__) && (__WORDSIZE == 64)
21 #define kernel_stat64 stat
23 #define kernel_stat stat
25 #include <bits/kernel_stat.h>
26 #include <bits/kernel_types.h>
28 /* Protection bits. */
29 #define S_ISUID 04000 /* Set user ID on execution. */
30 #define S_ISGID 02000 /* Set group ID on execution. */
33 /* Here are the definitions for some syscalls that are used
34 by the dynamic linker. The idea is that we want to be able
35 to call these before the errno symbol is dynamicly linked, so
36 we use our own version here. Note that we cannot assume any
37 dynamic linking at all, so we cannot return any error codes.
38 We just punt if there is an error. */
39 #define __NR__dl_exit __NR_exit
40 static __always_inline _syscall1(void, _dl_exit, int, status)
42 #define __NR__dl_close __NR_close
43 static __always_inline _syscall1(int, _dl_close, int, fd)
45 #define __NR__dl_open __NR_open
46 static __always_inline _syscall3(int, _dl_open, const char *, fn, int, flags,
47 __kernel_mode_t, mode)
49 #define __NR__dl_write __NR_write
50 static __always_inline _syscall3(unsigned long, _dl_write, int, fd,
51 const void *, buf, unsigned long, count)
53 #define __NR__dl_read __NR_read
54 static __always_inline _syscall3(unsigned long, _dl_read, int, fd,
55 const void *, buf, unsigned long, count)
57 #define __NR__dl_mprotect __NR_mprotect
58 static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
59 unsigned long, len, int, prot)
61 #define __NR__dl_stat __NR_stat
62 static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
65 #define __NR__dl_fstat __NR_fstat
66 static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf)
68 #define __NR__dl_munmap __NR_munmap
69 static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length)
72 # define __NR_getuid __NR_getxuid
74 #define __NR__dl_getuid __NR_getuid
75 static __always_inline _syscall0(uid_t, _dl_getuid)
78 # define __NR_geteuid __NR_getuid
80 #define __NR__dl_geteuid __NR_geteuid
81 static __always_inline _syscall0(uid_t, _dl_geteuid)
84 # define __NR_getgid __NR_getxgid
86 #define __NR__dl_getgid __NR_getgid
87 static __always_inline _syscall0(gid_t, _dl_getgid)
90 # define __NR_getegid __NR_getgid
92 #define __NR__dl_getegid __NR_getegid
93 static __always_inline _syscall0(gid_t, _dl_getegid)
96 # define __NR_getpid __NR_getxpid
98 #define __NR__dl_getpid __NR_getpid
99 static __always_inline _syscall0(gid_t, _dl_getpid)
101 #define __NR__dl_readlink __NR_readlink
102 static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
105 #ifdef __UCLIBC_HAS_SSP__
106 # include <sys/time.h>
107 # define __NR__dl_gettimeofday __NR_gettimeofday
108 static __always_inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
117 /* Some architectures always use 12 as page shift for mmap2() eventhough the
118 * real PAGE_SHIFT != 12. Other architectures use the same value as
121 #ifndef MMAP2_PAGE_SHIFT
122 # define MMAP2_PAGE_SHIFT 12
125 #define MAP_FAILED ((void *) -1)
126 #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
128 static __always_inline
129 void *_dl_mmap(void *addr, unsigned long size, int prot,
130 int flags, int fd, unsigned long offset)
132 #if defined(__UCLIBC_MMAP_HAS_6_ARGS__) && defined(__NR_mmap)
133 /* first try mmap(), syscall6() style */
134 return (void *)INLINE_SYSCALL(mmap, 6, addr, size, prot, flags, fd, offset);
136 #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
137 /* then try mmap2() */
138 unsigned long shifted;
140 if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
143 /* gcc needs help with putting things onto the stack */
144 shifted = offset >> MMAP2_PAGE_SHIFT;
145 return (void *)INLINE_SYSCALL(mmap2, 6, addr, size, prot, flags, fd, shifted);
147 #elif defined(__NR_mmap)
148 /* finally, fall back to mmap(), syscall1() style */
149 unsigned long buffer[6];
150 buffer[0] = (unsigned long) addr;
151 buffer[1] = (unsigned long) size;
152 buffer[2] = (unsigned long) prot;
153 buffer[3] = (unsigned long) flags;
154 buffer[4] = (unsigned long) fd;
155 buffer[5] = (unsigned long) offset;
156 return (void *)INLINE_SYSCALL(mmap, 1, buffer);
158 # error "Your architecture doesn't seem to provide mmap() !?"
162 #endif /* not for L4 */
163 #endif /* _LD_SYSCALL_H_ */