~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sh/kernel/sys_sh.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.14 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.57 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.138 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.193 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/arch/sh/kernel/sys_sh.c
  3  *
  4  * This file contains various random system calls that
  5  * have a non-standard calling sequence on the Linux/SuperH
  6  * platform.
  7  *
  8  * Taken from i386 version.
  9  */
 10 
 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/mman.h>
 21 #include <linux/file.h>
 22 #include <linux/utsname.h>
 23 
 24 #include <asm/uaccess.h>
 25 #include <asm/ipc.h>
 26 
 27 /*
 28  * sys_pipe() is the normal C calling standard for creating
 29  * a pipe. It's not the way Unix traditionally does this, though.
 30  */
 31 asmlinkage int sys_pipe(unsigned long r4, unsigned long r5,
 32         unsigned long r6, unsigned long r7,
 33         struct pt_regs regs)
 34 {
 35         int fd[2];
 36         int error;
 37 
 38         error = do_pipe(fd);
 39         if (!error) {
 40                 regs.regs[1] = fd[1];
 41                 return fd[0];
 42         }
 43         return error;
 44 }
 45 
 46 #if defined(CONFIG_CPU_SH4)
 47 /*
 48  * To avoid cache alias, we map the shard page with same color.
 49  */
 50 #define COLOUR_ALIGN(addr)      (((addr)+SHMLBA-1)&~(SHMLBA-1))
 51 
 52 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
 53         unsigned long len, unsigned long pgoff, unsigned long flags)
 54 {
 55         struct vm_area_struct *vma;
 56 
 57         if (flags & MAP_FIXED) {
 58                 /* We do not accept a shared mapping if it would violate
 59                  * cache aliasing constraints.
 60                  */
 61                 if ((flags & MAP_SHARED) && (addr & (SHMLBA - 1)))
 62                         return -EINVAL;
 63                 return addr;
 64         }
 65 
 66         if (len > TASK_SIZE)
 67                 return -ENOMEM;
 68         if (!addr)
 69                 addr = TASK_UNMAPPED_BASE;
 70 
 71         if (flags & MAP_PRIVATE)
 72                 addr = PAGE_ALIGN(addr);
 73         else
 74                 addr = COLOUR_ALIGN(addr);
 75 
 76         for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
 77                 /* At this point:  (!vma || addr < vma->vm_end). */
 78                 if (TASK_SIZE - len < addr)
 79                         return -ENOMEM;
 80                 if (!vma || addr + len <= vma->vm_start)
 81                         return addr;
 82                 addr = vma->vm_end;
 83                 if (!(flags & MAP_PRIVATE))
 84                         addr = COLOUR_ALIGN(addr);
 85         }
 86 }
 87 #endif
 88 
 89 static inline long
 90 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, 
 91          unsigned long flags, int fd, unsigned long pgoff)
 92 {
 93         int error = -EBADF;
 94         struct file *file = NULL;
 95 
 96         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 97         if (!(flags & MAP_ANONYMOUS)) {
 98                 file = fget(fd);
 99                 if (!file)
100                         goto out;
101         }
102 
103         down_write(&current->mm->mmap_sem);
104         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
105         up_write(&current->mm->mmap_sem);
106 
107         if (file)
108                 fput(file);
109 out:
110         return error;
111 }
112 
113 asmlinkage int old_mmap(unsigned long addr, unsigned long len,
114         unsigned long prot, unsigned long flags,
115         int fd, unsigned long off)
116 {
117         if (off & ~PAGE_MASK)
118                 return -EINVAL;
119         return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
120 }
121 
122 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
123         unsigned long prot, unsigned long flags,
124         unsigned long fd, unsigned long pgoff)
125 {
126         return do_mmap2(addr, len, prot, flags, fd, pgoff);
127 }
128 
129 /*
130  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
131  *
132  * This is really horribly ugly.
133  */
134 asmlinkage int sys_ipc(uint call, int first, int second,
135                        int third, void *ptr, long fifth)
136 {
137         int version, ret;
138 
139         version = call >> 16; /* hack for backward compatibility */
140         call &= 0xffff;
141 
142         if (call <= SEMCTL)
143                 switch (call) {
144                 case SEMOP:
145                         return sys_semtimedop(first, (struct sembuf *)ptr,
146                                               second, NULL);
147                 case SEMTIMEDOP:
148                         return sys_semtimedop(first, (struct sembuf *)ptr,
149                                               second,
150                                               (const struct timespec *)fifth);
151                 case SEMGET:
152                         return sys_semget (first, second, third);
153                 case SEMCTL: {
154                         union semun fourth;
155                         if (!ptr)
156                                 return -EINVAL;
157                         if (get_user(fourth.__pad, (void **) ptr))
158                                 return -EFAULT;
159                         return sys_semctl (first, second, third, fourth);
160                         }
161                 default:
162                         return -EINVAL;
163                 }
164 
165         if (call <= MSGCTL) 
166                 switch (call) {
167                 case MSGSND:
168                         return sys_msgsnd (first, (struct msgbuf *) ptr, 
169                                           second, third);
170                 case MSGRCV:
171                         switch (version) {
172                         case 0: {
173                                 struct ipc_kludge tmp;
174                                 if (!ptr)
175                                         return -EINVAL;
176                                 
177                                 if (copy_from_user(&tmp,
178                                                    (struct ipc_kludge *) ptr, 
179                                                    sizeof (tmp)))
180                                         return -EFAULT;
181                                 return sys_msgrcv (first, tmp.msgp, second,
182                                                    tmp.msgtyp, third);
183                                 }
184                         default:
185                                 return sys_msgrcv (first,
186                                                    (struct msgbuf *) ptr,
187                                                    second, fifth, third);
188                         }
189                 case MSGGET:
190                         return sys_msgget ((key_t) first, second);
191                 case MSGCTL:
192                         return sys_msgctl (first, second,
193                                            (struct msqid_ds *) ptr);
194                 default:
195                         return -EINVAL;
196                 }
197         if (call <= SHMCTL) 
198                 switch (call) {
199                 case SHMAT:
200                         switch (version) {
201                         default: {
202                                 ulong raddr;
203                                 ret = sys_shmat (first, (char *) ptr,
204                                                  second, &raddr);
205                                 if (ret)
206                                         return ret;
207                                 return put_user (raddr, (ulong *) third);
208                         }
209                         case 1: /* iBCS2 emulator entry point */
210                                 if (!segment_eq(get_fs(), get_ds()))
211                                         return -EINVAL;
212                                 return sys_shmat (first, (char *) ptr,
213                                                   second, (ulong *) third);
214                         }
215                 case SHMDT: 
216                         return sys_shmdt ((char *)ptr);
217                 case SHMGET:
218                         return sys_shmget (first, second, third);
219                 case SHMCTL:
220                         return sys_shmctl (first, second,
221                                            (struct shmid_ds *) ptr);
222                 default:
223                         return -EINVAL;
224                 }
225         
226         return -EINVAL;
227 }
228 
229 asmlinkage int sys_uname(struct old_utsname * name)
230 {
231         int err;
232         if (!name)
233                 return -EFAULT;
234         down_read(&uts_sem);
235         err=copy_to_user(name, &system_utsname, sizeof (*name));
236         up_read(&uts_sem);
237         return err?-EFAULT:0;
238 }
239 
240 asmlinkage ssize_t sys_pread_wrapper(unsigned int fd, char * buf,
241                              size_t count, long dummy, loff_t pos)
242 {
243         extern asmlinkage ssize_t sys_pread64(unsigned int fd, char * buf,
244                                         size_t count, loff_t pos);
245         return sys_pread64(fd, buf, count, pos);
246 }
247 
248 asmlinkage ssize_t sys_pwrite_wrapper(unsigned int fd, const char * buf,
249                               size_t count, long dummy, loff_t pos)
250 {
251         extern asmlinkage ssize_t sys_pwrite64(unsigned int fd, const char * buf,
252                                         size_t count, loff_t pos);
253         return sys_pwrite64(fd, buf, count, pos);
254 }
255 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp