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/errno.h>
12 #include <linux/linkage.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.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>
30 #include <asm/branch.h>
31 #include <asm/cachectl.h>
32 #include <asm/cacheflush.h>
34 #include <asm/offset.h>
35 #include <asm/signal.h>
37 #include <asm/shmparam.h>
38 #include <asm/sysmips.h>
39 #include <asm/uaccess.h>
41 asmlinkage
int sys_pipe(nabi_no_regargs
volatile struct pt_regs regs
)
57 unsigned long shm_align_mask
= PAGE_SIZE
- 1; /* Sane caches */
59 #define COLOUR_ALIGN(addr,pgoff) \
60 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
61 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
63 unsigned long arch_get_unmapped_area(struct file
*filp
, unsigned long addr
,
64 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
66 struct vm_area_struct
* vmm
;
68 unsigned long task_size
;
70 task_size
= STACK_TOP
;
72 if (flags
& MAP_FIXED
) {
74 * We do not accept a shared mapping if it would violate
75 * cache aliasing constraints.
77 if ((flags
& MAP_SHARED
) && (addr
& shm_align_mask
))
85 if (filp
|| (flags
& MAP_SHARED
))
89 addr
= COLOUR_ALIGN(addr
, pgoff
);
91 addr
= PAGE_ALIGN(addr
);
92 vmm
= find_vma(current
->mm
, addr
);
93 if (task_size
- len
>= addr
&&
94 (!vmm
|| addr
+ len
<= vmm
->vm_start
))
97 addr
= TASK_UNMAPPED_BASE
;
99 addr
= COLOUR_ALIGN(addr
, pgoff
);
101 addr
= PAGE_ALIGN(addr
);
103 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
104 /* At this point: (!vmm || addr < vmm->vm_end). */
105 if (task_size
- len
< addr
)
107 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
111 addr
= COLOUR_ALIGN(addr
, pgoff
);
115 /* common code for old and new mmaps */
116 static inline unsigned long
117 do_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
118 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
120 unsigned long error
= -EBADF
;
121 struct file
* file
= NULL
;
123 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
124 if (!(flags
& MAP_ANONYMOUS
)) {
130 down_write(¤t
->mm
->mmap_sem
);
131 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
132 up_write(¤t
->mm
->mmap_sem
);
140 asmlinkage
unsigned long
141 old_mmap(unsigned long addr
, unsigned long len
, int prot
,
142 int flags
, int fd
, off_t offset
)
144 unsigned long result
;
147 if (offset
& ~PAGE_MASK
)
150 result
= do_mmap2(addr
, len
, prot
, flags
, fd
, offset
>> PAGE_SHIFT
);
156 asmlinkage
unsigned long
157 sys_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
158 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
160 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
);
163 save_static_function(sys_fork
);
164 __attribute_used__ noinline
static int
165 _sys_fork(nabi_no_regargs
struct pt_regs regs
)
167 return do_fork(SIGCHLD
, regs
.regs
[29], ®s
, 0, NULL
, NULL
);
170 save_static_function(sys_clone
);
171 __attribute_used__ noinline
static int
172 _sys_clone(nabi_no_regargs
struct pt_regs regs
)
174 unsigned long clone_flags
;
176 int *parent_tidptr
, *child_tidptr
;
178 clone_flags
= regs
.regs
[4];
179 newsp
= regs
.regs
[5];
181 newsp
= regs
.regs
[29];
182 parent_tidptr
= (int *) regs
.regs
[6];
183 child_tidptr
= (int *) regs
.regs
[7];
184 return do_fork(clone_flags
, newsp
, ®s
, 0,
185 parent_tidptr
, child_tidptr
);
189 * sys_execve() executes a new program.
191 asmlinkage
int sys_execve(nabi_no_regargs
struct pt_regs regs
)
196 filename
= getname((char *) (long)regs
.regs
[4]);
197 error
= PTR_ERR(filename
);
198 if (IS_ERR(filename
))
200 error
= do_execve(filename
, (char **) (long)regs
.regs
[5],
201 (char **) (long)regs
.regs
[6], ®s
);
209 * Compacrapability ...
211 asmlinkage
int sys_uname(struct old_utsname
* name
)
213 if (name
&& !copy_to_user(name
, &system_utsname
, sizeof (*name
)))
219 * Compacrapability ...
221 asmlinkage
int sys_olduname(struct oldold_utsname
* name
)
227 if (!access_ok(VERIFY_WRITE
,name
,sizeof(struct oldold_utsname
)))
230 error
= __copy_to_user(&name
->sysname
,&system_utsname
.sysname
,__OLD_UTS_LEN
);
231 error
-= __put_user(0,name
->sysname
+__OLD_UTS_LEN
);
232 error
-= __copy_to_user(&name
->nodename
,&system_utsname
.nodename
,__OLD_UTS_LEN
);
233 error
-= __put_user(0,name
->nodename
+__OLD_UTS_LEN
);
234 error
-= __copy_to_user(&name
->release
,&system_utsname
.release
,__OLD_UTS_LEN
);
235 error
-= __put_user(0,name
->release
+__OLD_UTS_LEN
);
236 error
-= __copy_to_user(&name
->version
,&system_utsname
.version
,__OLD_UTS_LEN
);
237 error
-= __put_user(0,name
->version
+__OLD_UTS_LEN
);
238 error
-= __copy_to_user(&name
->machine
,&system_utsname
.machine
,__OLD_UTS_LEN
);
239 error
= __put_user(0,name
->machine
+__OLD_UTS_LEN
);
240 error
= error
? -EFAULT
: 0;
245 asmlinkage
int _sys_sysmips(int cmd
, long arg1
, int arg2
, int arg3
)
252 char nodename
[__NEW_UTS_LEN
+ 1];
254 if (!capable(CAP_SYS_ADMIN
))
257 name
= (char *) arg1
;
259 len
= strncpy_from_user(nodename
, name
, __NEW_UTS_LEN
);
263 down_write(&uts_sem
);
264 strncpy(system_utsname
.nodename
, nodename
, len
);
265 nodename
[__NEW_UTS_LEN
] = '\0';
266 strlcpy(system_utsname
.nodename
, nodename
,
267 sizeof(system_utsname
.nodename
));
272 case MIPS_ATOMIC_SET
:
273 printk(KERN_CRIT
"How did I get here?\n");
277 tmp
= current
->thread
.mflags
& ~3;
278 current
->thread
.mflags
= tmp
| (arg1
& 3);
293 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
295 * This is really horribly ugly.
297 asmlinkage
int sys_ipc (uint call
, int first
, int second
,
298 unsigned long third
, void *ptr
, long fifth
)
302 version
= call
>> 16; /* hack for backward compatibility */
307 return sys_semtimedop (first
, (struct sembuf
*)ptr
, second
,
310 return sys_semtimedop (first
, (struct sembuf
*)ptr
, second
,
311 (const struct timespec __user
*)fifth
);
313 return sys_semget (first
, second
, third
);
318 if (get_user(fourth
.__pad
, (void **) ptr
))
320 return sys_semctl (first
, second
, third
, fourth
);
324 return sys_msgsnd (first
, (struct msgbuf
*) ptr
,
329 struct ipc_kludge tmp
;
333 if (copy_from_user(&tmp
,
334 (struct ipc_kludge
*) ptr
,
337 return sys_msgrcv (first
, tmp
.msgp
, second
,
341 return sys_msgrcv (first
,
342 (struct msgbuf
*) ptr
,
343 second
, fifth
, third
);
346 return sys_msgget ((key_t
) first
, second
);
348 return sys_msgctl (first
, second
, (struct msqid_ds
*) ptr
);
354 ret
= do_shmat (first
, (char *) ptr
, second
, &raddr
);
357 return put_user (raddr
, (ulong
*) third
);
359 case 1: /* iBCS2 emulator entry point */
360 if (!segment_eq(get_fs(), get_ds()))
362 return do_shmat (first
, (char *) ptr
, second
, (ulong
*) third
);
365 return sys_shmdt ((char *)ptr
);
367 return sys_shmget (first
, second
, third
);
369 return sys_shmctl (first
, second
,
370 (struct shmid_ds
*) ptr
);
377 * No implemented yet ...
379 asmlinkage
int sys_cachectl(char *addr
, int nbytes
, int op
)
385 * If we ever come here the user sp is bad. Zap the process right away.
386 * Due to the bad stack signaling wouldn't work.
388 asmlinkage
void bad_stack(void)