2 * linux/arch/parisc/kernel/sys_parisc.c
4 * this implements syscalls which are handled per-arch.
7 #include <asm/uaccess.h>
8 #include <linux/file.h>
10 #include <linux/linkage.h>
12 #include <linux/mman.h>
13 #include <linux/shm.h>
14 #include <linux/smp_lock.h>
16 int sys_pipe(int *fildes)
23 if (copy_to_user(fildes, fd, 2*sizeof(int)))
29 static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
31 struct vm_area_struct *vma;
33 addr = PAGE_ALIGN(addr);
35 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
36 /* At this point: (!vma || addr < vma->vm_end). */
37 if (TASK_SIZE - len < addr)
39 if (!vma || addr + len <= vma->vm_start)
45 #define DCACHE_ALIGN(addr) (((addr) + (SHMLBA - 1)) &~ (SHMLBA - 1))
48 * We need to know the offset to use. Old scheme was to look for
49 * existing mapping and use the same offset. New scheme is to use the
50 * address of the kernel data structure as the seed for the offset.
51 * We'll see how that works...
54 static int get_offset(struct address_space *mapping)
56 struct vm_area_struct *vma = list_entry(mapping->i_mmap_shared.next,
57 struct vm_area_struct, shared);
58 return (vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT)) &
62 /* The mapping is cacheline aligned, so there's no information in the bottom
63 * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's
64 * drop the bottom 8 bits and use bits 8-17.
66 static int get_offset(struct address_space *mapping)
68 int offset = (unsigned long) mapping << (PAGE_SHIFT - 8);
69 return offset & 0x3FF000;
73 static unsigned long get_shared_area(struct address_space *mapping,
74 unsigned long addr, unsigned long len, unsigned long pgoff)
76 struct vm_area_struct *vma;
77 int offset = get_offset(mapping);
79 addr = DCACHE_ALIGN(addr - offset) + offset;
81 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
82 /* At this point: (!vma || addr < vma->vm_end). */
83 if (TASK_SIZE - len < addr)
85 if (!vma || addr + len <= vma->vm_start)
87 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
88 if (addr < vma->vm_end) /* handle wraparound */
93 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
94 unsigned long len, unsigned long pgoff, unsigned long flags)
101 addr = TASK_UNMAPPED_BASE;
103 inode = filp ? filp->f_dentry->d_inode : NULL;
105 if (inode && (flags & MAP_SHARED)) {
106 addr = get_shared_area(inode->i_mapping, addr, len, pgoff);
108 addr = get_unshared_area(addr, len);
113 static unsigned long do_mmap2(unsigned long addr, unsigned long len,
114 unsigned long prot, unsigned long flags, unsigned long fd,
117 struct file * file = NULL;
118 unsigned long error = -EBADF;
119 if (!(flags & MAP_ANONYMOUS)) {
125 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
127 down_write(¤t->mm->mmap_sem);
128 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
129 up_write(¤t->mm->mmap_sem);
137 asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
138 unsigned long prot, unsigned long flags, unsigned long fd,
141 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
143 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12));
146 asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
147 unsigned long prot, unsigned long flags, unsigned long fd,
148 unsigned long offset)
150 if (!(offset & ~PAGE_MASK)) {
151 return do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
157 long sys_shmat_wrapper(int shmid, char *shmaddr, int shmflag)
162 r = sys_shmat(shmid, shmaddr, shmflag, &raddr);
168 /* Fucking broken ABI */
170 #ifdef CONFIG_PARISC64
171 extern asmlinkage long sys_truncate(const char *, unsigned long);
172 extern asmlinkage long sys_ftruncate(unsigned int, unsigned long);
173 extern asmlinkage long sys_fcntl(unsigned int, unsigned int, unsigned long);
175 asmlinkage long parisc_truncate64(const char * path,
176 unsigned int high, unsigned int low)
178 return sys_truncate(path, (long)high << 32 | low);
181 asmlinkage long parisc_ftruncate64(unsigned int fd,
182 unsigned int high, unsigned int low)
184 return sys_ftruncate(fd, (long)high << 32 | low);
187 /* stubs for the benefit of the syscall_table since truncate64 and truncate
188 * are identical on LP64 */
189 asmlinkage long sys_truncate64(const char * path, unsigned long length)
191 return sys_truncate(path, length);
193 asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
195 return sys_ftruncate(fd, length);
197 asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
199 return sys_fcntl(fd, cmd, arg);
203 extern asmlinkage long sys_truncate64(const char *, loff_t);
204 extern asmlinkage long sys_ftruncate64(unsigned int, loff_t);
206 asmlinkage long parisc_truncate64(const char * path,
207 unsigned int high, unsigned int low)
209 return sys_truncate64(path, (loff_t)high << 32 | low);
212 asmlinkage long parisc_ftruncate64(unsigned int fd,
213 unsigned int high, unsigned int low)
215 return sys_ftruncate64(fd, (loff_t)high << 32 | low);
219 extern asmlinkage ssize_t sys_pread64(unsigned int fd, char *buf,
220 size_t count, loff_t pos);
221 extern asmlinkage ssize_t sys_pwrite64(unsigned int fd, const char *buf,
222 size_t count, loff_t pos);
223 extern asmlinkage ssize_t sys_readahead(int fd, loff_t offset, size_t count);
225 asmlinkage ssize_t parisc_pread64(unsigned int fd, char *buf, size_t count,
226 unsigned int high, unsigned int low)
228 return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
231 asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char *buf,
232 size_t count, unsigned int high, unsigned int low)
234 return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
237 asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
240 return sys_readahead(fd, (loff_t)high << 32 | low, count);
244 * This changes the io permissions bitmap in the current task.
246 asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on)
251 asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
256 asmlinkage int sys_free_hugepages(unsigned long addr)