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/sem.h>
16 #include <linux/msg.h>
17 #include <linux/shm.h>
18 #include <linux/stat.h>
19 #include <linux/syscalls.h>
20 #include <linux/mman.h>
21 #include <linux/file.h>
22 #include <linux/utsname.h>
23 #include <linux/module.h>
24 #include <asm/cacheflush.h>
25 #include <asm/uaccess.h>
27 #include <asm/unistd.h>
30 * sys_pipe() is the normal C calling standard for creating
31 * a pipe. It's not the way Unix traditionally does this, though.
33 asmlinkage int sys_pipe(unsigned long r4, unsigned long r5,
34 unsigned long r6, unsigned long r7,
35 struct pt_regs __regs)
37 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
43 regs->regs[1] = fd[1];
49 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
51 EXPORT_SYMBOL(shm_align_mask);
55 * To avoid cache aliases, we map the shared page with same color.
57 #define COLOUR_ALIGN(addr, pgoff) \
58 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
59 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
61 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
62 unsigned long len, unsigned long pgoff, unsigned long flags)
64 struct mm_struct *mm = current->mm;
65 struct vm_area_struct *vma;
66 unsigned long start_addr;
69 if (flags & MAP_FIXED) {
70 /* We do not accept a shared mapping if it would violate
71 * cache aliasing constraints.
73 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
78 if (unlikely(len > TASK_SIZE))
82 if (filp || (flags & MAP_SHARED))
87 addr = COLOUR_ALIGN(addr, pgoff);
89 addr = PAGE_ALIGN(addr);
91 vma = find_vma(mm, addr);
92 if (TASK_SIZE - len >= addr &&
93 (!vma || addr + len <= vma->vm_start))
97 if (len > mm->cached_hole_size) {
98 start_addr = addr = mm->free_area_cache;
100 mm->cached_hole_size = 0;
101 start_addr = addr = TASK_UNMAPPED_BASE;
106 addr = COLOUR_ALIGN(addr, pgoff);
108 addr = PAGE_ALIGN(mm->free_area_cache);
110 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
111 /* At this point: (!vma || addr < vma->vm_end). */
112 if (unlikely(TASK_SIZE - len < addr)) {
114 * Start a new search - just in case we missed
117 if (start_addr != TASK_UNMAPPED_BASE) {
118 start_addr = addr = TASK_UNMAPPED_BASE;
119 mm->cached_hole_size = 0;
124 if (likely(!vma || addr + len <= vma->vm_start)) {
126 * Remember the place where we stopped the search:
128 mm->free_area_cache = addr + len;
131 if (addr + mm->cached_hole_size < vma->vm_start)
132 mm->cached_hole_size = vma->vm_start - addr;
136 addr = COLOUR_ALIGN(addr, pgoff);
139 #endif /* CONFIG_MMU */
142 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
143 unsigned long flags, int fd, unsigned long pgoff)
146 struct file *file = NULL;
148 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
149 if (!(flags & MAP_ANONYMOUS)) {
155 down_write(¤t->mm->mmap_sem);
156 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
157 up_write(¤t->mm->mmap_sem);
165 asmlinkage int old_mmap(unsigned long addr, unsigned long len,
166 unsigned long prot, unsigned long flags,
167 int fd, unsigned long off)
169 if (off & ~PAGE_MASK)
171 return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
174 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
175 unsigned long prot, unsigned long flags,
176 unsigned long fd, unsigned long pgoff)
178 return do_mmap2(addr, len, prot, flags, fd, pgoff);
182 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
184 * This is really horribly ugly.
186 asmlinkage int sys_ipc(uint call, int first, int second,
187 int third, void __user *ptr, long fifth)
191 version = call >> 16; /* hack for backward compatibility */
197 return sys_semtimedop(first, (struct sembuf __user *)ptr,
200 return sys_semtimedop(first, (struct sembuf __user *)ptr,
202 (const struct timespec __user *)fifth);
204 return sys_semget (first, second, third);
209 if (get_user(fourth.__pad, (void * __user *) ptr))
211 return sys_semctl (first, second, third, fourth);
220 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
225 struct ipc_kludge tmp;
229 if (copy_from_user(&tmp,
230 (struct ipc_kludge __user *) ptr,
233 return sys_msgrcv (first, tmp.msgp, second,
237 return sys_msgrcv (first,
238 (struct msgbuf __user *) ptr,
239 second, fifth, third);
242 return sys_msgget ((key_t) first, second);
244 return sys_msgctl (first, second,
245 (struct msqid_ds __user *) ptr);
255 ret = do_shmat (first, (char __user *) ptr,
259 return put_user (raddr, (ulong __user *) third);
261 case 1: /* iBCS2 emulator entry point */
262 if (!segment_eq(get_fs(), get_ds()))
264 return do_shmat (first, (char __user *) ptr,
265 second, (ulong *) third);
268 return sys_shmdt ((char __user *)ptr);
270 return sys_shmget (first, second, third);
272 return sys_shmctl (first, second,
273 (struct shmid_ds __user *) ptr);
281 asmlinkage int sys_uname(struct old_utsname * name)
287 err = copy_to_user(name, utsname(), sizeof (*name));
289 return err?-EFAULT:0;
292 asmlinkage ssize_t sys_pread_wrapper(unsigned int fd, char * buf,
293 size_t count, long dummy, loff_t pos)
295 return sys_pread64(fd, buf, count, pos);
298 asmlinkage ssize_t sys_pwrite_wrapper(unsigned int fd, const char * buf,
299 size_t count, long dummy, loff_t pos)
301 return sys_pwrite64(fd, buf, count, pos);
304 asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1,
305 u32 len0, u32 len1, int advice)
307 #ifdef __LITTLE_ENDIAN__
308 return sys_fadvise64_64(fd, (u64)offset1 << 32 | offset0,
309 (u64)len1 << 32 | len0, advice);
311 return sys_fadvise64_64(fd, (u64)offset0 << 32 | offset1,
312 (u64)len0 << 32 | len1, advice);
316 #if defined(CONFIG_CPU_SH2) || defined(CONFIG_CPU_SH2A)
317 #define SYSCALL_ARG3 "trapa #0x23"
319 #define SYSCALL_ARG3 "trapa #0x13"
323 * Do a system call from kernel instead of calling sys_execve so we
324 * end up with proper pt_regs.
326 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
328 register long __sc0 __asm__ ("r3") = __NR_execve;
329 register long __sc4 __asm__ ("r4") = (long) filename;
330 register long __sc5 __asm__ ("r5") = (long) argv;
331 register long __sc6 __asm__ ("r6") = (long) envp;
332 __asm__ __volatile__ (SYSCALL_ARG3 : "=z" (__sc0)
333 : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6)