2 * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include "linux/sched.h"
7 #include "linux/file.h"
8 #include "linux/smp_lock.h"
10 #include "linux/utsname.h"
11 #include "linux/msg.h"
12 #include "linux/shm.h"
13 #include "linux/sys.h"
14 #include "linux/syscalls.h"
15 #include "linux/unistd.h"
16 #include "linux/slab.h"
17 #include "linux/utime.h"
18 #include <linux/vs_cvirt.h>
21 #include "asm/uaccess.h"
23 #include "kern_util.h"
24 #include "user_util.h"
25 #include "sysdep/syscalls.h"
26 #include "mode_kern.h"
27 #include "choose-mode.h"
29 /* Unlocked, I don't care if this is a bit off */
32 long um_mount(char * dev_name, char * dir_name, char * type,
33 unsigned long new_flags, void * data)
35 if(type == NULL) type = "";
36 return(sys_mount(dev_name, dir_name, type, new_flags, data));
41 struct task_struct *p;
43 current->thread.forking = 1;
44 p = do_fork(SIGCHLD, 0, NULL, 0, NULL, NULL);
45 current->thread.forking = 0;
46 return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
49 long sys_clone(unsigned long clone_flags, unsigned long newsp)
51 struct task_struct *p;
53 current->thread.forking = 1;
54 p = do_fork(clone_flags, newsp, NULL, 0, NULL, NULL);
55 current->thread.forking = 0;
56 return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
61 struct task_struct *p;
63 current->thread.forking = 1;
64 p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL, NULL);
65 current->thread.forking = 0;
66 return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
69 /* common code for old and new mmaps */
70 static inline long do_mmap2(
71 unsigned long addr, unsigned long len,
72 unsigned long prot, unsigned long flags,
73 unsigned long fd, unsigned long pgoff)
76 struct file * file = NULL;
78 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
79 if (!(flags & MAP_ANONYMOUS)) {
85 down_write(¤t->mm->mmap_sem);
86 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
87 up_write(¤t->mm->mmap_sem);
95 long sys_mmap2(unsigned long addr, unsigned long len,
96 unsigned long prot, unsigned long flags,
97 unsigned long fd, unsigned long pgoff)
99 return do_mmap2(addr, len, prot, flags, fd, pgoff);
103 * Perform the select(nd, in, out, ex, tv) and mmap() system
104 * calls. Linux/i386 didn't use to be able to handle more than
105 * 4 system call parameters, so these system calls used a memory
106 * block for parameter passing..
109 struct mmap_arg_struct {
115 unsigned long offset;
118 int old_mmap(unsigned long addr, unsigned long len,
119 unsigned long prot, unsigned long flags,
120 unsigned long fd, unsigned long offset)
123 if (offset & ~PAGE_MASK)
126 err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
131 * sys_pipe() is the normal C calling standard for creating
132 * a pipe. It's not the way unix traditionally does this, though.
134 int sys_pipe(unsigned long * fildes)
141 if (copy_to_user(fildes, fd, 2*sizeof(int)))
147 int sys_sigaction(int sig, const struct old_sigaction *act,
148 struct old_sigaction *oact)
150 struct k_sigaction new_ka, old_ka;
155 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
156 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
157 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
159 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
160 __get_user(mask, &act->sa_mask);
161 siginitset(&new_ka.sa.sa_mask, mask);
164 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
167 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
168 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
169 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
171 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
172 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
179 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
181 * This is really horribly ugly.
183 int sys_ipc (uint call, int first, int second,
184 int third, void *ptr, long fifth)
188 version = call >> 16; /* hack for backward compatibility */
193 return sys_semtimedop(first, (struct sembuf *) ptr, second,
196 return sys_semtimedop(first, (struct sembuf *) ptr, second,
197 (const struct timespec *) fifth);
199 return sys_semget (first, second, third);
204 if (get_user(fourth.__pad, (void **) ptr))
206 return sys_semctl (first, second, third, fourth);
210 return sys_msgsnd (first, (struct msgbuf *) ptr,
215 struct ipc_kludge tmp;
219 if (copy_from_user(&tmp,
220 (struct ipc_kludge *) ptr,
223 return sys_msgrcv (first, tmp.msgp, second,
227 panic("msgrcv with version != 0");
228 return sys_msgrcv (first,
229 (struct msgbuf *) ptr,
230 second, fifth, third);
233 return sys_msgget ((key_t) first, second);
235 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
241 ret = do_shmat (first, (char *) ptr, second, &raddr);
244 return put_user (raddr, (ulong *) third);
246 case 1: /* iBCS2 emulator entry point */
247 if (!segment_eq(get_fs(), get_ds()))
249 return do_shmat (first, (char *) ptr, second, (ulong *) third);
252 return sys_shmdt ((char *)ptr);
254 return sys_shmget (first, second, third);
256 return sys_shmctl (first, second,
257 (struct shmid_ds *) ptr);
263 int sys_uname(struct old_utsname * name)
269 err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
271 return err?-EFAULT:0;
274 int sys_olduname(struct oldold_utsname * name)
277 struct new_utsname *ptr;
281 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
286 ptr = vx_new_utsname();
287 error = __copy_to_user(&name->sysname,ptr->sysname,
289 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
290 error |= __copy_to_user(&name->nodename,ptr->nodename,
292 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
293 error |= __copy_to_user(&name->release,ptr->release,
295 error |= __put_user(0,name->release+__OLD_UTS_LEN);
296 error |= __copy_to_user(&name->version,ptr->version,
298 error |= __put_user(0,name->version+__OLD_UTS_LEN);
299 error |= __copy_to_user(&name->machine,ptr->machine,
301 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
305 error = error ? -EFAULT : 0;
310 int sys_sigaltstack(const stack_t *uss, stack_t *uoss)
312 return(do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs)));
315 long execute_syscall(void *r)
317 return(CHOOSE_MODE_PROC(execute_syscall_tt, execute_syscall_skas, r));
320 spinlock_t syscall_lock = SPIN_LOCK_UNLOCKED;
322 static int syscall_index = 0;
324 int next_syscall_index(int limit)
328 spin_lock(&syscall_lock);
330 if(++syscall_index == limit)
332 spin_unlock(&syscall_lock);
337 * Overrides for Emacs so that we follow Linus's tabbing style.
338 * Emacs will notice this stuff at the end of the file and automatically
339 * adjust the settings for this buffer only. This must remain at the end
341 * ---------------------------------------------------------------------------
343 * c-file-style: "linux"