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.
10 #include <linux/errno.h>
11 #include <linux/sched.h>
13 #include <linux/smp.h>
14 #include <linux/sem.h>
15 #include <linux/msg.h>
16 #include <linux/shm.h>
17 #include <linux/stat.h>
18 #include <linux/syscalls.h>
19 #include <linux/mman.h>
20 #include <linux/file.h>
21 #include <linux/utsname.h>
22 #include <linux/module.h>
24 #include <linux/ipc.h>
25 #include <asm/cacheflush.h>
26 #include <asm/syscalls.h>
27 #include <asm/uaccess.h>
28 #include <asm/unistd.h>
30 unsigned long shm_align_mask
= PAGE_SIZE
- 1; /* Sane caches */
31 EXPORT_SYMBOL(shm_align_mask
);
35 * To avoid cache aliases, we map the shared page with same color.
37 #define COLOUR_ALIGN(addr, pgoff) \
38 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
39 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
41 unsigned long arch_get_unmapped_area(struct file
*filp
, unsigned long addr
,
42 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
44 struct mm_struct
*mm
= current
->mm
;
45 struct vm_area_struct
*vma
;
46 unsigned long start_addr
;
49 if (flags
& MAP_FIXED
) {
50 /* We do not accept a shared mapping if it would violate
51 * cache aliasing constraints.
53 if ((flags
& MAP_SHARED
) && (addr
& shm_align_mask
))
58 if (unlikely(len
> TASK_SIZE
))
62 if (filp
|| (flags
& MAP_SHARED
))
67 addr
= COLOUR_ALIGN(addr
, pgoff
);
69 addr
= PAGE_ALIGN(addr
);
71 vma
= find_vma(mm
, addr
);
72 if (TASK_SIZE
- len
>= addr
&&
73 (!vma
|| addr
+ len
<= vma
->vm_start
))
77 if (len
> mm
->cached_hole_size
) {
78 start_addr
= addr
= mm
->free_area_cache
;
80 mm
->cached_hole_size
= 0;
81 start_addr
= addr
= TASK_UNMAPPED_BASE
;
86 addr
= COLOUR_ALIGN(addr
, pgoff
);
88 addr
= PAGE_ALIGN(mm
->free_area_cache
);
90 for (vma
= find_vma(mm
, addr
); ; vma
= vma
->vm_next
) {
91 /* At this point: (!vma || addr < vma->vm_end). */
92 if (unlikely(TASK_SIZE
- len
< addr
)) {
94 * Start a new search - just in case we missed
97 if (start_addr
!= TASK_UNMAPPED_BASE
) {
98 start_addr
= addr
= TASK_UNMAPPED_BASE
;
99 mm
->cached_hole_size
= 0;
104 if (likely(!vma
|| addr
+ len
<= vma
->vm_start
)) {
106 * Remember the place where we stopped the search:
108 mm
->free_area_cache
= addr
+ len
;
111 if (addr
+ mm
->cached_hole_size
< vma
->vm_start
)
112 mm
->cached_hole_size
= vma
->vm_start
- addr
;
116 addr
= COLOUR_ALIGN(addr
, pgoff
);
119 #endif /* CONFIG_MMU */
122 do_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
123 unsigned long flags
, int fd
, unsigned long pgoff
)
126 struct file
*file
= NULL
;
128 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
129 if (!(flags
& MAP_ANONYMOUS
)) {
135 down_write(¤t
->mm
->mmap_sem
);
136 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
137 up_write(¤t
->mm
->mmap_sem
);
145 asmlinkage
int old_mmap(unsigned long addr
, unsigned long len
,
146 unsigned long prot
, unsigned long flags
,
147 int fd
, unsigned long off
)
149 if (off
& ~PAGE_MASK
)
151 return do_mmap2(addr
, len
, prot
, flags
, fd
, off
>>PAGE_SHIFT
);
154 asmlinkage
long sys_mmap2(unsigned long addr
, unsigned long len
,
155 unsigned long prot
, unsigned long flags
,
156 unsigned long fd
, unsigned long pgoff
)
158 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
);
162 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
164 * This is really horribly ugly.
166 asmlinkage
int sys_ipc(uint call
, int first
, int second
,
167 int third
, void __user
*ptr
, long fifth
)
171 version
= call
>> 16; /* hack for backward compatibility */
174 trace_mark(kernel_arch_ipc_call
, "call %u first %d", call
, first
);
176 if (call
<= SEMTIMEDOP
)
179 return sys_semtimedop(first
,
180 (struct sembuf __user
*)ptr
,
183 return sys_semtimedop(first
,
184 (struct sembuf __user
*)ptr
, second
,
185 (const struct timespec __user
*)fifth
);
187 return sys_semget (first
, second
, third
);
192 if (get_user(fourth
.__pad
, (void __user
* __user
*) ptr
))
194 return sys_semctl (first
, second
, third
, fourth
);
203 return sys_msgsnd (first
, (struct msgbuf __user
*) ptr
,
209 struct ipc_kludge tmp
;
214 if (copy_from_user(&tmp
,
215 (struct ipc_kludge __user
*) ptr
,
219 return sys_msgrcv (first
, tmp
.msgp
, second
,
223 return sys_msgrcv (first
,
224 (struct msgbuf __user
*) ptr
,
225 second
, fifth
, third
);
228 return sys_msgget ((key_t
) first
, second
);
230 return sys_msgctl (first
, second
,
231 (struct msqid_ds __user
*) ptr
);
241 ret
= do_shmat (first
, (char __user
*) ptr
,
245 return put_user (raddr
, (ulong __user
*) third
);
247 case 1: /* iBCS2 emulator entry point */
248 if (!segment_eq(get_fs(), get_ds()))
250 return do_shmat (first
, (char __user
*) ptr
,
251 second
, (ulong
*) third
);
254 return sys_shmdt ((char __user
*)ptr
);
256 return sys_shmget (first
, second
, third
);
258 return sys_shmctl (first
, second
,
259 (struct shmid_ds __user
*) ptr
);
267 asmlinkage
int sys_uname(struct old_utsname __user
*name
)
273 err
= copy_to_user(name
, utsname(), sizeof(*name
));
275 return err
?-EFAULT
:0;