]> 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 _LD_SYSCALL_H_
9 #define _LD_SYSCALL_H_
10
11 /* Pull in the arch specific syscall implementation */
12 #include <dl-syscalls.h>
13 #ifdef NOT_FOR_L4
14 /*  For MAP_ANONYMOUS -- differs between platforms */
15 #define _SYS_MMAN_H 1
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
22 #else
23 #define kernel_stat stat
24 #endif
25 #include <bits/kernel_stat.h>
26 #include <bits/kernel_types.h>
27
28 /* Protection bits.  */
29 #define S_ISUID         04000   /* Set user ID on execution.  */
30 #define S_ISGID         02000   /* Set group ID on execution.  */
31
32
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)
41
42 #define __NR__dl_close __NR_close
43 static __always_inline _syscall1(int, _dl_close, int, fd)
44
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)
48
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)
52
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)
56
57 #define __NR__dl_mprotect __NR_mprotect
58 static __always_inline _syscall3(int, _dl_mprotect, const void *, addr,
59                         unsigned long, len, int, prot)
60
61 #define __NR__dl_stat __NR_stat
62 static __always_inline _syscall2(int, _dl_stat, const char *, file_name,
63                         struct stat *, buf)
64
65 #define __NR__dl_fstat __NR_fstat
66 static __always_inline _syscall2(int, _dl_fstat, int, fd, struct stat *, buf)
67
68 #define __NR__dl_munmap __NR_munmap
69 static __always_inline _syscall2(int, _dl_munmap, void *, start, unsigned long, length)
70
71 #ifdef __NR_getxuid
72 # define __NR_getuid __NR_getxuid
73 #endif
74 #define __NR__dl_getuid __NR_getuid
75 static __always_inline _syscall0(uid_t, _dl_getuid)
76
77 #ifndef __NR_geteuid
78 # define __NR_geteuid __NR_getuid
79 #endif
80 #define __NR__dl_geteuid __NR_geteuid
81 static __always_inline _syscall0(uid_t, _dl_geteuid)
82
83 #ifdef __NR_getxgid
84 # define __NR_getgid __NR_getxgid
85 #endif
86 #define __NR__dl_getgid __NR_getgid
87 static __always_inline _syscall0(gid_t, _dl_getgid)
88
89 #ifndef __NR_getegid
90 # define __NR_getegid __NR_getgid
91 #endif
92 #define __NR__dl_getegid __NR_getegid
93 static __always_inline _syscall0(gid_t, _dl_getegid)
94
95 #ifdef __NR_getxpid
96 # define __NR_getpid __NR_getxpid
97 #endif
98 #define __NR__dl_getpid __NR_getpid
99 static __always_inline _syscall0(gid_t, _dl_getpid)
100
101 #define __NR__dl_readlink __NR_readlink
102 static __always_inline _syscall3(int, _dl_readlink, const char *, path, char *, buf,
103                         size_t, bufsiz)
104
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,
109 # ifdef __USE_BSD
110                         struct timezone *
111 # else
112                         void *
113 # endif
114                                                 , tz)
115 #endif
116
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
119  * PAGE_SHIFT...
120  */
121 #ifndef MMAP2_PAGE_SHIFT
122 # define MMAP2_PAGE_SHIFT 12
123 #endif
124
125 #define MAP_FAILED ((void *) -1)
126 #define _dl_mmap_check_error(X) (((void *)X) == MAP_FAILED)
127
128 static __always_inline
129 void *_dl_mmap(void *addr, unsigned long size, int prot,
130                int flags, int fd, unsigned long offset)
131 {
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);
135
136 #elif defined(__NR_mmap2) && !defined (__mcoldfire__)
137         /* then try mmap2() */
138         unsigned long shifted;
139
140         if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
141                 return MAP_FAILED;
142
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);
146
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);
157 #else
158 # error "Your architecture doesn't seem to provide mmap() !?"
159 #endif
160 }
161
162 #endif /* not for L4 */
163 #endif /* _LD_SYSCALL_H_ */