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/semaphore.h>
33 #include <linux/uaccess.h>
34 #include <linux/unistd.h>
36 #include <asm/syscalls.h>
38 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
40 * This is really horribly ugly. This will be remove with new toolchain.
43 sys_ipc(uint call
, int first
, int second
, int third
, void *ptr
, long fifth
)
47 version
= call
>> 16; /* hack for backward compatibility */
53 ret
= sys_semop(first
, (struct sembuf
*)ptr
, second
);
56 ret
= sys_semget(first
, second
, third
);
64 ret
= (access_ok(VERIFY_READ
, ptr
, sizeof(long)) ? 0 : -EFAULT
)
65 || (get_user(fourth
.__pad
, (void **)ptr
)) ;
68 ret
= sys_semctl(first
, second
, third
, fourth
);
72 ret
= sys_msgsnd(first
, (struct msgbuf
*) ptr
, second
, third
);
77 struct ipc_kludge tmp
;
81 ret
= (access_ok(VERIFY_READ
, ptr
, sizeof(tmp
))
82 ? 0 : -EFAULT
) || copy_from_user(&tmp
,
83 (struct ipc_kludge
*) ptr
, sizeof(tmp
));
86 ret
= sys_msgrcv(first
, tmp
.msgp
, second
, tmp
.msgtyp
,
91 ret
= sys_msgrcv(first
, (struct msgbuf
*) ptr
,
92 second
, fifth
, third
);
97 ret
= sys_msgget((key_t
) first
, second
);
100 ret
= sys_msgctl(first
, second
, (struct msqid_ds
*) ptr
);
106 ret
= access_ok(VERIFY_WRITE
, (ulong
*) third
,
107 sizeof(ulong
)) ? 0 : -EFAULT
;
110 ret
= do_shmat(first
, (char *) ptr
, second
, &raddr
);
113 ret
= put_user(raddr
, (ulong
*) third
);
116 case 1: /* iBCS2 emulator entry point */
117 if (!segment_eq(get_fs(), get_ds()))
119 ret
= do_shmat(first
, (char *) ptr
, second
,
125 ret
= sys_shmdt((char *)ptr
);
128 ret
= sys_shmget(first
, second
, third
);
131 ret
= sys_shmctl(first
, second
, (struct shmid_ds
*) ptr
);
137 asmlinkage
int sys_vfork(struct pt_regs
*regs
)
139 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, regs
->r1
,
140 regs
, 0, NULL
, NULL
);
143 asmlinkage
int sys_clone(int flags
, unsigned long stack
, struct pt_regs
*regs
)
147 return do_fork(flags
, stack
, regs
, 0, NULL
, NULL
);
150 asmlinkage
int sys_execve(char __user
*filenamei
, char __user
*__user
*argv
,
151 char __user
*__user
*envp
, struct pt_regs
*regs
)
156 filename
= getname(filenamei
);
157 error
= PTR_ERR(filename
);
158 if (IS_ERR(filename
))
160 error
= do_execve(filename
, argv
, envp
, regs
);
166 asmlinkage
unsigned long
167 sys_mmap2(unsigned long addr
, size_t len
,
168 unsigned long prot
, unsigned long flags
,
169 unsigned long fd
, unsigned long pgoff
)
171 struct file
*file
= NULL
;
174 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
175 if (!(flags
& MAP_ANONYMOUS
)) {
178 printk(KERN_INFO
"no fd in mmap\r\n");
183 down_write(¤t
->mm
->mmap_sem
);
184 ret
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
185 up_write(¤t
->mm
->mmap_sem
);
192 asmlinkage
unsigned long sys_mmap(unsigned long addr
, size_t len
,
193 unsigned long prot
, unsigned long flags
,
194 unsigned long fd
, off_t offset
)
198 if (offset
& ~PAGE_MASK
) {
199 printk(KERN_INFO
"no pagemask in mmap\r\n");
203 err
= sys_mmap2(addr
, len
, prot
, flags
, fd
, offset
>> PAGE_SHIFT
);
209 * Do a system call from kernel instead of calling sys_execve so we
210 * end up with proper pt_regs.
212 int kernel_execve(const char *filename
, char *const argv
[], char *const envp
[])
214 register const char *__a
__asm__("r5") = filename
;
215 register const void *__b
__asm__("r6") = argv
;
216 register const void *__c
__asm__("r7") = envp
;
217 register unsigned long __syscall
__asm__("r12") = __NR_execve
;
218 register unsigned long __ret
__asm__("r3");
219 __asm__
__volatile__ ("brki r14, 0x8"
220 : "=r" (__ret
), "=r" (__syscall
)
221 : "1" (__syscall
), "r" (__a
), "r" (__b
), "r" (__c
)
223 "r10", "r11", "r14", "cc", "memory");