Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/arm/kernel/sys_arm.c | |
3 | * | |
4 | * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c | |
5 | * Copyright (C) 1995, 1996 Russell King. | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * This file contains various random system calls that | |
12 | * have a non-standard calling sequence on the Linux/arm | |
13 | * platform. | |
14 | */ | |
15 | #include <linux/module.h> | |
16 | #include <linux/errno.h> | |
17 | #include <linux/sched.h> | |
18 | #include <linux/slab.h> | |
19 | #include <linux/mm.h> | |
20 | #include <linux/sem.h> | |
21 | #include <linux/msg.h> | |
22 | #include <linux/shm.h> | |
23 | #include <linux/stat.h> | |
24 | #include <linux/syscalls.h> | |
25 | #include <linux/mman.h> | |
26 | #include <linux/fs.h> | |
27 | #include <linux/file.h> | |
cba4fbbf | 28 | #include <linux/ipc.h> |
33fa9b13 | 29 | #include <linux/uaccess.h> |
1da177e4 | 30 | |
1da177e4 LT |
31 | struct mmap_arg_struct { |
32 | unsigned long addr; | |
33 | unsigned long len; | |
34 | unsigned long prot; | |
35 | unsigned long flags; | |
36 | unsigned long fd; | |
37 | unsigned long offset; | |
38 | }; | |
39 | ||
40 | asmlinkage int old_mmap(struct mmap_arg_struct __user *arg) | |
41 | { | |
42 | int error = -EFAULT; | |
43 | struct mmap_arg_struct a; | |
44 | ||
45 | if (copy_from_user(&a, arg, sizeof(a))) | |
46 | goto out; | |
47 | ||
48 | error = -EINVAL; | |
49 | if (a.offset & ~PAGE_MASK) | |
50 | goto out; | |
51 | ||
f8b72560 | 52 | error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); |
1da177e4 LT |
53 | out: |
54 | return error; | |
55 | } | |
56 | ||
dd35afc2 | 57 | #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT) |
1da177e4 LT |
58 | /* |
59 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | |
60 | * | |
61 | * This is really horribly ugly. | |
62 | */ | |
63 | asmlinkage int sys_ipc(uint call, int first, int second, int third, | |
64 | void __user *ptr, long fifth) | |
65 | { | |
66 | int version, ret; | |
67 | ||
68 | version = call >> 16; /* hack for backward compatibility */ | |
69 | call &= 0xffff; | |
70 | ||
71 | switch (call) { | |
72 | case SEMOP: | |
73 | return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL); | |
74 | case SEMTIMEDOP: | |
75 | return sys_semtimedop(first, (struct sembuf __user *)ptr, second, | |
76 | (const struct timespec __user *)fifth); | |
77 | ||
78 | case SEMGET: | |
79 | return sys_semget (first, second, third); | |
80 | case SEMCTL: { | |
81 | union semun fourth; | |
82 | if (!ptr) | |
83 | return -EINVAL; | |
84 | if (get_user(fourth.__pad, (void __user * __user *) ptr)) | |
85 | return -EFAULT; | |
86 | return sys_semctl (first, second, third, fourth); | |
87 | } | |
88 | ||
89 | case MSGSND: | |
90 | return sys_msgsnd(first, (struct msgbuf __user *) ptr, | |
91 | second, third); | |
92 | case MSGRCV: | |
93 | switch (version) { | |
94 | case 0: { | |
95 | struct ipc_kludge tmp; | |
96 | if (!ptr) | |
97 | return -EINVAL; | |
98 | if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr, | |
99 | sizeof (tmp))) | |
100 | return -EFAULT; | |
101 | return sys_msgrcv (first, tmp.msgp, second, | |
102 | tmp.msgtyp, third); | |
103 | } | |
104 | default: | |
105 | return sys_msgrcv (first, | |
106 | (struct msgbuf __user *) ptr, | |
107 | second, fifth, third); | |
108 | } | |
109 | case MSGGET: | |
110 | return sys_msgget ((key_t) first, second); | |
111 | case MSGCTL: | |
112 | return sys_msgctl(first, second, (struct msqid_ds __user *)ptr); | |
113 | ||
114 | case SHMAT: | |
115 | switch (version) { | |
116 | default: { | |
117 | ulong raddr; | |
118 | ret = do_shmat(first, (char __user *)ptr, second, &raddr); | |
119 | if (ret) | |
120 | return ret; | |
121 | return put_user(raddr, (ulong __user *)third); | |
122 | } | |
123 | case 1: /* Of course, we don't support iBCS2! */ | |
124 | return -EINVAL; | |
125 | } | |
126 | case SHMDT: | |
127 | return sys_shmdt ((char __user *)ptr); | |
128 | case SHMGET: | |
129 | return sys_shmget (first, second, third); | |
130 | case SHMCTL: | |
131 | return sys_shmctl (first, second, | |
132 | (struct shmid_ds __user *) ptr); | |
133 | default: | |
134 | return -ENOSYS; | |
135 | } | |
136 | } | |
dd35afc2 | 137 | #endif |
1da177e4 | 138 | |
1da177e4 LT |
139 | /* Fork a new task - this creates a new program thread. |
140 | * This is called indirectly via a small wrapper | |
141 | */ | |
142 | asmlinkage int sys_fork(struct pt_regs *regs) | |
143 | { | |
f24284ad | 144 | #ifdef CONFIG_MMU |
1da177e4 | 145 | return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL); |
f24284ad HC |
146 | #else |
147 | /* can not support in nommu mode */ | |
148 | return(-EINVAL); | |
149 | #endif | |
1da177e4 LT |
150 | } |
151 | ||
152 | /* Clone a task - this clones the calling program thread. | |
153 | * This is called indirectly via a small wrapper | |
154 | */ | |
155 | asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, | |
156 | int __user *parent_tidptr, int tls_val, | |
157 | int __user *child_tidptr, struct pt_regs *regs) | |
158 | { | |
159 | if (!newsp) | |
160 | newsp = regs->ARM_sp; | |
161 | ||
162 | return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr); | |
163 | } | |
164 | ||
165 | asmlinkage int sys_vfork(struct pt_regs *regs) | |
166 | { | |
167 | return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL); | |
168 | } | |
169 | ||
170 | /* sys_execve() executes a new program. | |
171 | * This is called indirectly via a small wrapper | |
172 | */ | |
173 | asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv, | |
174 | char __user * __user *envp, struct pt_regs *regs) | |
175 | { | |
176 | int error; | |
177 | char * filename; | |
178 | ||
179 | filename = getname(filenamei); | |
180 | error = PTR_ERR(filename); | |
181 | if (IS_ERR(filename)) | |
182 | goto out; | |
183 | error = do_execve(filename, argv, envp, regs); | |
184 | putname(filename); | |
185 | out: | |
186 | return error; | |
187 | } | |
188 | ||
3db03b4a | 189 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) |
1da177e4 LT |
190 | { |
191 | struct pt_regs regs; | |
192 | int ret; | |
193 | ||
194 | memset(®s, 0, sizeof(struct pt_regs)); | |
195 | ret = do_execve((char *)filename, (char __user * __user *)argv, | |
196 | (char __user * __user *)envp, ®s); | |
197 | if (ret < 0) | |
198 | goto out; | |
199 | ||
200 | /* | |
201 | * Save argc to the register structure for userspace. | |
202 | */ | |
203 | regs.ARM_r0 = ret; | |
204 | ||
205 | /* | |
206 | * We were successful. We won't be returning to our caller, but | |
207 | * instead to user space by manipulating the kernel stack. | |
208 | */ | |
209 | asm( "add r0, %0, %1\n\t" | |
210 | "mov r1, %2\n\t" | |
211 | "mov r2, %3\n\t" | |
212 | "bl memmove\n\t" /* copy regs to top of stack */ | |
213 | "mov r8, #0\n\t" /* not a syscall */ | |
214 | "mov r9, %0\n\t" /* thread structure */ | |
215 | "mov sp, r0\n\t" /* reposition stack pointer */ | |
216 | "b ret_to_user" | |
217 | : | |
218 | : "r" (current_thread_info()), | |
4f7a1812 | 219 | "Ir" (THREAD_START_SP - sizeof(regs)), |
1da177e4 LT |
220 | "r" (®s), |
221 | "Ir" (sizeof(regs)) | |
c2f48086 | 222 | : "r0", "r1", "r2", "r3", "ip", "lr", "memory"); |
1da177e4 LT |
223 | |
224 | out: | |
225 | return ret; | |
226 | } | |
3db03b4a | 227 | EXPORT_SYMBOL(kernel_execve); |
68d9102f NP |
228 | |
229 | /* | |
6cbdc8c5 | 230 | * Since loff_t is a 64 bit type we avoid a lot of ABI hassle |
68d9102f NP |
231 | * with a different argument ordering. |
232 | */ | |
233 | asmlinkage long sys_arm_fadvise64_64(int fd, int advice, | |
234 | loff_t offset, loff_t len) | |
235 | { | |
236 | return sys_fadvise64_64(fd, offset, len, advice); | |
237 | } |