Blame view
arch/mips/kernel/syscall.c
7.79 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 |
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 1995, 1996, 1997, 2000, 2001, 05 by Ralf Baechle * Copyright (C) 1999, 2000 Silicon Graphics, Inc. * Copyright (C) 2001 MIPS Technologies, Inc. */ |
a94156445 [PATCH] capable/c... |
10 |
#include <linux/capability.h> |
1da177e4c Linux-2.6.12-rc2 |
11 12 |
#include <linux/errno.h> #include <linux/linkage.h> |
4e950f6f0 Remove fs.h from ... |
13 |
#include <linux/fs.h> |
1da177e4c Linux-2.6.12-rc2 |
14 |
#include <linux/smp.h> |
1da177e4c Linux-2.6.12-rc2 |
15 |
#include <linux/ptrace.h> |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 |
#include <linux/string.h> #include <linux/syscalls.h> #include <linux/file.h> |
1da177e4c Linux-2.6.12-rc2 |
19 20 21 22 23 24 |
#include <linux/utsname.h> #include <linux/unistd.h> #include <linux/sem.h> #include <linux/msg.h> #include <linux/shm.h> #include <linux/compiler.h> |
cba4fbbff remove include/as... |
25 |
#include <linux/ipc.h> |
f1e39a4a6 MIPS: Rewrite sys... |
26 |
#include <linux/uaccess.h> |
5a0e3ad6a include cleanup: ... |
27 |
#include <linux/slab.h> |
652b14aa8 MIPS: Enable heap... |
28 |
#include <linux/elf.h> |
1da177e4c Linux-2.6.12-rc2 |
29 |
|
f1e39a4a6 MIPS: Rewrite sys... |
30 |
#include <asm/asm.h> |
1da177e4c Linux-2.6.12-rc2 |
31 32 33 |
#include <asm/branch.h> #include <asm/cachectl.h> #include <asm/cacheflush.h> |
048eb582f kbuild: mips use ... |
34 |
#include <asm/asm-offsets.h> |
1da177e4c Linux-2.6.12-rc2 |
35 36 37 38 39 |
#include <asm/signal.h> #include <asm/sim.h> #include <asm/shmparam.h> #include <asm/sysmips.h> #include <asm/uaccess.h> |
8213bbf9c [MIPS] Rename MIP... |
40 41 42 43 44 45 46 47 |
/* * For historic reasons the pipe(2) syscall on MIPS has an unusual calling * convention. It returns results in registers $v0 / $v1 which means there * is no need for it to do verify the validity of a userspace pointer * argument. Historically that used to be expensive in Linux. These days * the performance advantage is negligible. */ asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs) |
1da177e4c Linux-2.6.12-rc2 |
48 49 50 |
{ int fd[2]; int error, res; |
ed8cae8ba flag parameters: ... |
51 |
error = do_pipe_flags(fd, 0); |
1da177e4c Linux-2.6.12-rc2 |
52 53 54 55 56 57 58 59 60 |
if (error) { res = error; goto out; } regs.regs[3] = fd[1]; res = fd[0]; out: return res; } |
dbda6ac08 MIPS: CVE-2009-00... |
61 62 63 |
SYSCALL_DEFINE6(mips_mmap, unsigned long, addr, unsigned long, len, unsigned long, prot, unsigned long, flags, unsigned long, fd, off_t, offset) |
1da177e4c Linux-2.6.12-rc2 |
64 65 66 67 68 69 |
{ unsigned long result; result = -EINVAL; if (offset & ~PAGE_MASK) goto out; |
f8b725609 Unify sys_mmap* |
70 |
result = sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
1da177e4c Linux-2.6.12-rc2 |
71 72 73 74 |
out: return result; } |
dbda6ac08 MIPS: CVE-2009-00... |
75 76 77 |
SYSCALL_DEFINE6(mips_mmap2, unsigned long, addr, unsigned long, len, unsigned long, prot, unsigned long, flags, unsigned long, fd, unsigned long, pgoff) |
1da177e4c Linux-2.6.12-rc2 |
78 |
{ |
947df17cb [MIPS] sys_mmap2 ... |
79 80 |
if (pgoff & (~PAGE_MASK >> 12)) return -EINVAL; |
f8b725609 Unify sys_mmap* |
81 |
return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12)); |
1da177e4c Linux-2.6.12-rc2 |
82 83 84 |
} save_static_function(sys_fork); |
f5dbeaf5e [MIPS] Replace __... |
85 |
static int __used noinline |
1da177e4c Linux-2.6.12-rc2 |
86 87 88 89 90 91 |
_sys_fork(nabi_no_regargs struct pt_regs regs) { return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL); } save_static_function(sys_clone); |
f5dbeaf5e [MIPS] Replace __... |
92 |
static int __used noinline |
1da177e4c Linux-2.6.12-rc2 |
93 94 95 96 |
_sys_clone(nabi_no_regargs struct pt_regs regs) { unsigned long clone_flags; unsigned long newsp; |
3c37026d4 NPTL, round one. |
97 |
int __user *parent_tidptr, *child_tidptr; |
1da177e4c Linux-2.6.12-rc2 |
98 99 100 101 102 |
clone_flags = regs.regs[4]; newsp = regs.regs[5]; if (!newsp) newsp = regs.regs[29]; |
3c37026d4 NPTL, round one. |
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
parent_tidptr = (int __user *) regs.regs[6]; #ifdef CONFIG_32BIT /* We need to fetch the fifth argument off the stack. */ child_tidptr = NULL; if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) { int __user *__user *usp = (int __user *__user *) regs.regs[29]; if (regs.regs[2] == __NR_syscall) { if (get_user (child_tidptr, &usp[5])) return -EFAULT; } else if (get_user (child_tidptr, &usp[4])) return -EFAULT; } #else child_tidptr = (int __user *) regs.regs[8]; #endif |
1da177e4c Linux-2.6.12-rc2 |
119 120 121 122 123 124 125 126 127 128 129 |
return do_fork(clone_flags, newsp, ®s, 0, parent_tidptr, child_tidptr); } /* * sys_execve() executes a new program. */ asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs) { int error; char * filename; |
c78873252 Mark arguments to... |
130 |
filename = getname((const char __user *) (long)regs.regs[4]); |
1da177e4c Linux-2.6.12-rc2 |
131 132 133 |
error = PTR_ERR(filename); if (IS_ERR(filename)) goto out; |
d7627467b Make do_execve() ... |
134 135 136 137 |
error = do_execve(filename, (const char __user *const __user *) (long)regs.regs[5], (const char __user *const __user *) (long)regs.regs[6], ®s); |
1da177e4c Linux-2.6.12-rc2 |
138 139 140 141 142 |
putname(filename); out: return error; } |
dbda6ac08 MIPS: CVE-2009-00... |
143 |
SYSCALL_DEFINE1(set_thread_area, unsigned long, addr) |
3c37026d4 NPTL, round one. |
144 |
{ |
dc8f6029c [PATCH] mips: tas... |
145 |
struct thread_info *ti = task_thread_info(current); |
3c37026d4 NPTL, round one. |
146 147 |
ti->tp_value = addr; |
a36920200 [MIPS] Enable sup... |
148 149 |
if (cpu_has_userlocal) write_c0_userlocal(addr); |
06be375b9 [MIPS] TLS: set_t... |
150 151 |
return 0; |
3c37026d4 NPTL, round one. |
152 |
} |
f1e39a4a6 MIPS: Rewrite sys... |
153 154 |
static inline int mips_atomic_set(struct pt_regs *regs, unsigned long addr, unsigned long new) |
1da177e4c Linux-2.6.12-rc2 |
155 |
{ |
f1e39a4a6 MIPS: Rewrite sys... |
156 157 158 159 160 161 162 163 164 165 166 |
unsigned long old, tmp; unsigned int err; if (unlikely(addr & 3)) return -EINVAL; if (unlikely(!access_ok(VERIFY_WRITE, addr, 4))) return -EINVAL; if (cpu_has_llsc && R10000_LLSC_WAR) { __asm__ __volatile__ ( |
a91be9ee6 MIPS: Fix MIPS I ... |
167 168 |
" .set mips3 " |
f1e39a4a6 MIPS: Rewrite sys... |
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
" li %[err], 0 " "1: ll %[old], (%[addr]) " " move %[tmp], %[new] " "2: sc %[tmp], (%[addr]) " " beqzl %[tmp], 1b " "3: " " .section .fixup,\"ax\" " "4: li %[err], %[efault] " " j 3b " " .previous " " .section __ex_table,\"a\" " " "STR(PTR)" 1b, 4b " " "STR(PTR)" 2b, 4b " " .previous " |
a91be9ee6 MIPS: Fix MIPS I ... |
197 198 |
" .set mips0 " |
f1e39a4a6 MIPS: Rewrite sys... |
199 200 201 202 203 204 205 206 207 |
: [old] "=&r" (old), [err] "=&r" (err), [tmp] "=&r" (tmp) : [addr] "r" (addr), [new] "r" (new), [efault] "i" (-EFAULT) : "memory"); } else if (cpu_has_llsc) { __asm__ __volatile__ ( |
a91be9ee6 MIPS: Fix MIPS I ... |
208 209 |
" .set mips3 " |
f1e39a4a6 MIPS: Rewrite sys... |
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
" li %[err], 0 " "1: ll %[old], (%[addr]) " " move %[tmp], %[new] " "2: sc %[tmp], (%[addr]) " " bnez %[tmp], 4f " "3: " " .subsection 2 " "4: b 1b " " .previous " " " " .section .fixup,\"ax\" " "5: li %[err], %[efault] " " j 3b " " .previous " " .section __ex_table,\"a\" " " "STR(PTR)" 1b, 5b " " "STR(PTR)" 2b, 5b " " .previous " |
a91be9ee6 MIPS: Fix MIPS I ... |
246 247 |
" .set mips0 " |
f1e39a4a6 MIPS: Rewrite sys... |
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
: [old] "=&r" (old), [err] "=&r" (err), [tmp] "=&r" (tmp) : [addr] "r" (addr), [new] "r" (new), [efault] "i" (-EFAULT) : "memory"); } else { do { preempt_disable(); ll_bit = 1; ll_task = current; preempt_enable(); err = __get_user(old, (unsigned int *) addr); err |= __put_user(new, (unsigned int *) addr); if (err) break; rmb(); } while (!ll_bit); } if (unlikely(err)) return err; regs->regs[2] = old; regs->regs[7] = 0; /* No error */ /* * Don't let your children do this ... */ __asm__ __volatile__( " move $29, %0 " " j syscall_exit " : /* no outputs */ : "r" (regs)); /* unreached. Honestly. */ while (1); } save_static_function(sys_sysmips); static int __used noinline _sys_sysmips(nabi_no_regargs struct pt_regs regs) { |
7a6e4ca1e MIPS: Remove unus... |
295 |
long cmd, arg1, arg2; |
f1e39a4a6 MIPS: Rewrite sys... |
296 297 298 299 |
cmd = regs.regs[4]; arg1 = regs.regs[5]; arg2 = regs.regs[6]; |
f1e39a4a6 MIPS: Rewrite sys... |
300 |
|
293c5bd13 [MIPS] Fixup secu... |
301 |
switch (cmd) { |
1da177e4c Linux-2.6.12-rc2 |
302 |
case MIPS_ATOMIC_SET: |
f1e39a4a6 MIPS: Rewrite sys... |
303 |
return mips_atomic_set(®s, arg1, arg2); |
1da177e4c Linux-2.6.12-rc2 |
304 305 |
case MIPS_FIXADE: |
293c5bd13 [MIPS] Fixup secu... |
306 307 308 309 310 311 312 313 314 315 |
if (arg1 & ~3) return -EINVAL; if (arg1 & 1) set_thread_flag(TIF_FIXADE); else clear_thread_flag(TIF_FIXADE); if (arg1 & 2) set_thread_flag(TIF_LOGADE); else |
e56293b12 MIPS: Clear the c... |
316 |
clear_thread_flag(TIF_LOGADE); |
293c5bd13 [MIPS] Fixup secu... |
317 |
|
1da177e4c Linux-2.6.12-rc2 |
318 319 320 321 322 |
return 0; case FLUSH_CACHE: __flush_cache_all(); return 0; |
1da177e4c Linux-2.6.12-rc2 |
323 324 325 326 327 328 |
} return -EINVAL; } /* |
1da177e4c Linux-2.6.12-rc2 |
329 330 |
* No implemented yet ... */ |
dbda6ac08 MIPS: CVE-2009-00... |
331 |
SYSCALL_DEFINE3(cachectl, char *, addr, int, nbytes, int, op) |
1da177e4c Linux-2.6.12-rc2 |
332 333 334 335 336 337 338 339 340 341 342 343 |
{ return -ENOSYS; } /* * If we ever come here the user sp is bad. Zap the process right away. * Due to the bad stack signaling wouldn't work. */ asmlinkage void bad_stack(void) { do_exit(SIGSEGV); } |
fe74290d5 [PATCH] provide k... |
344 345 346 347 348 |
/* * Do a system call from kernel instead of calling sys_execve so we * end up with proper pt_regs. */ |
d7627467b Make do_execve() ... |
349 350 351 |
int kernel_execve(const char *filename, const char *const argv[], const char *const envp[]) |
fe74290d5 [PATCH] provide k... |
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
{ register unsigned long __a0 asm("$4") = (unsigned long) filename; register unsigned long __a1 asm("$5") = (unsigned long) argv; register unsigned long __a2 asm("$6") = (unsigned long) envp; register unsigned long __a3 asm("$7"); unsigned long __v0; __asm__ volatile (" " " .set noreorder " " li $2, %5 # __NR_execve " " syscall " " move %0, $2 " " .set reorder " : "=&r" (__v0), "=r" (__a3) : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve) : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", "memory"); if (__a3 == 0) return __v0; return -__v0; } |