xref: /openbmc/linux/arch/parisc/kernel/sys_parisc.c (revision b97d6790d03b763eca08847a9a5869a4291b9f9a)
11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds 
31da177e4SLinus Torvalds /*
41da177e4SLinus Torvalds  *    PARISC specific syscalls
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *    Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
71da177e4SLinus Torvalds  *    Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
81da177e4SLinus Torvalds  *    Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
944a4c9e4SHelge Deller  *    Copyright (C) 1999-2020 Helge Deller <deller@gmx.de>
101da177e4SLinus Torvalds  */
111da177e4SLinus Torvalds 
127c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
139dabf60dSHelge Deller #include <asm/elf.h>
141da177e4SLinus Torvalds #include <linux/file.h>
151da177e4SLinus Torvalds #include <linux/fs.h>
161da177e4SLinus Torvalds #include <linux/linkage.h>
171da177e4SLinus Torvalds #include <linux/mm.h>
181da177e4SLinus Torvalds #include <linux/mman.h>
193f07c014SIngo Molnar #include <linux/sched/signal.h>
2001042607SIngo Molnar #include <linux/sched/mm.h>
211da177e4SLinus Torvalds #include <linux/shm.h>
221da177e4SLinus Torvalds #include <linux/syscalls.h>
2375a49581SKyle McMartin #include <linux/utsname.h>
2475a49581SKyle McMartin #include <linux/personality.h>
259dabf60dSHelge Deller #include <linux/random.h>
2644a4c9e4SHelge Deller #include <linux/compat.h>
27b5d89408SHelge Deller #include <linux/elf-randomize.h>
281da177e4SLinus Torvalds 
29567b3515SJohn David Anglin /*
3056675f8bSHelge Deller  * Construct an artificial page offset for the mapping based on the physical
31567b3515SJohn David Anglin  * address of the kernel file mapping variable.
32567b3515SJohn David Anglin  */
3356675f8bSHelge Deller #define GET_FILP_PGOFF(filp)		\
3456675f8bSHelge Deller 	(filp ? (((unsigned long) filp->f_mapping) >> 8)	\
3556675f8bSHelge Deller 		 & ((SHM_COLOUR-1) >> PAGE_SHIFT) : 0UL)
369dabf60dSHelge Deller 
shared_align_offset(unsigned long filp_pgoff,unsigned long pgoff)37567b3515SJohn David Anglin static unsigned long shared_align_offset(unsigned long filp_pgoff,
389dabf60dSHelge Deller 					 unsigned long pgoff)
399dabf60dSHelge Deller {
40567b3515SJohn David Anglin 	return (filp_pgoff + pgoff) << PAGE_SHIFT;
419dabf60dSHelge Deller }
429dabf60dSHelge Deller 
COLOR_ALIGN(unsigned long addr,unsigned long filp_pgoff,unsigned long pgoff)439dabf60dSHelge Deller static inline unsigned long COLOR_ALIGN(unsigned long addr,
44567b3515SJohn David Anglin 			 unsigned long filp_pgoff, unsigned long pgoff)
459dabf60dSHelge Deller {
460ef36bd2SHelge Deller 	unsigned long base = (addr+SHM_COLOUR-1) & ~(SHM_COLOUR-1);
470ef36bd2SHelge Deller 	unsigned long off  = (SHM_COLOUR-1) &
48567b3515SJohn David Anglin 		shared_align_offset(filp_pgoff, pgoff);
499dabf60dSHelge Deller 	return base + off;
501da177e4SLinus Torvalds }
511da177e4SLinus Torvalds 
5222ee3ea5SHelge Deller 
5322ee3ea5SHelge Deller #define STACK_SIZE_DEFAULT (USER_WIDE_MODE			\
5422ee3ea5SHelge Deller 			? (1 << 30)	/* 1 GB */		\
5522ee3ea5SHelge Deller 			: (CONFIG_STACK_MAX_DEFAULT_SIZE_MB*1024*1024))
5622ee3ea5SHelge Deller 
calc_max_stack_size(unsigned long stack_max)5722ee3ea5SHelge Deller unsigned long calc_max_stack_size(unsigned long stack_max)
5822ee3ea5SHelge Deller {
5922ee3ea5SHelge Deller #ifdef CONFIG_COMPAT
6022ee3ea5SHelge Deller 	if (!USER_WIDE_MODE && (stack_max == COMPAT_RLIM_INFINITY))
6122ee3ea5SHelge Deller 		stack_max = STACK_SIZE_DEFAULT;
6222ee3ea5SHelge Deller 	else
6322ee3ea5SHelge Deller #endif
6422ee3ea5SHelge Deller 	if (stack_max == RLIM_INFINITY)
6522ee3ea5SHelge Deller 		stack_max = STACK_SIZE_DEFAULT;
6622ee3ea5SHelge Deller 
6722ee3ea5SHelge Deller 	return stack_max;
6822ee3ea5SHelge Deller }
6922ee3ea5SHelge Deller 
7022ee3ea5SHelge Deller 
711da177e4SLinus Torvalds /*
729dabf60dSHelge Deller  * Top of mmap area (just below the process stack).
731da177e4SLinus Torvalds  */
749dabf60dSHelge Deller 
758f2af155SKees Cook /*
768f2af155SKees Cook  * When called from arch_get_unmapped_area(), rlim_stack will be NULL,
778f2af155SKees Cook  * indicating that "current" should be used instead of a passed-in
788f2af155SKees Cook  * value from the exec bprm as done with arch_pick_mmap_layout().
798f2af155SKees Cook  */
mmap_upper_limit(struct rlimit * rlim_stack)80*2345ef96SHelge Deller unsigned long mmap_upper_limit(struct rlimit *rlim_stack)
811da177e4SLinus Torvalds {
829dabf60dSHelge Deller 	unsigned long stack_base;
839dabf60dSHelge Deller 
84042d27acSHelge Deller 	/* Limit stack size - see setup_arg_pages() in fs/exec.c */
858f2af155SKees Cook 	stack_base = rlim_stack ? rlim_stack->rlim_max
868f2af155SKees Cook 				: rlimit_max(RLIMIT_STACK);
8722ee3ea5SHelge Deller 
8822ee3ea5SHelge Deller 	stack_base = calc_max_stack_size(stack_base);
899dabf60dSHelge Deller 
90d045c77cSHelge Deller 	/* Add space for stack randomization. */
9117d9822dSAlexandre Ghiti 	if (current->flags & PF_RANDOMIZE)
92d045c77cSHelge Deller 		stack_base += (STACK_RND_MASK << PAGE_SHIFT);
93d045c77cSHelge Deller 
949dabf60dSHelge Deller 	return PAGE_ALIGN(STACK_TOP - stack_base);
951da177e4SLinus Torvalds }
961da177e4SLinus Torvalds 
97567b3515SJohn David Anglin enum mmap_allocation_direction {UP, DOWN};
981da177e4SLinus Torvalds 
arch_get_unmapped_area_common(struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags,enum mmap_allocation_direction dir)99567b3515SJohn David Anglin static unsigned long arch_get_unmapped_area_common(struct file *filp,
100567b3515SJohn David Anglin 	unsigned long addr, unsigned long len, unsigned long pgoff,
101567b3515SJohn David Anglin 	unsigned long flags, enum mmap_allocation_direction dir)
1021da177e4SLinus Torvalds {
1039dabf60dSHelge Deller 	struct mm_struct *mm = current->mm;
1041be7107fSHugh Dickins 	struct vm_area_struct *vma, *prev;
105567b3515SJohn David Anglin 	unsigned long filp_pgoff;
106567b3515SJohn David Anglin 	int do_color_align;
1079dabf60dSHelge Deller 	struct vm_unmapped_area_info info;
1089dabf60dSHelge Deller 
109567b3515SJohn David Anglin 	if (unlikely(len > TASK_SIZE))
1109dabf60dSHelge Deller 		return -ENOMEM;
1119dabf60dSHelge Deller 
1129dabf60dSHelge Deller 	do_color_align = 0;
1139dabf60dSHelge Deller 	if (filp || (flags & MAP_SHARED))
1149dabf60dSHelge Deller 		do_color_align = 1;
11556675f8bSHelge Deller 	filp_pgoff = GET_FILP_PGOFF(filp);
1169dabf60dSHelge Deller 
1179dabf60dSHelge Deller 	if (flags & MAP_FIXED) {
118567b3515SJohn David Anglin 		/* Even MAP_FIXED mappings must reside within TASK_SIZE */
119567b3515SJohn David Anglin 		if (TASK_SIZE - len < addr)
120567b3515SJohn David Anglin 			return -EINVAL;
121567b3515SJohn David Anglin 
122567b3515SJohn David Anglin 		if ((flags & MAP_SHARED) && filp &&
123567b3515SJohn David Anglin 		    (addr - shared_align_offset(filp_pgoff, pgoff))
1240ef36bd2SHelge Deller 				& (SHM_COLOUR - 1))
1259dabf60dSHelge Deller 			return -EINVAL;
1269dabf60dSHelge Deller 		return addr;
1279dabf60dSHelge Deller 	}
1289dabf60dSHelge Deller 
1299dabf60dSHelge Deller 	if (addr) {
130567b3515SJohn David Anglin 		if (do_color_align)
131567b3515SJohn David Anglin 			addr = COLOR_ALIGN(addr, filp_pgoff, pgoff);
1320576da2cSHelge Deller 		else
1339dabf60dSHelge Deller 			addr = PAGE_ALIGN(addr);
1341be7107fSHugh Dickins 
1351be7107fSHugh Dickins 		vma = find_vma_prev(mm, addr, &prev);
1369dabf60dSHelge Deller 		if (TASK_SIZE - len >= addr &&
1371be7107fSHugh Dickins 		    (!vma || addr + len <= vm_start_gap(vma)) &&
1381be7107fSHugh Dickins 		    (!prev || addr >= vm_end_gap(prev)))
139567b3515SJohn David Anglin 			return addr;
1409dabf60dSHelge Deller 	}
1419dabf60dSHelge Deller 
1429dabf60dSHelge Deller 	info.length = len;
143567b3515SJohn David Anglin 	info.align_mask = do_color_align ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
144567b3515SJohn David Anglin 	info.align_offset = shared_align_offset(filp_pgoff, pgoff);
145567b3515SJohn David Anglin 
146567b3515SJohn David Anglin 	if (dir == DOWN) {
147567b3515SJohn David Anglin 		info.flags = VM_UNMAPPED_AREA_TOPDOWN;
1489dabf60dSHelge Deller 		info.low_limit = PAGE_SIZE;
1499dabf60dSHelge Deller 		info.high_limit = mm->mmap_base;
1509dabf60dSHelge Deller 		addr = vm_unmapped_area(&info);
1519dabf60dSHelge Deller 		if (!(addr & ~PAGE_MASK))
152567b3515SJohn David Anglin 			return addr;
1539dabf60dSHelge Deller 		VM_BUG_ON(addr != -ENOMEM);
1549dabf60dSHelge Deller 
1559dabf60dSHelge Deller 		/*
1569dabf60dSHelge Deller 		 * A failed mmap() very likely causes application failure,
1579dabf60dSHelge Deller 		 * so fall back to the bottom-up function here. This scenario
1589dabf60dSHelge Deller 		 * can happen with large stack limits and large mmap()
1599dabf60dSHelge Deller 		 * allocations.
1609dabf60dSHelge Deller 		 */
161567b3515SJohn David Anglin 	}
1629dabf60dSHelge Deller 
163567b3515SJohn David Anglin 	info.flags = 0;
1643033cd43SHelge Deller 	info.low_limit = mm->mmap_base;
165567b3515SJohn David Anglin 	info.high_limit = mmap_upper_limit(NULL);
166567b3515SJohn David Anglin 	return vm_unmapped_area(&info);
167567b3515SJohn David Anglin }
1680576da2cSHelge Deller 
arch_get_unmapped_area(struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags)169567b3515SJohn David Anglin unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
170567b3515SJohn David Anglin 	unsigned long len, unsigned long pgoff, unsigned long flags)
171567b3515SJohn David Anglin {
172567b3515SJohn David Anglin 	return arch_get_unmapped_area_common(filp,
173567b3515SJohn David Anglin 			addr, len, pgoff, flags, UP);
174567b3515SJohn David Anglin }
175567b3515SJohn David Anglin 
arch_get_unmapped_area_topdown(struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags)176567b3515SJohn David Anglin unsigned long arch_get_unmapped_area_topdown(struct file *filp,
177567b3515SJohn David Anglin 	unsigned long addr, unsigned long len, unsigned long pgoff,
178567b3515SJohn David Anglin 	unsigned long flags)
179567b3515SJohn David Anglin {
180567b3515SJohn David Anglin 	return arch_get_unmapped_area_common(filp,
181567b3515SJohn David Anglin 			addr, len, pgoff, flags, DOWN);
1821da177e4SLinus Torvalds }
1831da177e4SLinus Torvalds 
sys_mmap2(unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long pgoff)1841da177e4SLinus Torvalds asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
1851da177e4SLinus Torvalds 	unsigned long prot, unsigned long flags, unsigned long fd,
1861da177e4SLinus Torvalds 	unsigned long pgoff)
1871da177e4SLinus Torvalds {
1881da177e4SLinus Torvalds 	/* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
1891da177e4SLinus Torvalds 	   we have. */
190a90f590aSDominik Brodowski 	return ksys_mmap_pgoff(addr, len, prot, flags, fd,
191f8b72560SAl Viro 			       pgoff >> (PAGE_SHIFT - 12));
1921da177e4SLinus Torvalds }
1931da177e4SLinus Torvalds 
sys_mmap(unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long offset)1941da177e4SLinus Torvalds asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
1951da177e4SLinus Torvalds 		unsigned long prot, unsigned long flags, unsigned long fd,
1961da177e4SLinus Torvalds 		unsigned long offset)
1971da177e4SLinus Torvalds {
1981da177e4SLinus Torvalds 	if (!(offset & ~PAGE_MASK)) {
199a90f590aSDominik Brodowski 		return ksys_mmap_pgoff(addr, len, prot, flags, fd,
200f8b72560SAl Viro 					offset >> PAGE_SHIFT);
2011da177e4SLinus Torvalds 	} else {
2021da177e4SLinus Torvalds 		return -EINVAL;
2031da177e4SLinus Torvalds 	}
2041da177e4SLinus Torvalds }
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds /* Fucking broken ABI */
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds #ifdef CONFIG_64BIT
parisc_truncate64(const char __user * path,unsigned int high,unsigned int low)2091da177e4SLinus Torvalds asmlinkage long parisc_truncate64(const char __user * path,
2101da177e4SLinus Torvalds 					unsigned int high, unsigned int low)
2111da177e4SLinus Torvalds {
212df260e21SDominik Brodowski 	return ksys_truncate(path, (long)high << 32 | low);
2131da177e4SLinus Torvalds }
2141da177e4SLinus Torvalds 
parisc_ftruncate64(unsigned int fd,unsigned int high,unsigned int low)2151da177e4SLinus Torvalds asmlinkage long parisc_ftruncate64(unsigned int fd,
2161da177e4SLinus Torvalds 					unsigned int high, unsigned int low)
2171da177e4SLinus Torvalds {
218411d9475SDominik Brodowski 	return ksys_ftruncate(fd, (long)high << 32 | low);
2191da177e4SLinus Torvalds }
2201da177e4SLinus Torvalds 
2211da177e4SLinus Torvalds /* stubs for the benefit of the syscall_table since truncate64 and truncate
2221da177e4SLinus Torvalds  * are identical on LP64 */
sys_truncate64(const char __user * path,unsigned long length)2231da177e4SLinus Torvalds asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
2241da177e4SLinus Torvalds {
225df260e21SDominik Brodowski 	return ksys_truncate(path, length);
2261da177e4SLinus Torvalds }
sys_ftruncate64(unsigned int fd,unsigned long length)2271da177e4SLinus Torvalds asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
2281da177e4SLinus Torvalds {
229411d9475SDominik Brodowski 	return ksys_ftruncate(fd, length);
2301da177e4SLinus Torvalds }
sys_fcntl64(unsigned int fd,unsigned int cmd,unsigned long arg)2311da177e4SLinus Torvalds asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
2321da177e4SLinus Torvalds {
2331da177e4SLinus Torvalds 	return sys_fcntl(fd, cmd, arg);
2341da177e4SLinus Torvalds }
2351da177e4SLinus Torvalds #else
2361da177e4SLinus Torvalds 
parisc_truncate64(const char __user * path,unsigned int high,unsigned int low)2371da177e4SLinus Torvalds asmlinkage long parisc_truncate64(const char __user * path,
2381da177e4SLinus Torvalds 					unsigned int high, unsigned int low)
2391da177e4SLinus Torvalds {
240df260e21SDominik Brodowski 	return ksys_truncate(path, (loff_t)high << 32 | low);
2411da177e4SLinus Torvalds }
2421da177e4SLinus Torvalds 
parisc_ftruncate64(unsigned int fd,unsigned int high,unsigned int low)2431da177e4SLinus Torvalds asmlinkage long parisc_ftruncate64(unsigned int fd,
2441da177e4SLinus Torvalds 					unsigned int high, unsigned int low)
2451da177e4SLinus Torvalds {
2461da177e4SLinus Torvalds 	return sys_ftruncate64(fd, (loff_t)high << 32 | low);
2471da177e4SLinus Torvalds }
2481da177e4SLinus Torvalds #endif
2491da177e4SLinus Torvalds 
parisc_pread64(unsigned int fd,char __user * buf,size_t count,unsigned int high,unsigned int low)2501da177e4SLinus Torvalds asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
2511da177e4SLinus Torvalds 					unsigned int high, unsigned int low)
2521da177e4SLinus Torvalds {
25336028d5dSDominik Brodowski 	return ksys_pread64(fd, buf, count, (loff_t)high << 32 | low);
2541da177e4SLinus Torvalds }
2551da177e4SLinus Torvalds 
parisc_pwrite64(unsigned int fd,const char __user * buf,size_t count,unsigned int high,unsigned int low)2561da177e4SLinus Torvalds asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
2571da177e4SLinus Torvalds 			size_t count, unsigned int high, unsigned int low)
2581da177e4SLinus Torvalds {
25936028d5dSDominik Brodowski 	return ksys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
2601da177e4SLinus Torvalds }
2611da177e4SLinus Torvalds 
parisc_readahead(int fd,unsigned int high,unsigned int low,size_t count)2621da177e4SLinus Torvalds asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
2631da177e4SLinus Torvalds 		                    size_t count)
2641da177e4SLinus Torvalds {
265c7b95d51SDominik Brodowski 	return ksys_readahead(fd, (loff_t)high << 32 | low, count);
2661da177e4SLinus Torvalds }
2671da177e4SLinus Torvalds 
parisc_fadvise64_64(int fd,unsigned int high_off,unsigned int low_off,unsigned int high_len,unsigned int low_len,int advice)2681da177e4SLinus Torvalds asmlinkage long parisc_fadvise64_64(int fd,
2691da177e4SLinus Torvalds 			unsigned int high_off, unsigned int low_off,
2701da177e4SLinus Torvalds 			unsigned int high_len, unsigned int low_len, int advice)
2711da177e4SLinus Torvalds {
2729d5b7c95SDominik Brodowski 	return ksys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
2731da177e4SLinus Torvalds 			(loff_t)high_len << 32 | low_len, advice);
2741da177e4SLinus Torvalds }
2751da177e4SLinus Torvalds 
parisc_sync_file_range(int fd,u32 hi_off,u32 lo_off,u32 hi_nbytes,u32 lo_nbytes,unsigned int flags)2766ca773cfSKyle McMartin asmlinkage long parisc_sync_file_range(int fd,
2776ca773cfSKyle McMartin 			u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
2786ca773cfSKyle McMartin 			unsigned int flags)
2796ca773cfSKyle McMartin {
280806cbae1SDominik Brodowski 	return ksys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
2816ca773cfSKyle McMartin 			(loff_t)hi_nbytes << 32 | lo_nbytes, flags);
2826ca773cfSKyle McMartin }
2836ca773cfSKyle McMartin 
parisc_fallocate(int fd,int mode,u32 offhi,u32 offlo,u32 lenhi,u32 lenlo)2844474a331SHelge Deller asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo,
2854474a331SHelge Deller 				u32 lenhi, u32 lenlo)
2864474a331SHelge Deller {
287edf292c7SDominik Brodowski 	return ksys_fallocate(fd, mode, ((u64)offhi << 32) | offlo,
2884474a331SHelge Deller 			      ((u64)lenhi << 32) | lenlo);
2894474a331SHelge Deller }
2904474a331SHelge Deller 
parisc_personality(unsigned long personality)291b5d89408SHelge Deller asmlinkage long parisc_personality(unsigned long personality)
29275a49581SKyle McMartin {
29375a49581SKyle McMartin 	long err;
29475a49581SKyle McMartin 
29575a49581SKyle McMartin 	if (personality(current->personality) == PER_LINUX32
2965b24c421SJiri Kosina 	    && personality(personality) == PER_LINUX)
2975b24c421SJiri Kosina 		personality = (personality & ~PER_MASK) | PER_LINUX32;
29875a49581SKyle McMartin 
29975a49581SKyle McMartin 	err = sys_personality(personality);
3005b24c421SJiri Kosina 	if (personality(err) == PER_LINUX32)
3015b24c421SJiri Kosina 		err = (err & ~PER_MASK) | PER_LINUX;
30275a49581SKyle McMartin 
30375a49581SKyle McMartin 	return err;
30475a49581SKyle McMartin }
30544a4c9e4SHelge Deller 
30644a4c9e4SHelge Deller /*
30744a4c9e4SHelge Deller  * Up to kernel v5.9 we defined O_NONBLOCK as 000200004,
30844a4c9e4SHelge Deller  * since then O_NONBLOCK is defined as 000200000.
30944a4c9e4SHelge Deller  *
31044a4c9e4SHelge Deller  * The following wrapper functions mask out the old
31144a4c9e4SHelge Deller  * O_NDELAY bit from calls which use O_NONBLOCK.
31244a4c9e4SHelge Deller  *
31344a4c9e4SHelge Deller  * XXX: Remove those in year 2022 (or later)?
31444a4c9e4SHelge Deller  */
31544a4c9e4SHelge Deller 
31644a4c9e4SHelge Deller #define O_NONBLOCK_OLD		000200004
31744a4c9e4SHelge Deller #define O_NONBLOCK_MASK_OUT	(O_NONBLOCK_OLD & ~O_NONBLOCK)
31844a4c9e4SHelge Deller 
FIX_O_NONBLOCK(int flags)31944a4c9e4SHelge Deller static int FIX_O_NONBLOCK(int flags)
32044a4c9e4SHelge Deller {
3213759778eSHelge Deller 	if ((flags & O_NONBLOCK_MASK_OUT) &&
3223759778eSHelge Deller 			!test_thread_flag(TIF_NONBLOCK_WARNING)) {
3233759778eSHelge Deller 		set_thread_flag(TIF_NONBLOCK_WARNING);
3243759778eSHelge Deller 		pr_warn("%s(%d) uses a deprecated O_NONBLOCK value."
3253759778eSHelge Deller 			" Please recompile with newer glibc.\n",
3263759778eSHelge Deller 			current->comm, current->pid);
32744a4c9e4SHelge Deller 	}
32844a4c9e4SHelge Deller 	return flags & ~O_NONBLOCK_MASK_OUT;
32944a4c9e4SHelge Deller }
33044a4c9e4SHelge Deller 
parisc_timerfd_create(int clockid,int flags)33144a4c9e4SHelge Deller asmlinkage long parisc_timerfd_create(int clockid, int flags)
33244a4c9e4SHelge Deller {
33344a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
33444a4c9e4SHelge Deller 	return sys_timerfd_create(clockid, flags);
33544a4c9e4SHelge Deller }
33644a4c9e4SHelge Deller 
parisc_signalfd4(int ufd,sigset_t __user * user_mask,size_t sizemask,int flags)33744a4c9e4SHelge Deller asmlinkage long parisc_signalfd4(int ufd, sigset_t __user *user_mask,
33844a4c9e4SHelge Deller 	size_t sizemask, int flags)
33944a4c9e4SHelge Deller {
34044a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
34144a4c9e4SHelge Deller 	return sys_signalfd4(ufd, user_mask, sizemask, flags);
34244a4c9e4SHelge Deller }
34344a4c9e4SHelge Deller 
34444a4c9e4SHelge Deller #ifdef CONFIG_COMPAT
parisc_compat_signalfd4(int ufd,compat_sigset_t __user * user_mask,compat_size_t sizemask,int flags)34544a4c9e4SHelge Deller asmlinkage long parisc_compat_signalfd4(int ufd,
34644a4c9e4SHelge Deller 	compat_sigset_t __user *user_mask,
34744a4c9e4SHelge Deller 	compat_size_t sizemask, int flags)
34844a4c9e4SHelge Deller {
34944a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
35044a4c9e4SHelge Deller 	return compat_sys_signalfd4(ufd, user_mask, sizemask, flags);
35144a4c9e4SHelge Deller }
35244a4c9e4SHelge Deller #endif
35344a4c9e4SHelge Deller 
parisc_eventfd2(unsigned int count,int flags)35444a4c9e4SHelge Deller asmlinkage long parisc_eventfd2(unsigned int count, int flags)
35544a4c9e4SHelge Deller {
35644a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
35744a4c9e4SHelge Deller 	return sys_eventfd2(count, flags);
35844a4c9e4SHelge Deller }
35944a4c9e4SHelge Deller 
parisc_userfaultfd(int flags)36044a4c9e4SHelge Deller asmlinkage long parisc_userfaultfd(int flags)
36144a4c9e4SHelge Deller {
36244a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
36344a4c9e4SHelge Deller 	return sys_userfaultfd(flags);
36444a4c9e4SHelge Deller }
36544a4c9e4SHelge Deller 
parisc_pipe2(int __user * fildes,int flags)36644a4c9e4SHelge Deller asmlinkage long parisc_pipe2(int __user *fildes, int flags)
36744a4c9e4SHelge Deller {
36844a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
36944a4c9e4SHelge Deller 	return sys_pipe2(fildes, flags);
37044a4c9e4SHelge Deller }
37144a4c9e4SHelge Deller 
parisc_inotify_init1(int flags)37244a4c9e4SHelge Deller asmlinkage long parisc_inotify_init1(int flags)
37344a4c9e4SHelge Deller {
37444a4c9e4SHelge Deller 	flags = FIX_O_NONBLOCK(flags);
37544a4c9e4SHelge Deller 	return sys_inotify_init1(flags);
37644a4c9e4SHelge Deller }
37771bdea6fSHelge Deller 
37871bdea6fSHelge Deller /*
37971bdea6fSHelge Deller  * madvise() wrapper
38071bdea6fSHelge Deller  *
38171bdea6fSHelge Deller  * Up to kernel v6.1 parisc has different values than all other
38271bdea6fSHelge Deller  * platforms for the MADV_xxx flags listed below.
38371bdea6fSHelge Deller  * To keep binary compatibility with existing userspace programs
38471bdea6fSHelge Deller  * translate the former values to the new values.
38571bdea6fSHelge Deller  *
38671bdea6fSHelge Deller  * XXX: Remove this wrapper in year 2025 (or later)
38771bdea6fSHelge Deller  */
38871bdea6fSHelge Deller 
parisc_madvise(unsigned long start,size_t len_in,int behavior)38971bdea6fSHelge Deller asmlinkage notrace long parisc_madvise(unsigned long start, size_t len_in, int behavior)
39071bdea6fSHelge Deller {
39171bdea6fSHelge Deller 	switch (behavior) {
39271bdea6fSHelge Deller 	case 65: behavior = MADV_MERGEABLE;	break;
39371bdea6fSHelge Deller 	case 66: behavior = MADV_UNMERGEABLE;	break;
39471bdea6fSHelge Deller 	case 67: behavior = MADV_HUGEPAGE;	break;
39571bdea6fSHelge Deller 	case 68: behavior = MADV_NOHUGEPAGE;	break;
39671bdea6fSHelge Deller 	case 69: behavior = MADV_DONTDUMP;	break;
39771bdea6fSHelge Deller 	case 70: behavior = MADV_DODUMP;	break;
39871bdea6fSHelge Deller 	case 71: behavior = MADV_WIPEONFORK;	break;
39971bdea6fSHelge Deller 	case 72: behavior = MADV_KEEPONFORK;	break;
40071bdea6fSHelge Deller 	case 73: behavior = MADV_COLLAPSE;	break;
40171bdea6fSHelge Deller 	}
40271bdea6fSHelge Deller 
40371bdea6fSHelge Deller 	return sys_madvise(start, len_in, behavior);
40471bdea6fSHelge Deller }
405