2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1995, 1996, 1997, 2000, 2001, 05 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
10 #include <linux/a.out.h>
11 #include <linux/capability.h>
12 #include <linux/errno.h>
13 #include <linux/linkage.h>
15 #include <linux/smp.h>
16 #include <linux/mman.h>
17 #include <linux/ptrace.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/syscalls.h>
21 #include <linux/file.h>
22 #include <linux/slab.h>
23 #include <linux/utsname.h>
24 #include <linux/unistd.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/shm.h>
28 #include <linux/compiler.h>
29 #include <linux/module.h>
31 #include <asm/branch.h>
32 #include <asm/cachectl.h>
33 #include <asm/cacheflush.h>
35 #include <asm/asm-offsets.h>
36 #include <asm/signal.h>
38 #include <asm/shmparam.h>
39 #include <asm/sysmips.h>
40 #include <asm/uaccess.h>
42 asmlinkage
int sys_pipe(nabi_no_regargs
volatile struct pt_regs regs
)
58 unsigned long shm_align_mask
= PAGE_SIZE
- 1; /* Sane caches */
60 EXPORT_SYMBOL(shm_align_mask
);
62 #define COLOUR_ALIGN(addr,pgoff) \
63 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
64 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
66 unsigned long arch_get_unmapped_area(struct file
*filp
, unsigned long addr
,
67 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
69 struct vm_area_struct
* vmm
;
71 unsigned long task_size
;
73 task_size
= STACK_TOP
;
75 if (flags
& MAP_FIXED
) {
77 * We do not accept a shared mapping if it would violate
78 * cache aliasing constraints.
80 if ((flags
& MAP_SHARED
) && (addr
& shm_align_mask
))
88 if (filp
|| (flags
& MAP_SHARED
))
92 addr
= COLOUR_ALIGN(addr
, pgoff
);
94 addr
= PAGE_ALIGN(addr
);
95 vmm
= find_vma(current
->mm
, addr
);
96 if (task_size
- len
>= addr
&&
97 (!vmm
|| addr
+ len
<= vmm
->vm_start
))
100 addr
= TASK_UNMAPPED_BASE
;
102 addr
= COLOUR_ALIGN(addr
, pgoff
);
104 addr
= PAGE_ALIGN(addr
);
106 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
107 /* At this point: (!vmm || addr < vmm->vm_end). */
108 if (task_size
- len
< addr
)
110 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
114 addr
= COLOUR_ALIGN(addr
, pgoff
);
118 /* common code for old and new mmaps */
119 static inline unsigned long
120 do_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
121 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
123 unsigned long error
= -EBADF
;
124 struct file
* file
= NULL
;
126 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
127 if (!(flags
& MAP_ANONYMOUS
)) {
133 down_write(¤t
->mm
->mmap_sem
);
134 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
135 up_write(¤t
->mm
->mmap_sem
);
143 asmlinkage
unsigned long
144 old_mmap(unsigned long addr
, unsigned long len
, int prot
,
145 int flags
, int fd
, off_t offset
)
147 unsigned long result
;
150 if (offset
& ~PAGE_MASK
)
153 result
= do_mmap2(addr
, len
, prot
, flags
, fd
, offset
>> PAGE_SHIFT
);
159 asmlinkage
unsigned long
160 sys_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
161 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
163 if (pgoff
& (~PAGE_MASK
>> 12))
166 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
>> (PAGE_SHIFT
-12));
169 save_static_function(sys_fork
);
170 __attribute_used__ noinline
static int
171 _sys_fork(nabi_no_regargs
struct pt_regs regs
)
173 return do_fork(SIGCHLD
, regs
.regs
[29], ®s
, 0, NULL
, NULL
);
176 save_static_function(sys_clone
);
177 __attribute_used__ noinline
static int
178 _sys_clone(nabi_no_regargs
struct pt_regs regs
)
180 unsigned long clone_flags
;
182 int __user
*parent_tidptr
, *child_tidptr
;
184 clone_flags
= regs
.regs
[4];
185 newsp
= regs
.regs
[5];
187 newsp
= regs
.regs
[29];
188 parent_tidptr
= (int __user
*) regs
.regs
[6];
190 /* We need to fetch the fifth argument off the stack. */
192 if (clone_flags
& (CLONE_CHILD_SETTID
| CLONE_CHILD_CLEARTID
)) {
193 int __user
*__user
*usp
= (int __user
*__user
*) regs
.regs
[29];
194 if (regs
.regs
[2] == __NR_syscall
) {
195 if (get_user (child_tidptr
, &usp
[5]))
198 else if (get_user (child_tidptr
, &usp
[4]))
202 child_tidptr
= (int __user
*) regs
.regs
[8];
204 return do_fork(clone_flags
, newsp
, ®s
, 0,
205 parent_tidptr
, child_tidptr
);
209 * sys_execve() executes a new program.
211 asmlinkage
int sys_execve(nabi_no_regargs
struct pt_regs regs
)
216 filename
= getname((char __user
*) (long)regs
.regs
[4]);
217 error
= PTR_ERR(filename
);
218 if (IS_ERR(filename
))
220 error
= do_execve(filename
, (char __user
*__user
*) (long)regs
.regs
[5],
221 (char __user
*__user
*) (long)regs
.regs
[6], ®s
);
229 * Compacrapability ...
231 asmlinkage
int sys_uname(struct old_utsname __user
* name
)
233 if (name
&& !copy_to_user(name
, utsname(), sizeof (*name
)))
239 * Compacrapability ...
241 asmlinkage
int sys_olduname(struct oldold_utsname __user
* name
)
247 if (!access_ok(VERIFY_WRITE
,name
,sizeof(struct oldold_utsname
)))
250 error
= __copy_to_user(&name
->sysname
, &utsname()->sysname
,
252 error
-= __put_user(0, name
->sysname
+ __OLD_UTS_LEN
);
253 error
-= __copy_to_user(&name
->nodename
, &utsname()->nodename
,
255 error
-= __put_user(0, name
->nodename
+ __OLD_UTS_LEN
);
256 error
-= __copy_to_user(&name
->release
, &utsname()->release
,
258 error
-= __put_user(0, name
->release
+ __OLD_UTS_LEN
);
259 error
-= __copy_to_user(&name
->version
, &utsname()->version
,
261 error
-= __put_user(0, name
->version
+ __OLD_UTS_LEN
);
262 error
-= __copy_to_user(&name
->machine
, &utsname()->machine
,
264 error
= __put_user(0, name
->machine
+ __OLD_UTS_LEN
);
265 error
= error
? -EFAULT
: 0;
270 asmlinkage
int sys_set_thread_area(unsigned long addr
)
272 struct thread_info
*ti
= task_thread_info(current
);
276 /* If some future MIPS implementation has this register in hardware,
277 * we will need to update it here (and in context switches). */
282 asmlinkage
int _sys_sysmips(int cmd
, long arg1
, int arg2
, int arg3
)
287 case MIPS_ATOMIC_SET
:
288 printk(KERN_CRIT
"How did I get here?\n");
292 tmp
= current
->thread
.mflags
& ~3;
293 current
->thread
.mflags
= tmp
| (arg1
& 3);
305 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
307 * This is really horribly ugly.
309 asmlinkage
int sys_ipc (unsigned int call
, int first
, int second
,
310 unsigned long third
, void __user
*ptr
, long fifth
)
314 version
= call
>> 16; /* hack for backward compatibility */
319 return sys_semtimedop (first
, (struct sembuf __user
*)ptr
,
322 return sys_semtimedop (first
, (struct sembuf __user
*)ptr
,
324 (const struct timespec __user
*)fifth
);
326 return sys_semget (first
, second
, third
);
331 if (get_user(fourth
.__pad
, (void __user
*__user
*) ptr
))
333 return sys_semctl (first
, second
, third
, fourth
);
337 return sys_msgsnd (first
, (struct msgbuf __user
*) ptr
,
342 struct ipc_kludge tmp
;
346 if (copy_from_user(&tmp
,
347 (struct ipc_kludge __user
*) ptr
,
350 return sys_msgrcv (first
, tmp
.msgp
, second
,
354 return sys_msgrcv (first
,
355 (struct msgbuf __user
*) ptr
,
356 second
, fifth
, third
);
359 return sys_msgget ((key_t
) first
, second
);
361 return sys_msgctl (first
, second
,
362 (struct msqid_ds __user
*) ptr
);
368 ret
= do_shmat (first
, (char __user
*) ptr
, second
,
372 return put_user (raddr
, (unsigned long __user
*) third
);
374 case 1: /* iBCS2 emulator entry point */
375 if (!segment_eq(get_fs(), get_ds()))
377 return do_shmat (first
, (char __user
*) ptr
, second
,
378 (unsigned long *) third
);
381 return sys_shmdt ((char __user
*)ptr
);
383 return sys_shmget (first
, second
, third
);
385 return sys_shmctl (first
, second
,
386 (struct shmid_ds __user
*) ptr
);
393 * No implemented yet ...
395 asmlinkage
int sys_cachectl(char *addr
, int nbytes
, int op
)
401 * If we ever come here the user sp is bad. Zap the process right away.
402 * Due to the bad stack signaling wouldn't work.
404 asmlinkage
void bad_stack(void)
410 * Do a system call from kernel instead of calling sys_execve so we
411 * end up with proper pt_regs.
413 int kernel_execve(const char *filename
, char *const argv
[], char *const envp
[])
415 register unsigned long __a0
asm("$4") = (unsigned long) filename
;
416 register unsigned long __a1
asm("$5") = (unsigned long) argv
;
417 register unsigned long __a2
asm("$6") = (unsigned long) envp
;
418 register unsigned long __a3
asm("$7");
421 __asm__
volatile (" \n"
423 " li $2, %5 # __NR_execve \n"
427 : "=&r" (__v0
), "=r" (__a3
)
428 : "r" (__a0
), "r" (__a1
), "r" (__a2
), "i" (__NR_execve
)
429 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",