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"
19 #include "asm/uaccess.h"
21 #include "kern_util.h"
22 #include "user_util.h"
23 #include "sysdep/syscalls.h"
24 #include "mode_kern.h"
25 #include "choose-mode.h"
27 /* Unlocked, I don't care if this is a bit off */
30 long um_mount(char * dev_name, char * dir_name, char * type,
31 unsigned long new_flags, void * data)
33 if(type == NULL) type = "";
34 return(sys_mount(dev_name, dir_name, type, new_flags, data));
39 struct task_struct *p;
41 current->thread.forking = 1;
42 p = do_fork(SIGCHLD, 0, NULL, 0, NULL, NULL);
43 current->thread.forking = 0;
44 return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
47 long sys_clone(unsigned long clone_flags, unsigned long newsp)
49 struct task_struct *p;
51 current->thread.forking = 1;
52 p = do_fork(clone_flags, newsp, NULL, 0, NULL, NULL);
53 current->thread.forking = 0;
54 return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
59 struct task_struct *p;
61 current->thread.forking = 1;
62 p = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL, NULL);
63 current->thread.forking = 0;
64 return(IS_ERR(p) ? PTR_ERR(p) : p->pid);
67 /* common code for old and new mmaps */
68 static inline long do_mmap2(
69 unsigned long addr, unsigned long len,
70 unsigned long prot, unsigned long flags,
71 unsigned long fd, unsigned long pgoff)
74 struct file * file = NULL;
76 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
77 if (!(flags & MAP_ANONYMOUS)) {
83 down_write(¤t->mm->mmap_sem);
84 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
85 up_write(¤t->mm->mmap_sem);
93 long sys_mmap2(unsigned long addr, unsigned long len,
94 unsigned long prot, unsigned long flags,
95 unsigned long fd, unsigned long pgoff)
97 return do_mmap2(addr, len, prot, flags, fd, pgoff);
101 * Perform the select(nd, in, out, ex, tv) and mmap() system
102 * calls. Linux/i386 didn't use to be able to handle more than
103 * 4 system call parameters, so these system calls used a memory
104 * block for parameter passing..
107 struct mmap_arg_struct {
113 unsigned long offset;
116 int old_mmap(unsigned long addr, unsigned long len,
117 unsigned long prot, unsigned long flags,
118 unsigned long fd, unsigned long offset)
121 if (offset & ~PAGE_MASK)
124 err = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
129 * sys_pipe() is the normal C calling standard for creating
130 * a pipe. It's not the way unix traditionally does this, though.
132 int sys_pipe(unsigned long * fildes)
139 if (copy_to_user(fildes, fd, 2*sizeof(int)))
145 int sys_sigaction(int sig, const struct old_sigaction *act,
146 struct old_sigaction *oact)
148 struct k_sigaction new_ka, old_ka;
153 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
154 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
155 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
157 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
158 __get_user(mask, &act->sa_mask);
159 siginitset(&new_ka.sa.sa_mask, mask);
162 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
165 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
166 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
167 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
169 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
170 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
177 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
179 * This is really horribly ugly.
181 int sys_ipc (uint call, int first, int second,
182 int third, void *ptr, long fifth)
186 version = call >> 16; /* hack for backward compatibility */
191 return sys_semtimedop(first, (struct sembuf *) ptr, second,
194 return sys_semtimedop(first, (struct sembuf *) ptr, second,
195 (const struct timespec *) fifth);
197 return sys_semget (first, second, third);
202 if (get_user(fourth.__pad, (void **) ptr))
204 return sys_semctl (first, second, third, fourth);
208 return sys_msgsnd (first, (struct msgbuf *) ptr,
213 struct ipc_kludge tmp;
217 if (copy_from_user(&tmp,
218 (struct ipc_kludge *) ptr,
221 return sys_msgrcv (first, tmp.msgp, second,
225 panic("msgrcv with version != 0");
226 return sys_msgrcv (first,
227 (struct msgbuf *) ptr,
228 second, fifth, third);
231 return sys_msgget ((key_t) first, second);
233 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
239 ret = do_shmat (first, (char *) ptr, second, &raddr);
242 return put_user (raddr, (ulong *) third);
244 case 1: /* iBCS2 emulator entry point */
245 if (!segment_eq(get_fs(), get_ds()))
247 return do_shmat (first, (char *) ptr, second, (ulong *) third);
250 return sys_shmdt ((char *)ptr);
252 return sys_shmget (first, second, third);
254 return sys_shmctl (first, second,
255 (struct shmid_ds *) ptr);
261 int sys_uname(struct old_utsname * name)
267 err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
269 return err?-EFAULT:0;
272 int sys_olduname(struct oldold_utsname * name)
275 struct new_utsname *ptr;
279 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
284 ptr = vx_new_utsname();
285 error = __copy_to_user(&name->sysname,ptr->sysname,
287 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
288 error |= __copy_to_user(&name->nodename,ptr->nodename,
290 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
291 error |= __copy_to_user(&name->release,ptr->release,
293 error |= __put_user(0,name->release+__OLD_UTS_LEN);
294 error |= __copy_to_user(&name->version,ptr->version,
296 error |= __put_user(0,name->version+__OLD_UTS_LEN);
297 error |= __copy_to_user(&name->machine,ptr->machine,
299 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
303 error = error ? -EFAULT : 0;
308 int sys_sigaltstack(const stack_t *uss, stack_t *uoss)
310 return(do_sigaltstack(uss, uoss, PT_REGS_SP(¤t->thread.regs)));
313 long execute_syscall(void *r)
315 return(CHOOSE_MODE_PROC(execute_syscall_tt, execute_syscall_skas, r));
318 spinlock_t syscall_lock = SPIN_LOCK_UNLOCKED;
320 static int syscall_index = 0;
322 int next_syscall_index(int limit)
326 spin_lock(&syscall_lock);
328 if(++syscall_index == limit)
330 spin_unlock(&syscall_lock);
335 * Overrides for Emacs so that we follow Linus's tabbing style.
336 * Emacs will notice this stuff at the end of the file and automatically
337 * adjust the settings for this buffer only. This must remain at the end
339 * ---------------------------------------------------------------------------
341 * c-file-style: "linux"