xref: /linux-6.15/arch/xtensa/kernel/syscall.c (revision 25d4054c)
1fc4fb2adSChris Zankel /*
2fc4fb2adSChris Zankel  * arch/xtensa/kernel/syscall.c
3fc4fb2adSChris Zankel  *
4fc4fb2adSChris Zankel  * This file is subject to the terms and conditions of the GNU General Public
5fc4fb2adSChris Zankel  * License.  See the file "COPYING" in the main directory of this archive
6fc4fb2adSChris Zankel  * for more details.
7fc4fb2adSChris Zankel  *
8fc4fb2adSChris Zankel  * Copyright (C) 2001 - 2005 Tensilica Inc.
9fc4fb2adSChris Zankel  * Copyright (C) 2000 Silicon Graphics, Inc.
10fc4fb2adSChris Zankel  * Copyright (C) 1995 - 2000 by Ralf Baechle
11fc4fb2adSChris Zankel  *
12fc4fb2adSChris Zankel  * Joe Taylor <[email protected], [email protected]>
13fc4fb2adSChris Zankel  * Marc Gauthier <[email protected], [email protected]>
14fc4fb2adSChris Zankel  * Chris Zankel <[email protected]>
15fc4fb2adSChris Zankel  * Kevin Chea
16fc4fb2adSChris Zankel  *
17fc4fb2adSChris Zankel  */
187c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
191c0350bdSChris Zankel #include <asm/syscall.h>
20fc4fb2adSChris Zankel #include <linux/linkage.h>
21fc4fb2adSChris Zankel #include <linux/stringify.h>
22fc4fb2adSChris Zankel #include <linux/errno.h>
23fc4fb2adSChris Zankel #include <linux/syscalls.h>
24fc4fb2adSChris Zankel #include <linux/file.h>
25fc4fb2adSChris Zankel #include <linux/fs.h>
26fc4fb2adSChris Zankel #include <linux/mman.h>
2701042607SIngo Molnar #include <linux/sched/mm.h>
28fc4fb2adSChris Zankel #include <linux/shm.h>
29fc4fb2adSChris Zankel 
308d949ae2SMasahiro Yamada syscall_t sys_call_table[] /* FIXME __cacheline_aligned */= {
31daf26180SMasahiro Yamada #define __SYSCALL(nr, entry)	(syscall_t)entry,
325eacadb5SFiroz Khan #include <asm/syscall_table.h>
33fc4fb2adSChris Zankel };
34fc4fb2adSChris Zankel 
35de73b6b1SMax Filippov #define COLOUR_ALIGN(addr, pgoff) \
36de73b6b1SMax Filippov 	((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
37de73b6b1SMax Filippov 	 (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
38de73b6b1SMax Filippov 
xtensa_shmat(int shmid,char __user * shmaddr,int shmflg)39fc4fb2adSChris Zankel asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
40fc4fb2adSChris Zankel {
41fc4fb2adSChris Zankel 	unsigned long ret;
42fc4fb2adSChris Zankel 	long err;
43fc4fb2adSChris Zankel 
44079a96aeSWill Deacon 	err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
45fc4fb2adSChris Zankel 	if (err)
46fc4fb2adSChris Zankel 		return err;
47fc4fb2adSChris Zankel 	return (long)ret;
48fc4fb2adSChris Zankel }
49fc4fb2adSChris Zankel 
xtensa_fadvise64_64(int fd,int advice,unsigned long long offset,unsigned long long len)502f72d4f6SChris Zankel asmlinkage long xtensa_fadvise64_64(int fd, int advice,
512f72d4f6SChris Zankel 		unsigned long long offset, unsigned long long len)
52bc671aa9SChris Zankel {
539d5b7c95SDominik Brodowski 	return ksys_fadvise64_64(fd, offset, len, advice);
54bc671aa9SChris Zankel }
55de73b6b1SMax Filippov 
56d10fa7cfSMax Filippov #ifdef CONFIG_MMU
arch_get_unmapped_area(struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags,vm_flags_t vm_flags)57de73b6b1SMax Filippov unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
58*25d4054cSMark Brown 		unsigned long len, unsigned long pgoff, unsigned long flags,
59*25d4054cSMark Brown 		vm_flags_t vm_flags)
60de73b6b1SMax Filippov {
61de73b6b1SMax Filippov 	struct vm_area_struct *vmm;
6249c40fb4SMatthew Wilcox (Oracle) 	struct vma_iterator vmi;
63de73b6b1SMax Filippov 
64de73b6b1SMax Filippov 	if (flags & MAP_FIXED) {
65de73b6b1SMax Filippov 		/* We do not accept a shared mapping if it would violate
66de73b6b1SMax Filippov 		 * cache aliasing constraints.
67de73b6b1SMax Filippov 		 */
68de73b6b1SMax Filippov 		if ((flags & MAP_SHARED) &&
69de73b6b1SMax Filippov 				((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
70de73b6b1SMax Filippov 			return -EINVAL;
71de73b6b1SMax Filippov 		return addr;
72de73b6b1SMax Filippov 	}
73de73b6b1SMax Filippov 
74de73b6b1SMax Filippov 	if (len > TASK_SIZE)
75de73b6b1SMax Filippov 		return -ENOMEM;
76de73b6b1SMax Filippov 	if (!addr)
77de73b6b1SMax Filippov 		addr = TASK_UNMAPPED_BASE;
78de73b6b1SMax Filippov 
79de73b6b1SMax Filippov 	if (flags & MAP_SHARED)
80de73b6b1SMax Filippov 		addr = COLOUR_ALIGN(addr, pgoff);
81de73b6b1SMax Filippov 	else
82de73b6b1SMax Filippov 		addr = PAGE_ALIGN(addr);
83de73b6b1SMax Filippov 
8449c40fb4SMatthew Wilcox (Oracle) 	vma_iter_init(&vmi, current->mm, addr);
8549c40fb4SMatthew Wilcox (Oracle) 	for_each_vma(vmi, vmm) {
8649c40fb4SMatthew Wilcox (Oracle) 		/* At this point:  (addr < vmm->vm_end). */
8749c40fb4SMatthew Wilcox (Oracle) 		if (addr + len <= vm_start_gap(vmm))
8849c40fb4SMatthew Wilcox (Oracle) 			break;
8949c40fb4SMatthew Wilcox (Oracle) 
90de73b6b1SMax Filippov 		addr = vmm->vm_end;
91de73b6b1SMax Filippov 		if (flags & MAP_SHARED)
92de73b6b1SMax Filippov 			addr = COLOUR_ALIGN(addr, pgoff);
93de73b6b1SMax Filippov 	}
9449c40fb4SMatthew Wilcox (Oracle) 
9549c40fb4SMatthew Wilcox (Oracle) 	if (TASK_SIZE - len < addr)
9649c40fb4SMatthew Wilcox (Oracle) 		return -ENOMEM;
9749c40fb4SMatthew Wilcox (Oracle) 
9849c40fb4SMatthew Wilcox (Oracle) 	return addr;
99de73b6b1SMax Filippov }
100d10fa7cfSMax Filippov #endif
101