[POWERPC] ps3: add a default zImage target
[linux-2.6.22.y-op.git] / arch / sh / kernel / sys_sh.c
blob8fde95001c346873744057040b85c6f3cdbb094d
1 /*
2 * linux/arch/sh/kernel/sys_sh.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/SuperH
6 * platform.
8 * Taken from i386 version.
9 */
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/syscalls.h>
21 #include <linux/mman.h>
22 #include <linux/file.h>
23 #include <linux/utsname.h>
24 #include <linux/module.h>
25 #include <asm/cacheflush.h>
26 #include <asm/uaccess.h>
27 #include <asm/ipc.h>
28 #include <asm/unistd.h>
31 * sys_pipe() is the normal C calling standard for creating
32 * a pipe. It's not the way Unix traditionally does this, though.
34 asmlinkage int sys_pipe(unsigned long r4, unsigned long r5,
35 unsigned long r6, unsigned long r7,
36 struct pt_regs regs)
38 int fd[2];
39 int error;
41 error = do_pipe(fd);
42 if (!error) {
43 regs.regs[1] = fd[1];
44 return fd[0];
46 return error;
49 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
51 EXPORT_SYMBOL(shm_align_mask);
54 * To avoid cache aliases, we map the shared page with same color.
56 #define COLOUR_ALIGN(addr, pgoff) \
57 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
58 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
60 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
61 unsigned long len, unsigned long pgoff, unsigned long flags)
63 struct mm_struct *mm = current->mm;
64 struct vm_area_struct *vma;
65 unsigned long start_addr;
66 int do_colour_align;
68 if (flags & MAP_FIXED) {
69 /* We do not accept a shared mapping if it would violate
70 * cache aliasing constraints.
72 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
73 return -EINVAL;
74 return addr;
77 if (unlikely(len > TASK_SIZE))
78 return -ENOMEM;
80 do_colour_align = 0;
81 if (filp || (flags & MAP_SHARED))
82 do_colour_align = 1;
84 if (addr) {
85 if (do_colour_align)
86 addr = COLOUR_ALIGN(addr, pgoff);
87 else
88 addr = PAGE_ALIGN(addr);
90 vma = find_vma(mm, addr);
91 if (TASK_SIZE - len >= addr &&
92 (!vma || addr + len <= vma->vm_start))
93 return addr;
96 if (len > mm->cached_hole_size) {
97 start_addr = addr = mm->free_area_cache;
98 } else {
99 mm->cached_hole_size = 0;
100 start_addr = addr = TASK_UNMAPPED_BASE;
103 full_search:
104 if (do_colour_align)
105 addr = COLOUR_ALIGN(addr, pgoff);
106 else
107 addr = PAGE_ALIGN(mm->free_area_cache);
109 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
110 /* At this point: (!vma || addr < vma->vm_end). */
111 if (unlikely(TASK_SIZE - len < addr)) {
113 * Start a new search - just in case we missed
114 * some holes.
116 if (start_addr != TASK_UNMAPPED_BASE) {
117 start_addr = addr = TASK_UNMAPPED_BASE;
118 mm->cached_hole_size = 0;
119 goto full_search;
121 return -ENOMEM;
123 if (likely(!vma || addr + len <= vma->vm_start)) {
125 * Remember the place where we stopped the search:
127 mm->free_area_cache = addr + len;
128 return addr;
130 if (addr + mm->cached_hole_size < vma->vm_start)
131 mm->cached_hole_size = vma->vm_start - addr;
133 addr = vma->vm_end;
134 if (do_colour_align)
135 addr = COLOUR_ALIGN(addr, pgoff);
139 static inline long
140 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
141 unsigned long flags, int fd, unsigned long pgoff)
143 int error = -EBADF;
144 struct file *file = NULL;
146 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
147 if (!(flags & MAP_ANONYMOUS)) {
148 file = fget(fd);
149 if (!file)
150 goto out;
153 down_write(&current->mm->mmap_sem);
154 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
155 up_write(&current->mm->mmap_sem);
157 if (file)
158 fput(file);
159 out:
160 return error;
163 asmlinkage int old_mmap(unsigned long addr, unsigned long len,
164 unsigned long prot, unsigned long flags,
165 int fd, unsigned long off)
167 if (off & ~PAGE_MASK)
168 return -EINVAL;
169 return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
172 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
173 unsigned long prot, unsigned long flags,
174 unsigned long fd, unsigned long pgoff)
176 return do_mmap2(addr, len, prot, flags, fd, pgoff);
180 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
182 * This is really horribly ugly.
184 asmlinkage int sys_ipc(uint call, int first, int second,
185 int third, void __user *ptr, long fifth)
187 int version, ret;
189 version = call >> 16; /* hack for backward compatibility */
190 call &= 0xffff;
192 if (call <= SEMCTL)
193 switch (call) {
194 case SEMOP:
195 return sys_semtimedop(first, (struct sembuf __user *)ptr,
196 second, NULL);
197 case SEMTIMEDOP:
198 return sys_semtimedop(first, (struct sembuf __user *)ptr,
199 second,
200 (const struct timespec __user *)fifth);
201 case SEMGET:
202 return sys_semget (first, second, third);
203 case SEMCTL: {
204 union semun fourth;
205 if (!ptr)
206 return -EINVAL;
207 if (get_user(fourth.__pad, (void * __user *) ptr))
208 return -EFAULT;
209 return sys_semctl (first, second, third, fourth);
211 default:
212 return -EINVAL;
215 if (call <= MSGCTL)
216 switch (call) {
217 case MSGSND:
218 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
219 second, third);
220 case MSGRCV:
221 switch (version) {
222 case 0: {
223 struct ipc_kludge tmp;
224 if (!ptr)
225 return -EINVAL;
227 if (copy_from_user(&tmp,
228 (struct ipc_kludge __user *) ptr,
229 sizeof (tmp)))
230 return -EFAULT;
231 return sys_msgrcv (first, tmp.msgp, second,
232 tmp.msgtyp, third);
234 default:
235 return sys_msgrcv (first,
236 (struct msgbuf __user *) ptr,
237 second, fifth, third);
239 case MSGGET:
240 return sys_msgget ((key_t) first, second);
241 case MSGCTL:
242 return sys_msgctl (first, second,
243 (struct msqid_ds __user *) ptr);
244 default:
245 return -EINVAL;
247 if (call <= SHMCTL)
248 switch (call) {
249 case SHMAT:
250 switch (version) {
251 default: {
252 ulong raddr;
253 ret = do_shmat (first, (char __user *) ptr,
254 second, &raddr);
255 if (ret)
256 return ret;
257 return put_user (raddr, (ulong __user *) third);
259 case 1: /* iBCS2 emulator entry point */
260 if (!segment_eq(get_fs(), get_ds()))
261 return -EINVAL;
262 return do_shmat (first, (char __user *) ptr,
263 second, (ulong *) third);
265 case SHMDT:
266 return sys_shmdt ((char __user *)ptr);
267 case SHMGET:
268 return sys_shmget (first, second, third);
269 case SHMCTL:
270 return sys_shmctl (first, second,
271 (struct shmid_ds __user *) ptr);
272 default:
273 return -EINVAL;
276 return -EINVAL;
279 asmlinkage int sys_uname(struct old_utsname * name)
281 int err;
282 if (!name)
283 return -EFAULT;
284 down_read(&uts_sem);
285 err = copy_to_user(name, utsname(), sizeof (*name));
286 up_read(&uts_sem);
287 return err?-EFAULT:0;
290 asmlinkage ssize_t sys_pread_wrapper(unsigned int fd, char * buf,
291 size_t count, long dummy, loff_t pos)
293 return sys_pread64(fd, buf, count, pos);
296 asmlinkage ssize_t sys_pwrite_wrapper(unsigned int fd, const char * buf,
297 size_t count, long dummy, loff_t pos)
299 return sys_pwrite64(fd, buf, count, pos);
302 asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1,
303 u32 len0, u32 len1, int advice)
305 #ifdef __LITTLE_ENDIAN__
306 return sys_fadvise64_64(fd, (u64)offset1 << 32 | offset0,
307 (u64)len1 << 32 | len0, advice);
308 #else
309 return sys_fadvise64_64(fd, (u64)offset0 << 32 | offset1,
310 (u64)len0 << 32 | len1, advice);
311 #endif
315 * Do a system call from kernel instead of calling sys_execve so we
316 * end up with proper pt_regs.
318 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
320 register long __sc0 __asm__ ("r3") = __NR_execve;
321 register long __sc4 __asm__ ("r4") = (long) filename;
322 register long __sc5 __asm__ ("r5") = (long) argv;
323 register long __sc6 __asm__ ("r6") = (long) envp;
324 __asm__ __volatile__ ("trapa #0x13" : "=z" (__sc0)
325 : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6)
326 : "memory");
327 return __sc0;