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/uaccess.h>
27 #include <asm/unistd.h>
29 unsigned long shm_align_mask
= PAGE_SIZE
- 1; /* Sane caches */
30 EXPORT_SYMBOL(shm_align_mask
);
34 * To avoid cache aliases, we map the shared page with same color.
36 #define COLOUR_ALIGN(addr, pgoff) \
37 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
38 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
40 unsigned long arch_get_unmapped_area(struct file
*filp
, unsigned long addr
,
41 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
43 struct mm_struct
*mm
= current
->mm
;
44 struct vm_area_struct
*vma
;
45 unsigned long start_addr
;
48 if (flags
& MAP_FIXED
) {
49 /* We do not accept a shared mapping if it would violate
50 * cache aliasing constraints.
52 if ((flags
& MAP_SHARED
) && (addr
& shm_align_mask
))
57 if (unlikely(len
> TASK_SIZE
))
61 if (filp
|| (flags
& MAP_SHARED
))
66 addr
= COLOUR_ALIGN(addr
, pgoff
);
68 addr
= PAGE_ALIGN(addr
);
70 vma
= find_vma(mm
, addr
);
71 if (TASK_SIZE
- len
>= addr
&&
72 (!vma
|| addr
+ len
<= vma
->vm_start
))
76 if (len
> mm
->cached_hole_size
) {
77 start_addr
= addr
= mm
->free_area_cache
;
79 mm
->cached_hole_size
= 0;
80 start_addr
= addr
= TASK_UNMAPPED_BASE
;
85 addr
= COLOUR_ALIGN(addr
, pgoff
);
87 addr
= PAGE_ALIGN(mm
->free_area_cache
);
89 for (vma
= find_vma(mm
, addr
); ; vma
= vma
->vm_next
) {
90 /* At this point: (!vma || addr < vma->vm_end). */
91 if (unlikely(TASK_SIZE
- len
< addr
)) {
93 * Start a new search - just in case we missed
96 if (start_addr
!= TASK_UNMAPPED_BASE
) {
97 start_addr
= addr
= TASK_UNMAPPED_BASE
;
98 mm
->cached_hole_size
= 0;
103 if (likely(!vma
|| addr
+ len
<= vma
->vm_start
)) {
105 * Remember the place where we stopped the search:
107 mm
->free_area_cache
= addr
+ len
;
110 if (addr
+ mm
->cached_hole_size
< vma
->vm_start
)
111 mm
->cached_hole_size
= vma
->vm_start
- addr
;
115 addr
= COLOUR_ALIGN(addr
, pgoff
);
118 #endif /* CONFIG_MMU */
121 do_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
122 unsigned long flags
, int fd
, unsigned long pgoff
)
125 struct file
*file
= NULL
;
127 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
128 if (!(flags
& MAP_ANONYMOUS
)) {
134 down_write(¤t
->mm
->mmap_sem
);
135 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
136 up_write(¤t
->mm
->mmap_sem
);
144 asmlinkage
int old_mmap(unsigned long addr
, unsigned long len
,
145 unsigned long prot
, unsigned long flags
,
146 int fd
, unsigned long off
)
148 if (off
& ~PAGE_MASK
)
150 return do_mmap2(addr
, len
, prot
, flags
, fd
, off
>>PAGE_SHIFT
);
153 asmlinkage
long sys_mmap2(unsigned long addr
, unsigned long len
,
154 unsigned long prot
, unsigned long flags
,
155 unsigned long fd
, unsigned long pgoff
)
157 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
);
161 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
163 * This is really horribly ugly.
165 asmlinkage
int sys_ipc(uint call
, int first
, int second
,
166 int third
, void __user
*ptr
, long fifth
)
170 version
= call
>> 16; /* hack for backward compatibility */
176 return sys_semtimedop(first
,
177 (struct sembuf __user
*)ptr
,
180 return sys_semtimedop(first
,
181 (struct sembuf __user
*)ptr
, second
,
182 (const struct timespec __user
*)fifth
);
184 return sys_semget (first
, second
, third
);
189 if (get_user(fourth
.__pad
, (void * __user
*) ptr
))
191 return sys_semctl (first
, second
, third
, fourth
);
200 return sys_msgsnd (first
, (struct msgbuf __user
*) ptr
,
206 struct ipc_kludge tmp
;
211 if (copy_from_user(&tmp
,
212 (struct ipc_kludge __user
*) ptr
,
216 return sys_msgrcv (first
, tmp
.msgp
, second
,
220 return sys_msgrcv (first
,
221 (struct msgbuf __user
*) ptr
,
222 second
, fifth
, third
);
225 return sys_msgget ((key_t
) first
, second
);
227 return sys_msgctl (first
, second
,
228 (struct msqid_ds __user
*) ptr
);
238 ret
= do_shmat (first
, (char __user
*) ptr
,
242 return put_user (raddr
, (ulong __user
*) third
);
244 case 1: /* iBCS2 emulator entry point */
245 if (!segment_eq(get_fs(), get_ds()))
247 return do_shmat (first
, (char __user
*) ptr
,
248 second
, (ulong
*) third
);
251 return sys_shmdt ((char __user
*)ptr
);
253 return sys_shmget (first
, second
, third
);
255 return sys_shmctl (first
, second
,
256 (struct shmid_ds __user
*) ptr
);
264 asmlinkage
int sys_uname(struct old_utsname
* name
)
270 err
= copy_to_user(name
, utsname(), sizeof (*name
));
272 return err
?-EFAULT
:0;