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
8 * Taken from i386 version.
11 #include <linux/errno.h>
12 #include <linux/sched.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>
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,
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;
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))
77 if (unlikely(len > TASK_SIZE))
81 if (filp || (flags & MAP_SHARED))
86 addr = COLOUR_ALIGN(addr, pgoff);
88 addr = PAGE_ALIGN(addr);
90 vma = find_vma(mm, addr);
91 if (TASK_SIZE - len >= addr &&
92 (!vma || addr + len <= vma->vm_start))
96 if (len > mm->cached_hole_size) {
97 start_addr = addr = mm->free_area_cache;
99 mm->cached_hole_size = 0;
100 start_addr = addr = TASK_UNMAPPED_BASE;
105 addr = COLOUR_ALIGN(addr, pgoff);
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
116 if (start_addr != TASK_UNMAPPED_BASE) {
117 start_addr = addr = TASK_UNMAPPED_BASE;
118 mm->cached_hole_size = 0;
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;
130 if (addr + mm->cached_hole_size < vma->vm_start)
131 mm->cached_hole_size = vma->vm_start - addr;
135 addr = COLOUR_ALIGN(addr, pgoff);
140 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
141 unsigned long flags, int fd, unsigned long pgoff)
144 struct file *file = NULL;
146 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
147 if (!(flags & MAP_ANONYMOUS)) {
153 down_write(¤t->mm->mmap_sem);
154 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
155 up_write(¤t->mm->mmap_sem);
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)
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)
189 version = call >> 16; /* hack for backward compatibility */
195 return sys_semtimedop(first, (struct sembuf __user *)ptr,
198 return sys_semtimedop(first, (struct sembuf __user *)ptr,
200 (const struct timespec __user *)fifth);
202 return sys_semget (first, second, third);
207 if (get_user(fourth.__pad, (void * __user *) ptr))
209 return sys_semctl (first, second, third, fourth);
218 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
223 struct ipc_kludge tmp;
227 if (copy_from_user(&tmp,
228 (struct ipc_kludge __user *) ptr,
231 return sys_msgrcv (first, tmp.msgp, second,
235 return sys_msgrcv (first,
236 (struct msgbuf __user *) ptr,
237 second, fifth, third);
240 return sys_msgget ((key_t) first, second);
242 return sys_msgctl (first, second,
243 (struct msqid_ds __user *) ptr);
253 ret = do_shmat (first, (char __user *) ptr,
257 return put_user (raddr, (ulong __user *) third);
259 case 1: /* iBCS2 emulator entry point */
260 if (!segment_eq(get_fs(), get_ds()))
262 return do_shmat (first, (char __user *) ptr,
263 second, (ulong *) third);
266 return sys_shmdt ((char __user *)ptr);
268 return sys_shmget (first, second, third);
270 return sys_shmctl (first, second,
271 (struct shmid_ds __user *) ptr);
279 asmlinkage int sys_uname(struct old_utsname * name)
285 err = copy_to_user(name, utsname(), sizeof (*name));
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);
309 return sys_fadvise64_64(fd, (u64)offset0 << 32 | offset1,
310 (u64)len0 << 32 | len1, advice);
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)