]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - arch/mips/kernel/linux32.c
mips: properly account for stack randomization and stack guard gap
[mirror_ubuntu-eoan-kernel.git] / arch / mips / kernel / linux32.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * Conversion between 32-bit and 64-bit native system calls.
4 *
5 * Copyright (C) 2000 Silicon Graphics, Inc.
6 * Written by Ulf Carlsson (ulfc@engr.sgi.com)
1da177e4 7 */
1da177e4
LT
8#include <linux/compiler.h>
9#include <linux/mm.h>
10#include <linux/errno.h>
11#include <linux/file.h>
1da177e4 12#include <linux/highuid.h>
1da177e4
LT
13#include <linux/resource.h>
14#include <linux/highmem.h>
15#include <linux/time.h>
16#include <linux/times.h>
17#include <linux/poll.h>
1da177e4
LT
18#include <linux/skbuff.h>
19#include <linux/filter.h>
20#include <linux/shm.h>
21#include <linux/sem.h>
22#include <linux/msg.h>
23#include <linux/icmpv6.h>
24#include <linux/syscalls.h>
25#include <linux/sysctl.h>
26#include <linux/utime.h>
27#include <linux/utsname.h>
28#include <linux/personality.h>
1da177e4 29#include <linux/dnotify.h>
1da177e4
LT
30#include <linux/binfmts.h>
31#include <linux/security.h>
32#include <linux/compat.h>
33#include <linux/vfs.h>
cba4fbbf 34#include <linux/ipc.h>
5a0e3ad6 35#include <linux/slab.h>
1da177e4
LT
36
37#include <net/sock.h>
38#include <net/scm.h>
39
431dc804 40#include <asm/compat-signal.h>
1da177e4 41#include <asm/sim.h>
7c0f6ba6 42#include <linux/uaccess.h>
1da177e4
LT
43#include <asm/mmu_context.h>
44#include <asm/mman.h>
45
1da177e4 46#ifdef __MIPSEB__
21a151d8 47#define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
1da177e4
LT
48#endif
49#ifdef __MIPSEL__
21a151d8 50#define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
1da177e4
LT
51#endif
52
dbda6ac0
RB
53SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
54 unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
1da177e4 55{
df260e21 56 return ksys_truncate(path, merge_64(a2, a3));
1da177e4
LT
57}
58
dbda6ac0
RB
59SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
60 unsigned long, a2, unsigned long, a3)
1da177e4 61{
411d9475 62 return ksys_ftruncate(fd, merge_64(a2, a3));
1da177e4
LT
63}
64
d6c178e9
RB
65SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
66 unsigned int, offset_low, loff_t __user *, result,
67 unsigned int, origin)
1da177e4
LT
68{
69 return sys_llseek(fd, offset_high, offset_low, result, origin);
70}
71
72/* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
73 lseek back to original location. They fail just like lseek does on
70342287 74 non-seekable files. */
1da177e4 75
dbda6ac0
RB
76SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
77 unsigned long, unused, unsigned long, a4, unsigned long, a5)
1da177e4 78{
36028d5d 79 return ksys_pread64(fd, buf, count, merge_64(a4, a5));
1da177e4
LT
80}
81
dbda6ac0
RB
82SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
83 size_t, count, u32, unused, u64, a4, u64, a5)
1da177e4 84{
36028d5d 85 return ksys_pwrite64(fd, buf, count, merge_64(a4, a5));
1da177e4
LT
86}
87
dbda6ac0 88SYSCALL_DEFINE1(32_personality, unsigned long, personality)
1da177e4 89{
d62c9ced 90 unsigned int p = personality & 0xffffffff;
1da177e4 91 int ret;
d62c9ced 92
53571ce4 93 if (personality(current->personality) == PER_LINUX32 &&
d62c9ced
DD
94 personality(p) == PER_LINUX)
95 p = (p & ~PER_MASK) | PER_LINUX32;
96 ret = sys_personality(p);
97 if (ret != -1 && personality(ret) == PER_LINUX32)
98 ret = (ret & ~PER_MASK) | PER_LINUX;
1da177e4
LT
99 return ret;
100}
101
1da177e4 102asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
70342287 103 size_t count)
1da177e4 104{
c7b95d51 105 return ksys_readahead(fd, merge_64(a2, a3), count);
1da177e4
LT
106}
107
a8d587a7
RB
108asmlinkage long sys32_sync_file_range(int fd, int __pad,
109 unsigned long a2, unsigned long a3,
110 unsigned long a4, unsigned long a5,
111 int flags)
112{
806cbae1 113 return ksys_sync_file_range(fd,
a8d587a7
RB
114 merge_64(a2, a3), merge_64(a4, a5),
115 flags);
116}
117
8676d2e0
AN
118asmlinkage long sys32_fadvise64_64(int fd, int __pad,
119 unsigned long a2, unsigned long a3,
120 unsigned long a4, unsigned long a5,
121 int flags)
122{
9d5b7c95 123 return ksys_fadvise64_64(fd,
8676d2e0
AN
124 merge_64(a2, a3), merge_64(a4, a5),
125 flags);
126}
127
4dc46775
RB
128asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
129 unsigned offset_a3, unsigned len_a4, unsigned len_a5)
130{
edf292c7
DB
131 return ksys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
132 merge_64(len_a4, len_a5));
4dc46775 133}