Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * arch/xtensa/kernel/syscall.c |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
| 8 | * Copyright (C) 2001 - 2005 Tensilica Inc. |
| 9 | * Copyright (C) 2000 Silicon Graphics, Inc. |
| 10 | * Copyright (C) 1995 - 2000 by Ralf Baechle |
| 11 | * |
| 12 | * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com> |
| 13 | * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca> |
| 14 | * Chris Zankel <chris@zankel.net> |
| 15 | * Kevin Chea |
| 16 | * |
| 17 | */ |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 18 | #include <linux/uaccess.h> |
Chris Zankel | 1c0350b | 2006-12-13 00:34:32 -0800 | [diff] [blame] | 19 | #include <asm/syscall.h> |
Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 20 | #include <asm/unistd.h> |
| 21 | #include <linux/linkage.h> |
| 22 | #include <linux/stringify.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/syscalls.h> |
| 25 | #include <linux/file.h> |
| 26 | #include <linux/fs.h> |
| 27 | #include <linux/mman.h> |
Ingo Molnar | 0104260 | 2017-02-08 18:51:31 +0100 | [diff] [blame] | 28 | #include <linux/sched/mm.h> |
Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 29 | #include <linux/shm.h> |
| 30 | |
Firoz Khan | a86067f | 2018-11-13 15:49:28 +0530 | [diff] [blame] | 31 | syscall_t sys_call_table[__NR_syscalls] /* FIXME __cacheline_aligned */= { |
| 32 | [0 ... __NR_syscalls - 1] = (syscall_t)&sys_ni_syscall, |
Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 33 | |
Firoz Khan | 5eacadb | 2018-11-13 15:49:30 +0530 | [diff] [blame] | 34 | #define __SYSCALL(nr, entry, nargs)[nr] = (syscall_t)entry, |
| 35 | #include <asm/syscall_table.h> |
| 36 | #undef __SYSCALL |
Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
Max Filippov | de73b6b | 2012-12-22 06:35:04 +0400 | [diff] [blame] | 39 | #define COLOUR_ALIGN(addr, pgoff) \ |
| 40 | ((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \ |
| 41 | (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1))) |
| 42 | |
Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 43 | asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) |
| 44 | { |
| 45 | unsigned long ret; |
| 46 | long err; |
| 47 | |
Will Deacon | 079a96a | 2012-07-30 14:42:38 -0700 | [diff] [blame] | 48 | err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA); |
Chris Zankel | fc4fb2a | 2006-12-10 02:18:52 -0800 | [diff] [blame] | 49 | if (err) |
| 50 | return err; |
| 51 | return (long)ret; |
| 52 | } |
| 53 | |
Chris Zankel | 2f72d4f | 2012-10-23 20:17:05 -0700 | [diff] [blame] | 54 | asmlinkage long xtensa_fadvise64_64(int fd, int advice, |
| 55 | unsigned long long offset, unsigned long long len) |
Chris Zankel | bc671aa | 2007-08-05 10:22:58 -0700 | [diff] [blame] | 56 | { |
Dominik Brodowski | 9d5b7c9 | 2018-03-11 11:34:45 +0100 | [diff] [blame] | 57 | return ksys_fadvise64_64(fd, offset, len, advice); |
Chris Zankel | bc671aa | 2007-08-05 10:22:58 -0700 | [diff] [blame] | 58 | } |
Max Filippov | de73b6b | 2012-12-22 06:35:04 +0400 | [diff] [blame] | 59 | |
Max Filippov | d10fa7c | 2014-09-22 07:21:48 +0400 | [diff] [blame] | 60 | #ifdef CONFIG_MMU |
Max Filippov | de73b6b | 2012-12-22 06:35:04 +0400 | [diff] [blame] | 61 | unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, |
| 62 | unsigned long len, unsigned long pgoff, unsigned long flags) |
| 63 | { |
| 64 | struct vm_area_struct *vmm; |
| 65 | |
| 66 | if (flags & MAP_FIXED) { |
| 67 | /* We do not accept a shared mapping if it would violate |
| 68 | * cache aliasing constraints. |
| 69 | */ |
| 70 | if ((flags & MAP_SHARED) && |
| 71 | ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))) |
| 72 | return -EINVAL; |
| 73 | return addr; |
| 74 | } |
| 75 | |
| 76 | if (len > TASK_SIZE) |
| 77 | return -ENOMEM; |
| 78 | if (!addr) |
| 79 | addr = TASK_UNMAPPED_BASE; |
| 80 | |
| 81 | if (flags & MAP_SHARED) |
| 82 | addr = COLOUR_ALIGN(addr, pgoff); |
| 83 | else |
| 84 | addr = PAGE_ALIGN(addr); |
| 85 | |
| 86 | for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) { |
| 87 | /* At this point: (!vmm || addr < vmm->vm_end). */ |
| 88 | if (TASK_SIZE - len < addr) |
| 89 | return -ENOMEM; |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 90 | if (!vmm || addr + len <= vm_start_gap(vmm)) |
Max Filippov | de73b6b | 2012-12-22 06:35:04 +0400 | [diff] [blame] | 91 | return addr; |
| 92 | addr = vmm->vm_end; |
| 93 | if (flags & MAP_SHARED) |
| 94 | addr = COLOUR_ALIGN(addr, pgoff); |
| 95 | } |
| 96 | } |
Max Filippov | d10fa7c | 2014-09-22 07:21:48 +0400 | [diff] [blame] | 97 | #endif |