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/smp_lock.h>
17 #include <linux/mman.h>
18 #include <linux/ptrace.h>
19 #include <linux/sched.h>
20 #include <linux/string.h>
21 #include <linux/syscalls.h>
22 #include <linux/file.h>
23 #include <linux/slab.h>
24 #include <linux/utsname.h>
25 #include <linux/unistd.h>
26 #include <linux/sem.h>
27 #include <linux/msg.h>
28 #include <linux/shm.h>
29 #include <linux/compiler.h>
30 #include <linux/module.h>
32 #include <asm/branch.h>
33 #include <asm/cachectl.h>
34 #include <asm/cacheflush.h>
36 #include <asm/asm-offsets.h>
37 #include <asm/signal.h>
39 #include <asm/shmparam.h>
40 #include <asm/sysmips.h>
41 #include <asm/uaccess.h>
43 asmlinkage
int sys_pipe(nabi_no_regargs
volatile struct pt_regs regs
)
59 unsigned long shm_align_mask
= PAGE_SIZE
- 1; /* Sane caches */
61 EXPORT_SYMBOL(shm_align_mask
);
63 #define COLOUR_ALIGN(addr,pgoff) \
64 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
65 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
67 unsigned long arch_get_unmapped_area(struct file
*filp
, unsigned long addr
,
68 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
70 struct vm_area_struct
* vmm
;
72 unsigned long task_size
;
74 task_size
= STACK_TOP
;
76 if (flags
& MAP_FIXED
) {
78 * We do not accept a shared mapping if it would violate
79 * cache aliasing constraints.
81 if ((flags
& MAP_SHARED
) && (addr
& shm_align_mask
))
89 if (filp
|| (flags
& MAP_SHARED
))
93 addr
= COLOUR_ALIGN(addr
, pgoff
);
95 addr
= PAGE_ALIGN(addr
);
96 vmm
= find_vma(current
->mm
, addr
);
97 if (task_size
- len
>= addr
&&
98 (!vmm
|| addr
+ len
<= vmm
->vm_start
))
101 addr
= TASK_UNMAPPED_BASE
;
103 addr
= COLOUR_ALIGN(addr
, pgoff
);
105 addr
= PAGE_ALIGN(addr
);
107 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
108 /* At this point: (!vmm || addr < vmm->vm_end). */
109 if (task_size
- len
< addr
)
111 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
115 addr
= COLOUR_ALIGN(addr
, pgoff
);
119 /* common code for old and new mmaps */
120 static inline unsigned long
121 do_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
122 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
124 unsigned long error
= -EBADF
;
125 struct file
* file
= NULL
;
127 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
128 if (!(flags
& MAP_ANONYMOUS
)) {
134 down_write(¤t
->mm
->mmap_sem
);
135 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
136 up_write(¤t
->mm
->mmap_sem
);
144 asmlinkage
unsigned long
145 old_mmap(unsigned long addr
, unsigned long len
, int prot
,
146 int flags
, int fd
, off_t offset
)
148 unsigned long result
;
151 if (offset
& ~PAGE_MASK
)
154 result
= do_mmap2(addr
, len
, prot
, flags
, fd
, offset
>> PAGE_SHIFT
);
160 asmlinkage
unsigned long
161 sys_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
162 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
164 if (pgoff
& (~PAGE_MASK
>> 12))
167 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
>> (PAGE_SHIFT
-12));
170 save_static_function(sys_fork
);
171 __attribute_used__ noinline
static int
172 _sys_fork(nabi_no_regargs
struct pt_regs regs
)
174 return do_fork(SIGCHLD
, regs
.regs
[29], ®s
, 0, NULL
, NULL
);
177 save_static_function(sys_clone
);
178 __attribute_used__ noinline
static int
179 _sys_clone(nabi_no_regargs
struct pt_regs regs
)
181 unsigned long clone_flags
;
183 int __user
*parent_tidptr
, *child_tidptr
;
185 clone_flags
= regs
.regs
[4];
186 newsp
= regs
.regs
[5];
188 newsp
= regs
.regs
[29];
189 parent_tidptr
= (int __user
*) regs
.regs
[6];
191 /* We need to fetch the fifth argument off the stack. */
193 if (clone_flags
& (CLONE_CHILD_SETTID
| CLONE_CHILD_CLEARTID
)) {
194 int __user
*__user
*usp
= (int __user
*__user
*) regs
.regs
[29];
195 if (regs
.regs
[2] == __NR_syscall
) {
196 if (get_user (child_tidptr
, &usp
[5]))
199 else if (get_user (child_tidptr
, &usp
[4]))
203 child_tidptr
= (int __user
*) regs
.regs
[8];
205 return do_fork(clone_flags
, newsp
, ®s
, 0,
206 parent_tidptr
, child_tidptr
);
210 * sys_execve() executes a new program.
212 asmlinkage
int sys_execve(nabi_no_regargs
struct pt_regs regs
)
217 filename
= getname((char __user
*) (long)regs
.regs
[4]);
218 error
= PTR_ERR(filename
);
219 if (IS_ERR(filename
))
221 error
= do_execve(filename
, (char __user
*__user
*) (long)regs
.regs
[5],
222 (char __user
*__user
*) (long)regs
.regs
[6], ®s
);
230 * Compacrapability ...
232 asmlinkage
int sys_uname(struct old_utsname __user
* name
)
234 if (name
&& !copy_to_user(name
, &system_utsname
, sizeof (*name
)))
240 * Compacrapability ...
242 asmlinkage
int sys_olduname(struct oldold_utsname __user
* name
)
248 if (!access_ok(VERIFY_WRITE
,name
,sizeof(struct oldold_utsname
)))
251 error
= __copy_to_user(&name
->sysname
,&system_utsname
.sysname
,__OLD_UTS_LEN
);
252 error
-= __put_user(0,name
->sysname
+__OLD_UTS_LEN
);
253 error
-= __copy_to_user(&name
->nodename
,&system_utsname
.nodename
,__OLD_UTS_LEN
);
254 error
-= __put_user(0,name
->nodename
+__OLD_UTS_LEN
);
255 error
-= __copy_to_user(&name
->release
,&system_utsname
.release
,__OLD_UTS_LEN
);
256 error
-= __put_user(0,name
->release
+__OLD_UTS_LEN
);
257 error
-= __copy_to_user(&name
->version
,&system_utsname
.version
,__OLD_UTS_LEN
);
258 error
-= __put_user(0,name
->version
+__OLD_UTS_LEN
);
259 error
-= __copy_to_user(&name
->machine
,&system_utsname
.machine
,__OLD_UTS_LEN
);
260 error
= __put_user(0,name
->machine
+__OLD_UTS_LEN
);
261 error
= error
? -EFAULT
: 0;
266 void sys_set_thread_area(unsigned long addr
)
268 struct thread_info
*ti
= task_thread_info(current
);
272 /* If some future MIPS implementation has this register in hardware,
273 * we will need to update it here (and in context switches). */
276 asmlinkage
int _sys_sysmips(int cmd
, long arg1
, int arg2
, int arg3
)
281 case MIPS_ATOMIC_SET
:
282 printk(KERN_CRIT
"How did I get here?\n");
286 tmp
= current
->thread
.mflags
& ~3;
287 current
->thread
.mflags
= tmp
| (arg1
& 3);
299 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
301 * This is really horribly ugly.
303 asmlinkage
int sys_ipc (unsigned int call
, int first
, int second
,
304 unsigned long third
, void __user
*ptr
, long fifth
)
308 version
= call
>> 16; /* hack for backward compatibility */
313 return sys_semtimedop (first
, (struct sembuf __user
*)ptr
,
316 return sys_semtimedop (first
, (struct sembuf __user
*)ptr
,
318 (const struct timespec __user
*)fifth
);
320 return sys_semget (first
, second
, third
);
325 if (get_user(fourth
.__pad
, (void __user
*__user
*) ptr
))
327 return sys_semctl (first
, second
, third
, fourth
);
331 return sys_msgsnd (first
, (struct msgbuf __user
*) ptr
,
336 struct ipc_kludge tmp
;
340 if (copy_from_user(&tmp
,
341 (struct ipc_kludge __user
*) ptr
,
344 return sys_msgrcv (first
, tmp
.msgp
, second
,
348 return sys_msgrcv (first
,
349 (struct msgbuf __user
*) ptr
,
350 second
, fifth
, third
);
353 return sys_msgget ((key_t
) first
, second
);
355 return sys_msgctl (first
, second
,
356 (struct msqid_ds __user
*) ptr
);
362 ret
= do_shmat (first
, (char __user
*) ptr
, second
,
366 return put_user (raddr
, (unsigned long __user
*) third
);
368 case 1: /* iBCS2 emulator entry point */
369 if (!segment_eq(get_fs(), get_ds()))
371 return do_shmat (first
, (char __user
*) ptr
, second
,
372 (unsigned long *) third
);
375 return sys_shmdt ((char __user
*)ptr
);
377 return sys_shmget (first
, second
, third
);
379 return sys_shmctl (first
, second
,
380 (struct shmid_ds __user
*) ptr
);
387 * No implemented yet ...
389 asmlinkage
int sys_cachectl(char *addr
, int nbytes
, int op
)
395 * If we ever come here the user sp is bad. Zap the process right away.
396 * Due to the bad stack signaling wouldn't work.
398 asmlinkage
void bad_stack(void)