2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
4 * Copyright (C) 2007 John Williams <john.williams@petalogix.com>
6 * Copyright (C) 2006 Atmark Techno, Inc.
7 * Yasushi SHOJI <yashi@atmark-techno.com>
8 * Tetsuya OHKAWA <tetsuya@atmark-techno.com>
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
15 #include <linux/errno.h>
17 #include <linux/smp.h>
18 #include <linux/smp_lock.h>
19 #include <linux/syscalls.h>
20 #include <linux/sem.h>
21 #include <linux/msg.h>
22 #include <linux/shm.h>
23 #include <linux/stat.h>
24 #include <linux/mman.h>
25 #include <linux/sys.h>
26 #include <linux/ipc.h>
27 #include <linux/utsname.h>
28 #include <linux/file.h>
29 #include <linux/module.h>
30 #include <linux/err.h>
32 #include <linux/ipc.h>
33 #include <linux/semaphore.h>
34 #include <linux/syscalls.h>
35 #include <linux/uaccess.h>
36 #include <linux/unistd.h>
38 #include <asm/syscalls.h>
40 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
42 * This is really horribly ugly. This will be remove with new toolchain.
45 sys_ipc(uint call, int first, int second, int third, void *ptr, long fifth)
49 version = call >> 16; /* hack for backward compatibility */
55 ret = sys_semop(first, (struct sembuf *)ptr, second);
58 ret = sys_semget(first, second, third);
66 ret = (access_ok(VERIFY_READ, ptr, sizeof(long)) ? 0 : -EFAULT)
67 || (get_user(fourth.__pad, (void **)ptr)) ;
70 ret = sys_semctl(first, second, third, fourth);
74 ret = sys_msgsnd(first, (struct msgbuf *) ptr, second, third);
79 struct ipc_kludge tmp;
83 ret = (access_ok(VERIFY_READ, ptr, sizeof(tmp))
84 ? 0 : -EFAULT) || copy_from_user(&tmp,
85 (struct ipc_kludge *) ptr, sizeof(tmp));
88 ret = sys_msgrcv(first, tmp.msgp, second, tmp.msgtyp,
93 ret = sys_msgrcv(first, (struct msgbuf *) ptr,
94 second, fifth, third);
99 ret = sys_msgget((key_t) first, second);
102 ret = sys_msgctl(first, second, (struct msqid_ds *) ptr);
108 ret = access_ok(VERIFY_WRITE, (ulong *) third,
109 sizeof(ulong)) ? 0 : -EFAULT;
112 ret = do_shmat(first, (char *) ptr, second, &raddr);
115 ret = put_user(raddr, (ulong *) third);
118 case 1: /* iBCS2 emulator entry point */
119 if (!segment_eq(get_fs(), get_ds()))
121 ret = do_shmat(first, (char *) ptr, second,
127 ret = sys_shmdt((char *)ptr);
130 ret = sys_shmget(first, second, third);
133 ret = sys_shmctl(first, second, (struct shmid_ds *) ptr);
139 asmlinkage int sys_vfork(struct pt_regs *regs)
141 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->r1,
142 regs, 0, NULL, NULL);
145 asmlinkage int sys_clone(int flags, unsigned long stack, struct pt_regs *regs)
149 return do_fork(flags, stack, regs, 0, NULL, NULL);
152 asmlinkage int sys_execve(char __user *filenamei, char __user *__user *argv,
153 char __user *__user *envp, struct pt_regs *regs)
158 filename = getname(filenamei);
159 error = PTR_ERR(filename);
160 if (IS_ERR(filename))
162 error = do_execve(filename, argv, envp, regs);
168 asmlinkage unsigned long
169 sys_mmap2(unsigned long addr, size_t len,
170 unsigned long prot, unsigned long flags,
171 unsigned long fd, unsigned long pgoff)
173 struct file *file = NULL;
176 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
177 if (!(flags & MAP_ANONYMOUS)) {
180 printk(KERN_INFO "no fd in mmap\r\n");
185 down_write(¤t->mm->mmap_sem);
186 ret = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
187 up_write(¤t->mm->mmap_sem);
194 asmlinkage unsigned long sys_mmap(unsigned long addr, size_t len,
195 unsigned long prot, unsigned long flags,
196 unsigned long fd, off_t offset)
200 if (offset & ~PAGE_MASK) {
201 printk(KERN_INFO "no pagemask in mmap\r\n");
205 err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
211 * Do a system call from kernel instead of calling sys_execve so we
212 * end up with proper pt_regs.
214 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
216 register const char *__a __asm__("r5") = filename;
217 register const void *__b __asm__("r6") = argv;
218 register const void *__c __asm__("r7") = envp;
219 register unsigned long __syscall __asm__("r12") = __NR_execve;
220 register unsigned long __ret __asm__("r3");
221 __asm__ __volatile__ ("brki r14, 0x8"
222 : "=r" (__ret), "=r" (__syscall)
223 : "1" (__syscall), "r" (__a), "r" (__b), "r" (__c)
225 "r10", "r11", "r14", "cc", "memory");