bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Linux syscalls |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003 Fabrice Bellard |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 18 | */ |
Eduardo Habkost | d5b3a9b | 2009-06-09 18:26:31 -0300 | [diff] [blame] | 19 | #define _ATFILE_SOURCE |
Peter Maydell | d39594e | 2016-01-26 18:17:02 +0000 | [diff] [blame] | 20 | #include "qemu/osdep.h" |
Veronia Bahaa | f348b6d | 2016-03-20 19:16:19 +0200 | [diff] [blame] | 21 | #include "qemu/cutils.h" |
| 22 | #include "qemu/path.h" |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 23 | #include <elf.h> |
| 24 | #include <endian.h> |
John Spencer | c56dc77 | 2012-12-10 07:59:46 +0100 | [diff] [blame] | 25 | #include <grp.h> |
ths | d08d3bb | 2007-03-19 13:09:22 +0000 | [diff] [blame] | 26 | #include <sys/ipc.h> |
| 27 | #include <sys/msg.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 28 | #include <sys/wait.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 29 | #include <sys/mount.h> |
John Spencer | 586b0be | 2012-12-26 00:49:49 +0100 | [diff] [blame] | 30 | #include <sys/file.h> |
| 31 | #include <sys/fsuid.h> |
| 32 | #include <sys/personality.h> |
ths | 39b9aae | 2007-02-11 18:36:44 +0000 | [diff] [blame] | 33 | #include <sys/prctl.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 34 | #include <sys/resource.h> |
| 35 | #include <sys/mman.h> |
| 36 | #include <sys/swap.h> |
Peter Maydell | e0eb210 | 2014-03-17 12:15:35 +0000 | [diff] [blame] | 37 | #include <linux/capability.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 38 | #include <sched.h> |
Aurelien Jarno | 60e9924 | 2010-03-29 02:12:51 +0200 | [diff] [blame] | 39 | #ifdef __ia64__ |
| 40 | int __clone2(int (*fn)(void *), void *child_stack_base, |
| 41 | size_t stack_size, int flags, void *arg, ...); |
| 42 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 43 | #include <sys/socket.h> |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 44 | #include <sys/un.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 45 | #include <sys/uio.h> |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 46 | #include <sys/poll.h> |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 47 | #include <sys/times.h> |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 48 | #include <sys/shm.h> |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 49 | #include <sys/sem.h> |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 50 | #include <sys/statfs.h> |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 51 | #include <utime.h> |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 52 | #include <sys/sysinfo.h> |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 53 | #include <sys/signalfd.h> |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 54 | //#include <sys/user.h> |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 55 | #include <netinet/ip.h> |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 56 | #include <netinet/tcp.h> |
Laurent Vivier | 86fcd94 | 2011-03-30 01:35:23 +0200 | [diff] [blame] | 57 | #include <linux/wireless.h> |
Jing Huang | 920394d | 2012-07-24 13:59:23 +0000 | [diff] [blame] | 58 | #include <linux/icmp.h> |
Stefan Weil | 5a61cb6 | 2011-09-08 17:55:32 +0200 | [diff] [blame] | 59 | #include "qemu-common.h" |
Riku Voipio | d80a190 | 2014-10-01 16:05:46 +0300 | [diff] [blame] | 60 | #ifdef CONFIG_TIMERFD |
| 61 | #include <sys/timerfd.h> |
| 62 | #endif |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 63 | #ifdef TARGET_GPROF |
aurel32 | 6d946cd | 2008-11-06 16:15:18 +0000 | [diff] [blame] | 64 | #include <sys/gmon.h> |
| 65 | #endif |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 66 | #ifdef CONFIG_EVENTFD |
| 67 | #include <sys/eventfd.h> |
| 68 | #endif |
Peter Maydell | 3b6edd1 | 2011-02-15 18:35:05 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_EPOLL |
| 70 | #include <sys/epoll.h> |
| 71 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 72 | #ifdef CONFIG_ATTR |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 73 | #include "qemu/xattr.h" |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 74 | #endif |
Peter Maydell | a8fd1ab | 2013-02-08 07:31:55 +0000 | [diff] [blame] | 75 | #ifdef CONFIG_SENDFILE |
| 76 | #include <sys/sendfile.h> |
| 77 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 78 | |
| 79 | #define termios host_termios |
| 80 | #define winsize host_winsize |
| 81 | #define termio host_termio |
bellard | 04369ff | 2003-03-20 22:33:23 +0000 | [diff] [blame] | 82 | #define sgttyb host_sgttyb /* same as target */ |
| 83 | #define tchars host_tchars /* same as target */ |
| 84 | #define ltchars host_ltchars /* same as target */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 85 | |
| 86 | #include <linux/termios.h> |
| 87 | #include <linux/unistd.h> |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 88 | #include <linux/cdrom.h> |
| 89 | #include <linux/hdreg.h> |
| 90 | #include <linux/soundcard.h> |
bellard | 19b84f3 | 2003-05-08 15:41:49 +0000 | [diff] [blame] | 91 | #include <linux/kd.h> |
balrog | 8fbd6b5 | 2008-09-20 03:03:09 +0000 | [diff] [blame] | 92 | #include <linux/mtio.h> |
Martin Mohring | 350d177 | 2009-05-04 21:21:41 +0300 | [diff] [blame] | 93 | #include <linux/fs.h> |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 94 | #if defined(CONFIG_FIEMAP) |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 95 | #include <linux/fiemap.h> |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 96 | #endif |
Ulrich Hecht | f7680a5 | 2009-10-16 17:00:44 +0200 | [diff] [blame] | 97 | #include <linux/fb.h> |
| 98 | #include <linux/vt.h> |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 99 | #include <linux/dm-ioctl.h> |
Laurent Vivier | c07ecc6 | 2013-01-07 11:40:06 +0000 | [diff] [blame] | 100 | #include <linux/reboot.h> |
Laurent Vivier | 7ff7b66 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 101 | #include <linux/route.h> |
Laurent Vivier | f57d419 | 2013-08-30 01:46:41 +0200 | [diff] [blame] | 102 | #include <linux/filter.h> |
Andreas Färber | fff8c53 | 2014-01-18 07:38:30 +0100 | [diff] [blame] | 103 | #include <linux/blkpg.h> |
pbrook | d7e4036 | 2008-05-23 16:06:43 +0000 | [diff] [blame] | 104 | #include "linux_loop.h" |
Riku Voipio | 18cb008 | 2014-02-19 12:59:58 +0200 | [diff] [blame] | 105 | #include "uname.h" |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 106 | |
bellard | 3ef693a | 2003-03-23 20:17:16 +0000 | [diff] [blame] | 107 | #include "qemu.h" |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 108 | |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 109 | #define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \ |
| 110 | CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID) |
pbrook | 30813ce | 2008-06-02 15:45:44 +0000 | [diff] [blame] | 111 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 112 | //#define DEBUG |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 113 | |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 114 | //#include <linux/msdos_fs.h> |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 115 | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct linux_dirent [2]) |
| 116 | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct linux_dirent [2]) |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 117 | |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 118 | |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 119 | #undef _syscall0 |
| 120 | #undef _syscall1 |
| 121 | #undef _syscall2 |
| 122 | #undef _syscall3 |
| 123 | #undef _syscall4 |
| 124 | #undef _syscall5 |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 125 | #undef _syscall6 |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 126 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 127 | #define _syscall0(type,name) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 128 | static type name (void) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 129 | { \ |
| 130 | return syscall(__NR_##name); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 131 | } |
| 132 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 133 | #define _syscall1(type,name,type1,arg1) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 134 | static type name (type1 arg1) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 135 | { \ |
| 136 | return syscall(__NR_##name, arg1); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 137 | } |
| 138 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 139 | #define _syscall2(type,name,type1,arg1,type2,arg2) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 140 | static type name (type1 arg1,type2 arg2) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 141 | { \ |
| 142 | return syscall(__NR_##name, arg1, arg2); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 143 | } |
| 144 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 145 | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 146 | static type name (type1 arg1,type2 arg2,type3 arg3) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 147 | { \ |
| 148 | return syscall(__NR_##name, arg1, arg2, arg3); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 149 | } |
| 150 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 151 | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 152 | static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 153 | { \ |
| 154 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 155 | } |
| 156 | |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 157 | #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ |
| 158 | type5,arg5) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 159 | static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 160 | { \ |
| 161 | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \ |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 162 | } |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 163 | |
| 164 | |
| 165 | #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ |
| 166 | type5,arg5,type6,arg6) \ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 167 | static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \ |
| 168 | type6 arg6) \ |
bellard | 83fcb51 | 2006-06-14 13:37:16 +0000 | [diff] [blame] | 169 | { \ |
| 170 | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \ |
| 171 | } |
| 172 | |
bellard | 70a194b | 2003-08-11 22:20:16 +0000 | [diff] [blame] | 173 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 174 | #define __NR_sys_uname __NR_uname |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 175 | #define __NR_sys_getcwd1 __NR_getcwd |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 176 | #define __NR_sys_getdents __NR_getdents |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 177 | #define __NR_sys_getdents64 __NR_getdents64 |
ths | c6cda17 | 2007-10-09 03:42:34 +0000 | [diff] [blame] | 178 | #define __NR_sys_getpriority __NR_getpriority |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 179 | #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 180 | #define __NR_sys_syslog __NR_syslog |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 181 | #define __NR_sys_tgkill __NR_tgkill |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 182 | #define __NR_sys_tkill __NR_tkill |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 183 | #define __NR_sys_futex __NR_futex |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 184 | #define __NR_sys_inotify_init __NR_inotify_init |
| 185 | #define __NR_sys_inotify_add_watch __NR_inotify_add_watch |
| 186 | #define __NR_sys_inotify_rm_watch __NR_inotify_rm_watch |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 187 | |
Alexander Graf | 42a39fb | 2011-04-15 17:32:45 +0200 | [diff] [blame] | 188 | #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) || \ |
| 189 | defined(__s390x__) |
bellard | 9af9eaa | 2003-04-07 21:34:41 +0000 | [diff] [blame] | 190 | #define __NR__llseek __NR_lseek |
| 191 | #endif |
| 192 | |
James Hogan | a29e5ba | 2014-03-25 21:51:08 +0000 | [diff] [blame] | 193 | /* Newer kernel ports have llseek() instead of _llseek() */ |
| 194 | #if defined(TARGET_NR_llseek) && !defined(TARGET_NR__llseek) |
| 195 | #define TARGET_NR__llseek TARGET_NR_llseek |
| 196 | #endif |
| 197 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 198 | #ifdef __NR_gettid |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 199 | _syscall0(int, gettid) |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 200 | #else |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 201 | /* This is a replacement for the host gettid() and must return a host |
| 202 | errno. */ |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 203 | static int gettid(void) { |
| 204 | return -ENOSYS; |
| 205 | } |
| 206 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 207 | #if defined(TARGET_NR_getdents) && defined(__NR_getdents) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 208 | _syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count); |
Peter Maydell | 3307e23 | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 209 | #endif |
| 210 | #if !defined(__NR_getdents) || \ |
| 211 | (defined(TARGET_NR_getdents64) && defined(__NR_getdents64)) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 212 | _syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count); |
| 213 | #endif |
Richard Henderson | d35b261 | 2010-06-04 12:14:10 -0700 | [diff] [blame] | 214 | #if defined(TARGET_NR__llseek) && defined(__NR_llseek) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 215 | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, |
| 216 | loff_t *, res, uint, wh); |
| 217 | #endif |
| 218 | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
| 219 | _syscall3(int,sys_syslog,int,type,char*,bufp,int,len) |
| 220 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
| 221 | _syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig) |
| 222 | #endif |
| 223 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
| 224 | _syscall2(int,sys_tkill,int,tid,int,sig) |
| 225 | #endif |
| 226 | #ifdef __NR_exit_group |
| 227 | _syscall1(int,exit_group,int,error_code) |
| 228 | #endif |
| 229 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
| 230 | _syscall1(int,set_tid_address,int *,tidptr) |
| 231 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 232 | #if defined(TARGET_NR_futex) && defined(__NR_futex) |
| 233 | _syscall6(int,sys_futex,int *,uaddr,int,op,int,val, |
| 234 | const struct timespec *,timeout,int *,uaddr2,int,val3) |
| 235 | #endif |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 236 | #define __NR_sys_sched_getaffinity __NR_sched_getaffinity |
| 237 | _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len, |
| 238 | unsigned long *, user_mask_ptr); |
| 239 | #define __NR_sys_sched_setaffinity __NR_sched_setaffinity |
| 240 | _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, |
| 241 | unsigned long *, user_mask_ptr); |
Alexander Graf | 0f6b4d2 | 2011-09-27 14:39:42 +0200 | [diff] [blame] | 242 | _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, |
| 243 | void *, arg); |
Peter Maydell | e0eb210 | 2014-03-17 12:15:35 +0000 | [diff] [blame] | 244 | _syscall2(int, capget, struct __user_cap_header_struct *, header, |
| 245 | struct __user_cap_data_struct *, data); |
| 246 | _syscall2(int, capset, struct __user_cap_header_struct *, header, |
| 247 | struct __user_cap_data_struct *, data); |
Paul Burton | ab31cda | 2014-06-22 11:25:43 +0100 | [diff] [blame] | 248 | #if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get) |
| 249 | _syscall2(int, ioprio_get, int, which, int, who) |
| 250 | #endif |
| 251 | #if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set) |
| 252 | _syscall3(int, ioprio_set, int, which, int, who, int, ioprio) |
| 253 | #endif |
Laurent Vivier | f894efd | 2016-02-21 10:56:23 +0100 | [diff] [blame] | 254 | #if defined(TARGET_NR_getrandom) && defined(__NR_getrandom) |
| 255 | _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags) |
| 256 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 257 | |
| 258 | static bitmask_transtbl fcntl_flags_tbl[] = { |
| 259 | { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, |
| 260 | { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, }, |
| 261 | { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, }, |
| 262 | { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, }, |
| 263 | { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, }, |
| 264 | { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, }, |
| 265 | { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, }, |
| 266 | { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, }, |
Richard Henderson | afc8763 | 2012-07-25 14:30:34 -0700 | [diff] [blame] | 267 | { TARGET_O_SYNC, TARGET_O_DSYNC, O_SYNC, O_DSYNC, }, |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 268 | { TARGET_O_SYNC, TARGET_O_SYNC, O_SYNC, O_SYNC, }, |
| 269 | { TARGET_FASYNC, TARGET_FASYNC, FASYNC, FASYNC, }, |
| 270 | { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, }, |
| 271 | { TARGET_O_NOFOLLOW, TARGET_O_NOFOLLOW, O_NOFOLLOW, O_NOFOLLOW, }, |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 272 | #if defined(O_DIRECT) |
| 273 | { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, }, |
| 274 | #endif |
Richard Henderson | afc8763 | 2012-07-25 14:30:34 -0700 | [diff] [blame] | 275 | #if defined(O_NOATIME) |
| 276 | { TARGET_O_NOATIME, TARGET_O_NOATIME, O_NOATIME, O_NOATIME }, |
| 277 | #endif |
| 278 | #if defined(O_CLOEXEC) |
| 279 | { TARGET_O_CLOEXEC, TARGET_O_CLOEXEC, O_CLOEXEC, O_CLOEXEC }, |
| 280 | #endif |
| 281 | #if defined(O_PATH) |
| 282 | { TARGET_O_PATH, TARGET_O_PATH, O_PATH, O_PATH }, |
| 283 | #endif |
| 284 | /* Don't terminate the list prematurely on 64-bit host+guest. */ |
| 285 | #if TARGET_O_LARGEFILE != 0 || O_LARGEFILE != 0 |
| 286 | { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, }, |
| 287 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 288 | { 0, 0, 0, 0 } |
| 289 | }; |
| 290 | |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 291 | typedef abi_long (*TargetFdDataFunc)(void *, size_t); |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 292 | typedef abi_long (*TargetFdAddrFunc)(void *, abi_ulong, socklen_t); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 293 | typedef struct TargetFdTrans { |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 294 | TargetFdDataFunc host_to_target_data; |
| 295 | TargetFdDataFunc target_to_host_data; |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 296 | TargetFdAddrFunc target_to_host_addr; |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 297 | } TargetFdTrans; |
| 298 | |
| 299 | static TargetFdTrans **target_fd_trans; |
| 300 | |
| 301 | static unsigned int target_fd_max; |
| 302 | |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 303 | static TargetFdDataFunc fd_trans_host_to_target_data(int fd) |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 304 | { |
Laurent Vivier | 861d72c | 2015-10-28 21:40:46 +0100 | [diff] [blame] | 305 | if (fd >= 0 && fd < target_fd_max && target_fd_trans[fd]) { |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 306 | return target_fd_trans[fd]->host_to_target_data; |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 307 | } |
| 308 | return NULL; |
| 309 | } |
| 310 | |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 311 | static TargetFdAddrFunc fd_trans_target_to_host_addr(int fd) |
| 312 | { |
Laurent Vivier | 861d72c | 2015-10-28 21:40:46 +0100 | [diff] [blame] | 313 | if (fd >= 0 && fd < target_fd_max && target_fd_trans[fd]) { |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 314 | return target_fd_trans[fd]->target_to_host_addr; |
| 315 | } |
| 316 | return NULL; |
| 317 | } |
| 318 | |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 319 | static void fd_trans_register(int fd, TargetFdTrans *trans) |
| 320 | { |
| 321 | unsigned int oldmax; |
| 322 | |
| 323 | if (fd >= target_fd_max) { |
| 324 | oldmax = target_fd_max; |
| 325 | target_fd_max = ((fd >> 6) + 1) << 6; /* by slice of 64 entries */ |
Laurent Vivier | 5089c7c | 2016-01-18 23:50:45 +0100 | [diff] [blame] | 326 | target_fd_trans = g_renew(TargetFdTrans *, |
| 327 | target_fd_trans, target_fd_max); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 328 | memset((void *)(target_fd_trans + oldmax), 0, |
| 329 | (target_fd_max - oldmax) * sizeof(TargetFdTrans *)); |
| 330 | } |
| 331 | target_fd_trans[fd] = trans; |
| 332 | } |
| 333 | |
| 334 | static void fd_trans_unregister(int fd) |
| 335 | { |
| 336 | if (fd >= 0 && fd < target_fd_max) { |
| 337 | target_fd_trans[fd] = NULL; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static void fd_trans_dup(int oldfd, int newfd) |
| 342 | { |
| 343 | fd_trans_unregister(newfd); |
| 344 | if (oldfd < target_fd_max && target_fd_trans[oldfd]) { |
| 345 | fd_trans_register(newfd, target_fd_trans[oldfd]); |
| 346 | } |
| 347 | } |
| 348 | |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 349 | static int sys_getcwd1(char *buf, size_t size) |
| 350 | { |
| 351 | if (getcwd(buf, size) == NULL) { |
| 352 | /* getcwd() sets errno */ |
| 353 | return (-1); |
| 354 | } |
aurel32 | aaf4ad3 | 2009-04-16 14:17:14 +0000 | [diff] [blame] | 355 | return strlen(buf)+1; |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Alexander Graf | f4c6901 | 2011-09-25 06:25:35 +0200 | [diff] [blame] | 358 | static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 359 | { |
| 360 | /* |
| 361 | * open(2) has extra parameter 'mode' when called with |
| 362 | * flag O_CREAT. |
| 363 | */ |
| 364 | if ((flags & O_CREAT) != 0) { |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 365 | return (openat(dirfd, pathname, flags, mode)); |
| 366 | } |
| 367 | return (openat(dirfd, pathname, flags)); |
| 368 | } |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 369 | |
Peter Maydell | 1acae9f | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 370 | #ifdef TARGET_NR_utimensat |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 371 | #ifdef CONFIG_UTIMENSAT |
| 372 | static int sys_utimensat(int dirfd, const char *pathname, |
| 373 | const struct timespec times[2], int flags) |
| 374 | { |
| 375 | if (pathname == NULL) |
| 376 | return futimens(dirfd, times); |
| 377 | else |
| 378 | return utimensat(dirfd, pathname, times, flags); |
| 379 | } |
Peter Maydell | 1acae9f | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 380 | #elif defined(__NR_utimensat) |
| 381 | #define __NR_sys_utimensat __NR_utimensat |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 382 | _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, |
| 383 | const struct timespec *,tsp,int,flags) |
Peter Maydell | 1acae9f | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 384 | #else |
| 385 | static int sys_utimensat(int dirfd, const char *pathname, |
| 386 | const struct timespec times[2], int flags) |
| 387 | { |
| 388 | errno = ENOSYS; |
| 389 | return -1; |
| 390 | } |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 391 | #endif |
Peter Maydell | 1acae9f | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 392 | #endif /* TARGET_NR_utimensat */ |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 393 | |
| 394 | #ifdef CONFIG_INOTIFY |
aurel32 | 8690e42 | 2009-04-17 13:50:32 +0000 | [diff] [blame] | 395 | #include <sys/inotify.h> |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 396 | |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 397 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 398 | static int sys_inotify_init(void) |
| 399 | { |
| 400 | return (inotify_init()); |
| 401 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 402 | #endif |
| 403 | #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 404 | static int sys_inotify_add_watch(int fd,const char *pathname, int32_t mask) |
| 405 | { |
| 406 | return (inotify_add_watch(fd, pathname, mask)); |
| 407 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 408 | #endif |
| 409 | #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 410 | static int sys_inotify_rm_watch(int fd, int32_t wd) |
| 411 | { |
aurel32 | 8690e42 | 2009-04-17 13:50:32 +0000 | [diff] [blame] | 412 | return (inotify_rm_watch(fd, wd)); |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 413 | } |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 414 | #endif |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 415 | #ifdef CONFIG_INOTIFY1 |
| 416 | #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) |
| 417 | static int sys_inotify_init1(int flags) |
| 418 | { |
| 419 | return (inotify_init1(flags)); |
| 420 | } |
| 421 | #endif |
| 422 | #endif |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 423 | #else |
| 424 | /* Userspace can usually survive runtime without inotify */ |
| 425 | #undef TARGET_NR_inotify_init |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 426 | #undef TARGET_NR_inotify_init1 |
aurel32 | 3b3f24a | 2009-04-15 16:12:13 +0000 | [diff] [blame] | 427 | #undef TARGET_NR_inotify_add_watch |
| 428 | #undef TARGET_NR_inotify_rm_watch |
| 429 | #endif /* CONFIG_INOTIFY */ |
| 430 | |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 431 | #if defined(TARGET_NR_ppoll) |
| 432 | #ifndef __NR_ppoll |
| 433 | # define __NR_ppoll -1 |
| 434 | #endif |
| 435 | #define __NR_sys_ppoll __NR_ppoll |
| 436 | _syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, |
Natanael Copa | 34d6086 | 2014-04-29 13:11:20 +0200 | [diff] [blame] | 437 | struct timespec *, timeout, const sigset_t *, sigmask, |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 438 | size_t, sigsetsize) |
| 439 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 440 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 441 | #if defined(TARGET_NR_pselect6) |
| 442 | #ifndef __NR_pselect6 |
| 443 | # define __NR_pselect6 -1 |
| 444 | #endif |
| 445 | #define __NR_sys_pselect6 __NR_pselect6 |
| 446 | _syscall6(int, sys_pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, |
| 447 | fd_set *, exceptfds, struct timespec *, timeout, void *, sig); |
| 448 | #endif |
| 449 | |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 450 | #if defined(TARGET_NR_prlimit64) |
| 451 | #ifndef __NR_prlimit64 |
| 452 | # define __NR_prlimit64 -1 |
| 453 | #endif |
| 454 | #define __NR_sys_prlimit64 __NR_prlimit64 |
| 455 | /* The glibc rlimit structure may not be that used by the underlying syscall */ |
| 456 | struct host_rlimit64 { |
| 457 | uint64_t rlim_cur; |
| 458 | uint64_t rlim_max; |
| 459 | }; |
| 460 | _syscall4(int, sys_prlimit64, pid_t, pid, int, resource, |
| 461 | const struct host_rlimit64 *, new_limit, |
| 462 | struct host_rlimit64 *, old_limit) |
| 463 | #endif |
| 464 | |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 465 | |
| 466 | #if defined(TARGET_NR_timer_create) |
| 467 | /* Maxiumum of 32 active POSIX timers allowed at any one time. */ |
| 468 | static timer_t g_posix_timers[32] = { 0, } ; |
| 469 | |
| 470 | static inline int next_free_host_timer(void) |
| 471 | { |
| 472 | int k ; |
| 473 | /* FIXME: Does finding the next free slot require a lock? */ |
| 474 | for (k = 0; k < ARRAY_SIZE(g_posix_timers); k++) { |
| 475 | if (g_posix_timers[k] == 0) { |
| 476 | g_posix_timers[k] = (timer_t) 1; |
| 477 | return k; |
| 478 | } |
| 479 | } |
| 480 | return -1; |
| 481 | } |
| 482 | #endif |
| 483 | |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 484 | /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ |
Alexander Graf | 4a1def4 | 2012-09-29 15:32:38 +0000 | [diff] [blame] | 485 | #ifdef TARGET_ARM |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 486 | static inline int regpairs_aligned(void *cpu_env) { |
| 487 | return ((((CPUARMState *)cpu_env)->eabi) == 1) ; |
| 488 | } |
| 489 | #elif defined(TARGET_MIPS) |
| 490 | static inline int regpairs_aligned(void *cpu_env) { return 1; } |
Alexander Graf | 4a1def4 | 2012-09-29 15:32:38 +0000 | [diff] [blame] | 491 | #elif defined(TARGET_PPC) && !defined(TARGET_PPC64) |
| 492 | /* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs |
| 493 | * of registers which translates to the same as ARM/MIPS, because we start with |
| 494 | * r3 as arg1 */ |
| 495 | static inline int regpairs_aligned(void *cpu_env) { return 1; } |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 496 | #else |
| 497 | static inline int regpairs_aligned(void *cpu_env) { return 0; } |
| 498 | #endif |
| 499 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 500 | #define ERRNO_TABLE_SIZE 1200 |
| 501 | |
| 502 | /* target_to_host_errno_table[] is initialized from |
| 503 | * host_to_target_errno_table[] in syscall_init(). */ |
| 504 | static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { |
| 505 | }; |
| 506 | |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 507 | /* |
ths | fe8f096 | 2007-07-12 10:59:21 +0000 | [diff] [blame] | 508 | * This list is the union of errno values overridden in asm-<arch>/errno.h |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 509 | * minus the errnos that are not actually generic to all archs. |
| 510 | */ |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 511 | static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { |
Chen Gang | 08703b9 | 2015-09-07 10:35:06 +0800 | [diff] [blame] | 512 | [EAGAIN] = TARGET_EAGAIN, |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 513 | [EIDRM] = TARGET_EIDRM, |
| 514 | [ECHRNG] = TARGET_ECHRNG, |
| 515 | [EL2NSYNC] = TARGET_EL2NSYNC, |
| 516 | [EL3HLT] = TARGET_EL3HLT, |
| 517 | [EL3RST] = TARGET_EL3RST, |
| 518 | [ELNRNG] = TARGET_ELNRNG, |
| 519 | [EUNATCH] = TARGET_EUNATCH, |
| 520 | [ENOCSI] = TARGET_ENOCSI, |
| 521 | [EL2HLT] = TARGET_EL2HLT, |
| 522 | [EDEADLK] = TARGET_EDEADLK, |
| 523 | [ENOLCK] = TARGET_ENOLCK, |
| 524 | [EBADE] = TARGET_EBADE, |
| 525 | [EBADR] = TARGET_EBADR, |
| 526 | [EXFULL] = TARGET_EXFULL, |
| 527 | [ENOANO] = TARGET_ENOANO, |
| 528 | [EBADRQC] = TARGET_EBADRQC, |
| 529 | [EBADSLT] = TARGET_EBADSLT, |
| 530 | [EBFONT] = TARGET_EBFONT, |
| 531 | [ENOSTR] = TARGET_ENOSTR, |
| 532 | [ENODATA] = TARGET_ENODATA, |
| 533 | [ETIME] = TARGET_ETIME, |
| 534 | [ENOSR] = TARGET_ENOSR, |
| 535 | [ENONET] = TARGET_ENONET, |
| 536 | [ENOPKG] = TARGET_ENOPKG, |
| 537 | [EREMOTE] = TARGET_EREMOTE, |
| 538 | [ENOLINK] = TARGET_ENOLINK, |
| 539 | [EADV] = TARGET_EADV, |
| 540 | [ESRMNT] = TARGET_ESRMNT, |
| 541 | [ECOMM] = TARGET_ECOMM, |
| 542 | [EPROTO] = TARGET_EPROTO, |
| 543 | [EDOTDOT] = TARGET_EDOTDOT, |
| 544 | [EMULTIHOP] = TARGET_EMULTIHOP, |
| 545 | [EBADMSG] = TARGET_EBADMSG, |
| 546 | [ENAMETOOLONG] = TARGET_ENAMETOOLONG, |
| 547 | [EOVERFLOW] = TARGET_EOVERFLOW, |
| 548 | [ENOTUNIQ] = TARGET_ENOTUNIQ, |
| 549 | [EBADFD] = TARGET_EBADFD, |
| 550 | [EREMCHG] = TARGET_EREMCHG, |
| 551 | [ELIBACC] = TARGET_ELIBACC, |
| 552 | [ELIBBAD] = TARGET_ELIBBAD, |
| 553 | [ELIBSCN] = TARGET_ELIBSCN, |
| 554 | [ELIBMAX] = TARGET_ELIBMAX, |
| 555 | [ELIBEXEC] = TARGET_ELIBEXEC, |
| 556 | [EILSEQ] = TARGET_EILSEQ, |
| 557 | [ENOSYS] = TARGET_ENOSYS, |
| 558 | [ELOOP] = TARGET_ELOOP, |
| 559 | [ERESTART] = TARGET_ERESTART, |
| 560 | [ESTRPIPE] = TARGET_ESTRPIPE, |
| 561 | [ENOTEMPTY] = TARGET_ENOTEMPTY, |
| 562 | [EUSERS] = TARGET_EUSERS, |
| 563 | [ENOTSOCK] = TARGET_ENOTSOCK, |
| 564 | [EDESTADDRREQ] = TARGET_EDESTADDRREQ, |
| 565 | [EMSGSIZE] = TARGET_EMSGSIZE, |
| 566 | [EPROTOTYPE] = TARGET_EPROTOTYPE, |
| 567 | [ENOPROTOOPT] = TARGET_ENOPROTOOPT, |
| 568 | [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT, |
| 569 | [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT, |
| 570 | [EOPNOTSUPP] = TARGET_EOPNOTSUPP, |
| 571 | [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT, |
| 572 | [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT, |
| 573 | [EADDRINUSE] = TARGET_EADDRINUSE, |
| 574 | [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL, |
| 575 | [ENETDOWN] = TARGET_ENETDOWN, |
| 576 | [ENETUNREACH] = TARGET_ENETUNREACH, |
| 577 | [ENETRESET] = TARGET_ENETRESET, |
| 578 | [ECONNABORTED] = TARGET_ECONNABORTED, |
| 579 | [ECONNRESET] = TARGET_ECONNRESET, |
| 580 | [ENOBUFS] = TARGET_ENOBUFS, |
| 581 | [EISCONN] = TARGET_EISCONN, |
| 582 | [ENOTCONN] = TARGET_ENOTCONN, |
| 583 | [EUCLEAN] = TARGET_EUCLEAN, |
| 584 | [ENOTNAM] = TARGET_ENOTNAM, |
| 585 | [ENAVAIL] = TARGET_ENAVAIL, |
| 586 | [EISNAM] = TARGET_EISNAM, |
| 587 | [EREMOTEIO] = TARGET_EREMOTEIO, |
| 588 | [ESHUTDOWN] = TARGET_ESHUTDOWN, |
| 589 | [ETOOMANYREFS] = TARGET_ETOOMANYREFS, |
| 590 | [ETIMEDOUT] = TARGET_ETIMEDOUT, |
| 591 | [ECONNREFUSED] = TARGET_ECONNREFUSED, |
| 592 | [EHOSTDOWN] = TARGET_EHOSTDOWN, |
| 593 | [EHOSTUNREACH] = TARGET_EHOSTUNREACH, |
| 594 | [EALREADY] = TARGET_EALREADY, |
| 595 | [EINPROGRESS] = TARGET_EINPROGRESS, |
| 596 | [ESTALE] = TARGET_ESTALE, |
| 597 | [ECANCELED] = TARGET_ECANCELED, |
| 598 | [ENOMEDIUM] = TARGET_ENOMEDIUM, |
| 599 | [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 600 | #ifdef ENOKEY |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 601 | [ENOKEY] = TARGET_ENOKEY, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 602 | #endif |
| 603 | #ifdef EKEYEXPIRED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 604 | [EKEYEXPIRED] = TARGET_EKEYEXPIRED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 605 | #endif |
| 606 | #ifdef EKEYREVOKED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 607 | [EKEYREVOKED] = TARGET_EKEYREVOKED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 608 | #endif |
| 609 | #ifdef EKEYREJECTED |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 610 | [EKEYREJECTED] = TARGET_EKEYREJECTED, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 611 | #endif |
| 612 | #ifdef EOWNERDEAD |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 613 | [EOWNERDEAD] = TARGET_EOWNERDEAD, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 614 | #endif |
| 615 | #ifdef ENOTRECOVERABLE |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 616 | [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE, |
ths | b7fe5db | 2007-07-23 15:37:46 +0000 | [diff] [blame] | 617 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 618 | }; |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 619 | |
| 620 | static inline int host_to_target_errno(int err) |
| 621 | { |
| 622 | if(host_to_target_errno_table[err]) |
| 623 | return host_to_target_errno_table[err]; |
| 624 | return err; |
| 625 | } |
| 626 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 627 | static inline int target_to_host_errno(int err) |
| 628 | { |
| 629 | if (target_to_host_errno_table[err]) |
| 630 | return target_to_host_errno_table[err]; |
| 631 | return err; |
| 632 | } |
| 633 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 634 | static inline abi_long get_errno(abi_long ret) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 635 | { |
| 636 | if (ret == -1) |
ths | 637947f | 2007-06-01 12:09:19 +0000 | [diff] [blame] | 637 | return -host_to_target_errno(errno); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 638 | else |
| 639 | return ret; |
| 640 | } |
| 641 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 642 | static inline int is_error(abi_long ret) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 643 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 644 | return (abi_ulong)ret >= (abi_ulong)(-4096); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 645 | } |
| 646 | |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 647 | char *target_strerror(int err) |
| 648 | { |
Alexander Graf | 962b289 | 2011-11-21 12:04:07 +0100 | [diff] [blame] | 649 | if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) { |
| 650 | return NULL; |
| 651 | } |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 652 | return strerror(target_to_host_errno(err)); |
| 653 | } |
| 654 | |
Paul Burton | 8289d11 | 2014-06-22 11:25:33 +0100 | [diff] [blame] | 655 | static inline int host_to_target_sock_type(int host_type) |
| 656 | { |
| 657 | int target_type; |
| 658 | |
| 659 | switch (host_type & 0xf /* SOCK_TYPE_MASK */) { |
| 660 | case SOCK_DGRAM: |
| 661 | target_type = TARGET_SOCK_DGRAM; |
| 662 | break; |
| 663 | case SOCK_STREAM: |
| 664 | target_type = TARGET_SOCK_STREAM; |
| 665 | break; |
| 666 | default: |
| 667 | target_type = host_type & 0xf /* SOCK_TYPE_MASK */; |
| 668 | break; |
| 669 | } |
| 670 | |
| 671 | #if defined(SOCK_CLOEXEC) |
| 672 | if (host_type & SOCK_CLOEXEC) { |
| 673 | target_type |= TARGET_SOCK_CLOEXEC; |
| 674 | } |
| 675 | #endif |
| 676 | |
| 677 | #if defined(SOCK_NONBLOCK) |
| 678 | if (host_type & SOCK_NONBLOCK) { |
| 679 | target_type |= TARGET_SOCK_NONBLOCK; |
| 680 | } |
| 681 | #endif |
| 682 | |
| 683 | return target_type; |
| 684 | } |
| 685 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 686 | static abi_ulong target_brk; |
| 687 | static abi_ulong target_original_brk; |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 688 | static abi_ulong brk_page; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 689 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 690 | void target_set_brk(abi_ulong new_brk) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 691 | { |
blueswir1 | 4c1de73 | 2007-07-07 20:45:44 +0000 | [diff] [blame] | 692 | target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 693 | brk_page = HOST_PAGE_ALIGN(target_brk); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 694 | } |
| 695 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 696 | //#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0) |
| 697 | #define DEBUGF_BRK(message, args...) |
| 698 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 699 | /* do_brk() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 700 | abi_long do_brk(abi_ulong new_brk) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 701 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 702 | abi_long mapped_addr; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 703 | int new_alloc_size; |
| 704 | |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 705 | DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 706 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 707 | if (!new_brk) { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 708 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (!new_brk)\n", target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 709 | return target_brk; |
| 710 | } |
| 711 | if (new_brk < target_original_brk) { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 712 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk < target_original_brk)\n", |
| 713 | target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 714 | return target_brk; |
| 715 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 716 | |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 717 | /* If the new brk is less than the highest page reserved to the |
| 718 | * target heap allocation, set it and we're almost done... */ |
| 719 | if (new_brk <= brk_page) { |
| 720 | /* Heap contents are initialized to zero, as for anonymous |
| 721 | * mapped pages. */ |
| 722 | if (new_brk > target_brk) { |
| 723 | memset(g2h(target_brk), 0, new_brk - target_brk); |
| 724 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 725 | target_brk = new_brk; |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 726 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 727 | return target_brk; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 730 | /* We need to allocate more memory after the brk... Note that |
| 731 | * we don't use MAP_FIXED because that will map over the top of |
| 732 | * any existing mapping (like the one with the host libc or qemu |
| 733 | * itself); instead we treat "mapped but at wrong address" as |
| 734 | * a failure and unmap again. |
| 735 | */ |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 736 | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 737 | mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 738 | PROT_READ|PROT_WRITE, |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 739 | MAP_ANON|MAP_PRIVATE, 0, 0)); |
| 740 | |
| 741 | if (mapped_addr == brk_page) { |
CĂ©dric VINCENT | 70afc34 | 2011-08-26 10:56:50 +0200 | [diff] [blame] | 742 | /* Heap contents are initialized to zero, as for anonymous |
| 743 | * mapped pages. Technically the new pages are already |
| 744 | * initialized to zero since they *are* anonymous mapped |
| 745 | * pages, however we have to take care with the contents that |
| 746 | * come from the remaining part of the previous page: it may |
| 747 | * contains garbage data due to a previous heap usage (grown |
| 748 | * then shrunken). */ |
| 749 | memset(g2h(target_brk), 0, brk_page - target_brk); |
| 750 | |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 751 | target_brk = new_brk; |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 752 | brk_page = HOST_PAGE_ALIGN(target_brk); |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 753 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr == brk_page)\n", |
| 754 | target_brk); |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 755 | return target_brk; |
| 756 | } else if (mapped_addr != -1) { |
| 757 | /* Mapped but at wrong address, meaning there wasn't actually |
| 758 | * enough space for this brk. |
| 759 | */ |
| 760 | target_munmap(mapped_addr, new_alloc_size); |
| 761 | mapped_addr = -1; |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 762 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr != -1)\n", target_brk); |
vincent | 4d1de87 | 2011-06-14 21:56:33 +0000 | [diff] [blame] | 763 | } |
| 764 | else { |
Paul Brook | 3a0c6c4 | 2012-02-09 19:04:27 +0000 | [diff] [blame] | 765 | DEBUGF_BRK(TARGET_ABI_FMT_lx " (otherwise)\n", target_brk); |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 766 | } |
balrog | 7ab240a | 2008-04-26 12:17:34 +0000 | [diff] [blame] | 767 | |
Richard Henderson | 7dd46c0 | 2010-05-03 10:07:49 -0700 | [diff] [blame] | 768 | #if defined(TARGET_ALPHA) |
| 769 | /* We (partially) emulate OSF/1 on Alpha, which requires we |
| 770 | return a proper errno, not an unchanged brk value. */ |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 771 | return -TARGET_ENOMEM; |
Richard Henderson | 7dd46c0 | 2010-05-03 10:07:49 -0700 | [diff] [blame] | 772 | #endif |
Peter Maydell | 00faf08 | 2011-04-18 16:34:24 +0100 | [diff] [blame] | 773 | /* For everything else, return the previous break. */ |
balrog | 7ab240a | 2008-04-26 12:17:34 +0000 | [diff] [blame] | 774 | return target_brk; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 775 | } |
| 776 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 777 | static inline abi_long copy_from_user_fdset(fd_set *fds, |
| 778 | abi_ulong target_fds_addr, |
| 779 | int n) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 780 | { |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 781 | int i, nw, j, k; |
| 782 | abi_ulong b, *target_fds; |
| 783 | |
| 784 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
| 785 | if (!(target_fds = lock_user(VERIFY_READ, |
| 786 | target_fds_addr, |
| 787 | sizeof(abi_ulong) * nw, |
| 788 | 1))) |
| 789 | return -TARGET_EFAULT; |
| 790 | |
| 791 | FD_ZERO(fds); |
| 792 | k = 0; |
| 793 | for (i = 0; i < nw; i++) { |
| 794 | /* grab the abi_ulong */ |
| 795 | __get_user(b, &target_fds[i]); |
| 796 | for (j = 0; j < TARGET_ABI_BITS; j++) { |
| 797 | /* check the bit inside the abi_ulong */ |
| 798 | if ((b >> j) & 1) |
| 799 | FD_SET(k, fds); |
| 800 | k++; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 801 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 802 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 803 | |
| 804 | unlock_user(target_fds, target_fds_addr, 0); |
| 805 | |
| 806 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 809 | static inline abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr, |
| 810 | abi_ulong target_fds_addr, |
| 811 | int n) |
| 812 | { |
| 813 | if (target_fds_addr) { |
| 814 | if (copy_from_user_fdset(fds, target_fds_addr, n)) |
| 815 | return -TARGET_EFAULT; |
| 816 | *fds_ptr = fds; |
| 817 | } else { |
| 818 | *fds_ptr = NULL; |
| 819 | } |
| 820 | return 0; |
| 821 | } |
| 822 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 823 | static inline abi_long copy_to_user_fdset(abi_ulong target_fds_addr, |
| 824 | const fd_set *fds, |
| 825 | int n) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 826 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 827 | int i, nw, j, k; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 828 | abi_long v; |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 829 | abi_ulong *target_fds; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 830 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 831 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
| 832 | if (!(target_fds = lock_user(VERIFY_WRITE, |
| 833 | target_fds_addr, |
| 834 | sizeof(abi_ulong) * nw, |
| 835 | 0))) |
| 836 | return -TARGET_EFAULT; |
| 837 | |
| 838 | k = 0; |
| 839 | for (i = 0; i < nw; i++) { |
| 840 | v = 0; |
| 841 | for (j = 0; j < TARGET_ABI_BITS; j++) { |
Andreas Schwab | 9ab709b | 2013-04-09 01:02:34 +0000 | [diff] [blame] | 842 | v |= ((abi_ulong)(FD_ISSET(k, fds) != 0) << j); |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 843 | k++; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 844 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 845 | __put_user(v, &target_fds[i]); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 846 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 847 | |
| 848 | unlock_user(target_fds, target_fds_addr, sizeof(abi_ulong) * nw); |
| 849 | |
| 850 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 851 | } |
| 852 | |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 853 | #if defined(__alpha__) |
| 854 | #define HOST_HZ 1024 |
| 855 | #else |
| 856 | #define HOST_HZ 100 |
| 857 | #endif |
| 858 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 859 | static inline abi_long host_to_target_clock_t(long ticks) |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 860 | { |
| 861 | #if HOST_HZ == TARGET_HZ |
| 862 | return ticks; |
| 863 | #else |
| 864 | return ((int64_t)ticks * TARGET_HZ) / HOST_HZ; |
| 865 | #endif |
| 866 | } |
| 867 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 868 | static inline abi_long host_to_target_rusage(abi_ulong target_addr, |
| 869 | const struct rusage *rusage) |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 870 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 871 | struct target_rusage *target_rusage; |
| 872 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 873 | if (!lock_user_struct(VERIFY_WRITE, target_rusage, target_addr, 0)) |
| 874 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 875 | target_rusage->ru_utime.tv_sec = tswapal(rusage->ru_utime.tv_sec); |
| 876 | target_rusage->ru_utime.tv_usec = tswapal(rusage->ru_utime.tv_usec); |
| 877 | target_rusage->ru_stime.tv_sec = tswapal(rusage->ru_stime.tv_sec); |
| 878 | target_rusage->ru_stime.tv_usec = tswapal(rusage->ru_stime.tv_usec); |
| 879 | target_rusage->ru_maxrss = tswapal(rusage->ru_maxrss); |
| 880 | target_rusage->ru_ixrss = tswapal(rusage->ru_ixrss); |
| 881 | target_rusage->ru_idrss = tswapal(rusage->ru_idrss); |
| 882 | target_rusage->ru_isrss = tswapal(rusage->ru_isrss); |
| 883 | target_rusage->ru_minflt = tswapal(rusage->ru_minflt); |
| 884 | target_rusage->ru_majflt = tswapal(rusage->ru_majflt); |
| 885 | target_rusage->ru_nswap = tswapal(rusage->ru_nswap); |
| 886 | target_rusage->ru_inblock = tswapal(rusage->ru_inblock); |
| 887 | target_rusage->ru_oublock = tswapal(rusage->ru_oublock); |
| 888 | target_rusage->ru_msgsnd = tswapal(rusage->ru_msgsnd); |
| 889 | target_rusage->ru_msgrcv = tswapal(rusage->ru_msgrcv); |
| 890 | target_rusage->ru_nsignals = tswapal(rusage->ru_nsignals); |
| 891 | target_rusage->ru_nvcsw = tswapal(rusage->ru_nvcsw); |
| 892 | target_rusage->ru_nivcsw = tswapal(rusage->ru_nivcsw); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 893 | unlock_user_struct(target_rusage, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 894 | |
| 895 | return 0; |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 898 | static inline rlim_t target_to_host_rlim(abi_ulong target_rlim) |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 899 | { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 900 | abi_ulong target_rlim_swap; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 901 | rlim_t result; |
| 902 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 903 | target_rlim_swap = tswapal(target_rlim); |
| 904 | if (target_rlim_swap == TARGET_RLIM_INFINITY) |
| 905 | return RLIM_INFINITY; |
| 906 | |
| 907 | result = target_rlim_swap; |
| 908 | if (target_rlim_swap != (rlim_t)result) |
| 909 | return RLIM_INFINITY; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 910 | |
| 911 | return result; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 912 | } |
| 913 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 914 | static inline abi_ulong host_to_target_rlim(rlim_t rlim) |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 915 | { |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 916 | abi_ulong target_rlim_swap; |
| 917 | abi_ulong result; |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 918 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 919 | if (rlim == RLIM_INFINITY || rlim != (abi_long)rlim) |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 920 | target_rlim_swap = TARGET_RLIM_INFINITY; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 921 | else |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 922 | target_rlim_swap = rlim; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 923 | result = tswapal(target_rlim_swap); |
Wesley W. Terpstra | 95b33b2 | 2011-07-12 14:38:22 +0300 | [diff] [blame] | 924 | |
| 925 | return result; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 926 | } |
| 927 | |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 928 | static inline int target_to_host_resource(int code) |
| 929 | { |
| 930 | switch (code) { |
| 931 | case TARGET_RLIMIT_AS: |
| 932 | return RLIMIT_AS; |
| 933 | case TARGET_RLIMIT_CORE: |
| 934 | return RLIMIT_CORE; |
| 935 | case TARGET_RLIMIT_CPU: |
| 936 | return RLIMIT_CPU; |
| 937 | case TARGET_RLIMIT_DATA: |
| 938 | return RLIMIT_DATA; |
| 939 | case TARGET_RLIMIT_FSIZE: |
| 940 | return RLIMIT_FSIZE; |
| 941 | case TARGET_RLIMIT_LOCKS: |
| 942 | return RLIMIT_LOCKS; |
| 943 | case TARGET_RLIMIT_MEMLOCK: |
| 944 | return RLIMIT_MEMLOCK; |
| 945 | case TARGET_RLIMIT_MSGQUEUE: |
| 946 | return RLIMIT_MSGQUEUE; |
| 947 | case TARGET_RLIMIT_NICE: |
| 948 | return RLIMIT_NICE; |
| 949 | case TARGET_RLIMIT_NOFILE: |
| 950 | return RLIMIT_NOFILE; |
| 951 | case TARGET_RLIMIT_NPROC: |
| 952 | return RLIMIT_NPROC; |
| 953 | case TARGET_RLIMIT_RSS: |
| 954 | return RLIMIT_RSS; |
| 955 | case TARGET_RLIMIT_RTPRIO: |
| 956 | return RLIMIT_RTPRIO; |
| 957 | case TARGET_RLIMIT_SIGPENDING: |
| 958 | return RLIMIT_SIGPENDING; |
| 959 | case TARGET_RLIMIT_STACK: |
| 960 | return RLIMIT_STACK; |
| 961 | default: |
| 962 | return code; |
| 963 | } |
| 964 | } |
| 965 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 966 | static inline abi_long copy_from_user_timeval(struct timeval *tv, |
| 967 | abi_ulong target_tv_addr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 968 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 969 | struct target_timeval *target_tv; |
| 970 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 971 | if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 972 | return -TARGET_EFAULT; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 973 | |
| 974 | __get_user(tv->tv_sec, &target_tv->tv_sec); |
| 975 | __get_user(tv->tv_usec, &target_tv->tv_usec); |
| 976 | |
| 977 | unlock_user_struct(target_tv, target_tv_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 978 | |
| 979 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 980 | } |
| 981 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 982 | static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr, |
| 983 | const struct timeval *tv) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 984 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 985 | struct target_timeval *target_tv; |
| 986 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 987 | if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 988 | return -TARGET_EFAULT; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 989 | |
| 990 | __put_user(tv->tv_sec, &target_tv->tv_sec); |
| 991 | __put_user(tv->tv_usec, &target_tv->tv_usec); |
| 992 | |
| 993 | unlock_user_struct(target_tv, target_tv_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 994 | |
| 995 | return 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Paul Burton | ef4467e | 2014-06-22 11:25:40 +0100 | [diff] [blame] | 998 | static inline abi_long copy_from_user_timezone(struct timezone *tz, |
| 999 | abi_ulong target_tz_addr) |
| 1000 | { |
| 1001 | struct target_timezone *target_tz; |
| 1002 | |
| 1003 | if (!lock_user_struct(VERIFY_READ, target_tz, target_tz_addr, 1)) { |
| 1004 | return -TARGET_EFAULT; |
| 1005 | } |
| 1006 | |
| 1007 | __get_user(tz->tz_minuteswest, &target_tz->tz_minuteswest); |
| 1008 | __get_user(tz->tz_dsttime, &target_tz->tz_dsttime); |
| 1009 | |
| 1010 | unlock_user_struct(target_tz, target_tz_addr, 0); |
| 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 1015 | #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) |
| 1016 | #include <mqueue.h> |
| 1017 | |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 1018 | static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr, |
| 1019 | abi_ulong target_mq_attr_addr) |
| 1020 | { |
| 1021 | struct target_mq_attr *target_mq_attr; |
| 1022 | |
| 1023 | if (!lock_user_struct(VERIFY_READ, target_mq_attr, |
| 1024 | target_mq_attr_addr, 1)) |
| 1025 | return -TARGET_EFAULT; |
| 1026 | |
| 1027 | __get_user(attr->mq_flags, &target_mq_attr->mq_flags); |
| 1028 | __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); |
| 1029 | __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize); |
| 1030 | __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); |
| 1031 | |
| 1032 | unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0); |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
| 1037 | static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr, |
| 1038 | const struct mq_attr *attr) |
| 1039 | { |
| 1040 | struct target_mq_attr *target_mq_attr; |
| 1041 | |
| 1042 | if (!lock_user_struct(VERIFY_WRITE, target_mq_attr, |
| 1043 | target_mq_attr_addr, 0)) |
| 1044 | return -TARGET_EFAULT; |
| 1045 | |
| 1046 | __put_user(attr->mq_flags, &target_mq_attr->mq_flags); |
| 1047 | __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg); |
| 1048 | __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize); |
| 1049 | __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs); |
| 1050 | |
| 1051 | unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1); |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 1055 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1056 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1057 | #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1058 | /* do_select() must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1059 | static abi_long do_select(int n, |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1060 | abi_ulong rfd_addr, abi_ulong wfd_addr, |
| 1061 | abi_ulong efd_addr, abi_ulong target_tv_addr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1062 | { |
| 1063 | fd_set rfds, wfds, efds; |
| 1064 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
| 1065 | struct timeval tv, *tv_ptr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1066 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1067 | |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1068 | ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); |
| 1069 | if (ret) { |
| 1070 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1071 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1072 | ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); |
| 1073 | if (ret) { |
| 1074 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1075 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1076 | ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); |
| 1077 | if (ret) { |
| 1078 | return ret; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1079 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1080 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1081 | if (target_tv_addr) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1082 | if (copy_from_user_timeval(&tv, target_tv_addr)) |
| 1083 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1084 | tv_ptr = &tv; |
| 1085 | } else { |
| 1086 | tv_ptr = NULL; |
| 1087 | } |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1088 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1089 | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1090 | |
ths | 26edcf4 | 2007-12-09 02:25:24 +0000 | [diff] [blame] | 1091 | if (!is_error(ret)) { |
| 1092 | if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) |
| 1093 | return -TARGET_EFAULT; |
| 1094 | if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) |
| 1095 | return -TARGET_EFAULT; |
| 1096 | if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) |
| 1097 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1098 | |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 1099 | if (target_tv_addr && copy_to_user_timeval(target_tv_addr, &tv)) |
| 1100 | return -TARGET_EFAULT; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1101 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1102 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1103 | return ret; |
| 1104 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 1105 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 1106 | |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1107 | static abi_long do_pipe2(int host_pipe[], int flags) |
| 1108 | { |
| 1109 | #ifdef CONFIG_PIPE2 |
| 1110 | return pipe2(host_pipe, flags); |
| 1111 | #else |
| 1112 | return -ENOSYS; |
| 1113 | #endif |
| 1114 | } |
| 1115 | |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1116 | static abi_long do_pipe(void *cpu_env, abi_ulong pipedes, |
| 1117 | int flags, int is_pipe2) |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1118 | { |
| 1119 | int host_pipe[2]; |
| 1120 | abi_long ret; |
| 1121 | ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe); |
| 1122 | |
| 1123 | if (is_error(ret)) |
| 1124 | return get_errno(ret); |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Several targets have special calling conventions for the original |
| 1127 | pipe syscall, but didn't replicate this into the pipe2 syscall. */ |
| 1128 | if (!is_pipe2) { |
| 1129 | #if defined(TARGET_ALPHA) |
| 1130 | ((CPUAlphaState *)cpu_env)->ir[IR_A4] = host_pipe[1]; |
| 1131 | return host_pipe[0]; |
| 1132 | #elif defined(TARGET_MIPS) |
| 1133 | ((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1]; |
| 1134 | return host_pipe[0]; |
| 1135 | #elif defined(TARGET_SH4) |
takasi-y@ops.dti.ne.jp | 597c021 | 2010-02-18 00:35:03 +0900 | [diff] [blame] | 1136 | ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1]; |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1137 | return host_pipe[0]; |
Peter Maydell | 82f05b6 | 2013-07-06 17:39:48 +0100 | [diff] [blame] | 1138 | #elif defined(TARGET_SPARC) |
| 1139 | ((CPUSPARCState*)cpu_env)->regwptr[1] = host_pipe[1]; |
| 1140 | return host_pipe[0]; |
takasi-y@ops.dti.ne.jp | 597c021 | 2010-02-18 00:35:03 +0900 | [diff] [blame] | 1141 | #endif |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1144 | if (put_user_s32(host_pipe[0], pipedes) |
| 1145 | || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0]))) |
| 1146 | return -TARGET_EFAULT; |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 1147 | return get_errno(ret); |
| 1148 | } |
| 1149 | |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1150 | static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, |
| 1151 | abi_ulong target_addr, |
| 1152 | socklen_t len) |
| 1153 | { |
| 1154 | struct target_ip_mreqn *target_smreqn; |
| 1155 | |
| 1156 | target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1); |
| 1157 | if (!target_smreqn) |
| 1158 | return -TARGET_EFAULT; |
| 1159 | mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr; |
| 1160 | mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr; |
| 1161 | if (len == sizeof(struct target_ip_mreqn)) |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1162 | mreqn->imr_ifindex = tswapal(target_smreqn->imr_ifindex); |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1163 | unlock_user(target_smreqn, target_addr, 0); |
| 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 1168 | static inline abi_long target_to_host_sockaddr(int fd, struct sockaddr *addr, |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1169 | abi_ulong target_addr, |
| 1170 | socklen_t len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1171 | { |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1172 | const socklen_t unix_maxlen = sizeof (struct sockaddr_un); |
| 1173 | sa_family_t sa_family; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1174 | struct target_sockaddr *target_saddr; |
| 1175 | |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 1176 | if (fd_trans_target_to_host_addr(fd)) { |
| 1177 | return fd_trans_target_to_host_addr(fd)(addr, target_addr, len); |
| 1178 | } |
| 1179 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1180 | target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); |
| 1181 | if (!target_saddr) |
| 1182 | return -TARGET_EFAULT; |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1183 | |
| 1184 | sa_family = tswap16(target_saddr->sa_family); |
| 1185 | |
| 1186 | /* Oops. The caller might send a incomplete sun_path; sun_path |
| 1187 | * must be terminated by \0 (see the manual page), but |
| 1188 | * unfortunately it is quite common to specify sockaddr_un |
| 1189 | * length as "strlen(x->sun_path)" while it should be |
| 1190 | * "strlen(...) + 1". We'll fix that here if needed. |
| 1191 | * Linux kernel has a similar feature. |
| 1192 | */ |
| 1193 | |
| 1194 | if (sa_family == AF_UNIX) { |
| 1195 | if (len < unix_maxlen && len > 0) { |
| 1196 | char *cp = (char*)target_saddr; |
| 1197 | |
| 1198 | if ( cp[len-1] && !cp[len] ) |
| 1199 | len++; |
| 1200 | } |
| 1201 | if (len > unix_maxlen) |
| 1202 | len = unix_maxlen; |
| 1203 | } |
| 1204 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1205 | memcpy(addr, target_saddr, len); |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 1206 | addr->sa_family = sa_family; |
Joakim Tjernlund | 33a29b5 | 2014-07-12 15:47:07 +0200 | [diff] [blame] | 1207 | if (sa_family == AF_PACKET) { |
| 1208 | struct target_sockaddr_ll *lladdr; |
| 1209 | |
| 1210 | lladdr = (struct target_sockaddr_ll *)addr; |
| 1211 | lladdr->sll_ifindex = tswap32(lladdr->sll_ifindex); |
| 1212 | lladdr->sll_hatype = tswap16(lladdr->sll_hatype); |
| 1213 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1214 | unlock_user(target_saddr, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1215 | |
| 1216 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1219 | static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, |
| 1220 | struct sockaddr *addr, |
| 1221 | socklen_t len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1222 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1223 | struct target_sockaddr *target_saddr; |
| 1224 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1225 | target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); |
| 1226 | if (!target_saddr) |
| 1227 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1228 | memcpy(target_saddr, addr, len); |
| 1229 | target_saddr->sa_family = tswap16(addr->sa_family); |
| 1230 | unlock_user(target_saddr, target_addr, len); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 1231 | |
| 1232 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1235 | static inline abi_long target_to_host_cmsg(struct msghdr *msgh, |
| 1236 | struct target_msghdr *target_msgh) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1237 | { |
| 1238 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1239 | abi_long msg_controllen; |
| 1240 | abi_ulong target_cmsg_addr; |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1241 | struct target_cmsghdr *target_cmsg, *target_cmsg_start; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1242 | socklen_t space = 0; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1243 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1244 | msg_controllen = tswapal(target_msgh->msg_controllen); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1245 | if (msg_controllen < sizeof (struct target_cmsghdr)) |
| 1246 | goto the_end; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1247 | target_cmsg_addr = tswapal(target_msgh->msg_control); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1248 | target_cmsg = lock_user(VERIFY_READ, target_cmsg_addr, msg_controllen, 1); |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1249 | target_cmsg_start = target_cmsg; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1250 | if (!target_cmsg) |
| 1251 | return -TARGET_EFAULT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1252 | |
| 1253 | while (cmsg && target_cmsg) { |
| 1254 | void *data = CMSG_DATA(cmsg); |
| 1255 | void *target_data = TARGET_CMSG_DATA(target_cmsg); |
| 1256 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1257 | int len = tswapal(target_cmsg->cmsg_len) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1258 | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); |
| 1259 | |
| 1260 | space += CMSG_SPACE(len); |
| 1261 | if (space > msgh->msg_controllen) { |
| 1262 | space -= CMSG_SPACE(len); |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1263 | /* This is a QEMU bug, since we allocated the payload |
| 1264 | * area ourselves (unlike overflow in host-to-target |
| 1265 | * conversion, which is just the guest giving us a buffer |
| 1266 | * that's too small). It can't happen for the payload types |
| 1267 | * we currently support; if it becomes an issue in future |
| 1268 | * we would need to improve our allocation strategy to |
| 1269 | * something more intelligent than "twice the size of the |
| 1270 | * target buffer we're reading from". |
| 1271 | */ |
bellard | 31febb7 | 2005-12-18 20:03:27 +0000 | [diff] [blame] | 1272 | gemu_log("Host cmsg overflow\n"); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1273 | break; |
| 1274 | } |
| 1275 | |
Petar Jovanovic | dbf4f79 | 2013-09-13 19:27:29 +0200 | [diff] [blame] | 1276 | if (tswap32(target_cmsg->cmsg_level) == TARGET_SOL_SOCKET) { |
| 1277 | cmsg->cmsg_level = SOL_SOCKET; |
| 1278 | } else { |
| 1279 | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); |
| 1280 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1281 | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); |
| 1282 | cmsg->cmsg_len = CMSG_LEN(len); |
| 1283 | |
Alex Suykov | 30b8b68 | 2014-12-23 07:52:58 +0200 | [diff] [blame] | 1284 | if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1285 | int *fd = (int *)data; |
| 1286 | int *target_fd = (int *)target_data; |
| 1287 | int i, numfds = len / sizeof(int); |
| 1288 | |
Peter Maydell | 876e23c | 2015-05-26 19:46:32 +0100 | [diff] [blame] | 1289 | for (i = 0; i < numfds; i++) { |
| 1290 | __get_user(fd[i], target_fd + i); |
| 1291 | } |
Alex Suykov | 30b8b68 | 2014-12-23 07:52:58 +0200 | [diff] [blame] | 1292 | } else if (cmsg->cmsg_level == SOL_SOCKET |
| 1293 | && cmsg->cmsg_type == SCM_CREDENTIALS) { |
| 1294 | struct ucred *cred = (struct ucred *)data; |
| 1295 | struct target_ucred *target_cred = |
| 1296 | (struct target_ucred *)target_data; |
| 1297 | |
Peter Maydell | 876e23c | 2015-05-26 19:46:32 +0100 | [diff] [blame] | 1298 | __get_user(cred->pid, &target_cred->pid); |
| 1299 | __get_user(cred->uid, &target_cred->uid); |
| 1300 | __get_user(cred->gid, &target_cred->gid); |
Alex Suykov | 30b8b68 | 2014-12-23 07:52:58 +0200 | [diff] [blame] | 1301 | } else { |
| 1302 | gemu_log("Unsupported ancillary data: %d/%d\n", |
| 1303 | cmsg->cmsg_level, cmsg->cmsg_type); |
| 1304 | memcpy(data, target_data, len); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | cmsg = CMSG_NXTHDR(msgh, cmsg); |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1308 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg, |
| 1309 | target_cmsg_start); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1310 | } |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1311 | unlock_user(target_cmsg, target_cmsg_addr, 0); |
| 1312 | the_end: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1313 | msgh->msg_controllen = space; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1314 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1317 | static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, |
| 1318 | struct msghdr *msgh) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1319 | { |
| 1320 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1321 | abi_long msg_controllen; |
| 1322 | abi_ulong target_cmsg_addr; |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1323 | struct target_cmsghdr *target_cmsg, *target_cmsg_start; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1324 | socklen_t space = 0; |
| 1325 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1326 | msg_controllen = tswapal(target_msgh->msg_controllen); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1327 | if (msg_controllen < sizeof (struct target_cmsghdr)) |
| 1328 | goto the_end; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1329 | target_cmsg_addr = tswapal(target_msgh->msg_control); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1330 | target_cmsg = lock_user(VERIFY_WRITE, target_cmsg_addr, msg_controllen, 0); |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1331 | target_cmsg_start = target_cmsg; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1332 | if (!target_cmsg) |
| 1333 | return -TARGET_EFAULT; |
| 1334 | |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1335 | while (cmsg && target_cmsg) { |
| 1336 | void *data = CMSG_DATA(cmsg); |
| 1337 | void *target_data = TARGET_CMSG_DATA(target_cmsg); |
| 1338 | |
| 1339 | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1340 | int tgt_len, tgt_space; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1341 | |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1342 | /* We never copy a half-header but may copy half-data; |
| 1343 | * this is Linux's behaviour in put_cmsg(). Note that |
| 1344 | * truncation here is a guest problem (which we report |
| 1345 | * to the guest via the CTRUNC bit), unlike truncation |
| 1346 | * in target_to_host_cmsg, which is a QEMU bug. |
| 1347 | */ |
| 1348 | if (msg_controllen < sizeof(struct cmsghdr)) { |
| 1349 | target_msgh->msg_flags |= tswap32(MSG_CTRUNC); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1350 | break; |
| 1351 | } |
| 1352 | |
Petar Jovanovic | dbf4f79 | 2013-09-13 19:27:29 +0200 | [diff] [blame] | 1353 | if (cmsg->cmsg_level == SOL_SOCKET) { |
| 1354 | target_cmsg->cmsg_level = tswap32(TARGET_SOL_SOCKET); |
| 1355 | } else { |
| 1356 | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); |
| 1357 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1358 | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1359 | |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1360 | tgt_len = TARGET_CMSG_LEN(len); |
| 1361 | |
| 1362 | /* Payload types which need a different size of payload on |
| 1363 | * the target must adjust tgt_len here. |
| 1364 | */ |
| 1365 | switch (cmsg->cmsg_level) { |
| 1366 | case SOL_SOCKET: |
| 1367 | switch (cmsg->cmsg_type) { |
| 1368 | case SO_TIMESTAMP: |
| 1369 | tgt_len = sizeof(struct target_timeval); |
| 1370 | break; |
| 1371 | default: |
| 1372 | break; |
| 1373 | } |
| 1374 | default: |
| 1375 | break; |
| 1376 | } |
| 1377 | |
| 1378 | if (msg_controllen < tgt_len) { |
| 1379 | target_msgh->msg_flags |= tswap32(MSG_CTRUNC); |
| 1380 | tgt_len = msg_controllen; |
| 1381 | } |
| 1382 | |
| 1383 | /* We must now copy-and-convert len bytes of payload |
| 1384 | * into tgt_len bytes of destination space. Bear in mind |
| 1385 | * that in both source and destination we may be dealing |
| 1386 | * with a truncated value! |
| 1387 | */ |
Huw Davies | 52b6549 | 2014-04-17 14:02:47 +0100 | [diff] [blame] | 1388 | switch (cmsg->cmsg_level) { |
| 1389 | case SOL_SOCKET: |
| 1390 | switch (cmsg->cmsg_type) { |
| 1391 | case SCM_RIGHTS: |
| 1392 | { |
| 1393 | int *fd = (int *)data; |
| 1394 | int *target_fd = (int *)target_data; |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1395 | int i, numfds = tgt_len / sizeof(int); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1396 | |
Peter Maydell | 876e23c | 2015-05-26 19:46:32 +0100 | [diff] [blame] | 1397 | for (i = 0; i < numfds; i++) { |
| 1398 | __put_user(fd[i], target_fd + i); |
| 1399 | } |
Huw Davies | 52b6549 | 2014-04-17 14:02:47 +0100 | [diff] [blame] | 1400 | break; |
| 1401 | } |
| 1402 | case SO_TIMESTAMP: |
| 1403 | { |
| 1404 | struct timeval *tv = (struct timeval *)data; |
| 1405 | struct target_timeval *target_tv = |
| 1406 | (struct target_timeval *)target_data; |
Jing Huang | aebf5bc | 2012-07-24 14:01:42 +0000 | [diff] [blame] | 1407 | |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1408 | if (len != sizeof(struct timeval) || |
| 1409 | tgt_len != sizeof(struct target_timeval)) { |
Huw Davies | 52b6549 | 2014-04-17 14:02:47 +0100 | [diff] [blame] | 1410 | goto unimplemented; |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1411 | } |
Huw Davies | 52b6549 | 2014-04-17 14:02:47 +0100 | [diff] [blame] | 1412 | |
| 1413 | /* copy struct timeval to target */ |
Peter Maydell | 876e23c | 2015-05-26 19:46:32 +0100 | [diff] [blame] | 1414 | __put_user(tv->tv_sec, &target_tv->tv_sec); |
| 1415 | __put_user(tv->tv_usec, &target_tv->tv_usec); |
Huw Davies | 52b6549 | 2014-04-17 14:02:47 +0100 | [diff] [blame] | 1416 | break; |
| 1417 | } |
Huw Davies | 4bc2975 | 2014-04-17 14:02:48 +0100 | [diff] [blame] | 1418 | case SCM_CREDENTIALS: |
| 1419 | { |
| 1420 | struct ucred *cred = (struct ucred *)data; |
| 1421 | struct target_ucred *target_cred = |
| 1422 | (struct target_ucred *)target_data; |
| 1423 | |
| 1424 | __put_user(cred->pid, &target_cred->pid); |
| 1425 | __put_user(cred->uid, &target_cred->uid); |
| 1426 | __put_user(cred->gid, &target_cred->gid); |
| 1427 | break; |
| 1428 | } |
Huw Davies | 52b6549 | 2014-04-17 14:02:47 +0100 | [diff] [blame] | 1429 | default: |
| 1430 | goto unimplemented; |
| 1431 | } |
| 1432 | break; |
| 1433 | |
| 1434 | default: |
| 1435 | unimplemented: |
Jing Huang | aebf5bc | 2012-07-24 14:01:42 +0000 | [diff] [blame] | 1436 | gemu_log("Unsupported ancillary data: %d/%d\n", |
| 1437 | cmsg->cmsg_level, cmsg->cmsg_type); |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1438 | memcpy(target_data, data, MIN(len, tgt_len)); |
| 1439 | if (tgt_len > len) { |
| 1440 | memset(target_data + len, 0, tgt_len - len); |
| 1441 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1444 | target_cmsg->cmsg_len = tswapal(tgt_len); |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1445 | tgt_space = TARGET_CMSG_SPACE(len); |
Peter Maydell | c2aeb25 | 2015-05-26 19:46:31 +0100 | [diff] [blame] | 1446 | if (msg_controllen < tgt_space) { |
| 1447 | tgt_space = msg_controllen; |
| 1448 | } |
| 1449 | msg_controllen -= tgt_space; |
| 1450 | space += tgt_space; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1451 | cmsg = CMSG_NXTHDR(msgh, cmsg); |
Jonathan Neuschäfer | ee10458 | 2015-09-03 07:27:26 +0200 | [diff] [blame] | 1452 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg, |
| 1453 | target_cmsg_start); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1454 | } |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1455 | unlock_user(target_cmsg, target_cmsg_addr, space); |
| 1456 | the_end: |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 1457 | target_msgh->msg_controllen = tswapal(space); |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 1458 | return 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1461 | /* do_setsockopt() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1462 | static abi_long do_setsockopt(int sockfd, int level, int optname, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1463 | abi_ulong optval_addr, socklen_t optlen) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1464 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1465 | abi_long ret; |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 1466 | int val; |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1467 | struct ip_mreqn *ip_mreq; |
Lionel Landwerlin | 6e3cb58 | 2009-04-25 23:31:18 +0200 | [diff] [blame] | 1468 | struct ip_mreq_source *ip_mreq_source; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1469 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1470 | switch(level) { |
| 1471 | case SOL_TCP: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1472 | /* TCP options all take an 'int' value. */ |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1473 | if (optlen < sizeof(uint32_t)) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1474 | return -TARGET_EINVAL; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1475 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1476 | if (get_user_u32(val, optval_addr)) |
| 1477 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1478 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
| 1479 | break; |
| 1480 | case SOL_IP: |
| 1481 | switch(optname) { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1482 | case IP_TOS: |
| 1483 | case IP_TTL: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1484 | case IP_HDRINCL: |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1485 | case IP_ROUTER_ALERT: |
| 1486 | case IP_RECVOPTS: |
| 1487 | case IP_RETOPTS: |
| 1488 | case IP_PKTINFO: |
| 1489 | case IP_MTU_DISCOVER: |
| 1490 | case IP_RECVERR: |
| 1491 | case IP_RECVTOS: |
| 1492 | #ifdef IP_FREEBIND |
| 1493 | case IP_FREEBIND: |
| 1494 | #endif |
| 1495 | case IP_MULTICAST_TTL: |
| 1496 | case IP_MULTICAST_LOOP: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1497 | val = 0; |
| 1498 | if (optlen >= sizeof(uint32_t)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1499 | if (get_user_u32(val, optval_addr)) |
| 1500 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1501 | } else if (optlen >= 1) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1502 | if (get_user_u8(val, optval_addr)) |
| 1503 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1504 | } |
| 1505 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
| 1506 | break; |
Lionel Landwerlin | b975b83 | 2009-04-25 23:30:19 +0200 | [diff] [blame] | 1507 | case IP_ADD_MEMBERSHIP: |
| 1508 | case IP_DROP_MEMBERSHIP: |
| 1509 | if (optlen < sizeof (struct target_ip_mreq) || |
| 1510 | optlen > sizeof (struct target_ip_mreqn)) |
| 1511 | return -TARGET_EINVAL; |
| 1512 | |
| 1513 | ip_mreq = (struct ip_mreqn *) alloca(optlen); |
| 1514 | target_to_host_ip_mreq(ip_mreq, optval_addr, optlen); |
| 1515 | ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen)); |
| 1516 | break; |
| 1517 | |
Lionel Landwerlin | 6e3cb58 | 2009-04-25 23:31:18 +0200 | [diff] [blame] | 1518 | case IP_BLOCK_SOURCE: |
| 1519 | case IP_UNBLOCK_SOURCE: |
| 1520 | case IP_ADD_SOURCE_MEMBERSHIP: |
| 1521 | case IP_DROP_SOURCE_MEMBERSHIP: |
| 1522 | if (optlen != sizeof (struct target_ip_mreq_source)) |
| 1523 | return -TARGET_EINVAL; |
| 1524 | |
| 1525 | ip_mreq_source = lock_user(VERIFY_READ, optval_addr, optlen, 1); |
| 1526 | ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq_source, optlen)); |
| 1527 | unlock_user (ip_mreq_source, optval_addr, 0); |
| 1528 | break; |
| 1529 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1530 | default: |
| 1531 | goto unimplemented; |
| 1532 | } |
| 1533 | break; |
Laurent Vivier | 0d78b3b | 2013-08-30 01:46:43 +0200 | [diff] [blame] | 1534 | case SOL_IPV6: |
| 1535 | switch (optname) { |
| 1536 | case IPV6_MTU_DISCOVER: |
| 1537 | case IPV6_MTU: |
| 1538 | case IPV6_V6ONLY: |
| 1539 | case IPV6_RECVPKTINFO: |
| 1540 | val = 0; |
| 1541 | if (optlen < sizeof(uint32_t)) { |
| 1542 | return -TARGET_EINVAL; |
| 1543 | } |
| 1544 | if (get_user_u32(val, optval_addr)) { |
| 1545 | return -TARGET_EFAULT; |
| 1546 | } |
| 1547 | ret = get_errno(setsockopt(sockfd, level, optname, |
| 1548 | &val, sizeof(val))); |
| 1549 | break; |
| 1550 | default: |
| 1551 | goto unimplemented; |
| 1552 | } |
| 1553 | break; |
Jing Huang | 920394d | 2012-07-24 13:59:23 +0000 | [diff] [blame] | 1554 | case SOL_RAW: |
| 1555 | switch (optname) { |
| 1556 | case ICMP_FILTER: |
| 1557 | /* struct icmp_filter takes an u32 value */ |
| 1558 | if (optlen < sizeof(uint32_t)) { |
| 1559 | return -TARGET_EINVAL; |
| 1560 | } |
| 1561 | |
| 1562 | if (get_user_u32(val, optval_addr)) { |
| 1563 | return -TARGET_EFAULT; |
| 1564 | } |
| 1565 | ret = get_errno(setsockopt(sockfd, level, optname, |
| 1566 | &val, sizeof(val))); |
| 1567 | break; |
| 1568 | |
| 1569 | default: |
| 1570 | goto unimplemented; |
| 1571 | } |
| 1572 | break; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1573 | case TARGET_SOL_SOCKET: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1574 | switch (optname) { |
Laurent Vivier | 1b09aeb | 2013-01-01 08:24:11 +0000 | [diff] [blame] | 1575 | case TARGET_SO_RCVTIMEO: |
| 1576 | { |
| 1577 | struct timeval tv; |
| 1578 | |
| 1579 | optname = SO_RCVTIMEO; |
| 1580 | |
| 1581 | set_timeout: |
| 1582 | if (optlen != sizeof(struct target_timeval)) { |
| 1583 | return -TARGET_EINVAL; |
| 1584 | } |
| 1585 | |
| 1586 | if (copy_from_user_timeval(&tv, optval_addr)) { |
| 1587 | return -TARGET_EFAULT; |
| 1588 | } |
| 1589 | |
| 1590 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, |
| 1591 | &tv, sizeof(tv))); |
| 1592 | return ret; |
| 1593 | } |
| 1594 | case TARGET_SO_SNDTIMEO: |
| 1595 | optname = SO_SNDTIMEO; |
| 1596 | goto set_timeout; |
Laurent Vivier | f57d419 | 2013-08-30 01:46:41 +0200 | [diff] [blame] | 1597 | case TARGET_SO_ATTACH_FILTER: |
| 1598 | { |
| 1599 | struct target_sock_fprog *tfprog; |
| 1600 | struct target_sock_filter *tfilter; |
| 1601 | struct sock_fprog fprog; |
| 1602 | struct sock_filter *filter; |
| 1603 | int i; |
| 1604 | |
| 1605 | if (optlen != sizeof(*tfprog)) { |
| 1606 | return -TARGET_EINVAL; |
| 1607 | } |
| 1608 | if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0)) { |
| 1609 | return -TARGET_EFAULT; |
| 1610 | } |
| 1611 | if (!lock_user_struct(VERIFY_READ, tfilter, |
| 1612 | tswapal(tfprog->filter), 0)) { |
| 1613 | unlock_user_struct(tfprog, optval_addr, 1); |
| 1614 | return -TARGET_EFAULT; |
| 1615 | } |
| 1616 | |
| 1617 | fprog.len = tswap16(tfprog->len); |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 1618 | filter = g_try_new(struct sock_filter, fprog.len); |
Laurent Vivier | f57d419 | 2013-08-30 01:46:41 +0200 | [diff] [blame] | 1619 | if (filter == NULL) { |
| 1620 | unlock_user_struct(tfilter, tfprog->filter, 1); |
| 1621 | unlock_user_struct(tfprog, optval_addr, 1); |
| 1622 | return -TARGET_ENOMEM; |
| 1623 | } |
| 1624 | for (i = 0; i < fprog.len; i++) { |
| 1625 | filter[i].code = tswap16(tfilter[i].code); |
| 1626 | filter[i].jt = tfilter[i].jt; |
| 1627 | filter[i].jf = tfilter[i].jf; |
| 1628 | filter[i].k = tswap32(tfilter[i].k); |
| 1629 | } |
| 1630 | fprog.filter = filter; |
| 1631 | |
| 1632 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, |
| 1633 | SO_ATTACH_FILTER, &fprog, sizeof(fprog))); |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 1634 | g_free(filter); |
Laurent Vivier | f57d419 | 2013-08-30 01:46:41 +0200 | [diff] [blame] | 1635 | |
| 1636 | unlock_user_struct(tfilter, tfprog->filter, 1); |
| 1637 | unlock_user_struct(tfprog, optval_addr, 1); |
| 1638 | return ret; |
| 1639 | } |
Joakim Tjernlund | 451aaf6 | 2014-07-12 15:47:06 +0200 | [diff] [blame] | 1640 | case TARGET_SO_BINDTODEVICE: |
| 1641 | { |
| 1642 | char *dev_ifname, *addr_ifname; |
| 1643 | |
| 1644 | if (optlen > IFNAMSIZ - 1) { |
| 1645 | optlen = IFNAMSIZ - 1; |
| 1646 | } |
| 1647 | dev_ifname = lock_user(VERIFY_READ, optval_addr, optlen, 1); |
| 1648 | if (!dev_ifname) { |
| 1649 | return -TARGET_EFAULT; |
| 1650 | } |
| 1651 | optname = SO_BINDTODEVICE; |
| 1652 | addr_ifname = alloca(IFNAMSIZ); |
| 1653 | memcpy(addr_ifname, dev_ifname, optlen); |
| 1654 | addr_ifname[optlen] = 0; |
Chen Gang | fad6c58 | 2016-01-11 13:58:50 +0800 | [diff] [blame] | 1655 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, |
| 1656 | addr_ifname, optlen)); |
Joakim Tjernlund | 451aaf6 | 2014-07-12 15:47:06 +0200 | [diff] [blame] | 1657 | unlock_user (dev_ifname, optval_addr, 0); |
| 1658 | return ret; |
| 1659 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1660 | /* Options with 'int' argument. */ |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1661 | case TARGET_SO_DEBUG: |
| 1662 | optname = SO_DEBUG; |
| 1663 | break; |
| 1664 | case TARGET_SO_REUSEADDR: |
| 1665 | optname = SO_REUSEADDR; |
| 1666 | break; |
| 1667 | case TARGET_SO_TYPE: |
| 1668 | optname = SO_TYPE; |
| 1669 | break; |
| 1670 | case TARGET_SO_ERROR: |
| 1671 | optname = SO_ERROR; |
| 1672 | break; |
| 1673 | case TARGET_SO_DONTROUTE: |
| 1674 | optname = SO_DONTROUTE; |
| 1675 | break; |
| 1676 | case TARGET_SO_BROADCAST: |
| 1677 | optname = SO_BROADCAST; |
| 1678 | break; |
| 1679 | case TARGET_SO_SNDBUF: |
| 1680 | optname = SO_SNDBUF; |
| 1681 | break; |
Paul Burton | d79b6cc | 2014-06-22 11:25:35 +0100 | [diff] [blame] | 1682 | case TARGET_SO_SNDBUFFORCE: |
| 1683 | optname = SO_SNDBUFFORCE; |
| 1684 | break; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1685 | case TARGET_SO_RCVBUF: |
| 1686 | optname = SO_RCVBUF; |
| 1687 | break; |
Paul Burton | d79b6cc | 2014-06-22 11:25:35 +0100 | [diff] [blame] | 1688 | case TARGET_SO_RCVBUFFORCE: |
| 1689 | optname = SO_RCVBUFFORCE; |
| 1690 | break; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1691 | case TARGET_SO_KEEPALIVE: |
| 1692 | optname = SO_KEEPALIVE; |
| 1693 | break; |
| 1694 | case TARGET_SO_OOBINLINE: |
| 1695 | optname = SO_OOBINLINE; |
| 1696 | break; |
| 1697 | case TARGET_SO_NO_CHECK: |
| 1698 | optname = SO_NO_CHECK; |
| 1699 | break; |
| 1700 | case TARGET_SO_PRIORITY: |
| 1701 | optname = SO_PRIORITY; |
| 1702 | break; |
bellard | 5e83e8e | 2005-03-01 22:32:06 +0000 | [diff] [blame] | 1703 | #ifdef SO_BSDCOMPAT |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1704 | case TARGET_SO_BSDCOMPAT: |
| 1705 | optname = SO_BSDCOMPAT; |
| 1706 | break; |
bellard | 5e83e8e | 2005-03-01 22:32:06 +0000 | [diff] [blame] | 1707 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1708 | case TARGET_SO_PASSCRED: |
| 1709 | optname = SO_PASSCRED; |
| 1710 | break; |
Paul Burton | 82d0fe6 | 2014-06-22 11:25:36 +0100 | [diff] [blame] | 1711 | case TARGET_SO_PASSSEC: |
| 1712 | optname = SO_PASSSEC; |
| 1713 | break; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1714 | case TARGET_SO_TIMESTAMP: |
| 1715 | optname = SO_TIMESTAMP; |
| 1716 | break; |
| 1717 | case TARGET_SO_RCVLOWAT: |
| 1718 | optname = SO_RCVLOWAT; |
| 1719 | break; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1720 | break; |
| 1721 | default: |
| 1722 | goto unimplemented; |
| 1723 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1724 | if (optlen < sizeof(uint32_t)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1725 | return -TARGET_EINVAL; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1726 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1727 | if (get_user_u32(val, optval_addr)) |
| 1728 | return -TARGET_EFAULT; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1729 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val))); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1730 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1731 | default: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1732 | unimplemented: |
Stefan Weil | b2bedb2 | 2011-09-12 22:33:01 +0200 | [diff] [blame] | 1733 | gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname); |
ths | 6fa13c1 | 2007-12-18 02:41:04 +0000 | [diff] [blame] | 1734 | ret = -TARGET_ENOPROTOOPT; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1735 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1736 | return ret; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1739 | /* do_getsockopt() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1740 | static abi_long do_getsockopt(int sockfd, int level, int optname, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1741 | abi_ulong optval_addr, abi_ulong optlen) |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1742 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 1743 | abi_long ret; |
blueswir1 | b55266b | 2008-09-20 08:07:15 +0000 | [diff] [blame] | 1744 | int len, val; |
| 1745 | socklen_t lv; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1746 | |
| 1747 | switch(level) { |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 1748 | case TARGET_SOL_SOCKET: |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1749 | level = SOL_SOCKET; |
| 1750 | switch (optname) { |
| 1751 | /* These don't just return a single integer */ |
| 1752 | case TARGET_SO_LINGER: |
| 1753 | case TARGET_SO_RCVTIMEO: |
| 1754 | case TARGET_SO_SNDTIMEO: |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1755 | case TARGET_SO_PEERNAME: |
| 1756 | goto unimplemented; |
Akos PASZTORY | 583359a | 2011-11-14 15:09:49 +0200 | [diff] [blame] | 1757 | case TARGET_SO_PEERCRED: { |
| 1758 | struct ucred cr; |
| 1759 | socklen_t crlen; |
| 1760 | struct target_ucred *tcr; |
| 1761 | |
| 1762 | if (get_user_u32(len, optlen)) { |
| 1763 | return -TARGET_EFAULT; |
| 1764 | } |
| 1765 | if (len < 0) { |
| 1766 | return -TARGET_EINVAL; |
| 1767 | } |
| 1768 | |
| 1769 | crlen = sizeof(cr); |
| 1770 | ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED, |
| 1771 | &cr, &crlen)); |
| 1772 | if (ret < 0) { |
| 1773 | return ret; |
| 1774 | } |
| 1775 | if (len > crlen) { |
| 1776 | len = crlen; |
| 1777 | } |
| 1778 | if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)) { |
| 1779 | return -TARGET_EFAULT; |
| 1780 | } |
| 1781 | __put_user(cr.pid, &tcr->pid); |
| 1782 | __put_user(cr.uid, &tcr->uid); |
| 1783 | __put_user(cr.gid, &tcr->gid); |
| 1784 | unlock_user_struct(tcr, optval_addr, 1); |
| 1785 | if (put_user_u32(len, optlen)) { |
| 1786 | return -TARGET_EFAULT; |
| 1787 | } |
| 1788 | break; |
| 1789 | } |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1790 | /* Options with 'int' argument. */ |
| 1791 | case TARGET_SO_DEBUG: |
| 1792 | optname = SO_DEBUG; |
| 1793 | goto int_case; |
| 1794 | case TARGET_SO_REUSEADDR: |
| 1795 | optname = SO_REUSEADDR; |
| 1796 | goto int_case; |
| 1797 | case TARGET_SO_TYPE: |
| 1798 | optname = SO_TYPE; |
| 1799 | goto int_case; |
| 1800 | case TARGET_SO_ERROR: |
| 1801 | optname = SO_ERROR; |
| 1802 | goto int_case; |
| 1803 | case TARGET_SO_DONTROUTE: |
| 1804 | optname = SO_DONTROUTE; |
| 1805 | goto int_case; |
| 1806 | case TARGET_SO_BROADCAST: |
| 1807 | optname = SO_BROADCAST; |
| 1808 | goto int_case; |
| 1809 | case TARGET_SO_SNDBUF: |
| 1810 | optname = SO_SNDBUF; |
| 1811 | goto int_case; |
| 1812 | case TARGET_SO_RCVBUF: |
| 1813 | optname = SO_RCVBUF; |
| 1814 | goto int_case; |
| 1815 | case TARGET_SO_KEEPALIVE: |
| 1816 | optname = SO_KEEPALIVE; |
| 1817 | goto int_case; |
| 1818 | case TARGET_SO_OOBINLINE: |
| 1819 | optname = SO_OOBINLINE; |
| 1820 | goto int_case; |
| 1821 | case TARGET_SO_NO_CHECK: |
| 1822 | optname = SO_NO_CHECK; |
| 1823 | goto int_case; |
| 1824 | case TARGET_SO_PRIORITY: |
| 1825 | optname = SO_PRIORITY; |
| 1826 | goto int_case; |
| 1827 | #ifdef SO_BSDCOMPAT |
| 1828 | case TARGET_SO_BSDCOMPAT: |
| 1829 | optname = SO_BSDCOMPAT; |
| 1830 | goto int_case; |
| 1831 | #endif |
| 1832 | case TARGET_SO_PASSCRED: |
| 1833 | optname = SO_PASSCRED; |
| 1834 | goto int_case; |
| 1835 | case TARGET_SO_TIMESTAMP: |
| 1836 | optname = SO_TIMESTAMP; |
| 1837 | goto int_case; |
| 1838 | case TARGET_SO_RCVLOWAT: |
| 1839 | optname = SO_RCVLOWAT; |
| 1840 | goto int_case; |
Paul Burton | aec1ca4 | 2014-06-22 11:25:34 +0100 | [diff] [blame] | 1841 | case TARGET_SO_ACCEPTCONN: |
| 1842 | optname = SO_ACCEPTCONN; |
| 1843 | goto int_case; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1844 | default: |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1845 | goto int_case; |
| 1846 | } |
| 1847 | break; |
| 1848 | case SOL_TCP: |
| 1849 | /* TCP options all take an 'int' value. */ |
| 1850 | int_case: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1851 | if (get_user_u32(len, optlen)) |
| 1852 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1853 | if (len < 0) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1854 | return -TARGET_EINVAL; |
Mike Frysinger | 73160d9 | 2011-02-07 01:05:49 -0500 | [diff] [blame] | 1855 | lv = sizeof(lv); |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1856 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
| 1857 | if (ret < 0) |
| 1858 | return ret; |
Paul Burton | 8289d11 | 2014-06-22 11:25:33 +0100 | [diff] [blame] | 1859 | if (optname == SO_TYPE) { |
| 1860 | val = host_to_target_sock_type(val); |
| 1861 | } |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1862 | if (len > lv) |
| 1863 | len = lv; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1864 | if (len == 4) { |
| 1865 | if (put_user_u32(val, optval_addr)) |
| 1866 | return -TARGET_EFAULT; |
| 1867 | } else { |
| 1868 | if (put_user_u8(val, optval_addr)) |
| 1869 | return -TARGET_EFAULT; |
Jamie Lentin | f3b974c | 2010-11-26 15:04:08 +0200 | [diff] [blame] | 1870 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1871 | if (put_user_u32(len, optlen)) |
| 1872 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1873 | break; |
| 1874 | case SOL_IP: |
| 1875 | switch(optname) { |
| 1876 | case IP_TOS: |
| 1877 | case IP_TTL: |
| 1878 | case IP_HDRINCL: |
| 1879 | case IP_ROUTER_ALERT: |
| 1880 | case IP_RECVOPTS: |
| 1881 | case IP_RETOPTS: |
| 1882 | case IP_PKTINFO: |
| 1883 | case IP_MTU_DISCOVER: |
| 1884 | case IP_RECVERR: |
| 1885 | case IP_RECVTOS: |
| 1886 | #ifdef IP_FREEBIND |
| 1887 | case IP_FREEBIND: |
| 1888 | #endif |
| 1889 | case IP_MULTICAST_TTL: |
| 1890 | case IP_MULTICAST_LOOP: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1891 | if (get_user_u32(len, optlen)) |
| 1892 | return -TARGET_EFAULT; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1893 | if (len < 0) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 1894 | return -TARGET_EINVAL; |
Mike Frysinger | 73160d9 | 2011-02-07 01:05:49 -0500 | [diff] [blame] | 1895 | lv = sizeof(lv); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1896 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
| 1897 | if (ret < 0) |
| 1898 | return ret; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1899 | if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1900 | len = 1; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1901 | if (put_user_u32(len, optlen) |
| 1902 | || put_user_u8(val, optval_addr)) |
| 1903 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1904 | } else { |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1905 | if (len > sizeof(int)) |
| 1906 | len = sizeof(int); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 1907 | if (put_user_u32(len, optlen) |
| 1908 | || put_user_u32(val, optval_addr)) |
| 1909 | return -TARGET_EFAULT; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1910 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1911 | break; |
bellard | 2efbe91 | 2005-07-23 15:10:20 +0000 | [diff] [blame] | 1912 | default: |
ths | c02f499 | 2007-12-18 02:39:59 +0000 | [diff] [blame] | 1913 | ret = -TARGET_ENOPROTOOPT; |
| 1914 | break; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1915 | } |
| 1916 | break; |
| 1917 | default: |
| 1918 | unimplemented: |
| 1919 | gemu_log("getsockopt level=%d optname=%d not yet supported\n", |
| 1920 | level, optname); |
ths | c02f499 | 2007-12-18 02:39:59 +0000 | [diff] [blame] | 1921 | ret = -TARGET_EOPNOTSUPP; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 1922 | break; |
| 1923 | } |
| 1924 | return ret; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1927 | static struct iovec *lock_iovec(int type, abi_ulong target_addr, |
| 1928 | int count, int copy) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1929 | { |
| 1930 | struct target_iovec *target_vec; |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1931 | struct iovec *vec; |
| 1932 | abi_ulong total_len, max_len; |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 1933 | int i; |
Peter Maydell | 501bb4b | 2014-02-17 18:55:33 +0000 | [diff] [blame] | 1934 | int err = 0; |
Tom Musta | 29560a6 | 2014-08-12 13:53:43 -0500 | [diff] [blame] | 1935 | bool bad_address = false; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1936 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1937 | if (count == 0) { |
| 1938 | errno = 0; |
| 1939 | return NULL; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1940 | } |
Peter Maydell | dfae8e0 | 2013-02-08 07:58:41 +0000 | [diff] [blame] | 1941 | if (count < 0 || count > IOV_MAX) { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1942 | errno = EINVAL; |
| 1943 | return NULL; |
| 1944 | } |
| 1945 | |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 1946 | vec = g_try_new0(struct iovec, count); |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1947 | if (vec == NULL) { |
| 1948 | errno = ENOMEM; |
| 1949 | return NULL; |
| 1950 | } |
| 1951 | |
| 1952 | target_vec = lock_user(VERIFY_READ, target_addr, |
| 1953 | count * sizeof(struct target_iovec), 1); |
| 1954 | if (target_vec == NULL) { |
Peter Maydell | 501bb4b | 2014-02-17 18:55:33 +0000 | [diff] [blame] | 1955 | err = EFAULT; |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1956 | goto fail2; |
| 1957 | } |
| 1958 | |
| 1959 | /* ??? If host page size > target page size, this will result in a |
| 1960 | value larger than what we can actually support. */ |
| 1961 | max_len = 0x7fffffff & TARGET_PAGE_MASK; |
| 1962 | total_len = 0; |
| 1963 | |
| 1964 | for (i = 0; i < count; i++) { |
| 1965 | abi_ulong base = tswapal(target_vec[i].iov_base); |
| 1966 | abi_long len = tswapal(target_vec[i].iov_len); |
| 1967 | |
| 1968 | if (len < 0) { |
Peter Maydell | 501bb4b | 2014-02-17 18:55:33 +0000 | [diff] [blame] | 1969 | err = EINVAL; |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1970 | goto fail; |
| 1971 | } else if (len == 0) { |
| 1972 | /* Zero length pointer is ignored. */ |
| 1973 | vec[i].iov_base = 0; |
| 1974 | } else { |
| 1975 | vec[i].iov_base = lock_user(type, base, len, copy); |
Tom Musta | 29560a6 | 2014-08-12 13:53:43 -0500 | [diff] [blame] | 1976 | /* If the first buffer pointer is bad, this is a fault. But |
| 1977 | * subsequent bad buffers will result in a partial write; this |
| 1978 | * is realized by filling the vector with null pointers and |
| 1979 | * zero lengths. */ |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1980 | if (!vec[i].iov_base) { |
Tom Musta | 29560a6 | 2014-08-12 13:53:43 -0500 | [diff] [blame] | 1981 | if (i == 0) { |
| 1982 | err = EFAULT; |
| 1983 | goto fail; |
| 1984 | } else { |
| 1985 | bad_address = true; |
| 1986 | } |
| 1987 | } |
| 1988 | if (bad_address) { |
| 1989 | len = 0; |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 1990 | } |
| 1991 | if (len > max_len - total_len) { |
| 1992 | len = max_len - total_len; |
| 1993 | } |
| 1994 | } |
| 1995 | vec[i].iov_len = len; |
| 1996 | total_len += len; |
| 1997 | } |
| 1998 | |
| 1999 | unlock_user(target_vec, target_addr, 0); |
| 2000 | return vec; |
| 2001 | |
| 2002 | fail: |
Chen Gang S | 7eff518 | 2015-01-23 18:01:09 +0800 | [diff] [blame] | 2003 | while (--i >= 0) { |
| 2004 | if (tswapal(target_vec[i].iov_len) > 0) { |
| 2005 | unlock_user(vec[i].iov_base, tswapal(target_vec[i].iov_base), 0); |
| 2006 | } |
| 2007 | } |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2008 | unlock_user(target_vec, target_addr, 0); |
Peter Maydell | 501bb4b | 2014-02-17 18:55:33 +0000 | [diff] [blame] | 2009 | fail2: |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 2010 | g_free(vec); |
Peter Maydell | 501bb4b | 2014-02-17 18:55:33 +0000 | [diff] [blame] | 2011 | errno = err; |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2012 | return NULL; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2015 | static void unlock_iovec(struct iovec *vec, abi_ulong target_addr, |
| 2016 | int count, int copy) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 2017 | { |
| 2018 | struct target_iovec *target_vec; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 2019 | int i; |
| 2020 | |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2021 | target_vec = lock_user(VERIFY_READ, target_addr, |
| 2022 | count * sizeof(struct target_iovec), 1); |
| 2023 | if (target_vec) { |
| 2024 | for (i = 0; i < count; i++) { |
| 2025 | abi_ulong base = tswapal(target_vec[i].iov_base); |
Chen Gang S | 71ec7ce | 2015-01-23 18:07:50 +0800 | [diff] [blame] | 2026 | abi_long len = tswapal(target_vec[i].iov_len); |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2027 | if (len < 0) { |
| 2028 | break; |
| 2029 | } |
balrog | d732dcb | 2008-10-28 10:21:03 +0000 | [diff] [blame] | 2030 | unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0); |
| 2031 | } |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2032 | unlock_user(target_vec, target_addr, 0); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 2033 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2034 | |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 2035 | g_free(vec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2038 | static inline int target_to_host_sock_type(int *type) |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2039 | { |
| 2040 | int host_type = 0; |
| 2041 | int target_type = *type; |
| 2042 | |
| 2043 | switch (target_type & TARGET_SOCK_TYPE_MASK) { |
| 2044 | case TARGET_SOCK_DGRAM: |
| 2045 | host_type = SOCK_DGRAM; |
| 2046 | break; |
| 2047 | case TARGET_SOCK_STREAM: |
| 2048 | host_type = SOCK_STREAM; |
| 2049 | break; |
| 2050 | default: |
| 2051 | host_type = target_type & TARGET_SOCK_TYPE_MASK; |
| 2052 | break; |
| 2053 | } |
| 2054 | if (target_type & TARGET_SOCK_CLOEXEC) { |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2055 | #if defined(SOCK_CLOEXEC) |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2056 | host_type |= SOCK_CLOEXEC; |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2057 | #else |
| 2058 | return -TARGET_EINVAL; |
| 2059 | #endif |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2060 | } |
| 2061 | if (target_type & TARGET_SOCK_NONBLOCK) { |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2062 | #if defined(SOCK_NONBLOCK) |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2063 | host_type |= SOCK_NONBLOCK; |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2064 | #elif !defined(O_NONBLOCK) |
| 2065 | return -TARGET_EINVAL; |
| 2066 | #endif |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2067 | } |
| 2068 | *type = host_type; |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | /* Try to emulate socket type flags after socket creation. */ |
| 2073 | static int sock_flags_fixup(int fd, int target_type) |
| 2074 | { |
| 2075 | #if !defined(SOCK_NONBLOCK) && defined(O_NONBLOCK) |
| 2076 | if (target_type & TARGET_SOCK_NONBLOCK) { |
| 2077 | int flags = fcntl(fd, F_GETFL); |
| 2078 | if (fcntl(fd, F_SETFL, O_NONBLOCK | flags) == -1) { |
| 2079 | close(fd); |
| 2080 | return -TARGET_EINVAL; |
| 2081 | } |
| 2082 | } |
| 2083 | #endif |
| 2084 | return fd; |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2085 | } |
| 2086 | |
Laurent Vivier | 0cf2272 | 2015-10-28 21:40:45 +0100 | [diff] [blame] | 2087 | static abi_long packet_target_to_host_sockaddr(void *host_addr, |
| 2088 | abi_ulong target_addr, |
| 2089 | socklen_t len) |
| 2090 | { |
| 2091 | struct sockaddr *addr = host_addr; |
| 2092 | struct target_sockaddr *target_saddr; |
| 2093 | |
| 2094 | target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); |
| 2095 | if (!target_saddr) { |
| 2096 | return -TARGET_EFAULT; |
| 2097 | } |
| 2098 | |
| 2099 | memcpy(addr, target_saddr, len); |
| 2100 | addr->sa_family = tswap16(target_saddr->sa_family); |
| 2101 | /* spkt_protocol is big-endian */ |
| 2102 | |
| 2103 | unlock_user(target_saddr, target_addr, 0); |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
| 2107 | static TargetFdTrans target_packet_trans = { |
| 2108 | .target_to_host_addr = packet_target_to_host_sockaddr, |
| 2109 | }; |
| 2110 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2111 | /* do_socket() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2112 | static abi_long do_socket(int domain, int type, int protocol) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2113 | { |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2114 | int target_type = type; |
| 2115 | int ret; |
| 2116 | |
| 2117 | ret = target_to_host_sock_type(&type); |
| 2118 | if (ret) { |
| 2119 | return ret; |
| 2120 | } |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2121 | |
balrog | 12bc92a | 2007-10-30 21:06:14 +0000 | [diff] [blame] | 2122 | if (domain == PF_NETLINK) |
Ed Swierk | 480eda2 | 2014-05-05 20:04:45 -0700 | [diff] [blame] | 2123 | return -TARGET_EAFNOSUPPORT; |
Laurent Vivier | ff626f2 | 2015-10-28 21:40:42 +0100 | [diff] [blame] | 2124 | |
| 2125 | if (domain == AF_PACKET || |
| 2126 | (domain == AF_INET && type == SOCK_PACKET)) { |
| 2127 | protocol = tswap16(protocol); |
| 2128 | } |
| 2129 | |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2130 | ret = get_errno(socket(domain, type, protocol)); |
| 2131 | if (ret >= 0) { |
| 2132 | ret = sock_flags_fixup(ret, target_type); |
Laurent Vivier | 0cf2272 | 2015-10-28 21:40:45 +0100 | [diff] [blame] | 2133 | if (type == SOCK_PACKET) { |
| 2134 | /* Manage an obsolete case : |
| 2135 | * if socket type is SOCK_PACKET, bind by name |
| 2136 | */ |
| 2137 | fd_trans_register(ret, &target_packet_trans); |
| 2138 | } |
Edgar E. Iglesias | 53d09b7 | 2013-09-23 14:11:53 +0200 | [diff] [blame] | 2139 | } |
| 2140 | return ret; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2143 | /* do_bind() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2144 | static abi_long do_bind(int sockfd, abi_ulong target_addr, |
| 2145 | socklen_t addrlen) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2146 | { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2147 | void *addr; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2148 | abi_long ret; |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2149 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2150 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2151 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2152 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2153 | |
aurel32 | 607175e | 2009-04-15 16:11:59 +0000 | [diff] [blame] | 2154 | addr = alloca(addrlen+1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2155 | |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 2156 | ret = target_to_host_sockaddr(sockfd, addr, target_addr, addrlen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2157 | if (ret) |
| 2158 | return ret; |
| 2159 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2160 | return get_errno(bind(sockfd, addr, addrlen)); |
| 2161 | } |
| 2162 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2163 | /* do_connect() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2164 | static abi_long do_connect(int sockfd, abi_ulong target_addr, |
| 2165 | socklen_t addrlen) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2166 | { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2167 | void *addr; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2168 | abi_long ret; |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2169 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2170 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2171 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2172 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2173 | |
Joakim Tjernlund | 2dd08df | 2014-07-11 17:18:03 +0200 | [diff] [blame] | 2174 | addr = alloca(addrlen+1); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2175 | |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 2176 | ret = target_to_host_sockaddr(sockfd, addr, target_addr, addrlen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2177 | if (ret) |
| 2178 | return ret; |
| 2179 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2180 | return get_errno(connect(sockfd, addr, addrlen)); |
| 2181 | } |
| 2182 | |
Alexander Graf | f19e00d | 2014-03-02 19:36:42 +0000 | [diff] [blame] | 2183 | /* do_sendrecvmsg_locked() Must return target values and target errnos. */ |
| 2184 | static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, |
| 2185 | int flags, int send) |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2186 | { |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 2187 | abi_long ret, len; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2188 | struct msghdr msg; |
| 2189 | int count; |
| 2190 | struct iovec *vec; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2191 | abi_ulong target_vec; |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2192 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2193 | if (msgp->msg_name) { |
| 2194 | msg.msg_namelen = tswap32(msgp->msg_namelen); |
Joakim Tjernlund | 2dd08df | 2014-07-11 17:18:03 +0200 | [diff] [blame] | 2195 | msg.msg_name = alloca(msg.msg_namelen+1); |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 2196 | ret = target_to_host_sockaddr(fd, msg.msg_name, |
| 2197 | tswapal(msgp->msg_name), |
| 2198 | msg.msg_namelen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2199 | if (ret) { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2200 | goto out2; |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2201 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2202 | } else { |
| 2203 | msg.msg_name = NULL; |
| 2204 | msg.msg_namelen = 0; |
| 2205 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2206 | msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2207 | msg.msg_control = alloca(msg.msg_controllen); |
| 2208 | msg.msg_flags = tswap32(msgp->msg_flags); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2209 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2210 | count = tswapal(msgp->msg_iovlen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2211 | target_vec = tswapal(msgp->msg_iov); |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2212 | vec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, |
| 2213 | target_vec, count, send); |
| 2214 | if (vec == NULL) { |
| 2215 | ret = -host_to_target_errno(errno); |
| 2216 | goto out2; |
| 2217 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2218 | msg.msg_iovlen = count; |
| 2219 | msg.msg_iov = vec; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2220 | |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2221 | if (send) { |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 2222 | ret = target_to_host_cmsg(&msg, msgp); |
| 2223 | if (ret == 0) |
| 2224 | ret = get_errno(sendmsg(fd, &msg, flags)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2225 | } else { |
| 2226 | ret = get_errno(recvmsg(fd, &msg, flags)); |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 2227 | if (!is_error(ret)) { |
| 2228 | len = ret; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 2229 | ret = host_to_target_cmsg(msgp, &msg); |
Jing Huang | ca61906 | 2012-07-24 13:58:02 +0000 | [diff] [blame] | 2230 | if (!is_error(ret)) { |
| 2231 | msgp->msg_namelen = tswap32(msg.msg_namelen); |
| 2232 | if (msg.msg_name != NULL) { |
| 2233 | ret = host_to_target_sockaddr(tswapal(msgp->msg_name), |
| 2234 | msg.msg_name, msg.msg_namelen); |
| 2235 | if (ret) { |
| 2236 | goto out; |
| 2237 | } |
| 2238 | } |
| 2239 | |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 2240 | ret = len; |
Jing Huang | ca61906 | 2012-07-24 13:58:02 +0000 | [diff] [blame] | 2241 | } |
balrog | 6de645c | 2008-10-28 10:26:29 +0000 | [diff] [blame] | 2242 | } |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2243 | } |
Jing Huang | ca61906 | 2012-07-24 13:58:02 +0000 | [diff] [blame] | 2244 | |
| 2245 | out: |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2246 | unlock_iovec(vec, target_vec, count, !send); |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 2247 | out2: |
Alexander Graf | f19e00d | 2014-03-02 19:36:42 +0000 | [diff] [blame] | 2248 | return ret; |
| 2249 | } |
| 2250 | |
| 2251 | static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, |
| 2252 | int flags, int send) |
| 2253 | { |
| 2254 | abi_long ret; |
| 2255 | struct target_msghdr *msgp; |
| 2256 | |
| 2257 | if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE, |
| 2258 | msgp, |
| 2259 | target_msg, |
| 2260 | send ? 1 : 0)) { |
| 2261 | return -TARGET_EFAULT; |
| 2262 | } |
| 2263 | ret = do_sendrecvmsg_locked(fd, msgp, flags, send); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2264 | unlock_user_struct(msgp, target_msg, send ? 0 : 1); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 2265 | return ret; |
| 2266 | } |
| 2267 | |
Alexander Graf | f19e00d | 2014-03-02 19:36:42 +0000 | [diff] [blame] | 2268 | /* We don't rely on the C library to have sendmmsg/recvmmsg support, |
| 2269 | * so it might not have this *mmsg-specific flag either. |
| 2270 | */ |
| 2271 | #ifndef MSG_WAITFORONE |
| 2272 | #define MSG_WAITFORONE 0x10000 |
| 2273 | #endif |
| 2274 | |
| 2275 | static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec, |
| 2276 | unsigned int vlen, unsigned int flags, |
| 2277 | int send) |
| 2278 | { |
| 2279 | struct target_mmsghdr *mmsgp; |
| 2280 | abi_long ret = 0; |
| 2281 | int i; |
| 2282 | |
| 2283 | if (vlen > UIO_MAXIOV) { |
| 2284 | vlen = UIO_MAXIOV; |
| 2285 | } |
| 2286 | |
| 2287 | mmsgp = lock_user(VERIFY_WRITE, target_msgvec, sizeof(*mmsgp) * vlen, 1); |
| 2288 | if (!mmsgp) { |
| 2289 | return -TARGET_EFAULT; |
| 2290 | } |
| 2291 | |
| 2292 | for (i = 0; i < vlen; i++) { |
| 2293 | ret = do_sendrecvmsg_locked(fd, &mmsgp[i].msg_hdr, flags, send); |
| 2294 | if (is_error(ret)) { |
| 2295 | break; |
| 2296 | } |
| 2297 | mmsgp[i].msg_len = tswap32(ret); |
| 2298 | /* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */ |
| 2299 | if (flags & MSG_WAITFORONE) { |
| 2300 | flags |= MSG_DONTWAIT; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | unlock_user(mmsgp, target_msgvec, sizeof(*mmsgp) * i); |
| 2305 | |
| 2306 | /* Return number of datagrams sent if we sent any at all; |
| 2307 | * otherwise return the error. |
| 2308 | */ |
| 2309 | if (i) { |
| 2310 | return i; |
| 2311 | } |
| 2312 | return ret; |
| 2313 | } |
Alexander Graf | f19e00d | 2014-03-02 19:36:42 +0000 | [diff] [blame] | 2314 | |
Peter Maydell | a94b498 | 2013-02-08 04:35:04 +0000 | [diff] [blame] | 2315 | /* If we don't have a system accept4() then just call accept. |
| 2316 | * The callsites to do_accept4() will ensure that they don't |
| 2317 | * pass a non-zero flags argument in this config. |
| 2318 | */ |
| 2319 | #ifndef CONFIG_ACCEPT4 |
| 2320 | static inline int accept4(int sockfd, struct sockaddr *addr, |
| 2321 | socklen_t *addrlen, int flags) |
| 2322 | { |
| 2323 | assert(flags == 0); |
| 2324 | return accept(sockfd, addr, addrlen); |
| 2325 | } |
| 2326 | #endif |
| 2327 | |
| 2328 | /* do_accept4() Must return target values and target errnos. */ |
| 2329 | static abi_long do_accept4(int fd, abi_ulong target_addr, |
| 2330 | abi_ulong target_addrlen_addr, int flags) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2331 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2332 | socklen_t addrlen; |
| 2333 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2334 | abi_long ret; |
Petar Jovanovic | d25295d | 2014-03-31 17:41:23 +0200 | [diff] [blame] | 2335 | int host_flags; |
| 2336 | |
| 2337 | host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl); |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2338 | |
Peter Maydell | a94b498 | 2013-02-08 04:35:04 +0000 | [diff] [blame] | 2339 | if (target_addr == 0) { |
Petar Jovanovic | d25295d | 2014-03-31 17:41:23 +0200 | [diff] [blame] | 2340 | return get_errno(accept4(fd, NULL, NULL, host_flags)); |
Peter Maydell | a94b498 | 2013-02-08 04:35:04 +0000 | [diff] [blame] | 2341 | } |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2342 | |
| 2343 | /* linux returns EINVAL if addrlen pointer is invalid */ |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2344 | if (get_user_u32(addrlen, target_addrlen_addr)) |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2345 | return -TARGET_EINVAL; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2346 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2347 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2348 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2349 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2350 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2351 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2352 | return -TARGET_EINVAL; |
| 2353 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2354 | addr = alloca(addrlen); |
| 2355 | |
Petar Jovanovic | d25295d | 2014-03-31 17:41:23 +0200 | [diff] [blame] | 2356 | ret = get_errno(accept4(fd, addr, &addrlen, host_flags)); |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2357 | if (!is_error(ret)) { |
| 2358 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2359 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2360 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2361 | } |
| 2362 | return ret; |
| 2363 | } |
| 2364 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2365 | /* do_getpeername() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2366 | static abi_long do_getpeername(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2367 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2368 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2369 | socklen_t addrlen; |
| 2370 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2371 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2372 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2373 | if (get_user_u32(addrlen, target_addrlen_addr)) |
| 2374 | return -TARGET_EFAULT; |
| 2375 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2376 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2377 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2378 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2379 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2380 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2381 | return -TARGET_EFAULT; |
| 2382 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2383 | addr = alloca(addrlen); |
| 2384 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2385 | ret = get_errno(getpeername(fd, addr, &addrlen)); |
| 2386 | if (!is_error(ret)) { |
| 2387 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2388 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2389 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2390 | } |
| 2391 | return ret; |
| 2392 | } |
| 2393 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2394 | /* do_getsockname() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2395 | static abi_long do_getsockname(int fd, abi_ulong target_addr, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2396 | abi_ulong target_addrlen_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2397 | { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2398 | socklen_t addrlen; |
| 2399 | void *addr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2400 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2401 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2402 | if (get_user_u32(addrlen, target_addrlen_addr)) |
| 2403 | return -TARGET_EFAULT; |
| 2404 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2405 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2406 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2407 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2408 | |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2409 | if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) |
| 2410 | return -TARGET_EFAULT; |
| 2411 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2412 | addr = alloca(addrlen); |
| 2413 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2414 | ret = get_errno(getsockname(fd, addr, &addrlen)); |
| 2415 | if (!is_error(ret)) { |
| 2416 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2417 | if (put_user_u32(addrlen, target_addrlen_addr)) |
| 2418 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2419 | } |
| 2420 | return ret; |
| 2421 | } |
| 2422 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2423 | /* do_socketpair() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2424 | static abi_long do_socketpair(int domain, int type, int protocol, |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2425 | abi_ulong target_tab_addr) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2426 | { |
| 2427 | int tab[2]; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2428 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2429 | |
Petar Jovanovic | f651e6a | 2013-07-01 02:44:14 +0200 | [diff] [blame] | 2430 | target_to_host_sock_type(&type); |
| 2431 | |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2432 | ret = get_errno(socketpair(domain, type, protocol, tab)); |
| 2433 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2434 | if (put_user_s32(tab[0], target_tab_addr) |
| 2435 | || put_user_s32(tab[1], target_tab_addr + sizeof(tab[0]))) |
| 2436 | ret = -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2437 | } |
| 2438 | return ret; |
| 2439 | } |
| 2440 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2441 | /* do_sendto() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2442 | static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, |
| 2443 | abi_ulong target_addr, socklen_t addrlen) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2444 | { |
| 2445 | void *addr; |
| 2446 | void *host_msg; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2447 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2448 | |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2449 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2450 | return -TARGET_EINVAL; |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2451 | } |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2452 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2453 | host_msg = lock_user(VERIFY_READ, msg, len, 1); |
| 2454 | if (!host_msg) |
| 2455 | return -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2456 | if (target_addr) { |
Joakim Tjernlund | 2dd08df | 2014-07-11 17:18:03 +0200 | [diff] [blame] | 2457 | addr = alloca(addrlen+1); |
Laurent Vivier | 7b36f78 | 2015-10-28 21:40:44 +0100 | [diff] [blame] | 2458 | ret = target_to_host_sockaddr(fd, addr, target_addr, addrlen); |
Arnaud Patard | 917507b | 2009-06-19 10:44:45 +0300 | [diff] [blame] | 2459 | if (ret) { |
| 2460 | unlock_user(host_msg, msg, 0); |
| 2461 | return ret; |
| 2462 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2463 | ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen)); |
| 2464 | } else { |
| 2465 | ret = get_errno(send(fd, host_msg, len, flags)); |
| 2466 | } |
| 2467 | unlock_user(host_msg, msg, 0); |
| 2468 | return ret; |
| 2469 | } |
| 2470 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2471 | /* do_recvfrom() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2472 | static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, |
| 2473 | abi_ulong target_addr, |
| 2474 | abi_ulong target_addrlen) |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2475 | { |
| 2476 | socklen_t addrlen; |
| 2477 | void *addr; |
| 2478 | void *host_msg; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2479 | abi_long ret; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2480 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2481 | host_msg = lock_user(VERIFY_WRITE, msg, len, 0); |
| 2482 | if (!host_msg) |
| 2483 | return -TARGET_EFAULT; |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2484 | if (target_addr) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2485 | if (get_user_u32(addrlen, target_addrlen)) { |
| 2486 | ret = -TARGET_EFAULT; |
| 2487 | goto fail; |
| 2488 | } |
Blue Swirl | 3872425 | 2010-09-18 05:53:14 +0000 | [diff] [blame] | 2489 | if ((int)addrlen < 0) { |
aurel32 | 8f7aeaf | 2009-01-30 19:47:57 +0000 | [diff] [blame] | 2490 | ret = -TARGET_EINVAL; |
| 2491 | goto fail; |
| 2492 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2493 | addr = alloca(addrlen); |
| 2494 | ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen)); |
| 2495 | } else { |
| 2496 | addr = NULL; /* To keep compiler quiet. */ |
Blue Swirl | 00aa004 | 2011-07-23 20:04:29 +0000 | [diff] [blame] | 2497 | ret = get_errno(qemu_recv(fd, host_msg, len, flags)); |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2498 | } |
| 2499 | if (!is_error(ret)) { |
| 2500 | if (target_addr) { |
| 2501 | host_to_target_sockaddr(target_addr, addr, addrlen); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2502 | if (put_user_u32(addrlen, target_addrlen)) { |
| 2503 | ret = -TARGET_EFAULT; |
| 2504 | goto fail; |
| 2505 | } |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2506 | } |
| 2507 | unlock_user(host_msg, msg, len); |
| 2508 | } else { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2509 | fail: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 2510 | unlock_user(host_msg, msg, 0); |
| 2511 | } |
| 2512 | return ret; |
| 2513 | } |
| 2514 | |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 2515 | #ifdef TARGET_NR_socketcall |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 2516 | /* do_socketcall() Must return target values and target errnos. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2517 | static abi_long do_socketcall(int num, abi_ulong vptr) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2518 | { |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2519 | static const unsigned ac[] = { /* number of arguments per call */ |
| 2520 | [SOCKOP_socket] = 3, /* domain, type, protocol */ |
| 2521 | [SOCKOP_bind] = 3, /* sockfd, addr, addrlen */ |
| 2522 | [SOCKOP_connect] = 3, /* sockfd, addr, addrlen */ |
| 2523 | [SOCKOP_listen] = 2, /* sockfd, backlog */ |
| 2524 | [SOCKOP_accept] = 3, /* sockfd, addr, addrlen */ |
| 2525 | [SOCKOP_accept4] = 4, /* sockfd, addr, addrlen, flags */ |
| 2526 | [SOCKOP_getsockname] = 3, /* sockfd, addr, addrlen */ |
| 2527 | [SOCKOP_getpeername] = 3, /* sockfd, addr, addrlen */ |
| 2528 | [SOCKOP_socketpair] = 4, /* domain, type, protocol, tab */ |
| 2529 | [SOCKOP_send] = 4, /* sockfd, msg, len, flags */ |
| 2530 | [SOCKOP_recv] = 4, /* sockfd, msg, len, flags */ |
| 2531 | [SOCKOP_sendto] = 6, /* sockfd, msg, len, flags, addr, addrlen */ |
| 2532 | [SOCKOP_recvfrom] = 6, /* sockfd, msg, len, flags, addr, addrlen */ |
| 2533 | [SOCKOP_shutdown] = 2, /* sockfd, how */ |
| 2534 | [SOCKOP_sendmsg] = 3, /* sockfd, msg, flags */ |
| 2535 | [SOCKOP_recvmsg] = 3, /* sockfd, msg, flags */ |
John Paul Adrian Glaubitz | 5a53dc5 | 2015-12-24 19:59:59 +0100 | [diff] [blame] | 2536 | [SOCKOP_sendmmsg] = 4, /* sockfd, msgvec, vlen, flags */ |
| 2537 | [SOCKOP_recvmmsg] = 4, /* sockfd, msgvec, vlen, flags */ |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2538 | [SOCKOP_setsockopt] = 5, /* sockfd, level, optname, optval, optlen */ |
| 2539 | [SOCKOP_getsockopt] = 5, /* sockfd, level, optname, optval, optlen */ |
| 2540 | }; |
| 2541 | abi_long a[6]; /* max 6 args */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2542 | |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2543 | /* first, collect the arguments in a[] according to ac[] */ |
| 2544 | if (num >= 0 && num < ARRAY_SIZE(ac)) { |
| 2545 | unsigned i; |
| 2546 | assert(ARRAY_SIZE(a) >= ac[num]); /* ensure we have space for args */ |
| 2547 | for (i = 0; i < ac[num]; ++i) { |
| 2548 | if (get_user_ual(a[i], vptr + i * sizeof(abi_long)) != 0) { |
André Hentschel | b9d36eb | 2014-01-06 20:18:52 +0100 | [diff] [blame] | 2549 | return -TARGET_EFAULT; |
| 2550 | } |
André Hentschel | b9d36eb | 2014-01-06 20:18:52 +0100 | [diff] [blame] | 2551 | } |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2552 | } |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 2553 | |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2554 | /* now when we have the args, actually handle the call */ |
| 2555 | switch (num) { |
| 2556 | case SOCKOP_socket: /* domain, type, protocol */ |
| 2557 | return do_socket(a[0], a[1], a[2]); |
| 2558 | case SOCKOP_bind: /* sockfd, addr, addrlen */ |
| 2559 | return do_bind(a[0], a[1], a[2]); |
| 2560 | case SOCKOP_connect: /* sockfd, addr, addrlen */ |
| 2561 | return do_connect(a[0], a[1], a[2]); |
| 2562 | case SOCKOP_listen: /* sockfd, backlog */ |
| 2563 | return get_errno(listen(a[0], a[1])); |
| 2564 | case SOCKOP_accept: /* sockfd, addr, addrlen */ |
| 2565 | return do_accept4(a[0], a[1], a[2], 0); |
| 2566 | case SOCKOP_accept4: /* sockfd, addr, addrlen, flags */ |
| 2567 | return do_accept4(a[0], a[1], a[2], a[3]); |
| 2568 | case SOCKOP_getsockname: /* sockfd, addr, addrlen */ |
| 2569 | return do_getsockname(a[0], a[1], a[2]); |
| 2570 | case SOCKOP_getpeername: /* sockfd, addr, addrlen */ |
| 2571 | return do_getpeername(a[0], a[1], a[2]); |
| 2572 | case SOCKOP_socketpair: /* domain, type, protocol, tab */ |
| 2573 | return do_socketpair(a[0], a[1], a[2], a[3]); |
| 2574 | case SOCKOP_send: /* sockfd, msg, len, flags */ |
| 2575 | return do_sendto(a[0], a[1], a[2], a[3], 0, 0); |
| 2576 | case SOCKOP_recv: /* sockfd, msg, len, flags */ |
| 2577 | return do_recvfrom(a[0], a[1], a[2], a[3], 0, 0); |
| 2578 | case SOCKOP_sendto: /* sockfd, msg, len, flags, addr, addrlen */ |
| 2579 | return do_sendto(a[0], a[1], a[2], a[3], a[4], a[5]); |
| 2580 | case SOCKOP_recvfrom: /* sockfd, msg, len, flags, addr, addrlen */ |
| 2581 | return do_recvfrom(a[0], a[1], a[2], a[3], a[4], a[5]); |
| 2582 | case SOCKOP_shutdown: /* sockfd, how */ |
| 2583 | return get_errno(shutdown(a[0], a[1])); |
| 2584 | case SOCKOP_sendmsg: /* sockfd, msg, flags */ |
| 2585 | return do_sendrecvmsg(a[0], a[1], a[2], 1); |
| 2586 | case SOCKOP_recvmsg: /* sockfd, msg, flags */ |
| 2587 | return do_sendrecvmsg(a[0], a[1], a[2], 0); |
John Paul Adrian Glaubitz | 5a53dc5 | 2015-12-24 19:59:59 +0100 | [diff] [blame] | 2588 | case SOCKOP_sendmmsg: /* sockfd, msgvec, vlen, flags */ |
| 2589 | return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 1); |
| 2590 | case SOCKOP_recvmmsg: /* sockfd, msgvec, vlen, flags */ |
| 2591 | return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 0); |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2592 | case SOCKOP_setsockopt: /* sockfd, level, optname, optval, optlen */ |
| 2593 | return do_setsockopt(a[0], a[1], a[2], a[3], a[4]); |
| 2594 | case SOCKOP_getsockopt: /* sockfd, level, optname, optval, optlen */ |
| 2595 | return do_getsockopt(a[0], a[1], a[2], a[3], a[4]); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2596 | default: |
| 2597 | gemu_log("Unsupported socketcall: %d\n", num); |
Michael Tokarev | 62dc90c | 2014-01-17 14:23:51 +0400 | [diff] [blame] | 2598 | return -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2599 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2600 | } |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 2601 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 2602 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 2603 | #define N_SHM_REGIONS 32 |
| 2604 | |
| 2605 | static struct shm_region { |
Peter Maydell | b6e1787 | 2016-02-09 15:57:11 +0000 | [diff] [blame] | 2606 | abi_ulong start; |
| 2607 | abi_ulong size; |
| 2608 | bool in_use; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 2609 | } shm_regions[N_SHM_REGIONS]; |
| 2610 | |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2611 | struct target_semid_ds |
| 2612 | { |
| 2613 | struct target_ipc_perm sem_perm; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2614 | abi_ulong sem_otime; |
Tom Musta | 0352734 | 2014-08-12 13:53:32 -0500 | [diff] [blame] | 2615 | #if !defined(TARGET_PPC64) |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2616 | abi_ulong __unused1; |
Tom Musta | 0352734 | 2014-08-12 13:53:32 -0500 | [diff] [blame] | 2617 | #endif |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2618 | abi_ulong sem_ctime; |
Tom Musta | 0352734 | 2014-08-12 13:53:32 -0500 | [diff] [blame] | 2619 | #if !defined(TARGET_PPC64) |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2620 | abi_ulong __unused2; |
Tom Musta | 0352734 | 2014-08-12 13:53:32 -0500 | [diff] [blame] | 2621 | #endif |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 2622 | abi_ulong sem_nsems; |
| 2623 | abi_ulong __unused3; |
| 2624 | abi_ulong __unused4; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2625 | }; |
| 2626 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2627 | static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, |
| 2628 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2629 | { |
| 2630 | struct target_ipc_perm *target_ip; |
| 2631 | struct target_semid_ds *target_sd; |
| 2632 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2633 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2634 | return -TARGET_EFAULT; |
Michael S. Tsirkin | e8bbe36 | 2009-09-30 18:56:44 +0000 | [diff] [blame] | 2635 | target_ip = &(target_sd->sem_perm); |
Petar Jovanovic | 55a2b16 | 2013-10-30 14:46:31 +0100 | [diff] [blame] | 2636 | host_ip->__key = tswap32(target_ip->__key); |
| 2637 | host_ip->uid = tswap32(target_ip->uid); |
| 2638 | host_ip->gid = tswap32(target_ip->gid); |
| 2639 | host_ip->cuid = tswap32(target_ip->cuid); |
| 2640 | host_ip->cgid = tswap32(target_ip->cgid); |
| 2641 | #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC) |
| 2642 | host_ip->mode = tswap32(target_ip->mode); |
| 2643 | #else |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2644 | host_ip->mode = tswap16(target_ip->mode); |
Petar Jovanovic | 55a2b16 | 2013-10-30 14:46:31 +0100 | [diff] [blame] | 2645 | #endif |
| 2646 | #if defined(TARGET_PPC) |
| 2647 | host_ip->__seq = tswap32(target_ip->__seq); |
| 2648 | #else |
| 2649 | host_ip->__seq = tswap16(target_ip->__seq); |
| 2650 | #endif |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2651 | unlock_user_struct(target_sd, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2652 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2655 | static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, |
| 2656 | struct ipc_perm *host_ip) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2657 | { |
| 2658 | struct target_ipc_perm *target_ip; |
| 2659 | struct target_semid_ds *target_sd; |
| 2660 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2661 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2662 | return -TARGET_EFAULT; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2663 | target_ip = &(target_sd->sem_perm); |
Petar Jovanovic | 55a2b16 | 2013-10-30 14:46:31 +0100 | [diff] [blame] | 2664 | target_ip->__key = tswap32(host_ip->__key); |
| 2665 | target_ip->uid = tswap32(host_ip->uid); |
| 2666 | target_ip->gid = tswap32(host_ip->gid); |
| 2667 | target_ip->cuid = tswap32(host_ip->cuid); |
| 2668 | target_ip->cgid = tswap32(host_ip->cgid); |
| 2669 | #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC) |
| 2670 | target_ip->mode = tswap32(host_ip->mode); |
| 2671 | #else |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2672 | target_ip->mode = tswap16(host_ip->mode); |
Petar Jovanovic | 55a2b16 | 2013-10-30 14:46:31 +0100 | [diff] [blame] | 2673 | #endif |
| 2674 | #if defined(TARGET_PPC) |
| 2675 | target_ip->__seq = tswap32(host_ip->__seq); |
| 2676 | #else |
| 2677 | target_ip->__seq = tswap16(host_ip->__seq); |
| 2678 | #endif |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2679 | unlock_user_struct(target_sd, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2680 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2683 | static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd, |
| 2684 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2685 | { |
| 2686 | struct target_semid_ds *target_sd; |
| 2687 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2688 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 2689 | return -TARGET_EFAULT; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2690 | if (target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr)) |
| 2691 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2692 | host_sd->sem_nsems = tswapal(target_sd->sem_nsems); |
| 2693 | host_sd->sem_otime = tswapal(target_sd->sem_otime); |
| 2694 | host_sd->sem_ctime = tswapal(target_sd->sem_ctime); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2695 | unlock_user_struct(target_sd, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2696 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2697 | } |
| 2698 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2699 | static inline abi_long host_to_target_semid_ds(abi_ulong target_addr, |
| 2700 | struct semid_ds *host_sd) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2701 | { |
| 2702 | struct target_semid_ds *target_sd; |
| 2703 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2704 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 2705 | return -TARGET_EFAULT; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2706 | if (host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm))) |
Dong Xu Wang | 3a93113 | 2011-11-29 16:52:38 +0800 | [diff] [blame] | 2707 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2708 | target_sd->sem_nsems = tswapal(host_sd->sem_nsems); |
| 2709 | target_sd->sem_otime = tswapal(host_sd->sem_otime); |
| 2710 | target_sd->sem_ctime = tswapal(host_sd->sem_ctime); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2711 | unlock_user_struct(target_sd, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2712 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2715 | struct target_seminfo { |
| 2716 | int semmap; |
| 2717 | int semmni; |
| 2718 | int semmns; |
| 2719 | int semmnu; |
| 2720 | int semmsl; |
| 2721 | int semopm; |
| 2722 | int semume; |
| 2723 | int semusz; |
| 2724 | int semvmx; |
| 2725 | int semaem; |
| 2726 | }; |
| 2727 | |
| 2728 | static inline abi_long host_to_target_seminfo(abi_ulong target_addr, |
| 2729 | struct seminfo *host_seminfo) |
| 2730 | { |
| 2731 | struct target_seminfo *target_seminfo; |
| 2732 | if (!lock_user_struct(VERIFY_WRITE, target_seminfo, target_addr, 0)) |
| 2733 | return -TARGET_EFAULT; |
| 2734 | __put_user(host_seminfo->semmap, &target_seminfo->semmap); |
| 2735 | __put_user(host_seminfo->semmni, &target_seminfo->semmni); |
| 2736 | __put_user(host_seminfo->semmns, &target_seminfo->semmns); |
| 2737 | __put_user(host_seminfo->semmnu, &target_seminfo->semmnu); |
| 2738 | __put_user(host_seminfo->semmsl, &target_seminfo->semmsl); |
| 2739 | __put_user(host_seminfo->semopm, &target_seminfo->semopm); |
| 2740 | __put_user(host_seminfo->semume, &target_seminfo->semume); |
| 2741 | __put_user(host_seminfo->semusz, &target_seminfo->semusz); |
| 2742 | __put_user(host_seminfo->semvmx, &target_seminfo->semvmx); |
| 2743 | __put_user(host_seminfo->semaem, &target_seminfo->semaem); |
| 2744 | unlock_user_struct(target_seminfo, target_addr, 1); |
| 2745 | return 0; |
| 2746 | } |
| 2747 | |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2748 | union semun { |
| 2749 | int val; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2750 | struct semid_ds *buf; |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2751 | unsigned short *array; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2752 | struct seminfo *__buf; |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 2753 | }; |
| 2754 | |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2755 | union target_semun { |
| 2756 | int val; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2757 | abi_ulong buf; |
| 2758 | abi_ulong array; |
| 2759 | abi_ulong __buf; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2760 | }; |
| 2761 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2762 | static inline abi_long target_to_host_semarray(int semid, unsigned short **host_array, |
| 2763 | abi_ulong target_addr) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2764 | { |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2765 | int nsems; |
| 2766 | unsigned short *array; |
| 2767 | union semun semun; |
| 2768 | struct semid_ds semid_ds; |
| 2769 | int i, ret; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2770 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2771 | semun.buf = &semid_ds; |
| 2772 | |
| 2773 | ret = semctl(semid, 0, IPC_STAT, semun); |
| 2774 | if (ret == -1) |
| 2775 | return get_errno(ret); |
| 2776 | |
| 2777 | nsems = semid_ds.sem_nsems; |
| 2778 | |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 2779 | *host_array = g_try_new(unsigned short, nsems); |
Peter Maydell | 69d4c70 | 2014-02-17 18:55:34 +0000 | [diff] [blame] | 2780 | if (!*host_array) { |
| 2781 | return -TARGET_ENOMEM; |
| 2782 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2783 | array = lock_user(VERIFY_READ, target_addr, |
| 2784 | nsems*sizeof(unsigned short), 1); |
Peter Maydell | 69d4c70 | 2014-02-17 18:55:34 +0000 | [diff] [blame] | 2785 | if (!array) { |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 2786 | g_free(*host_array); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2787 | return -TARGET_EFAULT; |
Peter Maydell | 69d4c70 | 2014-02-17 18:55:34 +0000 | [diff] [blame] | 2788 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2789 | |
| 2790 | for(i=0; i<nsems; i++) { |
| 2791 | __get_user((*host_array)[i], &array[i]); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2792 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2793 | unlock_user(array, target_addr, 0); |
| 2794 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2795 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2798 | static inline abi_long host_to_target_semarray(int semid, abi_ulong target_addr, |
| 2799 | unsigned short **host_array) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2800 | { |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2801 | int nsems; |
| 2802 | unsigned short *array; |
| 2803 | union semun semun; |
| 2804 | struct semid_ds semid_ds; |
| 2805 | int i, ret; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2806 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2807 | semun.buf = &semid_ds; |
| 2808 | |
| 2809 | ret = semctl(semid, 0, IPC_STAT, semun); |
| 2810 | if (ret == -1) |
| 2811 | return get_errno(ret); |
| 2812 | |
| 2813 | nsems = semid_ds.sem_nsems; |
| 2814 | |
| 2815 | array = lock_user(VERIFY_WRITE, target_addr, |
| 2816 | nsems*sizeof(unsigned short), 0); |
| 2817 | if (!array) |
| 2818 | return -TARGET_EFAULT; |
| 2819 | |
| 2820 | for(i=0; i<nsems; i++) { |
| 2821 | __put_user((*host_array)[i], &array[i]); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2822 | } |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 2823 | g_free(*host_array); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2824 | unlock_user(array, target_addr, 1); |
| 2825 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2826 | return 0; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2827 | } |
| 2828 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2829 | static inline abi_long do_semctl(int semid, int semnum, int cmd, |
Stefan Weil | d1c002b | 2015-02-08 15:40:58 +0100 | [diff] [blame] | 2830 | abi_ulong target_arg) |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2831 | { |
Stefan Weil | d1c002b | 2015-02-08 15:40:58 +0100 | [diff] [blame] | 2832 | union target_semun target_su = { .buf = target_arg }; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2833 | union semun arg; |
| 2834 | struct semid_ds dsarg; |
vibi sreenivasan | 7b8118e | 2009-06-19 13:34:39 +0530 | [diff] [blame] | 2835 | unsigned short *array = NULL; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2836 | struct seminfo seminfo; |
| 2837 | abi_long ret = -TARGET_EINVAL; |
| 2838 | abi_long err; |
| 2839 | cmd &= 0xff; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2840 | |
| 2841 | switch( cmd ) { |
| 2842 | case GETVAL: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2843 | case SETVAL: |
Tom Musta | 5464bae | 2014-08-12 13:53:34 -0500 | [diff] [blame] | 2844 | /* In 64 bit cross-endian situations, we will erroneously pick up |
| 2845 | * the wrong half of the union for the "val" element. To rectify |
| 2846 | * this, the entire 8-byte structure is byteswapped, followed by |
| 2847 | * a swap of the 4 byte val field. In other cases, the data is |
| 2848 | * already in proper host byte order. */ |
| 2849 | if (sizeof(target_su.val) != (sizeof(target_su.buf))) { |
| 2850 | target_su.buf = tswapal(target_su.buf); |
| 2851 | arg.val = tswap32(target_su.val); |
| 2852 | } else { |
| 2853 | arg.val = target_su.val; |
| 2854 | } |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2855 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | case GETALL: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2858 | case SETALL: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2859 | err = target_to_host_semarray(semid, &array, target_su.array); |
| 2860 | if (err) |
| 2861 | return err; |
| 2862 | arg.array = array; |
| 2863 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2864 | err = host_to_target_semarray(semid, target_su.array, &array); |
| 2865 | if (err) |
| 2866 | return err; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2867 | break; |
| 2868 | case IPC_STAT: |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2869 | case IPC_SET: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2870 | case SEM_STAT: |
| 2871 | err = target_to_host_semid_ds(&dsarg, target_su.buf); |
| 2872 | if (err) |
| 2873 | return err; |
| 2874 | arg.buf = &dsarg; |
| 2875 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2876 | err = host_to_target_semid_ds(target_su.buf, &dsarg); |
| 2877 | if (err) |
| 2878 | return err; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2879 | break; |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2880 | case IPC_INFO: |
| 2881 | case SEM_INFO: |
| 2882 | arg.__buf = &seminfo; |
| 2883 | ret = get_errno(semctl(semid, semnum, cmd, arg)); |
| 2884 | err = host_to_target_seminfo(target_su.__buf, &seminfo); |
| 2885 | if (err) |
| 2886 | return err; |
| 2887 | break; |
| 2888 | case IPC_RMID: |
| 2889 | case GETPID: |
| 2890 | case GETNCNT: |
| 2891 | case GETZCNT: |
| 2892 | ret = get_errno(semctl(semid, semnum, cmd, NULL)); |
| 2893 | break; |
ths | 3eb6b04 | 2007-06-03 14:26:27 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | return ret; |
| 2897 | } |
| 2898 | |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2899 | struct target_sembuf { |
| 2900 | unsigned short sem_num; |
| 2901 | short sem_op; |
| 2902 | short sem_flg; |
| 2903 | }; |
| 2904 | |
| 2905 | static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf, |
| 2906 | abi_ulong target_addr, |
| 2907 | unsigned nsops) |
| 2908 | { |
| 2909 | struct target_sembuf *target_sembuf; |
| 2910 | int i; |
| 2911 | |
| 2912 | target_sembuf = lock_user(VERIFY_READ, target_addr, |
| 2913 | nsops*sizeof(struct target_sembuf), 1); |
| 2914 | if (!target_sembuf) |
| 2915 | return -TARGET_EFAULT; |
| 2916 | |
| 2917 | for(i=0; i<nsops; i++) { |
| 2918 | __get_user(host_sembuf[i].sem_num, &target_sembuf[i].sem_num); |
| 2919 | __get_user(host_sembuf[i].sem_op, &target_sembuf[i].sem_op); |
| 2920 | __get_user(host_sembuf[i].sem_flg, &target_sembuf[i].sem_flg); |
| 2921 | } |
| 2922 | |
| 2923 | unlock_user(target_sembuf, target_addr, 0); |
| 2924 | |
| 2925 | return 0; |
| 2926 | } |
| 2927 | |
| 2928 | static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops) |
| 2929 | { |
| 2930 | struct sembuf sops[nsops]; |
| 2931 | |
| 2932 | if (target_to_host_sembuf(sops, ptr, nsops)) |
| 2933 | return -TARGET_EFAULT; |
| 2934 | |
Petar Jovanovic | c7128c9 | 2013-03-21 07:57:36 +0000 | [diff] [blame] | 2935 | return get_errno(semop(semid, sops, nsops)); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2938 | struct target_msqid_ds |
| 2939 | { |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2940 | struct target_ipc_perm msg_perm; |
| 2941 | abi_ulong msg_stime; |
| 2942 | #if TARGET_ABI_BITS == 32 |
| 2943 | abi_ulong __unused1; |
| 2944 | #endif |
| 2945 | abi_ulong msg_rtime; |
| 2946 | #if TARGET_ABI_BITS == 32 |
| 2947 | abi_ulong __unused2; |
| 2948 | #endif |
| 2949 | abi_ulong msg_ctime; |
| 2950 | #if TARGET_ABI_BITS == 32 |
| 2951 | abi_ulong __unused3; |
| 2952 | #endif |
| 2953 | abi_ulong __msg_cbytes; |
| 2954 | abi_ulong msg_qnum; |
| 2955 | abi_ulong msg_qbytes; |
| 2956 | abi_ulong msg_lspid; |
| 2957 | abi_ulong msg_lrpid; |
| 2958 | abi_ulong __unused4; |
| 2959 | abi_ulong __unused5; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2960 | }; |
| 2961 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2962 | static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md, |
| 2963 | abi_ulong target_addr) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2964 | { |
| 2965 | struct target_msqid_ds *target_md; |
| 2966 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2967 | if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)) |
| 2968 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2969 | if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr)) |
| 2970 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2971 | host_md->msg_stime = tswapal(target_md->msg_stime); |
| 2972 | host_md->msg_rtime = tswapal(target_md->msg_rtime); |
| 2973 | host_md->msg_ctime = tswapal(target_md->msg_ctime); |
| 2974 | host_md->__msg_cbytes = tswapal(target_md->__msg_cbytes); |
| 2975 | host_md->msg_qnum = tswapal(target_md->msg_qnum); |
| 2976 | host_md->msg_qbytes = tswapal(target_md->msg_qbytes); |
| 2977 | host_md->msg_lspid = tswapal(target_md->msg_lspid); |
| 2978 | host_md->msg_lrpid = tswapal(target_md->msg_lrpid); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2979 | unlock_user_struct(target_md, target_addr, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2980 | return 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2983 | static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr, |
| 2984 | struct msqid_ds *host_md) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 2985 | { |
| 2986 | struct target_msqid_ds *target_md; |
| 2987 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 2988 | if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0)) |
| 2989 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 2990 | if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm))) |
| 2991 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 2992 | target_md->msg_stime = tswapal(host_md->msg_stime); |
| 2993 | target_md->msg_rtime = tswapal(host_md->msg_rtime); |
| 2994 | target_md->msg_ctime = tswapal(host_md->msg_ctime); |
| 2995 | target_md->__msg_cbytes = tswapal(host_md->__msg_cbytes); |
| 2996 | target_md->msg_qnum = tswapal(host_md->msg_qnum); |
| 2997 | target_md->msg_qbytes = tswapal(host_md->msg_qbytes); |
| 2998 | target_md->msg_lspid = tswapal(host_md->msg_lspid); |
| 2999 | target_md->msg_lrpid = tswapal(host_md->msg_lrpid); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3000 | unlock_user_struct(target_md, target_addr, 1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3001 | return 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3002 | } |
| 3003 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3004 | struct target_msginfo { |
| 3005 | int msgpool; |
| 3006 | int msgmap; |
| 3007 | int msgmax; |
| 3008 | int msgmnb; |
| 3009 | int msgmni; |
| 3010 | int msgssz; |
| 3011 | int msgtql; |
| 3012 | unsigned short int msgseg; |
| 3013 | }; |
| 3014 | |
| 3015 | static inline abi_long host_to_target_msginfo(abi_ulong target_addr, |
| 3016 | struct msginfo *host_msginfo) |
| 3017 | { |
| 3018 | struct target_msginfo *target_msginfo; |
| 3019 | if (!lock_user_struct(VERIFY_WRITE, target_msginfo, target_addr, 0)) |
| 3020 | return -TARGET_EFAULT; |
| 3021 | __put_user(host_msginfo->msgpool, &target_msginfo->msgpool); |
| 3022 | __put_user(host_msginfo->msgmap, &target_msginfo->msgmap); |
| 3023 | __put_user(host_msginfo->msgmax, &target_msginfo->msgmax); |
| 3024 | __put_user(host_msginfo->msgmnb, &target_msginfo->msgmnb); |
| 3025 | __put_user(host_msginfo->msgmni, &target_msginfo->msgmni); |
| 3026 | __put_user(host_msginfo->msgssz, &target_msginfo->msgssz); |
| 3027 | __put_user(host_msginfo->msgtql, &target_msginfo->msgtql); |
| 3028 | __put_user(host_msginfo->msgseg, &target_msginfo->msgseg); |
| 3029 | unlock_user_struct(target_msginfo, target_addr, 1); |
aurel32 | 00b229a | 2008-10-24 13:12:52 +0000 | [diff] [blame] | 3030 | return 0; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | static inline abi_long do_msgctl(int msgid, int cmd, abi_long ptr) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3034 | { |
| 3035 | struct msqid_ds dsarg; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3036 | struct msginfo msginfo; |
| 3037 | abi_long ret = -TARGET_EINVAL; |
| 3038 | |
| 3039 | cmd &= 0xff; |
| 3040 | |
| 3041 | switch (cmd) { |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3042 | case IPC_STAT: |
| 3043 | case IPC_SET: |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3044 | case MSG_STAT: |
| 3045 | if (target_to_host_msqid_ds(&dsarg,ptr)) |
| 3046 | return -TARGET_EFAULT; |
| 3047 | ret = get_errno(msgctl(msgid, cmd, &dsarg)); |
| 3048 | if (host_to_target_msqid_ds(ptr,&dsarg)) |
| 3049 | return -TARGET_EFAULT; |
| 3050 | break; |
| 3051 | case IPC_RMID: |
| 3052 | ret = get_errno(msgctl(msgid, cmd, NULL)); |
| 3053 | break; |
| 3054 | case IPC_INFO: |
| 3055 | case MSG_INFO: |
| 3056 | ret = get_errno(msgctl(msgid, cmd, (struct msqid_ds *)&msginfo)); |
| 3057 | if (host_to_target_msginfo(ptr, &msginfo)) |
| 3058 | return -TARGET_EFAULT; |
| 3059 | break; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3060 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3061 | |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3062 | return ret; |
| 3063 | } |
| 3064 | |
| 3065 | struct target_msgbuf { |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3066 | abi_long mtype; |
| 3067 | char mtext[1]; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3068 | }; |
| 3069 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3070 | static inline abi_long do_msgsnd(int msqid, abi_long msgp, |
Tom Musta | edcc5f9 | 2014-08-12 13:53:37 -0500 | [diff] [blame] | 3071 | ssize_t msgsz, int msgflg) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3072 | { |
| 3073 | struct target_msgbuf *target_mb; |
| 3074 | struct msgbuf *host_mb; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3075 | abi_long ret = 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3076 | |
Tom Musta | edcc5f9 | 2014-08-12 13:53:37 -0500 | [diff] [blame] | 3077 | if (msgsz < 0) { |
| 3078 | return -TARGET_EINVAL; |
| 3079 | } |
| 3080 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3081 | if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0)) |
| 3082 | return -TARGET_EFAULT; |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 3083 | host_mb = g_try_malloc(msgsz + sizeof(long)); |
zhanghailiang | 29e03fc | 2014-08-14 15:29:18 +0800 | [diff] [blame] | 3084 | if (!host_mb) { |
| 3085 | unlock_user_struct(target_mb, msgp, 0); |
| 3086 | return -TARGET_ENOMEM; |
| 3087 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 3088 | host_mb->mtype = (abi_long) tswapal(target_mb->mtype); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3089 | memcpy(host_mb->mtext, target_mb->mtext, msgsz); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3090 | ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg)); |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 3091 | g_free(host_mb); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3092 | unlock_user_struct(target_mb, msgp, 0); |
| 3093 | |
| 3094 | return ret; |
| 3095 | } |
| 3096 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3097 | static inline abi_long do_msgrcv(int msqid, abi_long msgp, |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3098 | unsigned int msgsz, abi_long msgtyp, |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3099 | int msgflg) |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3100 | { |
| 3101 | struct target_msgbuf *target_mb; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3102 | char *target_mtext; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3103 | struct msgbuf *host_mb; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3104 | abi_long ret = 0; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3105 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3106 | if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)) |
| 3107 | return -TARGET_EFAULT; |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3108 | |
Jim Meyering | 0d07fe4 | 2012-08-22 13:55:53 +0200 | [diff] [blame] | 3109 | host_mb = g_malloc(msgsz+sizeof(long)); |
Laurent Vivier | 79dd77d | 2012-12-20 11:00:11 +0000 | [diff] [blame] | 3110 | ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg)); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3111 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3112 | if (ret > 0) { |
| 3113 | abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong); |
| 3114 | target_mtext = lock_user(VERIFY_WRITE, target_mtext_addr, ret, 0); |
| 3115 | if (!target_mtext) { |
| 3116 | ret = -TARGET_EFAULT; |
| 3117 | goto end; |
| 3118 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3119 | memcpy(target_mb->mtext, host_mb->mtext, ret); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3120 | unlock_user(target_mtext, target_mtext_addr, ret); |
| 3121 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3122 | |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 3123 | target_mb->mtype = tswapal(host_mb->mtype); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3124 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 3125 | end: |
| 3126 | if (target_mb) |
| 3127 | unlock_user_struct(target_mb, msgp, 1); |
Jim Meyering | 0d07fe4 | 2012-08-22 13:55:53 +0200 | [diff] [blame] | 3128 | g_free(host_mb); |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3129 | return ret; |
| 3130 | } |
| 3131 | |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3132 | static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, |
| 3133 | abi_ulong target_addr) |
| 3134 | { |
| 3135 | struct target_shmid_ds *target_sd; |
| 3136 | |
| 3137 | if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) |
| 3138 | return -TARGET_EFAULT; |
| 3139 | if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr)) |
| 3140 | return -TARGET_EFAULT; |
| 3141 | __get_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 3142 | __get_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 3143 | __get_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 3144 | __get_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 3145 | __get_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 3146 | __get_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 3147 | __get_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 3148 | unlock_user_struct(target_sd, target_addr, 0); |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
| 3152 | static inline abi_long host_to_target_shmid_ds(abi_ulong target_addr, |
| 3153 | struct shmid_ds *host_sd) |
| 3154 | { |
| 3155 | struct target_shmid_ds *target_sd; |
| 3156 | |
| 3157 | if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) |
| 3158 | return -TARGET_EFAULT; |
| 3159 | if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm))) |
| 3160 | return -TARGET_EFAULT; |
| 3161 | __put_user(host_sd->shm_segsz, &target_sd->shm_segsz); |
| 3162 | __put_user(host_sd->shm_atime, &target_sd->shm_atime); |
| 3163 | __put_user(host_sd->shm_dtime, &target_sd->shm_dtime); |
| 3164 | __put_user(host_sd->shm_ctime, &target_sd->shm_ctime); |
| 3165 | __put_user(host_sd->shm_cpid, &target_sd->shm_cpid); |
| 3166 | __put_user(host_sd->shm_lpid, &target_sd->shm_lpid); |
| 3167 | __put_user(host_sd->shm_nattch, &target_sd->shm_nattch); |
| 3168 | unlock_user_struct(target_sd, target_addr, 1); |
| 3169 | return 0; |
| 3170 | } |
| 3171 | |
| 3172 | struct target_shminfo { |
| 3173 | abi_ulong shmmax; |
| 3174 | abi_ulong shmmin; |
| 3175 | abi_ulong shmmni; |
| 3176 | abi_ulong shmseg; |
| 3177 | abi_ulong shmall; |
| 3178 | }; |
| 3179 | |
| 3180 | static inline abi_long host_to_target_shminfo(abi_ulong target_addr, |
| 3181 | struct shminfo *host_shminfo) |
| 3182 | { |
| 3183 | struct target_shminfo *target_shminfo; |
| 3184 | if (!lock_user_struct(VERIFY_WRITE, target_shminfo, target_addr, 0)) |
| 3185 | return -TARGET_EFAULT; |
| 3186 | __put_user(host_shminfo->shmmax, &target_shminfo->shmmax); |
| 3187 | __put_user(host_shminfo->shmmin, &target_shminfo->shmmin); |
| 3188 | __put_user(host_shminfo->shmmni, &target_shminfo->shmmni); |
| 3189 | __put_user(host_shminfo->shmseg, &target_shminfo->shmseg); |
| 3190 | __put_user(host_shminfo->shmall, &target_shminfo->shmall); |
| 3191 | unlock_user_struct(target_shminfo, target_addr, 1); |
| 3192 | return 0; |
| 3193 | } |
| 3194 | |
| 3195 | struct target_shm_info { |
| 3196 | int used_ids; |
| 3197 | abi_ulong shm_tot; |
| 3198 | abi_ulong shm_rss; |
| 3199 | abi_ulong shm_swp; |
| 3200 | abi_ulong swap_attempts; |
| 3201 | abi_ulong swap_successes; |
| 3202 | }; |
| 3203 | |
| 3204 | static inline abi_long host_to_target_shm_info(abi_ulong target_addr, |
| 3205 | struct shm_info *host_shm_info) |
| 3206 | { |
| 3207 | struct target_shm_info *target_shm_info; |
| 3208 | if (!lock_user_struct(VERIFY_WRITE, target_shm_info, target_addr, 0)) |
| 3209 | return -TARGET_EFAULT; |
| 3210 | __put_user(host_shm_info->used_ids, &target_shm_info->used_ids); |
| 3211 | __put_user(host_shm_info->shm_tot, &target_shm_info->shm_tot); |
| 3212 | __put_user(host_shm_info->shm_rss, &target_shm_info->shm_rss); |
| 3213 | __put_user(host_shm_info->shm_swp, &target_shm_info->shm_swp); |
| 3214 | __put_user(host_shm_info->swap_attempts, &target_shm_info->swap_attempts); |
| 3215 | __put_user(host_shm_info->swap_successes, &target_shm_info->swap_successes); |
| 3216 | unlock_user_struct(target_shm_info, target_addr, 1); |
| 3217 | return 0; |
| 3218 | } |
| 3219 | |
| 3220 | static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf) |
| 3221 | { |
| 3222 | struct shmid_ds dsarg; |
| 3223 | struct shminfo shminfo; |
| 3224 | struct shm_info shm_info; |
| 3225 | abi_long ret = -TARGET_EINVAL; |
| 3226 | |
| 3227 | cmd &= 0xff; |
| 3228 | |
| 3229 | switch(cmd) { |
| 3230 | case IPC_STAT: |
| 3231 | case IPC_SET: |
| 3232 | case SHM_STAT: |
| 3233 | if (target_to_host_shmid_ds(&dsarg, buf)) |
| 3234 | return -TARGET_EFAULT; |
| 3235 | ret = get_errno(shmctl(shmid, cmd, &dsarg)); |
| 3236 | if (host_to_target_shmid_ds(buf, &dsarg)) |
| 3237 | return -TARGET_EFAULT; |
| 3238 | break; |
| 3239 | case IPC_INFO: |
| 3240 | ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shminfo)); |
| 3241 | if (host_to_target_shminfo(buf, &shminfo)) |
| 3242 | return -TARGET_EFAULT; |
| 3243 | break; |
| 3244 | case SHM_INFO: |
| 3245 | ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shm_info)); |
| 3246 | if (host_to_target_shm_info(buf, &shm_info)) |
| 3247 | return -TARGET_EFAULT; |
| 3248 | break; |
| 3249 | case IPC_RMID: |
| 3250 | case SHM_LOCK: |
| 3251 | case SHM_UNLOCK: |
| 3252 | ret = get_errno(shmctl(shmid, cmd, NULL)); |
| 3253 | break; |
| 3254 | } |
| 3255 | |
| 3256 | return ret; |
| 3257 | } |
| 3258 | |
| 3259 | static inline abi_ulong do_shmat(int shmid, abi_ulong shmaddr, int shmflg) |
| 3260 | { |
| 3261 | abi_long raddr; |
| 3262 | void *host_raddr; |
| 3263 | struct shmid_ds shm_info; |
| 3264 | int i,ret; |
| 3265 | |
| 3266 | /* find out the length of the shared memory segment */ |
| 3267 | ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info)); |
| 3268 | if (is_error(ret)) { |
| 3269 | /* can't get length, bail out */ |
| 3270 | return ret; |
| 3271 | } |
| 3272 | |
| 3273 | mmap_lock(); |
| 3274 | |
| 3275 | if (shmaddr) |
| 3276 | host_raddr = shmat(shmid, (void *)g2h(shmaddr), shmflg); |
| 3277 | else { |
| 3278 | abi_ulong mmap_start; |
| 3279 | |
| 3280 | mmap_start = mmap_find_vma(0, shm_info.shm_segsz); |
| 3281 | |
| 3282 | if (mmap_start == -1) { |
| 3283 | errno = ENOMEM; |
| 3284 | host_raddr = (void *)-1; |
| 3285 | } else |
| 3286 | host_raddr = shmat(shmid, g2h(mmap_start), shmflg | SHM_REMAP); |
| 3287 | } |
| 3288 | |
| 3289 | if (host_raddr == (void *)-1) { |
| 3290 | mmap_unlock(); |
| 3291 | return get_errno((long)host_raddr); |
| 3292 | } |
| 3293 | raddr=h2g((unsigned long)host_raddr); |
| 3294 | |
| 3295 | page_set_flags(raddr, raddr + shm_info.shm_segsz, |
| 3296 | PAGE_VALID | PAGE_READ | |
| 3297 | ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); |
| 3298 | |
| 3299 | for (i = 0; i < N_SHM_REGIONS; i++) { |
Peter Maydell | b6e1787 | 2016-02-09 15:57:11 +0000 | [diff] [blame] | 3300 | if (!shm_regions[i].in_use) { |
| 3301 | shm_regions[i].in_use = true; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3302 | shm_regions[i].start = raddr; |
| 3303 | shm_regions[i].size = shm_info.shm_segsz; |
| 3304 | break; |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | mmap_unlock(); |
| 3309 | return raddr; |
| 3310 | |
| 3311 | } |
| 3312 | |
| 3313 | static inline abi_long do_shmdt(abi_ulong shmaddr) |
| 3314 | { |
| 3315 | int i; |
| 3316 | |
| 3317 | for (i = 0; i < N_SHM_REGIONS; ++i) { |
Peter Maydell | b6e1787 | 2016-02-09 15:57:11 +0000 | [diff] [blame] | 3318 | if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { |
| 3319 | shm_regions[i].in_use = false; |
takasi-y@ops.dti.ne.jp | e00ac24 | 2010-04-11 02:09:57 +0900 | [diff] [blame] | 3320 | page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0); |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3321 | break; |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | return get_errno(shmdt(g2h(shmaddr))); |
| 3326 | } |
| 3327 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3328 | #ifdef TARGET_NR_ipc |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 3329 | /* ??? This only works with linear mappings. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3330 | /* do_ipc() must return target values and target errnos. */ |
Tom Musta | 37ed095 | 2014-08-12 13:53:35 -0500 | [diff] [blame] | 3331 | static abi_long do_ipc(unsigned int call, abi_long first, |
| 3332 | abi_long second, abi_long third, |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3333 | abi_long ptr, abi_long fifth) |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3334 | { |
| 3335 | int version; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 3336 | abi_long ret = 0; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3337 | |
| 3338 | version = call >> 16; |
| 3339 | call &= 0xffff; |
| 3340 | |
| 3341 | switch (call) { |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3342 | case IPCOP_semop: |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 3343 | ret = do_semop(first, ptr, second); |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3344 | break; |
| 3345 | |
| 3346 | case IPCOP_semget: |
| 3347 | ret = get_errno(semget(first, second, third)); |
| 3348 | break; |
| 3349 | |
Tom Musta | 5d2fa8e | 2014-08-12 13:53:33 -0500 | [diff] [blame] | 3350 | case IPCOP_semctl: { |
| 3351 | /* The semun argument to semctl is passed by value, so dereference the |
| 3352 | * ptr argument. */ |
| 3353 | abi_ulong atptr; |
Tom Musta | 37ed095 | 2014-08-12 13:53:35 -0500 | [diff] [blame] | 3354 | get_user_ual(atptr, ptr); |
Stefan Weil | d1c002b | 2015-02-08 15:40:58 +0100 | [diff] [blame] | 3355 | ret = do_semctl(first, second, third, atptr); |
ths | fa29481 | 2007-02-02 22:05:00 +0000 | [diff] [blame] | 3356 | break; |
Tom Musta | 5d2fa8e | 2014-08-12 13:53:33 -0500 | [diff] [blame] | 3357 | } |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3358 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3359 | case IPCOP_msgget: |
| 3360 | ret = get_errno(msgget(first, second)); |
| 3361 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3362 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3363 | case IPCOP_msgsnd: |
| 3364 | ret = do_msgsnd(first, ptr, second, third); |
| 3365 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3366 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3367 | case IPCOP_msgctl: |
| 3368 | ret = do_msgctl(first, second, ptr); |
| 3369 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3370 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3371 | case IPCOP_msgrcv: |
| 3372 | switch (version) { |
| 3373 | case 0: |
| 3374 | { |
| 3375 | struct target_ipc_kludge { |
| 3376 | abi_long msgp; |
| 3377 | abi_long msgtyp; |
| 3378 | } *tmp; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3379 | |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3380 | if (!lock_user_struct(VERIFY_READ, tmp, ptr, 1)) { |
| 3381 | ret = -TARGET_EFAULT; |
| 3382 | break; |
ths | 1bc012f | 2007-06-03 14:27:49 +0000 | [diff] [blame] | 3383 | } |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3384 | |
Laurent Vivier | 79dd77d | 2012-12-20 11:00:11 +0000 | [diff] [blame] | 3385 | ret = do_msgrcv(first, tswapal(tmp->msgp), second, tswapal(tmp->msgtyp), third); |
aurel32 | 1c54ff9 | 2008-10-13 21:08:44 +0000 | [diff] [blame] | 3386 | |
| 3387 | unlock_user_struct(tmp, ptr, 0); |
| 3388 | break; |
| 3389 | } |
| 3390 | default: |
| 3391 | ret = do_msgrcv(first, ptr, second, fifth, third); |
| 3392 | } |
| 3393 | break; |
ths | d96372e | 2007-02-02 22:05:44 +0000 | [diff] [blame] | 3394 | |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3395 | case IPCOP_shmat: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3396 | switch (version) { |
| 3397 | default: |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3398 | { |
| 3399 | abi_ulong raddr; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3400 | raddr = do_shmat(first, ptr, second); |
| 3401 | if (is_error(raddr)) |
| 3402 | return get_errno(raddr); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 3403 | if (put_user_ual(raddr, third)) |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3404 | return -TARGET_EFAULT; |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3405 | break; |
| 3406 | } |
| 3407 | case 1: |
| 3408 | ret = -TARGET_EINVAL; |
| 3409 | break; |
bellard | 5a4a898 | 2007-11-11 17:39:18 +0000 | [diff] [blame] | 3410 | } |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3411 | break; |
| 3412 | case IPCOP_shmdt: |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 3413 | ret = do_shmdt(ptr); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3414 | break; |
| 3415 | |
| 3416 | case IPCOP_shmget: |
| 3417 | /* IPC_* flag values are the same on all linux platforms */ |
| 3418 | ret = get_errno(shmget(first, second, third)); |
| 3419 | break; |
| 3420 | |
| 3421 | /* IPC_* and SHM_* command values are the same on all linux platforms */ |
| 3422 | case IPCOP_shmctl: |
Petar Jovanovic | a292678 | 2013-10-30 14:46:32 +0100 | [diff] [blame] | 3423 | ret = do_shmctl(first, second, ptr); |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3424 | break; |
| 3425 | default: |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3426 | gemu_log("Unsupported ipc call: %d (version %d)\n", call, version); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 3427 | ret = -TARGET_ENOSYS; |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3428 | break; |
| 3429 | } |
| 3430 | return ret; |
| 3431 | } |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 3432 | #endif |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 3433 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3434 | /* kernel structure types definitions */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3435 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3436 | #define STRUCT(name, ...) STRUCT_ ## name, |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3437 | #define STRUCT_SPECIAL(name) STRUCT_ ## name, |
| 3438 | enum { |
| 3439 | #include "syscall_types.h" |
Alexander Graf | 8be656b | 2015-05-06 23:47:32 +0200 | [diff] [blame] | 3440 | STRUCT_MAX |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3441 | }; |
| 3442 | #undef STRUCT |
| 3443 | #undef STRUCT_SPECIAL |
| 3444 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 3445 | #define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL }; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3446 | #define STRUCT_SPECIAL(name) |
| 3447 | #include "syscall_types.h" |
| 3448 | #undef STRUCT |
| 3449 | #undef STRUCT_SPECIAL |
| 3450 | |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3451 | typedef struct IOCTLEntry IOCTLEntry; |
| 3452 | |
| 3453 | typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3454 | int fd, int cmd, abi_long arg); |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3455 | |
| 3456 | struct IOCTLEntry { |
Ed Swierk | 9c6bf9c | 2014-12-16 12:55:31 -0800 | [diff] [blame] | 3457 | int target_cmd; |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 3458 | unsigned int host_cmd; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3459 | const char *name; |
| 3460 | int access; |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3461 | do_ioctl_fn *do_ioctl; |
bellard | 1a9353d | 2003-03-16 20:28:50 +0000 | [diff] [blame] | 3462 | const argtype arg_type[5]; |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 3463 | }; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 3464 | |
| 3465 | #define IOC_R 0x0001 |
| 3466 | #define IOC_W 0x0002 |
| 3467 | #define IOC_RW (IOC_R | IOC_W) |
| 3468 | |
| 3469 | #define MAX_STRUCT_SIZE 4096 |
| 3470 | |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 3471 | #ifdef CONFIG_FIEMAP |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3472 | /* So fiemap access checks don't overflow on 32 bit systems. |
| 3473 | * This is very slightly smaller than the limit imposed by |
| 3474 | * the underlying kernel. |
| 3475 | */ |
| 3476 | #define FIEMAP_MAX_EXTENTS ((UINT_MAX - sizeof(struct fiemap)) \ |
| 3477 | / sizeof(struct fiemap_extent)) |
| 3478 | |
| 3479 | static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3480 | int fd, int cmd, abi_long arg) |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3481 | { |
| 3482 | /* The parameter for this ioctl is a struct fiemap followed |
| 3483 | * by an array of struct fiemap_extent whose size is set |
| 3484 | * in fiemap->fm_extent_count. The array is filled in by the |
| 3485 | * ioctl. |
| 3486 | */ |
| 3487 | int target_size_in, target_size_out; |
| 3488 | struct fiemap *fm; |
| 3489 | const argtype *arg_type = ie->arg_type; |
| 3490 | const argtype extent_arg_type[] = { MK_STRUCT(STRUCT_fiemap_extent) }; |
| 3491 | void *argptr, *p; |
| 3492 | abi_long ret; |
| 3493 | int i, extent_size = thunk_type_size(extent_arg_type, 0); |
| 3494 | uint32_t outbufsz; |
| 3495 | int free_fm = 0; |
| 3496 | |
| 3497 | assert(arg_type[0] == TYPE_PTR); |
| 3498 | assert(ie->access == IOC_RW); |
| 3499 | arg_type++; |
| 3500 | target_size_in = thunk_type_size(arg_type, 0); |
| 3501 | argptr = lock_user(VERIFY_READ, arg, target_size_in, 1); |
| 3502 | if (!argptr) { |
| 3503 | return -TARGET_EFAULT; |
| 3504 | } |
| 3505 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3506 | unlock_user(argptr, arg, 0); |
| 3507 | fm = (struct fiemap *)buf_temp; |
| 3508 | if (fm->fm_extent_count > FIEMAP_MAX_EXTENTS) { |
| 3509 | return -TARGET_EINVAL; |
| 3510 | } |
| 3511 | |
| 3512 | outbufsz = sizeof (*fm) + |
| 3513 | (sizeof(struct fiemap_extent) * fm->fm_extent_count); |
| 3514 | |
| 3515 | if (outbufsz > MAX_STRUCT_SIZE) { |
| 3516 | /* We can't fit all the extents into the fixed size buffer. |
| 3517 | * Allocate one that is large enough and use it instead. |
| 3518 | */ |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 3519 | fm = g_try_malloc(outbufsz); |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3520 | if (!fm) { |
| 3521 | return -TARGET_ENOMEM; |
| 3522 | } |
| 3523 | memcpy(fm, buf_temp, sizeof(struct fiemap)); |
| 3524 | free_fm = 1; |
| 3525 | } |
| 3526 | ret = get_errno(ioctl(fd, ie->host_cmd, fm)); |
| 3527 | if (!is_error(ret)) { |
| 3528 | target_size_out = target_size_in; |
| 3529 | /* An extent_count of 0 means we were only counting the extents |
| 3530 | * so there are no structs to copy |
| 3531 | */ |
| 3532 | if (fm->fm_extent_count != 0) { |
| 3533 | target_size_out += fm->fm_mapped_extents * extent_size; |
| 3534 | } |
| 3535 | argptr = lock_user(VERIFY_WRITE, arg, target_size_out, 0); |
| 3536 | if (!argptr) { |
| 3537 | ret = -TARGET_EFAULT; |
| 3538 | } else { |
| 3539 | /* Convert the struct fiemap */ |
| 3540 | thunk_convert(argptr, fm, arg_type, THUNK_TARGET); |
| 3541 | if (fm->fm_extent_count != 0) { |
| 3542 | p = argptr + target_size_in; |
| 3543 | /* ...and then all the struct fiemap_extents */ |
| 3544 | for (i = 0; i < fm->fm_mapped_extents; i++) { |
| 3545 | thunk_convert(p, &fm->fm_extents[i], extent_arg_type, |
| 3546 | THUNK_TARGET); |
| 3547 | p += extent_size; |
| 3548 | } |
| 3549 | } |
| 3550 | unlock_user(argptr, arg, target_size_out); |
| 3551 | } |
| 3552 | } |
| 3553 | if (free_fm) { |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 3554 | g_free(fm); |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3555 | } |
| 3556 | return ret; |
| 3557 | } |
Peter Maydell | dace20d | 2011-01-10 13:11:24 +0000 | [diff] [blame] | 3558 | #endif |
Peter Maydell | 285da2b | 2011-01-06 15:04:18 +0000 | [diff] [blame] | 3559 | |
Laurent Vivier | 059c2f2 | 2011-03-30 00:12:12 +0200 | [diff] [blame] | 3560 | static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3561 | int fd, int cmd, abi_long arg) |
Laurent Vivier | 059c2f2 | 2011-03-30 00:12:12 +0200 | [diff] [blame] | 3562 | { |
| 3563 | const argtype *arg_type = ie->arg_type; |
| 3564 | int target_size; |
| 3565 | void *argptr; |
| 3566 | int ret; |
| 3567 | struct ifconf *host_ifconf; |
| 3568 | uint32_t outbufsz; |
| 3569 | const argtype ifreq_arg_type[] = { MK_STRUCT(STRUCT_sockaddr_ifreq) }; |
| 3570 | int target_ifreq_size; |
| 3571 | int nb_ifreq; |
| 3572 | int free_buf = 0; |
| 3573 | int i; |
| 3574 | int target_ifc_len; |
| 3575 | abi_long target_ifc_buf; |
| 3576 | int host_ifc_len; |
| 3577 | char *host_ifc_buf; |
| 3578 | |
| 3579 | assert(arg_type[0] == TYPE_PTR); |
| 3580 | assert(ie->access == IOC_RW); |
| 3581 | |
| 3582 | arg_type++; |
| 3583 | target_size = thunk_type_size(arg_type, 0); |
| 3584 | |
| 3585 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3586 | if (!argptr) |
| 3587 | return -TARGET_EFAULT; |
| 3588 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3589 | unlock_user(argptr, arg, 0); |
| 3590 | |
| 3591 | host_ifconf = (struct ifconf *)(unsigned long)buf_temp; |
| 3592 | target_ifc_len = host_ifconf->ifc_len; |
| 3593 | target_ifc_buf = (abi_long)(unsigned long)host_ifconf->ifc_buf; |
| 3594 | |
| 3595 | target_ifreq_size = thunk_type_size(ifreq_arg_type, 0); |
| 3596 | nb_ifreq = target_ifc_len / target_ifreq_size; |
| 3597 | host_ifc_len = nb_ifreq * sizeof(struct ifreq); |
| 3598 | |
| 3599 | outbufsz = sizeof(*host_ifconf) + host_ifc_len; |
| 3600 | if (outbufsz > MAX_STRUCT_SIZE) { |
| 3601 | /* We can't fit all the extents into the fixed size buffer. |
| 3602 | * Allocate one that is large enough and use it instead. |
| 3603 | */ |
| 3604 | host_ifconf = malloc(outbufsz); |
| 3605 | if (!host_ifconf) { |
| 3606 | return -TARGET_ENOMEM; |
| 3607 | } |
| 3608 | memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf)); |
| 3609 | free_buf = 1; |
| 3610 | } |
| 3611 | host_ifc_buf = (char*)host_ifconf + sizeof(*host_ifconf); |
| 3612 | |
| 3613 | host_ifconf->ifc_len = host_ifc_len; |
| 3614 | host_ifconf->ifc_buf = host_ifc_buf; |
| 3615 | |
| 3616 | ret = get_errno(ioctl(fd, ie->host_cmd, host_ifconf)); |
| 3617 | if (!is_error(ret)) { |
| 3618 | /* convert host ifc_len to target ifc_len */ |
| 3619 | |
| 3620 | nb_ifreq = host_ifconf->ifc_len / sizeof(struct ifreq); |
| 3621 | target_ifc_len = nb_ifreq * target_ifreq_size; |
| 3622 | host_ifconf->ifc_len = target_ifc_len; |
| 3623 | |
| 3624 | /* restore target ifc_buf */ |
| 3625 | |
| 3626 | host_ifconf->ifc_buf = (char *)(unsigned long)target_ifc_buf; |
| 3627 | |
| 3628 | /* copy struct ifconf to target user */ |
| 3629 | |
| 3630 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3631 | if (!argptr) |
| 3632 | return -TARGET_EFAULT; |
| 3633 | thunk_convert(argptr, host_ifconf, arg_type, THUNK_TARGET); |
| 3634 | unlock_user(argptr, arg, target_size); |
| 3635 | |
| 3636 | /* copy ifreq[] to target user */ |
| 3637 | |
| 3638 | argptr = lock_user(VERIFY_WRITE, target_ifc_buf, target_ifc_len, 0); |
| 3639 | for (i = 0; i < nb_ifreq ; i++) { |
| 3640 | thunk_convert(argptr + i * target_ifreq_size, |
| 3641 | host_ifc_buf + i * sizeof(struct ifreq), |
| 3642 | ifreq_arg_type, THUNK_TARGET); |
| 3643 | } |
| 3644 | unlock_user(argptr, target_ifc_buf, target_ifc_len); |
| 3645 | } |
| 3646 | |
| 3647 | if (free_buf) { |
| 3648 | free(host_ifconf); |
| 3649 | } |
| 3650 | |
| 3651 | return ret; |
| 3652 | } |
| 3653 | |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3654 | static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3655 | int cmd, abi_long arg) |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3656 | { |
| 3657 | void *argptr; |
| 3658 | struct dm_ioctl *host_dm; |
| 3659 | abi_long guest_data; |
| 3660 | uint32_t guest_data_size; |
| 3661 | int target_size; |
| 3662 | const argtype *arg_type = ie->arg_type; |
| 3663 | abi_long ret; |
| 3664 | void *big_buf = NULL; |
| 3665 | char *host_data; |
| 3666 | |
| 3667 | arg_type++; |
| 3668 | target_size = thunk_type_size(arg_type, 0); |
| 3669 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3670 | if (!argptr) { |
| 3671 | ret = -TARGET_EFAULT; |
| 3672 | goto out; |
| 3673 | } |
| 3674 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3675 | unlock_user(argptr, arg, 0); |
| 3676 | |
| 3677 | /* buf_temp is too small, so fetch things into a bigger buffer */ |
| 3678 | big_buf = g_malloc0(((struct dm_ioctl*)buf_temp)->data_size * 2); |
| 3679 | memcpy(big_buf, buf_temp, target_size); |
| 3680 | buf_temp = big_buf; |
| 3681 | host_dm = big_buf; |
| 3682 | |
| 3683 | guest_data = arg + host_dm->data_start; |
| 3684 | if ((guest_data - arg) < 0) { |
| 3685 | ret = -EINVAL; |
| 3686 | goto out; |
| 3687 | } |
| 3688 | guest_data_size = host_dm->data_size - host_dm->data_start; |
| 3689 | host_data = (char*)host_dm + host_dm->data_start; |
| 3690 | |
| 3691 | argptr = lock_user(VERIFY_READ, guest_data, guest_data_size, 1); |
| 3692 | switch (ie->host_cmd) { |
| 3693 | case DM_REMOVE_ALL: |
| 3694 | case DM_LIST_DEVICES: |
| 3695 | case DM_DEV_CREATE: |
| 3696 | case DM_DEV_REMOVE: |
| 3697 | case DM_DEV_SUSPEND: |
| 3698 | case DM_DEV_STATUS: |
| 3699 | case DM_DEV_WAIT: |
| 3700 | case DM_TABLE_STATUS: |
| 3701 | case DM_TABLE_CLEAR: |
| 3702 | case DM_TABLE_DEPS: |
| 3703 | case DM_LIST_VERSIONS: |
| 3704 | /* no input data */ |
| 3705 | break; |
| 3706 | case DM_DEV_RENAME: |
| 3707 | case DM_DEV_SET_GEOMETRY: |
| 3708 | /* data contains only strings */ |
| 3709 | memcpy(host_data, argptr, guest_data_size); |
| 3710 | break; |
| 3711 | case DM_TARGET_MSG: |
| 3712 | memcpy(host_data, argptr, guest_data_size); |
| 3713 | *(uint64_t*)host_data = tswap64(*(uint64_t*)argptr); |
| 3714 | break; |
| 3715 | case DM_TABLE_LOAD: |
| 3716 | { |
| 3717 | void *gspec = argptr; |
| 3718 | void *cur_data = host_data; |
| 3719 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec) }; |
| 3720 | int spec_size = thunk_type_size(arg_type, 0); |
| 3721 | int i; |
| 3722 | |
| 3723 | for (i = 0; i < host_dm->target_count; i++) { |
| 3724 | struct dm_target_spec *spec = cur_data; |
| 3725 | uint32_t next; |
| 3726 | int slen; |
| 3727 | |
| 3728 | thunk_convert(spec, gspec, arg_type, THUNK_HOST); |
| 3729 | slen = strlen((char*)gspec + spec_size) + 1; |
| 3730 | next = spec->next; |
| 3731 | spec->next = sizeof(*spec) + slen; |
| 3732 | strcpy((char*)&spec[1], gspec + spec_size); |
| 3733 | gspec += next; |
| 3734 | cur_data += spec->next; |
| 3735 | } |
| 3736 | break; |
| 3737 | } |
| 3738 | default: |
| 3739 | ret = -TARGET_EINVAL; |
Chen Gang S | dec0473 | 2015-01-25 08:00:42 +0800 | [diff] [blame] | 3740 | unlock_user(argptr, guest_data, 0); |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3741 | goto out; |
| 3742 | } |
| 3743 | unlock_user(argptr, guest_data, 0); |
| 3744 | |
| 3745 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3746 | if (!is_error(ret)) { |
| 3747 | guest_data = arg + host_dm->data_start; |
| 3748 | guest_data_size = host_dm->data_size - host_dm->data_start; |
| 3749 | argptr = lock_user(VERIFY_WRITE, guest_data, guest_data_size, 0); |
| 3750 | switch (ie->host_cmd) { |
| 3751 | case DM_REMOVE_ALL: |
| 3752 | case DM_DEV_CREATE: |
| 3753 | case DM_DEV_REMOVE: |
| 3754 | case DM_DEV_RENAME: |
| 3755 | case DM_DEV_SUSPEND: |
| 3756 | case DM_DEV_STATUS: |
| 3757 | case DM_TABLE_LOAD: |
| 3758 | case DM_TABLE_CLEAR: |
| 3759 | case DM_TARGET_MSG: |
| 3760 | case DM_DEV_SET_GEOMETRY: |
| 3761 | /* no return data */ |
| 3762 | break; |
| 3763 | case DM_LIST_DEVICES: |
| 3764 | { |
| 3765 | struct dm_name_list *nl = (void*)host_dm + host_dm->data_start; |
| 3766 | uint32_t remaining_data = guest_data_size; |
| 3767 | void *cur_data = argptr; |
| 3768 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_name_list) }; |
| 3769 | int nl_size = 12; /* can't use thunk_size due to alignment */ |
| 3770 | |
| 3771 | while (1) { |
| 3772 | uint32_t next = nl->next; |
| 3773 | if (next) { |
| 3774 | nl->next = nl_size + (strlen(nl->name) + 1); |
| 3775 | } |
| 3776 | if (remaining_data < nl->next) { |
| 3777 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3778 | break; |
| 3779 | } |
| 3780 | thunk_convert(cur_data, nl, arg_type, THUNK_TARGET); |
| 3781 | strcpy(cur_data + nl_size, nl->name); |
| 3782 | cur_data += nl->next; |
| 3783 | remaining_data -= nl->next; |
| 3784 | if (!next) { |
| 3785 | break; |
| 3786 | } |
| 3787 | nl = (void*)nl + next; |
| 3788 | } |
| 3789 | break; |
| 3790 | } |
| 3791 | case DM_DEV_WAIT: |
| 3792 | case DM_TABLE_STATUS: |
| 3793 | { |
| 3794 | struct dm_target_spec *spec = (void*)host_dm + host_dm->data_start; |
| 3795 | void *cur_data = argptr; |
| 3796 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec) }; |
| 3797 | int spec_size = thunk_type_size(arg_type, 0); |
| 3798 | int i; |
| 3799 | |
| 3800 | for (i = 0; i < host_dm->target_count; i++) { |
| 3801 | uint32_t next = spec->next; |
| 3802 | int slen = strlen((char*)&spec[1]) + 1; |
| 3803 | spec->next = (cur_data - argptr) + spec_size + slen; |
| 3804 | if (guest_data_size < spec->next) { |
| 3805 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3806 | break; |
| 3807 | } |
| 3808 | thunk_convert(cur_data, spec, arg_type, THUNK_TARGET); |
| 3809 | strcpy(cur_data + spec_size, (char*)&spec[1]); |
| 3810 | cur_data = argptr + spec->next; |
| 3811 | spec = (void*)host_dm + host_dm->data_start + next; |
| 3812 | } |
| 3813 | break; |
| 3814 | } |
| 3815 | case DM_TABLE_DEPS: |
| 3816 | { |
| 3817 | void *hdata = (void*)host_dm + host_dm->data_start; |
| 3818 | int count = *(uint32_t*)hdata; |
| 3819 | uint64_t *hdev = hdata + 8; |
| 3820 | uint64_t *gdev = argptr + 8; |
| 3821 | int i; |
| 3822 | |
| 3823 | *(uint32_t*)argptr = tswap32(count); |
| 3824 | for (i = 0; i < count; i++) { |
| 3825 | *gdev = tswap64(*hdev); |
| 3826 | gdev++; |
| 3827 | hdev++; |
| 3828 | } |
| 3829 | break; |
| 3830 | } |
| 3831 | case DM_LIST_VERSIONS: |
| 3832 | { |
| 3833 | struct dm_target_versions *vers = (void*)host_dm + host_dm->data_start; |
| 3834 | uint32_t remaining_data = guest_data_size; |
| 3835 | void *cur_data = argptr; |
| 3836 | const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_versions) }; |
| 3837 | int vers_size = thunk_type_size(arg_type, 0); |
| 3838 | |
| 3839 | while (1) { |
| 3840 | uint32_t next = vers->next; |
| 3841 | if (next) { |
| 3842 | vers->next = vers_size + (strlen(vers->name) + 1); |
| 3843 | } |
| 3844 | if (remaining_data < vers->next) { |
| 3845 | host_dm->flags |= DM_BUFFER_FULL_FLAG; |
| 3846 | break; |
| 3847 | } |
| 3848 | thunk_convert(cur_data, vers, arg_type, THUNK_TARGET); |
| 3849 | strcpy(cur_data + vers_size, vers->name); |
| 3850 | cur_data += vers->next; |
| 3851 | remaining_data -= vers->next; |
| 3852 | if (!next) { |
| 3853 | break; |
| 3854 | } |
| 3855 | vers = (void*)vers + next; |
| 3856 | } |
| 3857 | break; |
| 3858 | } |
| 3859 | default: |
Chen Gang S | dec0473 | 2015-01-25 08:00:42 +0800 | [diff] [blame] | 3860 | unlock_user(argptr, guest_data, 0); |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3861 | ret = -TARGET_EINVAL; |
| 3862 | goto out; |
| 3863 | } |
| 3864 | unlock_user(argptr, guest_data, guest_data_size); |
| 3865 | |
| 3866 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 3867 | if (!argptr) { |
| 3868 | ret = -TARGET_EFAULT; |
| 3869 | goto out; |
| 3870 | } |
| 3871 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 3872 | unlock_user(argptr, arg, target_size); |
| 3873 | } |
| 3874 | out: |
Stefan Weil | ad11ad7 | 2012-09-04 22:14:19 +0200 | [diff] [blame] | 3875 | g_free(big_buf); |
Alexander Graf | 56e904e | 2012-01-31 18:42:06 +0100 | [diff] [blame] | 3876 | return ret; |
| 3877 | } |
| 3878 | |
Alexander Graf | a59b5e3 | 2014-08-22 13:15:50 +0200 | [diff] [blame] | 3879 | static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3880 | int cmd, abi_long arg) |
Alexander Graf | a59b5e3 | 2014-08-22 13:15:50 +0200 | [diff] [blame] | 3881 | { |
| 3882 | void *argptr; |
| 3883 | int target_size; |
| 3884 | const argtype *arg_type = ie->arg_type; |
| 3885 | const argtype part_arg_type[] = { MK_STRUCT(STRUCT_blkpg_partition) }; |
| 3886 | abi_long ret; |
| 3887 | |
| 3888 | struct blkpg_ioctl_arg *host_blkpg = (void*)buf_temp; |
| 3889 | struct blkpg_partition host_part; |
| 3890 | |
| 3891 | /* Read and convert blkpg */ |
| 3892 | arg_type++; |
| 3893 | target_size = thunk_type_size(arg_type, 0); |
| 3894 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3895 | if (!argptr) { |
| 3896 | ret = -TARGET_EFAULT; |
| 3897 | goto out; |
| 3898 | } |
| 3899 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 3900 | unlock_user(argptr, arg, 0); |
| 3901 | |
| 3902 | switch (host_blkpg->op) { |
| 3903 | case BLKPG_ADD_PARTITION: |
| 3904 | case BLKPG_DEL_PARTITION: |
| 3905 | /* payload is struct blkpg_partition */ |
| 3906 | break; |
| 3907 | default: |
| 3908 | /* Unknown opcode */ |
| 3909 | ret = -TARGET_EINVAL; |
| 3910 | goto out; |
| 3911 | } |
| 3912 | |
| 3913 | /* Read and convert blkpg->data */ |
| 3914 | arg = (abi_long)(uintptr_t)host_blkpg->data; |
| 3915 | target_size = thunk_type_size(part_arg_type, 0); |
| 3916 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3917 | if (!argptr) { |
| 3918 | ret = -TARGET_EFAULT; |
| 3919 | goto out; |
| 3920 | } |
| 3921 | thunk_convert(&host_part, argptr, part_arg_type, THUNK_HOST); |
| 3922 | unlock_user(argptr, arg, 0); |
| 3923 | |
| 3924 | /* Swizzle the data pointer to our local copy and call! */ |
| 3925 | host_blkpg->data = &host_part; |
| 3926 | ret = get_errno(ioctl(fd, ie->host_cmd, host_blkpg)); |
| 3927 | |
| 3928 | out: |
| 3929 | return ret; |
| 3930 | } |
| 3931 | |
Laurent Vivier | 7ff7b66 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 3932 | static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3933 | int fd, int cmd, abi_long arg) |
Laurent Vivier | 7ff7b66 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 3934 | { |
| 3935 | const argtype *arg_type = ie->arg_type; |
| 3936 | const StructEntry *se; |
| 3937 | const argtype *field_types; |
| 3938 | const int *dst_offsets, *src_offsets; |
| 3939 | int target_size; |
| 3940 | void *argptr; |
| 3941 | abi_ulong *target_rt_dev_ptr; |
| 3942 | unsigned long *host_rt_dev_ptr; |
| 3943 | abi_long ret; |
| 3944 | int i; |
| 3945 | |
| 3946 | assert(ie->access == IOC_W); |
| 3947 | assert(*arg_type == TYPE_PTR); |
| 3948 | arg_type++; |
| 3949 | assert(*arg_type == TYPE_STRUCT); |
| 3950 | target_size = thunk_type_size(arg_type, 0); |
| 3951 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 3952 | if (!argptr) { |
| 3953 | return -TARGET_EFAULT; |
| 3954 | } |
| 3955 | arg_type++; |
| 3956 | assert(*arg_type == (int)STRUCT_rtentry); |
| 3957 | se = struct_entries + *arg_type++; |
| 3958 | assert(se->convert[0] == NULL); |
| 3959 | /* convert struct here to be able to catch rt_dev string */ |
| 3960 | field_types = se->field_types; |
| 3961 | dst_offsets = se->field_offsets[THUNK_HOST]; |
| 3962 | src_offsets = se->field_offsets[THUNK_TARGET]; |
| 3963 | for (i = 0; i < se->nb_fields; i++) { |
| 3964 | if (dst_offsets[i] == offsetof(struct rtentry, rt_dev)) { |
| 3965 | assert(*field_types == TYPE_PTRVOID); |
| 3966 | target_rt_dev_ptr = (abi_ulong *)(argptr + src_offsets[i]); |
| 3967 | host_rt_dev_ptr = (unsigned long *)(buf_temp + dst_offsets[i]); |
| 3968 | if (*target_rt_dev_ptr != 0) { |
| 3969 | *host_rt_dev_ptr = (unsigned long)lock_user_string( |
| 3970 | tswapal(*target_rt_dev_ptr)); |
| 3971 | if (!*host_rt_dev_ptr) { |
| 3972 | unlock_user(argptr, arg, 0); |
| 3973 | return -TARGET_EFAULT; |
| 3974 | } |
| 3975 | } else { |
| 3976 | *host_rt_dev_ptr = 0; |
| 3977 | } |
| 3978 | field_types++; |
| 3979 | continue; |
| 3980 | } |
| 3981 | field_types = thunk_convert(buf_temp + dst_offsets[i], |
| 3982 | argptr + src_offsets[i], |
| 3983 | field_types, THUNK_HOST); |
| 3984 | } |
| 3985 | unlock_user(argptr, arg, 0); |
| 3986 | |
| 3987 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 3988 | if (*host_rt_dev_ptr != 0) { |
| 3989 | unlock_user((void *)*host_rt_dev_ptr, |
| 3990 | *target_rt_dev_ptr, 0); |
| 3991 | } |
| 3992 | return ret; |
| 3993 | } |
| 3994 | |
Paul Burton | ca56f5b | 2014-06-22 11:25:47 +0100 | [diff] [blame] | 3995 | static abi_long do_ioctl_kdsigaccept(const IOCTLEntry *ie, uint8_t *buf_temp, |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 3996 | int fd, int cmd, abi_long arg) |
Paul Burton | ca56f5b | 2014-06-22 11:25:47 +0100 | [diff] [blame] | 3997 | { |
| 3998 | int sig = target_to_host_signal(arg); |
| 3999 | return get_errno(ioctl(fd, ie->host_cmd, sig)); |
| 4000 | } |
| 4001 | |
blueswir1 | 9f106a7 | 2008-10-05 10:52:52 +0000 | [diff] [blame] | 4002 | static IOCTLEntry ioctl_entries[] = { |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 4003 | #define IOCTL(cmd, access, ...) \ |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 4004 | { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } }, |
| 4005 | #define IOCTL_SPECIAL(cmd, access, dofn, ...) \ |
| 4006 | { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } }, |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4007 | #include "ioctls.h" |
| 4008 | { 0, 0, }, |
| 4009 | }; |
| 4010 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4011 | /* ??? Implement proper locking for ioctls. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 4012 | /* do_ioctl() Must return target values and target errnos. */ |
Laurent Vivier | 45c874e | 2015-06-16 00:35:28 +0200 | [diff] [blame] | 4013 | static abi_long do_ioctl(int fd, int cmd, abi_long arg) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4014 | { |
| 4015 | const IOCTLEntry *ie; |
| 4016 | const argtype *arg_type; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4017 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4018 | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4019 | int target_size; |
| 4020 | void *argptr; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4021 | |
| 4022 | ie = ioctl_entries; |
| 4023 | for(;;) { |
| 4024 | if (ie->target_cmd == 0) { |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 4025 | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 4026 | return -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4027 | } |
| 4028 | if (ie->target_cmd == cmd) |
| 4029 | break; |
| 4030 | ie++; |
| 4031 | } |
| 4032 | arg_type = ie->arg_type; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 4033 | #if defined(DEBUG) |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 4034 | gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name); |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 4035 | #endif |
Peter Maydell | d2ef05b | 2011-01-06 15:04:17 +0000 | [diff] [blame] | 4036 | if (ie->do_ioctl) { |
| 4037 | return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); |
| 4038 | } |
| 4039 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4040 | switch(arg_type[0]) { |
| 4041 | case TYPE_NULL: |
| 4042 | /* no argument */ |
| 4043 | ret = get_errno(ioctl(fd, ie->host_cmd)); |
| 4044 | break; |
| 4045 | case TYPE_PTRVOID: |
| 4046 | case TYPE_INT: |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4047 | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); |
| 4048 | break; |
| 4049 | case TYPE_PTR: |
| 4050 | arg_type++; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4051 | target_size = thunk_type_size(arg_type, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4052 | switch(ie->access) { |
| 4053 | case IOC_R: |
| 4054 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 4055 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4056 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 4057 | if (!argptr) |
| 4058 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4059 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 4060 | unlock_user(argptr, arg, target_size); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4061 | } |
| 4062 | break; |
| 4063 | case IOC_W: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4064 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 4065 | if (!argptr) |
| 4066 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4067 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 4068 | unlock_user(argptr, arg, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4069 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 4070 | break; |
| 4071 | default: |
| 4072 | case IOC_RW: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4073 | argptr = lock_user(VERIFY_READ, arg, target_size, 1); |
| 4074 | if (!argptr) |
| 4075 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4076 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
| 4077 | unlock_user(argptr, arg, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4078 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
| 4079 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4080 | argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); |
| 4081 | if (!argptr) |
| 4082 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4083 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
| 4084 | unlock_user(argptr, arg, target_size); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4085 | } |
| 4086 | break; |
| 4087 | } |
| 4088 | break; |
| 4089 | default: |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 4090 | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", |
| 4091 | (long)cmd, arg_type[0]); |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 4092 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4093 | break; |
| 4094 | } |
| 4095 | return ret; |
| 4096 | } |
| 4097 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 4098 | static const bitmask_transtbl iflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4099 | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, |
| 4100 | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, |
| 4101 | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, |
| 4102 | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, |
| 4103 | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, |
| 4104 | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, |
| 4105 | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, |
| 4106 | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, |
| 4107 | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, |
| 4108 | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, |
| 4109 | { TARGET_IXON, TARGET_IXON, IXON, IXON }, |
| 4110 | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, |
| 4111 | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, |
| 4112 | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, |
| 4113 | { 0, 0, 0, 0 } |
| 4114 | }; |
| 4115 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 4116 | static const bitmask_transtbl oflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4117 | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, |
| 4118 | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, |
| 4119 | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, |
| 4120 | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, |
| 4121 | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, |
| 4122 | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, |
| 4123 | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, |
| 4124 | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, |
| 4125 | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, |
| 4126 | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, |
| 4127 | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, |
| 4128 | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, |
| 4129 | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, |
| 4130 | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, |
| 4131 | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, |
| 4132 | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, |
| 4133 | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, |
| 4134 | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, |
| 4135 | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, |
| 4136 | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, |
| 4137 | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, |
| 4138 | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, |
| 4139 | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, |
| 4140 | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, |
| 4141 | { 0, 0, 0, 0 } |
| 4142 | }; |
| 4143 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 4144 | static const bitmask_transtbl cflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4145 | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, |
| 4146 | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, |
| 4147 | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, |
| 4148 | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, |
| 4149 | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, |
| 4150 | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, |
| 4151 | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, |
| 4152 | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, |
| 4153 | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, |
| 4154 | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, |
| 4155 | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, |
| 4156 | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, |
| 4157 | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, |
| 4158 | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, |
| 4159 | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, |
| 4160 | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, |
| 4161 | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, |
| 4162 | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, |
| 4163 | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, |
| 4164 | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, |
| 4165 | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, |
| 4166 | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, |
| 4167 | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, |
| 4168 | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, |
| 4169 | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, |
| 4170 | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, |
| 4171 | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, |
| 4172 | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, |
| 4173 | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, |
| 4174 | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, |
| 4175 | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, |
| 4176 | { 0, 0, 0, 0 } |
| 4177 | }; |
| 4178 | |
blueswir1 | b39bc50 | 2008-10-05 10:51:10 +0000 | [diff] [blame] | 4179 | static const bitmask_transtbl lflag_tbl[] = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4180 | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, |
| 4181 | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, |
| 4182 | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, |
| 4183 | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, |
| 4184 | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, |
| 4185 | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, |
| 4186 | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, |
| 4187 | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, |
| 4188 | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, |
| 4189 | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, |
| 4190 | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, |
| 4191 | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, |
| 4192 | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, |
| 4193 | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, |
| 4194 | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, |
| 4195 | { 0, 0, 0, 0 } |
| 4196 | }; |
| 4197 | |
| 4198 | static void target_to_host_termios (void *dst, const void *src) |
| 4199 | { |
| 4200 | struct host_termios *host = dst; |
| 4201 | const struct target_termios *target = src; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4202 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4203 | host->c_iflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4204 | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4205 | host->c_oflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4206 | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4207 | host->c_cflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4208 | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4209 | host->c_lflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4210 | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); |
| 4211 | host->c_line = target->c_line; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4212 | |
Arnaud Patard | 4460712 | 2009-04-21 17:39:08 +0300 | [diff] [blame] | 4213 | memset(host->c_cc, 0, sizeof(host->c_cc)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4214 | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; |
| 4215 | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4216 | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4217 | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4218 | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4219 | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4220 | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4221 | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4222 | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4223 | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; |
| 4224 | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4225 | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; |
| 4226 | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; |
| 4227 | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; |
| 4228 | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; |
| 4229 | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4230 | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4231 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4232 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4233 | static void host_to_target_termios (void *dst, const void *src) |
| 4234 | { |
| 4235 | struct target_termios *target = dst; |
| 4236 | const struct host_termios *host = src; |
| 4237 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4238 | target->c_iflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4239 | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4240 | target->c_oflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4241 | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4242 | target->c_cflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4243 | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 4244 | target->c_lflag = |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4245 | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); |
| 4246 | target->c_line = host->c_line; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4247 | |
Arnaud Patard | 4460712 | 2009-04-21 17:39:08 +0300 | [diff] [blame] | 4248 | memset(target->c_cc, 0, sizeof(target->c_cc)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4249 | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; |
| 4250 | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; |
| 4251 | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; |
| 4252 | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; |
| 4253 | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; |
| 4254 | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; |
| 4255 | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; |
| 4256 | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; |
| 4257 | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; |
| 4258 | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; |
| 4259 | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; |
| 4260 | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; |
| 4261 | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; |
| 4262 | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; |
| 4263 | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; |
| 4264 | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; |
| 4265 | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; |
| 4266 | } |
| 4267 | |
blueswir1 | 8e853dc | 2008-10-05 10:49:32 +0000 | [diff] [blame] | 4268 | static const StructEntry struct_termios_def = { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 4269 | .convert = { host_to_target_termios, target_to_host_termios }, |
| 4270 | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, |
| 4271 | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, |
| 4272 | }; |
| 4273 | |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 4274 | static bitmask_transtbl mmap_flags_tbl[] = { |
| 4275 | { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, |
| 4276 | { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, |
| 4277 | { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, |
| 4278 | { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, |
| 4279 | { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN }, |
| 4280 | { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, |
| 4281 | { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, |
| 4282 | { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, |
Christophe Lyon | e8efd8e | 2014-02-03 17:04:32 +0100 | [diff] [blame] | 4283 | { TARGET_MAP_NORESERVE, TARGET_MAP_NORESERVE, MAP_NORESERVE, |
| 4284 | MAP_NORESERVE }, |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 4285 | { 0, 0, 0, 0 } |
| 4286 | }; |
| 4287 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4288 | #if defined(TARGET_I386) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4289 | |
| 4290 | /* NOTE: there is really one LDT for all the threads */ |
blueswir1 | b1d8e52 | 2008-10-26 13:43:07 +0000 | [diff] [blame] | 4291 | static uint8_t *ldt_table; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4292 | |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4293 | static abi_long read_ldt(abi_ulong ptr, unsigned long bytecount) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4294 | { |
| 4295 | int size; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4296 | void *p; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4297 | |
| 4298 | if (!ldt_table) |
| 4299 | return 0; |
| 4300 | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; |
| 4301 | if (size > bytecount) |
| 4302 | size = bytecount; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4303 | p = lock_user(VERIFY_WRITE, ptr, size, 0); |
| 4304 | if (!p) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4305 | return -TARGET_EFAULT; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4306 | /* ??? Should this by byteswapped? */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4307 | memcpy(p, ldt_table, size); |
| 4308 | unlock_user(p, ptr, size); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4309 | return size; |
| 4310 | } |
| 4311 | |
| 4312 | /* XXX: add locking support */ |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4313 | static abi_long write_ldt(CPUX86State *env, |
| 4314 | abi_ulong ptr, unsigned long bytecount, int oldmode) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4315 | { |
| 4316 | struct target_modify_ldt_ldt_s ldt_info; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4317 | struct target_modify_ldt_ldt_s *target_ldt_info; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4318 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4319 | int seg_not_present, useable, lm; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4320 | uint32_t *lp, entry_1, entry_2; |
| 4321 | |
| 4322 | if (bytecount != sizeof(ldt_info)) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4323 | return -TARGET_EINVAL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4324 | if (!lock_user_struct(VERIFY_READ, target_ldt_info, ptr, 1)) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4325 | return -TARGET_EFAULT; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4326 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4327 | ldt_info.base_addr = tswapal(target_ldt_info->base_addr); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4328 | ldt_info.limit = tswap32(target_ldt_info->limit); |
| 4329 | ldt_info.flags = tswap32(target_ldt_info->flags); |
| 4330 | unlock_user_struct(target_ldt_info, ptr, 0); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4331 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4332 | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4333 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4334 | seg_32bit = ldt_info.flags & 1; |
| 4335 | contents = (ldt_info.flags >> 1) & 3; |
| 4336 | read_exec_only = (ldt_info.flags >> 3) & 1; |
| 4337 | limit_in_pages = (ldt_info.flags >> 4) & 1; |
| 4338 | seg_not_present = (ldt_info.flags >> 5) & 1; |
| 4339 | useable = (ldt_info.flags >> 6) & 1; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4340 | #ifdef TARGET_ABI32 |
| 4341 | lm = 0; |
| 4342 | #else |
| 4343 | lm = (ldt_info.flags >> 7) & 1; |
| 4344 | #endif |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4345 | if (contents == 3) { |
| 4346 | if (oldmode) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4347 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4348 | if (seg_not_present == 0) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4349 | return -TARGET_EINVAL; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4350 | } |
| 4351 | /* allocate the LDT */ |
| 4352 | if (!ldt_table) { |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 4353 | env->ldt.base = target_mmap(0, |
| 4354 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE, |
| 4355 | PROT_READ|PROT_WRITE, |
| 4356 | MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); |
| 4357 | if (env->ldt.base == -1) |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4358 | return -TARGET_ENOMEM; |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 4359 | memset(g2h(env->ldt.base), 0, |
| 4360 | TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4361 | env->ldt.limit = 0xffff; |
balrog | e441570 | 2008-11-10 02:55:33 +0000 | [diff] [blame] | 4362 | ldt_table = g2h(env->ldt.base); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | /* NOTE: same code as Linux kernel */ |
| 4366 | /* Allow LDTs to be cleared by the user. */ |
| 4367 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
| 4368 | if (oldmode || |
| 4369 | (contents == 0 && |
| 4370 | read_exec_only == 1 && |
| 4371 | seg_32bit == 0 && |
| 4372 | limit_in_pages == 0 && |
| 4373 | seg_not_present == 1 && |
| 4374 | useable == 0 )) { |
| 4375 | entry_1 = 0; |
| 4376 | entry_2 = 0; |
| 4377 | goto install; |
| 4378 | } |
| 4379 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4380 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4381 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
| 4382 | (ldt_info.limit & 0x0ffff); |
| 4383 | entry_2 = (ldt_info.base_addr & 0xff000000) | |
| 4384 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
| 4385 | (ldt_info.limit & 0xf0000) | |
| 4386 | ((read_exec_only ^ 1) << 9) | |
| 4387 | (contents << 10) | |
| 4388 | ((seg_not_present ^ 1) << 15) | |
| 4389 | (seg_32bit << 22) | |
| 4390 | (limit_in_pages << 23) | |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4391 | (lm << 21) | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4392 | 0x7000; |
| 4393 | if (!oldmode) |
| 4394 | entry_2 |= (useable << 20); |
bellard | 14ae3ba | 2003-05-27 23:25:06 +0000 | [diff] [blame] | 4395 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4396 | /* Install the new entry ... */ |
| 4397 | install: |
| 4398 | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3)); |
| 4399 | lp[0] = tswap32(entry_1); |
| 4400 | lp[1] = tswap32(entry_2); |
| 4401 | return 0; |
| 4402 | } |
| 4403 | |
| 4404 | /* specific and weird i386 syscalls */ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4405 | static abi_long do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr, |
| 4406 | unsigned long bytecount) |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4407 | { |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4408 | abi_long ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4409 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4410 | switch (func) { |
| 4411 | case 0: |
| 4412 | ret = read_ldt(ptr, bytecount); |
| 4413 | break; |
| 4414 | case 1: |
| 4415 | ret = write_ldt(env, ptr, bytecount, 1); |
| 4416 | break; |
| 4417 | case 0x11: |
| 4418 | ret = write_ldt(env, ptr, bytecount, 0); |
| 4419 | break; |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 4420 | default: |
| 4421 | ret = -TARGET_ENOSYS; |
| 4422 | break; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 4423 | } |
| 4424 | return ret; |
| 4425 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4426 | |
blueswir1 | 4583f58 | 2008-08-24 10:35:55 +0000 | [diff] [blame] | 4427 | #if defined(TARGET_I386) && defined(TARGET_ABI32) |
Alexander Graf | bc22eb4 | 2013-07-16 18:44:58 +0100 | [diff] [blame] | 4428 | abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr) |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4429 | { |
| 4430 | uint64_t *gdt_table = g2h(env->gdt.base); |
| 4431 | struct target_modify_ldt_ldt_s ldt_info; |
| 4432 | struct target_modify_ldt_ldt_s *target_ldt_info; |
| 4433 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
| 4434 | int seg_not_present, useable, lm; |
| 4435 | uint32_t *lp, entry_1, entry_2; |
| 4436 | int i; |
| 4437 | |
| 4438 | lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1); |
| 4439 | if (!target_ldt_info) |
| 4440 | return -TARGET_EFAULT; |
| 4441 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4442 | ldt_info.base_addr = tswapal(target_ldt_info->base_addr); |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4443 | ldt_info.limit = tswap32(target_ldt_info->limit); |
| 4444 | ldt_info.flags = tswap32(target_ldt_info->flags); |
| 4445 | if (ldt_info.entry_number == -1) { |
| 4446 | for (i=TARGET_GDT_ENTRY_TLS_MIN; i<=TARGET_GDT_ENTRY_TLS_MAX; i++) { |
| 4447 | if (gdt_table[i] == 0) { |
| 4448 | ldt_info.entry_number = i; |
| 4449 | target_ldt_info->entry_number = tswap32(i); |
| 4450 | break; |
| 4451 | } |
| 4452 | } |
| 4453 | } |
| 4454 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4455 | |
| 4456 | if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN || |
| 4457 | ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX) |
| 4458 | return -TARGET_EINVAL; |
| 4459 | seg_32bit = ldt_info.flags & 1; |
| 4460 | contents = (ldt_info.flags >> 1) & 3; |
| 4461 | read_exec_only = (ldt_info.flags >> 3) & 1; |
| 4462 | limit_in_pages = (ldt_info.flags >> 4) & 1; |
| 4463 | seg_not_present = (ldt_info.flags >> 5) & 1; |
| 4464 | useable = (ldt_info.flags >> 6) & 1; |
| 4465 | #ifdef TARGET_ABI32 |
| 4466 | lm = 0; |
| 4467 | #else |
| 4468 | lm = (ldt_info.flags >> 7) & 1; |
| 4469 | #endif |
| 4470 | |
| 4471 | if (contents == 3) { |
| 4472 | if (seg_not_present == 0) |
| 4473 | return -TARGET_EINVAL; |
| 4474 | } |
| 4475 | |
| 4476 | /* NOTE: same code as Linux kernel */ |
| 4477 | /* Allow LDTs to be cleared by the user. */ |
| 4478 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
| 4479 | if ((contents == 0 && |
| 4480 | read_exec_only == 1 && |
| 4481 | seg_32bit == 0 && |
| 4482 | limit_in_pages == 0 && |
| 4483 | seg_not_present == 1 && |
| 4484 | useable == 0 )) { |
| 4485 | entry_1 = 0; |
| 4486 | entry_2 = 0; |
| 4487 | goto install; |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
| 4492 | (ldt_info.limit & 0x0ffff); |
| 4493 | entry_2 = (ldt_info.base_addr & 0xff000000) | |
| 4494 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
| 4495 | (ldt_info.limit & 0xf0000) | |
| 4496 | ((read_exec_only ^ 1) << 9) | |
| 4497 | (contents << 10) | |
| 4498 | ((seg_not_present ^ 1) << 15) | |
| 4499 | (seg_32bit << 22) | |
| 4500 | (limit_in_pages << 23) | |
| 4501 | (useable << 20) | |
| 4502 | (lm << 21) | |
| 4503 | 0x7000; |
| 4504 | |
| 4505 | /* Install the new entry ... */ |
| 4506 | install: |
| 4507 | lp = (uint32_t *)(gdt_table + ldt_info.entry_number); |
| 4508 | lp[0] = tswap32(entry_1); |
| 4509 | lp[1] = tswap32(entry_2); |
| 4510 | return 0; |
| 4511 | } |
| 4512 | |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 4513 | static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr) |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4514 | { |
| 4515 | struct target_modify_ldt_ldt_s *target_ldt_info; |
| 4516 | uint64_t *gdt_table = g2h(env->gdt.base); |
| 4517 | uint32_t base_addr, limit, flags; |
| 4518 | int seg_32bit, contents, read_exec_only, limit_in_pages, idx; |
| 4519 | int seg_not_present, useable, lm; |
| 4520 | uint32_t *lp, entry_1, entry_2; |
| 4521 | |
| 4522 | lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1); |
| 4523 | if (!target_ldt_info) |
| 4524 | return -TARGET_EFAULT; |
| 4525 | idx = tswap32(target_ldt_info->entry_number); |
| 4526 | if (idx < TARGET_GDT_ENTRY_TLS_MIN || |
| 4527 | idx > TARGET_GDT_ENTRY_TLS_MAX) { |
| 4528 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4529 | return -TARGET_EINVAL; |
| 4530 | } |
| 4531 | lp = (uint32_t *)(gdt_table + idx); |
| 4532 | entry_1 = tswap32(lp[0]); |
| 4533 | entry_2 = tswap32(lp[1]); |
| 4534 | |
| 4535 | read_exec_only = ((entry_2 >> 9) & 1) ^ 1; |
| 4536 | contents = (entry_2 >> 10) & 3; |
| 4537 | seg_not_present = ((entry_2 >> 15) & 1) ^ 1; |
| 4538 | seg_32bit = (entry_2 >> 22) & 1; |
| 4539 | limit_in_pages = (entry_2 >> 23) & 1; |
| 4540 | useable = (entry_2 >> 20) & 1; |
| 4541 | #ifdef TARGET_ABI32 |
| 4542 | lm = 0; |
| 4543 | #else |
| 4544 | lm = (entry_2 >> 21) & 1; |
| 4545 | #endif |
| 4546 | flags = (seg_32bit << 0) | (contents << 1) | |
| 4547 | (read_exec_only << 3) | (limit_in_pages << 4) | |
| 4548 | (seg_not_present << 5) | (useable << 6) | (lm << 7); |
| 4549 | limit = (entry_1 & 0xffff) | (entry_2 & 0xf0000); |
| 4550 | base_addr = (entry_1 >> 16) | |
| 4551 | (entry_2 & 0xff000000) | |
| 4552 | ((entry_2 & 0xff) << 16); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4553 | target_ldt_info->base_addr = tswapal(base_addr); |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4554 | target_ldt_info->limit = tswap32(limit); |
| 4555 | target_ldt_info->flags = tswap32(flags); |
| 4556 | unlock_user_struct(target_ldt_info, ptr, 1); |
| 4557 | return 0; |
| 4558 | } |
blueswir1 | 4583f58 | 2008-08-24 10:35:55 +0000 | [diff] [blame] | 4559 | #endif /* TARGET_I386 && TARGET_ABI32 */ |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 4560 | |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4561 | #ifndef TARGET_ABI32 |
Peter Maydell | 2667e71 | 2013-07-16 18:44:59 +0100 | [diff] [blame] | 4562 | abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr) |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4563 | { |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4564 | abi_long ret = 0; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4565 | abi_ulong val; |
| 4566 | int idx; |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4567 | |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4568 | switch(code) { |
| 4569 | case TARGET_ARCH_SET_GS: |
| 4570 | case TARGET_ARCH_SET_FS: |
| 4571 | if (code == TARGET_ARCH_SET_GS) |
| 4572 | idx = R_GS; |
| 4573 | else |
| 4574 | idx = R_FS; |
| 4575 | cpu_x86_load_seg(env, idx, 0); |
| 4576 | env->segs[idx].base = addr; |
| 4577 | break; |
| 4578 | case TARGET_ARCH_GET_GS: |
| 4579 | case TARGET_ARCH_GET_FS: |
| 4580 | if (code == TARGET_ARCH_GET_GS) |
| 4581 | idx = R_GS; |
| 4582 | else |
| 4583 | idx = R_FS; |
| 4584 | val = env->segs[idx].base; |
| 4585 | if (put_user(val, addr, abi_ulong)) |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4586 | ret = -TARGET_EFAULT; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4587 | break; |
| 4588 | default: |
| 4589 | ret = -TARGET_EINVAL; |
| 4590 | break; |
| 4591 | } |
Juan Quintela | 1add869 | 2011-06-16 17:37:09 +0100 | [diff] [blame] | 4592 | return ret; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 4593 | } |
| 4594 | #endif |
| 4595 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 4596 | #endif /* defined(TARGET_I386) */ |
| 4597 | |
Riku Voipio | 05098a9 | 2011-03-04 15:27:29 +0200 | [diff] [blame] | 4598 | #define NEW_STACK_SIZE 0x40000 |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4599 | |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4600 | |
| 4601 | static pthread_mutex_t clone_lock = PTHREAD_MUTEX_INITIALIZER; |
| 4602 | typedef struct { |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4603 | CPUArchState *env; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4604 | pthread_mutex_t mutex; |
| 4605 | pthread_cond_t cond; |
| 4606 | pthread_t thread; |
| 4607 | uint32_t tid; |
| 4608 | abi_ulong child_tidptr; |
| 4609 | abi_ulong parent_tidptr; |
| 4610 | sigset_t sigmask; |
| 4611 | } new_thread_info; |
| 4612 | |
| 4613 | static void *clone_func(void *arg) |
| 4614 | { |
| 4615 | new_thread_info *info = arg; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4616 | CPUArchState *env; |
Andreas Färber | 0d34282 | 2012-12-17 07:12:13 +0100 | [diff] [blame] | 4617 | CPUState *cpu; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4618 | TaskState *ts; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4619 | |
Emilio G. Cota | 7090376 | 2015-08-23 20:23:41 -0400 | [diff] [blame] | 4620 | rcu_register_thread(); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4621 | env = info->env; |
Andreas Färber | 0d34282 | 2012-12-17 07:12:13 +0100 | [diff] [blame] | 4622 | cpu = ENV_GET_CPU(env); |
Andreas Färber | a2247f8 | 2013-06-09 19:47:04 +0200 | [diff] [blame] | 4623 | thread_cpu = cpu; |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 4624 | ts = (TaskState *)cpu->opaque; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4625 | info->tid = gettid(); |
Andreas Färber | 0d34282 | 2012-12-17 07:12:13 +0100 | [diff] [blame] | 4626 | cpu->host_tid = info->tid; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4627 | task_settid(ts); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4628 | if (info->child_tidptr) |
| 4629 | put_user_u32(info->tid, info->child_tidptr); |
| 4630 | if (info->parent_tidptr) |
| 4631 | put_user_u32(info->tid, info->parent_tidptr); |
| 4632 | /* Enable signals. */ |
| 4633 | sigprocmask(SIG_SETMASK, &info->sigmask, NULL); |
| 4634 | /* Signal to the parent that we're ready. */ |
| 4635 | pthread_mutex_lock(&info->mutex); |
| 4636 | pthread_cond_broadcast(&info->cond); |
| 4637 | pthread_mutex_unlock(&info->mutex); |
| 4638 | /* Wait until the parent has finshed initializing the tls state. */ |
| 4639 | pthread_mutex_lock(&clone_lock); |
| 4640 | pthread_mutex_unlock(&clone_lock); |
| 4641 | cpu_loop(env); |
| 4642 | /* never exits */ |
| 4643 | return NULL; |
| 4644 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4645 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 4646 | /* do_fork() Must return host values and target errnos (unlike most |
| 4647 | do_*() functions). */ |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4648 | static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4649 | abi_ulong parent_tidptr, target_ulong newtls, |
| 4650 | abi_ulong child_tidptr) |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4651 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 4652 | CPUState *cpu = ENV_GET_CPU(env); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4653 | int ret; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 4654 | TaskState *ts; |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 4655 | CPUState *new_cpu; |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 4656 | CPUArchState *new_env; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4657 | unsigned int nptl_flags; |
| 4658 | sigset_t sigmask; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4659 | |
balrog | 436d124 | 2008-09-21 02:39:45 +0000 | [diff] [blame] | 4660 | /* Emulate vfork() with fork() */ |
| 4661 | if (flags & CLONE_VFORK) |
| 4662 | flags &= ~(CLONE_VFORK | CLONE_VM); |
| 4663 | |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4664 | if (flags & CLONE_VM) { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 4665 | TaskState *parent_ts = (TaskState *)cpu->opaque; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4666 | new_thread_info info; |
| 4667 | pthread_attr_t attr; |
Peter Maydell | 24cb36a | 2013-07-16 18:45:00 +0100 | [diff] [blame] | 4668 | |
Markus Armbruster | c78d65e | 2015-09-14 13:53:03 +0200 | [diff] [blame] | 4669 | ts = g_new0(TaskState, 1); |
pbrook | 624f797 | 2008-05-31 16:11:38 +0000 | [diff] [blame] | 4670 | init_task_state(ts); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4671 | /* we create a new CPU instance. */ |
ths | c5be9f0 | 2007-02-28 20:20:53 +0000 | [diff] [blame] | 4672 | new_env = cpu_copy(env); |
pbrook | 6e68e07 | 2008-05-30 17:22:15 +0000 | [diff] [blame] | 4673 | /* Init regs that differ from the parent. */ |
| 4674 | cpu_clone_regs(new_env, newsp); |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 4675 | new_cpu = ENV_GET_CPU(new_env); |
| 4676 | new_cpu->opaque = ts; |
Mika Westerberg | edf8e2a | 2009-04-07 09:57:11 +0300 | [diff] [blame] | 4677 | ts->bprm = parent_ts->bprm; |
| 4678 | ts->info = parent_ts->info; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4679 | nptl_flags = flags; |
| 4680 | flags &= ~CLONE_NPTL_FLAGS2; |
| 4681 | |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4682 | if (nptl_flags & CLONE_CHILD_CLEARTID) { |
| 4683 | ts->child_tidptr = child_tidptr; |
| 4684 | } |
| 4685 | |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4686 | if (nptl_flags & CLONE_SETTLS) |
| 4687 | cpu_set_tls (new_env, newtls); |
| 4688 | |
| 4689 | /* Grab a mutex so that thread setup appears atomic. */ |
| 4690 | pthread_mutex_lock(&clone_lock); |
| 4691 | |
| 4692 | memset(&info, 0, sizeof(info)); |
| 4693 | pthread_mutex_init(&info.mutex, NULL); |
| 4694 | pthread_mutex_lock(&info.mutex); |
| 4695 | pthread_cond_init(&info.cond, NULL); |
| 4696 | info.env = new_env; |
| 4697 | if (nptl_flags & CLONE_CHILD_SETTID) |
| 4698 | info.child_tidptr = child_tidptr; |
| 4699 | if (nptl_flags & CLONE_PARENT_SETTID) |
| 4700 | info.parent_tidptr = parent_tidptr; |
| 4701 | |
| 4702 | ret = pthread_attr_init(&attr); |
Nathan Froyd | 48e15fc | 2010-10-29 07:48:57 -0700 | [diff] [blame] | 4703 | ret = pthread_attr_setstacksize(&attr, NEW_STACK_SIZE); |
| 4704 | ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4705 | /* It is not safe to deliver signals until the child has finished |
| 4706 | initializing, so temporarily block all signals. */ |
| 4707 | sigfillset(&sigmask); |
| 4708 | sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); |
| 4709 | |
| 4710 | ret = pthread_create(&info.thread, &attr, clone_func, &info); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4711 | /* TODO: Free new CPU state if thread creation failed. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4712 | |
| 4713 | sigprocmask(SIG_SETMASK, &info.sigmask, NULL); |
| 4714 | pthread_attr_destroy(&attr); |
| 4715 | if (ret == 0) { |
| 4716 | /* Wait for the child to initialize. */ |
| 4717 | pthread_cond_wait(&info.cond, &info.mutex); |
| 4718 | ret = info.tid; |
| 4719 | if (flags & CLONE_PARENT_SETTID) |
| 4720 | put_user_u32(ret, parent_tidptr); |
| 4721 | } else { |
| 4722 | ret = -1; |
| 4723 | } |
| 4724 | pthread_mutex_unlock(&info.mutex); |
| 4725 | pthread_cond_destroy(&info.cond); |
| 4726 | pthread_mutex_destroy(&info.mutex); |
| 4727 | pthread_mutex_unlock(&clone_lock); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4728 | } else { |
| 4729 | /* if no CLONE_VM, we consider it is a fork */ |
Timothy E Baldwin | 93b4eff | 2015-08-31 00:26:21 +0100 | [diff] [blame] | 4730 | if ((flags & ~(CSIGNAL | CLONE_NPTL_FLAGS2)) != 0) { |
| 4731 | return -TARGET_EINVAL; |
| 4732 | } |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4733 | fork_start(); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4734 | ret = fork(); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4735 | if (ret == 0) { |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4736 | /* Child Process. */ |
Paolo Bonzini | a59629f | 2015-03-31 13:01:05 +0200 | [diff] [blame] | 4737 | rcu_after_fork(); |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4738 | cpu_clone_regs(env, newsp); |
| 4739 | fork_end(1); |
aurel32 | 2b1319c | 2008-12-18 22:44:04 +0000 | [diff] [blame] | 4740 | /* There is a race condition here. The parent process could |
| 4741 | theoretically read the TID in the child process before the child |
| 4742 | tid is set. This would require using either ptrace |
| 4743 | (not implemented) or having *_tidptr to point at a shared memory |
| 4744 | mapping. We can't repeat the spinlock hack used above because |
| 4745 | the child process gets its own copy of the lock. */ |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4746 | if (flags & CLONE_CHILD_SETTID) |
| 4747 | put_user_u32(gettid(), child_tidptr); |
| 4748 | if (flags & CLONE_PARENT_SETTID) |
| 4749 | put_user_u32(gettid(), parent_tidptr); |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 4750 | ts = (TaskState *)cpu->opaque; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4751 | if (flags & CLONE_SETTLS) |
| 4752 | cpu_set_tls (env, newtls); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 4753 | if (flags & CLONE_CHILD_CLEARTID) |
| 4754 | ts->child_tidptr = child_tidptr; |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 4755 | } else { |
| 4756 | fork_end(0); |
| 4757 | } |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 4758 | } |
| 4759 | return ret; |
| 4760 | } |
| 4761 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4762 | /* warning : doesn't handle linux specific flags... */ |
| 4763 | static int target_to_host_fcntl_cmd(int cmd) |
| 4764 | { |
| 4765 | switch(cmd) { |
| 4766 | case TARGET_F_DUPFD: |
| 4767 | case TARGET_F_GETFD: |
| 4768 | case TARGET_F_SETFD: |
| 4769 | case TARGET_F_GETFL: |
| 4770 | case TARGET_F_SETFL: |
| 4771 | return cmd; |
| 4772 | case TARGET_F_GETLK: |
| 4773 | return F_GETLK; |
| 4774 | case TARGET_F_SETLK: |
| 4775 | return F_SETLK; |
| 4776 | case TARGET_F_SETLKW: |
| 4777 | return F_SETLKW; |
| 4778 | case TARGET_F_GETOWN: |
| 4779 | return F_GETOWN; |
| 4780 | case TARGET_F_SETOWN: |
| 4781 | return F_SETOWN; |
| 4782 | case TARGET_F_GETSIG: |
| 4783 | return F_GETSIG; |
| 4784 | case TARGET_F_SETSIG: |
| 4785 | return F_SETSIG; |
| 4786 | #if TARGET_ABI_BITS == 32 |
| 4787 | case TARGET_F_GETLK64: |
| 4788 | return F_GETLK64; |
| 4789 | case TARGET_F_SETLK64: |
| 4790 | return F_SETLK64; |
| 4791 | case TARGET_F_SETLKW64: |
| 4792 | return F_SETLKW64; |
| 4793 | #endif |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4794 | case TARGET_F_SETLEASE: |
| 4795 | return F_SETLEASE; |
| 4796 | case TARGET_F_GETLEASE: |
| 4797 | return F_GETLEASE; |
malc | fbd5de9 | 2009-09-06 06:31:59 +0400 | [diff] [blame] | 4798 | #ifdef F_DUPFD_CLOEXEC |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4799 | case TARGET_F_DUPFD_CLOEXEC: |
| 4800 | return F_DUPFD_CLOEXEC; |
malc | fbd5de9 | 2009-09-06 06:31:59 +0400 | [diff] [blame] | 4801 | #endif |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4802 | case TARGET_F_NOTIFY: |
| 4803 | return F_NOTIFY; |
Andreas Schwab | 8d5d300 | 2014-03-07 15:24:08 +0100 | [diff] [blame] | 4804 | #ifdef F_GETOWN_EX |
| 4805 | case TARGET_F_GETOWN_EX: |
| 4806 | return F_GETOWN_EX; |
| 4807 | #endif |
| 4808 | #ifdef F_SETOWN_EX |
| 4809 | case TARGET_F_SETOWN_EX: |
| 4810 | return F_SETOWN_EX; |
| 4811 | #endif |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4812 | default: |
| 4813 | return -TARGET_EINVAL; |
| 4814 | } |
| 4815 | return -TARGET_EINVAL; |
| 4816 | } |
| 4817 | |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4818 | #define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a } |
| 4819 | static const bitmask_transtbl flock_tbl[] = { |
| 4820 | TRANSTBL_CONVERT(F_RDLCK), |
| 4821 | TRANSTBL_CONVERT(F_WRLCK), |
| 4822 | TRANSTBL_CONVERT(F_UNLCK), |
| 4823 | TRANSTBL_CONVERT(F_EXLCK), |
| 4824 | TRANSTBL_CONVERT(F_SHLCK), |
| 4825 | { 0, 0, 0, 0 } |
| 4826 | }; |
| 4827 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4828 | static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4829 | { |
| 4830 | struct flock fl; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4831 | struct target_flock *target_fl; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4832 | struct flock64 fl64; |
| 4833 | struct target_flock64 *target_fl64; |
Andreas Schwab | 8d5d300 | 2014-03-07 15:24:08 +0100 | [diff] [blame] | 4834 | #ifdef F_GETOWN_EX |
| 4835 | struct f_owner_ex fox; |
| 4836 | struct target_f_owner_ex *target_fox; |
| 4837 | #endif |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 4838 | abi_long ret; |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4839 | int host_cmd = target_to_host_fcntl_cmd(cmd); |
| 4840 | |
| 4841 | if (host_cmd == -TARGET_EINVAL) |
| 4842 | return host_cmd; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4843 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4844 | switch(cmd) { |
| 4845 | case TARGET_F_GETLK: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4846 | if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)) |
| 4847 | return -TARGET_EFAULT; |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4848 | fl.l_type = |
| 4849 | target_to_host_bitmask(tswap16(target_fl->l_type), flock_tbl); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4850 | fl.l_whence = tswap16(target_fl->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4851 | fl.l_start = tswapal(target_fl->l_start); |
| 4852 | fl.l_len = tswapal(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4853 | fl.l_pid = tswap32(target_fl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4854 | unlock_user_struct(target_fl, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4855 | ret = get_errno(fcntl(fd, host_cmd, &fl)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4856 | if (ret == 0) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4857 | if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0)) |
| 4858 | return -TARGET_EFAULT; |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4859 | target_fl->l_type = |
| 4860 | host_to_target_bitmask(tswap16(fl.l_type), flock_tbl); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4861 | target_fl->l_whence = tswap16(fl.l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4862 | target_fl->l_start = tswapal(fl.l_start); |
| 4863 | target_fl->l_len = tswapal(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4864 | target_fl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4865 | unlock_user_struct(target_fl, arg, 1); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4866 | } |
| 4867 | break; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4868 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4869 | case TARGET_F_SETLK: |
| 4870 | case TARGET_F_SETLKW: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4871 | if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)) |
| 4872 | return -TARGET_EFAULT; |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4873 | fl.l_type = |
| 4874 | target_to_host_bitmask(tswap16(target_fl->l_type), flock_tbl); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4875 | fl.l_whence = tswap16(target_fl->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4876 | fl.l_start = tswapal(target_fl->l_start); |
| 4877 | fl.l_len = tswapal(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4878 | fl.l_pid = tswap32(target_fl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 4879 | unlock_user_struct(target_fl, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4880 | ret = get_errno(fcntl(fd, host_cmd, &fl)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4881 | break; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 4882 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4883 | case TARGET_F_GETLK64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4884 | if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)) |
| 4885 | return -TARGET_EFAULT; |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4886 | fl64.l_type = |
| 4887 | target_to_host_bitmask(tswap16(target_fl64->l_type), flock_tbl) >> 1; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4888 | fl64.l_whence = tswap16(target_fl64->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4889 | fl64.l_start = tswap64(target_fl64->l_start); |
| 4890 | fl64.l_len = tswap64(target_fl64->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4891 | fl64.l_pid = tswap32(target_fl64->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 4892 | unlock_user_struct(target_fl64, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4893 | ret = get_errno(fcntl(fd, host_cmd, &fl64)); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4894 | if (ret == 0) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4895 | if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0)) |
| 4896 | return -TARGET_EFAULT; |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4897 | target_fl64->l_type = |
| 4898 | host_to_target_bitmask(tswap16(fl64.l_type), flock_tbl) >> 1; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4899 | target_fl64->l_whence = tswap16(fl64.l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4900 | target_fl64->l_start = tswap64(fl64.l_start); |
| 4901 | target_fl64->l_len = tswap64(fl64.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4902 | target_fl64->l_pid = tswap32(fl64.l_pid); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4903 | unlock_user_struct(target_fl64, arg, 1); |
| 4904 | } |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4905 | break; |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4906 | case TARGET_F_SETLK64: |
| 4907 | case TARGET_F_SETLKW64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 4908 | if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)) |
| 4909 | return -TARGET_EFAULT; |
Laurent Vivier | 2ba7f73 | 2013-01-10 21:42:48 +0100 | [diff] [blame] | 4910 | fl64.l_type = |
| 4911 | target_to_host_bitmask(tswap16(target_fl64->l_type), flock_tbl) >> 1; |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4912 | fl64.l_whence = tswap16(target_fl64->l_whence); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 4913 | fl64.l_start = tswap64(target_fl64->l_start); |
| 4914 | fl64.l_len = tswap64(target_fl64->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4915 | fl64.l_pid = tswap32(target_fl64->l_pid); |
ths | 43f238d | 2007-01-05 20:55:49 +0000 | [diff] [blame] | 4916 | unlock_user_struct(target_fl64, arg, 0); |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4917 | ret = get_errno(fcntl(fd, host_cmd, &fl64)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4918 | break; |
| 4919 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4920 | case TARGET_F_GETFL: |
| 4921 | ret = get_errno(fcntl(fd, host_cmd, arg)); |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4922 | if (ret >= 0) { |
| 4923 | ret = host_to_target_bitmask(ret, fcntl_flags_tbl); |
| 4924 | } |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 4925 | break; |
| 4926 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4927 | case TARGET_F_SETFL: |
| 4928 | ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl))); |
| 4929 | break; |
| 4930 | |
Andreas Schwab | 8d5d300 | 2014-03-07 15:24:08 +0100 | [diff] [blame] | 4931 | #ifdef F_GETOWN_EX |
| 4932 | case TARGET_F_GETOWN_EX: |
| 4933 | ret = get_errno(fcntl(fd, host_cmd, &fox)); |
| 4934 | if (ret >= 0) { |
| 4935 | if (!lock_user_struct(VERIFY_WRITE, target_fox, arg, 0)) |
| 4936 | return -TARGET_EFAULT; |
| 4937 | target_fox->type = tswap32(fox.type); |
| 4938 | target_fox->pid = tswap32(fox.pid); |
| 4939 | unlock_user_struct(target_fox, arg, 1); |
| 4940 | } |
| 4941 | break; |
| 4942 | #endif |
| 4943 | |
| 4944 | #ifdef F_SETOWN_EX |
| 4945 | case TARGET_F_SETOWN_EX: |
| 4946 | if (!lock_user_struct(VERIFY_READ, target_fox, arg, 1)) |
| 4947 | return -TARGET_EFAULT; |
| 4948 | fox.type = tswap32(target_fox->type); |
| 4949 | fox.pid = tswap32(target_fox->pid); |
| 4950 | unlock_user_struct(target_fox, arg, 0); |
| 4951 | ret = get_errno(fcntl(fd, host_cmd, &fox)); |
| 4952 | break; |
| 4953 | #endif |
| 4954 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4955 | case TARGET_F_SETOWN: |
| 4956 | case TARGET_F_GETOWN: |
| 4957 | case TARGET_F_SETSIG: |
| 4958 | case TARGET_F_GETSIG: |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 4959 | case TARGET_F_SETLEASE: |
| 4960 | case TARGET_F_GETLEASE: |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 4961 | ret = get_errno(fcntl(fd, host_cmd, arg)); |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 4962 | break; |
| 4963 | |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4964 | default: |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 4965 | ret = get_errno(fcntl(fd, cmd, arg)); |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4966 | break; |
| 4967 | } |
| 4968 | return ret; |
| 4969 | } |
| 4970 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4971 | #ifdef USE_UID16 |
bellard | 7775e9e | 2003-05-14 22:46:48 +0000 | [diff] [blame] | 4972 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 4973 | static inline int high2lowuid(int uid) |
| 4974 | { |
| 4975 | if (uid > 65535) |
| 4976 | return 65534; |
| 4977 | else |
| 4978 | return uid; |
| 4979 | } |
| 4980 | |
| 4981 | static inline int high2lowgid(int gid) |
| 4982 | { |
| 4983 | if (gid > 65535) |
| 4984 | return 65534; |
| 4985 | else |
| 4986 | return gid; |
| 4987 | } |
| 4988 | |
| 4989 | static inline int low2highuid(int uid) |
| 4990 | { |
| 4991 | if ((int16_t)uid == -1) |
| 4992 | return -1; |
| 4993 | else |
| 4994 | return uid; |
| 4995 | } |
| 4996 | |
| 4997 | static inline int low2highgid(int gid) |
| 4998 | { |
| 4999 | if ((int16_t)gid == -1) |
| 5000 | return -1; |
| 5001 | else |
| 5002 | return gid; |
| 5003 | } |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 5004 | static inline int tswapid(int id) |
| 5005 | { |
| 5006 | return tswap16(id); |
| 5007 | } |
Peter Maydell | 76ca310 | 2014-03-02 19:36:41 +0000 | [diff] [blame] | 5008 | |
| 5009 | #define put_user_id(x, gaddr) put_user_u16(x, gaddr) |
| 5010 | |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 5011 | #else /* !USE_UID16 */ |
| 5012 | static inline int high2lowuid(int uid) |
| 5013 | { |
| 5014 | return uid; |
| 5015 | } |
| 5016 | static inline int high2lowgid(int gid) |
| 5017 | { |
| 5018 | return gid; |
| 5019 | } |
| 5020 | static inline int low2highuid(int uid) |
| 5021 | { |
| 5022 | return uid; |
| 5023 | } |
| 5024 | static inline int low2highgid(int gid) |
| 5025 | { |
| 5026 | return gid; |
| 5027 | } |
| 5028 | static inline int tswapid(int id) |
| 5029 | { |
| 5030 | return tswap32(id); |
| 5031 | } |
Peter Maydell | 76ca310 | 2014-03-02 19:36:41 +0000 | [diff] [blame] | 5032 | |
| 5033 | #define put_user_id(x, gaddr) put_user_u32(x, gaddr) |
| 5034 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 5035 | #endif /* USE_UID16 */ |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 5036 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5037 | void syscall_init(void) |
| 5038 | { |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5039 | IOCTLEntry *ie; |
| 5040 | const argtype *arg_type; |
| 5041 | int size; |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 5042 | int i; |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5043 | |
Alexander Graf | 8be656b | 2015-05-06 23:47:32 +0200 | [diff] [blame] | 5044 | thunk_init(STRUCT_MAX); |
| 5045 | |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 5046 | #define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5047 | #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5048 | #include "syscall_types.h" |
| 5049 | #undef STRUCT |
| 5050 | #undef STRUCT_SPECIAL |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5051 | |
Peter Maydell | dd6e957 | 2012-07-23 08:07:22 +0000 | [diff] [blame] | 5052 | /* Build target_to_host_errno_table[] table from |
| 5053 | * host_to_target_errno_table[]. */ |
| 5054 | for (i = 0; i < ERRNO_TABLE_SIZE; i++) { |
| 5055 | target_to_host_errno_table[host_to_target_errno_table[i]] = i; |
| 5056 | } |
| 5057 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5058 | /* we patch the ioctl size if necessary. We rely on the fact that |
| 5059 | no ioctl has all the bits at '1' in the size field */ |
| 5060 | ie = ioctl_entries; |
| 5061 | while (ie->target_cmd != 0) { |
| 5062 | if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == |
| 5063 | TARGET_IOC_SIZEMASK) { |
| 5064 | arg_type = ie->arg_type; |
| 5065 | if (arg_type[0] != TYPE_PTR) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5066 | fprintf(stderr, "cannot patch size for ioctl 0x%x\n", |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5067 | ie->target_cmd); |
| 5068 | exit(1); |
| 5069 | } |
| 5070 | arg_type++; |
| 5071 | size = thunk_type_size(arg_type, 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5072 | ie->target_cmd = (ie->target_cmd & |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5073 | ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | |
| 5074 | (size << TARGET_IOC_SIZESHIFT); |
| 5075 | } |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 5076 | |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5077 | /* automatic consistency check if same arch */ |
balrog | 872ea0c | 2008-09-21 02:31:19 +0000 | [diff] [blame] | 5078 | #if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \ |
| 5079 | (defined(__x86_64__) && defined(TARGET_X86_64)) |
| 5080 | if (unlikely(ie->target_cmd != ie->host_cmd)) { |
| 5081 | fprintf(stderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n", |
| 5082 | ie->name, ie->target_cmd, ie->host_cmd); |
bellard | 2ab83ea | 2003-06-15 19:56:46 +0000 | [diff] [blame] | 5083 | } |
| 5084 | #endif |
| 5085 | ie++; |
| 5086 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5087 | } |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 5088 | |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5089 | #if TARGET_ABI_BITS == 32 |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5090 | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
| 5091 | { |
ths | af325d3 | 2008-06-10 15:29:15 +0000 | [diff] [blame] | 5092 | #ifdef TARGET_WORDS_BIGENDIAN |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5093 | return ((uint64_t)word0 << 32) | word1; |
| 5094 | #else |
| 5095 | return ((uint64_t)word1 << 32) | word0; |
| 5096 | #endif |
| 5097 | } |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5098 | #else /* TARGET_ABI_BITS == 32 */ |
j_mayer | 3240710 | 2007-09-26 23:01:49 +0000 | [diff] [blame] | 5099 | static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) |
| 5100 | { |
| 5101 | return word0; |
| 5102 | } |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5103 | #endif /* TARGET_ABI_BITS != 32 */ |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5104 | |
| 5105 | #ifdef TARGET_NR_truncate64 |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5106 | static inline abi_long target_truncate64(void *cpu_env, const char *arg1, |
| 5107 | abi_long arg2, |
| 5108 | abi_long arg3, |
| 5109 | abi_long arg4) |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5110 | { |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 5111 | if (regpairs_aligned(cpu_env)) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5112 | arg2 = arg3; |
| 5113 | arg3 = arg4; |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 5114 | } |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5115 | return get_errno(truncate64(arg1, target_offset64(arg2, arg3))); |
| 5116 | } |
| 5117 | #endif |
| 5118 | |
| 5119 | #ifdef TARGET_NR_ftruncate64 |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5120 | static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1, |
| 5121 | abi_long arg2, |
| 5122 | abi_long arg3, |
| 5123 | abi_long arg4) |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5124 | { |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 5125 | if (regpairs_aligned(cpu_env)) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5126 | arg2 = arg3; |
| 5127 | arg3 = arg4; |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 5128 | } |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 5129 | return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3))); |
| 5130 | } |
| 5131 | #endif |
| 5132 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5133 | static inline abi_long target_to_host_timespec(struct timespec *host_ts, |
| 5134 | abi_ulong target_addr) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5135 | { |
| 5136 | struct target_timespec *target_ts; |
| 5137 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5138 | if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)) |
| 5139 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 5140 | host_ts->tv_sec = tswapal(target_ts->tv_sec); |
| 5141 | host_ts->tv_nsec = tswapal(target_ts->tv_nsec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5142 | unlock_user_struct(target_ts, target_addr, 0); |
bellard | b255bfa | 2008-05-10 21:51:02 +0000 | [diff] [blame] | 5143 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5144 | } |
| 5145 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5146 | static inline abi_long host_to_target_timespec(abi_ulong target_addr, |
| 5147 | struct timespec *host_ts) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5148 | { |
| 5149 | struct target_timespec *target_ts; |
| 5150 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5151 | if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)) |
| 5152 | return -TARGET_EFAULT; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 5153 | target_ts->tv_sec = tswapal(host_ts->tv_sec); |
| 5154 | target_ts->tv_nsec = tswapal(host_ts->tv_nsec); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5155 | unlock_user_struct(target_ts, target_addr, 1); |
bellard | b255bfa | 2008-05-10 21:51:02 +0000 | [diff] [blame] | 5156 | return 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5157 | } |
| 5158 | |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 5159 | static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec, |
| 5160 | abi_ulong target_addr) |
| 5161 | { |
| 5162 | struct target_itimerspec *target_itspec; |
| 5163 | |
| 5164 | if (!lock_user_struct(VERIFY_READ, target_itspec, target_addr, 1)) { |
| 5165 | return -TARGET_EFAULT; |
| 5166 | } |
| 5167 | |
| 5168 | host_itspec->it_interval.tv_sec = |
| 5169 | tswapal(target_itspec->it_interval.tv_sec); |
| 5170 | host_itspec->it_interval.tv_nsec = |
| 5171 | tswapal(target_itspec->it_interval.tv_nsec); |
| 5172 | host_itspec->it_value.tv_sec = tswapal(target_itspec->it_value.tv_sec); |
| 5173 | host_itspec->it_value.tv_nsec = tswapal(target_itspec->it_value.tv_nsec); |
| 5174 | |
| 5175 | unlock_user_struct(target_itspec, target_addr, 1); |
| 5176 | return 0; |
| 5177 | } |
| 5178 | |
| 5179 | static inline abi_long host_to_target_itimerspec(abi_ulong target_addr, |
| 5180 | struct itimerspec *host_its) |
| 5181 | { |
| 5182 | struct target_itimerspec *target_itspec; |
| 5183 | |
| 5184 | if (!lock_user_struct(VERIFY_WRITE, target_itspec, target_addr, 0)) { |
| 5185 | return -TARGET_EFAULT; |
| 5186 | } |
| 5187 | |
| 5188 | target_itspec->it_interval.tv_sec = tswapal(host_its->it_interval.tv_sec); |
| 5189 | target_itspec->it_interval.tv_nsec = tswapal(host_its->it_interval.tv_nsec); |
| 5190 | |
| 5191 | target_itspec->it_value.tv_sec = tswapal(host_its->it_value.tv_sec); |
| 5192 | target_itspec->it_value.tv_nsec = tswapal(host_its->it_value.tv_nsec); |
| 5193 | |
| 5194 | unlock_user_struct(target_itspec, target_addr, 0); |
| 5195 | return 0; |
| 5196 | } |
| 5197 | |
Peter Maydell | c065976 | 2014-08-09 15:42:32 +0100 | [diff] [blame] | 5198 | static inline abi_long target_to_host_sigevent(struct sigevent *host_sevp, |
| 5199 | abi_ulong target_addr) |
| 5200 | { |
| 5201 | struct target_sigevent *target_sevp; |
| 5202 | |
| 5203 | if (!lock_user_struct(VERIFY_READ, target_sevp, target_addr, 1)) { |
| 5204 | return -TARGET_EFAULT; |
| 5205 | } |
| 5206 | |
| 5207 | /* This union is awkward on 64 bit systems because it has a 32 bit |
| 5208 | * integer and a pointer in it; we follow the conversion approach |
| 5209 | * used for handling sigval types in signal.c so the guest should get |
| 5210 | * the correct value back even if we did a 64 bit byteswap and it's |
| 5211 | * using the 32 bit integer. |
| 5212 | */ |
| 5213 | host_sevp->sigev_value.sival_ptr = |
| 5214 | (void *)(uintptr_t)tswapal(target_sevp->sigev_value.sival_ptr); |
| 5215 | host_sevp->sigev_signo = |
| 5216 | target_to_host_signal(tswap32(target_sevp->sigev_signo)); |
| 5217 | host_sevp->sigev_notify = tswap32(target_sevp->sigev_notify); |
| 5218 | host_sevp->_sigev_un._tid = tswap32(target_sevp->_sigev_un._tid); |
| 5219 | |
| 5220 | unlock_user_struct(target_sevp, target_addr, 1); |
| 5221 | return 0; |
| 5222 | } |
| 5223 | |
Tom Musta | 6f6a403 | 2014-08-12 13:53:42 -0500 | [diff] [blame] | 5224 | #if defined(TARGET_NR_mlockall) |
| 5225 | static inline int target_to_host_mlockall_arg(int arg) |
| 5226 | { |
| 5227 | int result = 0; |
| 5228 | |
| 5229 | if (arg & TARGET_MLOCKALL_MCL_CURRENT) { |
| 5230 | result |= MCL_CURRENT; |
| 5231 | } |
| 5232 | if (arg & TARGET_MLOCKALL_MCL_FUTURE) { |
| 5233 | result |= MCL_FUTURE; |
| 5234 | } |
| 5235 | return result; |
| 5236 | } |
| 5237 | #endif |
| 5238 | |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 5239 | static inline abi_long host_to_target_stat64(void *cpu_env, |
| 5240 | abi_ulong target_addr, |
| 5241 | struct stat *host_st) |
| 5242 | { |
Alexander Graf | 0970119 | 2013-09-03 20:12:15 +0100 | [diff] [blame] | 5243 | #if defined(TARGET_ARM) && defined(TARGET_ABI32) |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 5244 | if (((CPUARMState *)cpu_env)->eabi) { |
| 5245 | struct target_eabi_stat64 *target_st; |
| 5246 | |
| 5247 | if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) |
| 5248 | return -TARGET_EFAULT; |
| 5249 | memset(target_st, 0, sizeof(struct target_eabi_stat64)); |
| 5250 | __put_user(host_st->st_dev, &target_st->st_dev); |
| 5251 | __put_user(host_st->st_ino, &target_st->st_ino); |
| 5252 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
| 5253 | __put_user(host_st->st_ino, &target_st->__st_ino); |
| 5254 | #endif |
| 5255 | __put_user(host_st->st_mode, &target_st->st_mode); |
| 5256 | __put_user(host_st->st_nlink, &target_st->st_nlink); |
| 5257 | __put_user(host_st->st_uid, &target_st->st_uid); |
| 5258 | __put_user(host_st->st_gid, &target_st->st_gid); |
| 5259 | __put_user(host_st->st_rdev, &target_st->st_rdev); |
| 5260 | __put_user(host_st->st_size, &target_st->st_size); |
| 5261 | __put_user(host_st->st_blksize, &target_st->st_blksize); |
| 5262 | __put_user(host_st->st_blocks, &target_st->st_blocks); |
| 5263 | __put_user(host_st->st_atime, &target_st->target_st_atime); |
| 5264 | __put_user(host_st->st_mtime, &target_st->target_st_mtime); |
| 5265 | __put_user(host_st->st_ctime, &target_st->target_st_ctime); |
| 5266 | unlock_user_struct(target_st, target_addr, 1); |
| 5267 | } else |
| 5268 | #endif |
| 5269 | { |
Stefan Weil | 20d155b | 2013-10-30 22:52:24 +0100 | [diff] [blame] | 5270 | #if defined(TARGET_HAS_STRUCT_STAT64) |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 5271 | struct target_stat64 *target_st; |
Stefan Weil | 20d155b | 2013-10-30 22:52:24 +0100 | [diff] [blame] | 5272 | #else |
| 5273 | struct target_stat *target_st; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 5274 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 5275 | |
| 5276 | if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) |
| 5277 | return -TARGET_EFAULT; |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 5278 | memset(target_st, 0, sizeof(*target_st)); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 5279 | __put_user(host_st->st_dev, &target_st->st_dev); |
| 5280 | __put_user(host_st->st_ino, &target_st->st_ino); |
| 5281 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
| 5282 | __put_user(host_st->st_ino, &target_st->__st_ino); |
| 5283 | #endif |
| 5284 | __put_user(host_st->st_mode, &target_st->st_mode); |
| 5285 | __put_user(host_st->st_nlink, &target_st->st_nlink); |
| 5286 | __put_user(host_st->st_uid, &target_st->st_uid); |
| 5287 | __put_user(host_st->st_gid, &target_st->st_gid); |
| 5288 | __put_user(host_st->st_rdev, &target_st->st_rdev); |
| 5289 | /* XXX: better use of kernel struct */ |
| 5290 | __put_user(host_st->st_size, &target_st->st_size); |
| 5291 | __put_user(host_st->st_blksize, &target_st->st_blksize); |
| 5292 | __put_user(host_st->st_blocks, &target_st->st_blocks); |
| 5293 | __put_user(host_st->st_atime, &target_st->target_st_atime); |
| 5294 | __put_user(host_st->st_mtime, &target_st->target_st_mtime); |
| 5295 | __put_user(host_st->st_ctime, &target_st->target_st_ctime); |
| 5296 | unlock_user_struct(target_st, target_addr, 1); |
| 5297 | } |
| 5298 | |
| 5299 | return 0; |
| 5300 | } |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 5301 | |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5302 | /* ??? Using host futex calls even when target atomic operations |
| 5303 | are not really atomic probably breaks things. However implementing |
| 5304 | futexes locally would make futexes shared between multiple processes |
| 5305 | tricky. However they're probably useless because guest atomic |
| 5306 | operations won't work either. */ |
blueswir1 | 8fcd369 | 2008-08-17 20:26:25 +0000 | [diff] [blame] | 5307 | static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout, |
| 5308 | target_ulong uaddr2, int val3) |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5309 | { |
| 5310 | struct timespec ts, *pts; |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 5311 | int base_op; |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5312 | |
| 5313 | /* ??? We assume FUTEX_* constants are the same on both host |
| 5314 | and target. */ |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 5315 | #ifdef FUTEX_CMD_MASK |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 5316 | base_op = op & FUTEX_CMD_MASK; |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 5317 | #else |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 5318 | base_op = op; |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 5319 | #endif |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 5320 | switch (base_op) { |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5321 | case FUTEX_WAIT: |
John Rigby | cce246e | 2013-02-23 16:14:07 -0700 | [diff] [blame] | 5322 | case FUTEX_WAIT_BITSET: |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5323 | if (timeout) { |
| 5324 | pts = &ts; |
| 5325 | target_to_host_timespec(pts, timeout); |
| 5326 | } else { |
| 5327 | pts = NULL; |
| 5328 | } |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 5329 | return get_errno(sys_futex(g2h(uaddr), op, tswap32(val), |
John Rigby | cce246e | 2013-02-23 16:14:07 -0700 | [diff] [blame] | 5330 | pts, NULL, val3)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5331 | case FUTEX_WAKE: |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 5332 | return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5333 | case FUTEX_FD: |
Martin Mohring | a29ccd6 | 2009-05-04 21:34:56 +0300 | [diff] [blame] | 5334 | return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0)); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5335 | case FUTEX_REQUEUE: |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5336 | case FUTEX_CMP_REQUEUE: |
Nathan Froyd | a16aae0 | 2009-08-03 08:43:29 -0700 | [diff] [blame] | 5337 | case FUTEX_WAKE_OP: |
| 5338 | /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the |
| 5339 | TIMEOUT parameter is interpreted as a uint32_t by the kernel. |
| 5340 | But the prototype takes a `struct timespec *'; insert casts |
| 5341 | to satisfy the compiler. We do not need to tswap TIMEOUT |
| 5342 | since it's not compared to guest memory. */ |
| 5343 | pts = (struct timespec *)(uintptr_t) timeout; |
| 5344 | return get_errno(sys_futex(g2h(uaddr), op, val, pts, |
| 5345 | g2h(uaddr2), |
| 5346 | (base_op == FUTEX_CMP_REQUEUE |
| 5347 | ? tswap32(val3) |
| 5348 | : val3))); |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5349 | default: |
| 5350 | return -TARGET_ENOSYS; |
| 5351 | } |
| 5352 | } |
Laurent Vivier | 0f0426f | 2015-09-01 22:27:33 +0200 | [diff] [blame] | 5353 | #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) |
| 5354 | static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname, |
| 5355 | abi_long handle, abi_long mount_id, |
| 5356 | abi_long flags) |
| 5357 | { |
| 5358 | struct file_handle *target_fh; |
| 5359 | struct file_handle *fh; |
| 5360 | int mid = 0; |
| 5361 | abi_long ret; |
| 5362 | char *name; |
| 5363 | unsigned int size, total_size; |
| 5364 | |
| 5365 | if (get_user_s32(size, handle)) { |
| 5366 | return -TARGET_EFAULT; |
| 5367 | } |
| 5368 | |
| 5369 | name = lock_user_string(pathname); |
| 5370 | if (!name) { |
| 5371 | return -TARGET_EFAULT; |
| 5372 | } |
| 5373 | |
| 5374 | total_size = sizeof(struct file_handle) + size; |
| 5375 | target_fh = lock_user(VERIFY_WRITE, handle, total_size, 0); |
| 5376 | if (!target_fh) { |
| 5377 | unlock_user(name, pathname, 0); |
| 5378 | return -TARGET_EFAULT; |
| 5379 | } |
| 5380 | |
| 5381 | fh = g_malloc0(total_size); |
| 5382 | fh->handle_bytes = size; |
| 5383 | |
| 5384 | ret = get_errno(name_to_handle_at(dirfd, path(name), fh, &mid, flags)); |
| 5385 | unlock_user(name, pathname, 0); |
| 5386 | |
| 5387 | /* man name_to_handle_at(2): |
| 5388 | * Other than the use of the handle_bytes field, the caller should treat |
| 5389 | * the file_handle structure as an opaque data type |
| 5390 | */ |
| 5391 | |
| 5392 | memcpy(target_fh, fh, total_size); |
| 5393 | target_fh->handle_bytes = tswap32(fh->handle_bytes); |
| 5394 | target_fh->handle_type = tswap32(fh->handle_type); |
| 5395 | g_free(fh); |
| 5396 | unlock_user(target_fh, handle, total_size); |
| 5397 | |
| 5398 | if (put_user_s32(mid, mount_id)) { |
| 5399 | return -TARGET_EFAULT; |
| 5400 | } |
| 5401 | |
| 5402 | return ret; |
| 5403 | |
| 5404 | } |
| 5405 | #endif |
| 5406 | |
| 5407 | #if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) |
| 5408 | static abi_long do_open_by_handle_at(abi_long mount_fd, abi_long handle, |
| 5409 | abi_long flags) |
| 5410 | { |
| 5411 | struct file_handle *target_fh; |
| 5412 | struct file_handle *fh; |
| 5413 | unsigned int size, total_size; |
| 5414 | abi_long ret; |
| 5415 | |
| 5416 | if (get_user_s32(size, handle)) { |
| 5417 | return -TARGET_EFAULT; |
| 5418 | } |
| 5419 | |
| 5420 | total_size = sizeof(struct file_handle) + size; |
| 5421 | target_fh = lock_user(VERIFY_READ, handle, total_size, 1); |
| 5422 | if (!target_fh) { |
| 5423 | return -TARGET_EFAULT; |
| 5424 | } |
| 5425 | |
Thomas Huth | e9d49d5 | 2015-10-09 17:56:38 +0200 | [diff] [blame] | 5426 | fh = g_memdup(target_fh, total_size); |
Laurent Vivier | 0f0426f | 2015-09-01 22:27:33 +0200 | [diff] [blame] | 5427 | fh->handle_bytes = size; |
| 5428 | fh->handle_type = tswap32(target_fh->handle_type); |
| 5429 | |
| 5430 | ret = get_errno(open_by_handle_at(mount_fd, fh, |
| 5431 | target_to_host_bitmask(flags, fcntl_flags_tbl))); |
| 5432 | |
| 5433 | g_free(fh); |
| 5434 | |
| 5435 | unlock_user(target_fh, handle, total_size); |
| 5436 | |
| 5437 | return ret; |
| 5438 | } |
| 5439 | #endif |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 5440 | |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5441 | #if defined(TARGET_NR_signalfd) || defined(TARGET_NR_signalfd4) |
| 5442 | |
| 5443 | /* signalfd siginfo conversion */ |
| 5444 | |
| 5445 | static void |
| 5446 | host_to_target_signalfd_siginfo(struct signalfd_siginfo *tinfo, |
| 5447 | const struct signalfd_siginfo *info) |
| 5448 | { |
| 5449 | int sig = host_to_target_signal(info->ssi_signo); |
| 5450 | |
| 5451 | /* linux/signalfd.h defines a ssi_addr_lsb |
| 5452 | * not defined in sys/signalfd.h but used by some kernels |
| 5453 | */ |
| 5454 | |
| 5455 | #ifdef BUS_MCEERR_AO |
| 5456 | if (tinfo->ssi_signo == SIGBUS && |
| 5457 | (tinfo->ssi_code == BUS_MCEERR_AR || |
| 5458 | tinfo->ssi_code == BUS_MCEERR_AO)) { |
| 5459 | uint16_t *ssi_addr_lsb = (uint16_t *)(&info->ssi_addr + 1); |
| 5460 | uint16_t *tssi_addr_lsb = (uint16_t *)(&tinfo->ssi_addr + 1); |
| 5461 | *tssi_addr_lsb = tswap16(*ssi_addr_lsb); |
| 5462 | } |
| 5463 | #endif |
| 5464 | |
| 5465 | tinfo->ssi_signo = tswap32(sig); |
| 5466 | tinfo->ssi_errno = tswap32(tinfo->ssi_errno); |
| 5467 | tinfo->ssi_code = tswap32(info->ssi_code); |
| 5468 | tinfo->ssi_pid = tswap32(info->ssi_pid); |
| 5469 | tinfo->ssi_uid = tswap32(info->ssi_uid); |
| 5470 | tinfo->ssi_fd = tswap32(info->ssi_fd); |
| 5471 | tinfo->ssi_tid = tswap32(info->ssi_tid); |
| 5472 | tinfo->ssi_band = tswap32(info->ssi_band); |
| 5473 | tinfo->ssi_overrun = tswap32(info->ssi_overrun); |
| 5474 | tinfo->ssi_trapno = tswap32(info->ssi_trapno); |
| 5475 | tinfo->ssi_status = tswap32(info->ssi_status); |
| 5476 | tinfo->ssi_int = tswap32(info->ssi_int); |
| 5477 | tinfo->ssi_ptr = tswap64(info->ssi_ptr); |
| 5478 | tinfo->ssi_utime = tswap64(info->ssi_utime); |
| 5479 | tinfo->ssi_stime = tswap64(info->ssi_stime); |
| 5480 | tinfo->ssi_addr = tswap64(info->ssi_addr); |
| 5481 | } |
| 5482 | |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 5483 | static abi_long host_to_target_data_signalfd(void *buf, size_t len) |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5484 | { |
| 5485 | int i; |
| 5486 | |
| 5487 | for (i = 0; i < len; i += sizeof(struct signalfd_siginfo)) { |
| 5488 | host_to_target_signalfd_siginfo(buf + i, buf + i); |
| 5489 | } |
| 5490 | |
| 5491 | return len; |
| 5492 | } |
| 5493 | |
| 5494 | static TargetFdTrans target_signalfd_trans = { |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 5495 | .host_to_target_data = host_to_target_data_signalfd, |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5496 | }; |
| 5497 | |
| 5498 | static abi_long do_signalfd4(int fd, abi_long mask, int flags) |
| 5499 | { |
| 5500 | int host_flags; |
| 5501 | target_sigset_t *target_mask; |
| 5502 | sigset_t host_mask; |
| 5503 | abi_long ret; |
| 5504 | |
| 5505 | if (flags & ~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC)) { |
| 5506 | return -TARGET_EINVAL; |
| 5507 | } |
| 5508 | if (!lock_user_struct(VERIFY_READ, target_mask, mask, 1)) { |
| 5509 | return -TARGET_EFAULT; |
| 5510 | } |
| 5511 | |
| 5512 | target_to_host_sigset(&host_mask, target_mask); |
| 5513 | |
| 5514 | host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl); |
| 5515 | |
| 5516 | ret = get_errno(signalfd(fd, &host_mask, host_flags)); |
| 5517 | if (ret >= 0) { |
| 5518 | fd_trans_register(ret, &target_signalfd_trans); |
| 5519 | } |
| 5520 | |
| 5521 | unlock_user_struct(target_mask, mask, 0); |
| 5522 | |
| 5523 | return ret; |
| 5524 | } |
| 5525 | #endif |
| 5526 | |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 5527 | /* Map host to target signal numbers for the wait family of syscalls. |
| 5528 | Assume all other status bits are the same. */ |
Richard Henderson | a05c640 | 2012-09-15 11:34:20 -0700 | [diff] [blame] | 5529 | int host_to_target_waitstatus(int status) |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 5530 | { |
| 5531 | if (WIFSIGNALED(status)) { |
| 5532 | return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); |
| 5533 | } |
| 5534 | if (WIFSTOPPED(status)) { |
| 5535 | return (host_to_target_signal(WSTOPSIG(status)) << 8) |
| 5536 | | (status & 0xff); |
| 5537 | } |
| 5538 | return status; |
| 5539 | } |
| 5540 | |
Wim Vander Schelden | 76b9424 | 2014-06-18 11:02:39 +0200 | [diff] [blame] | 5541 | static int open_self_cmdline(void *cpu_env, int fd) |
| 5542 | { |
| 5543 | int fd_orig = -1; |
| 5544 | bool word_skipped = false; |
| 5545 | |
| 5546 | fd_orig = open("/proc/self/cmdline", O_RDONLY); |
| 5547 | if (fd_orig < 0) { |
| 5548 | return fd_orig; |
| 5549 | } |
| 5550 | |
| 5551 | while (true) { |
| 5552 | ssize_t nb_read; |
| 5553 | char buf[128]; |
| 5554 | char *cp_buf = buf; |
| 5555 | |
| 5556 | nb_read = read(fd_orig, buf, sizeof(buf)); |
| 5557 | if (nb_read < 0) { |
| 5558 | fd_orig = close(fd_orig); |
| 5559 | return -1; |
| 5560 | } else if (nb_read == 0) { |
| 5561 | break; |
| 5562 | } |
| 5563 | |
| 5564 | if (!word_skipped) { |
| 5565 | /* Skip the first string, which is the path to qemu-*-static |
| 5566 | instead of the actual command. */ |
| 5567 | cp_buf = memchr(buf, 0, sizeof(buf)); |
| 5568 | if (cp_buf) { |
| 5569 | /* Null byte found, skip one string */ |
| 5570 | cp_buf++; |
| 5571 | nb_read -= cp_buf - buf; |
| 5572 | word_skipped = true; |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | if (word_skipped) { |
| 5577 | if (write(fd, cp_buf, nb_read) != nb_read) { |
zhanghailiang | 680dfde | 2014-08-22 16:23:51 +0800 | [diff] [blame] | 5578 | close(fd_orig); |
Wim Vander Schelden | 76b9424 | 2014-06-18 11:02:39 +0200 | [diff] [blame] | 5579 | return -1; |
| 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | return close(fd_orig); |
| 5585 | } |
| 5586 | |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5587 | static int open_self_maps(void *cpu_env, int fd) |
| 5588 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 5589 | CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env); |
| 5590 | TaskState *ts = cpu->opaque; |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 5591 | FILE *fp; |
| 5592 | char *line = NULL; |
| 5593 | size_t len = 0; |
| 5594 | ssize_t read; |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5595 | |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 5596 | fp = fopen("/proc/self/maps", "r"); |
| 5597 | if (fp == NULL) { |
| 5598 | return -EACCES; |
| 5599 | } |
| 5600 | |
| 5601 | while ((read = getline(&line, &len, fp)) != -1) { |
| 5602 | int fields, dev_maj, dev_min, inode; |
| 5603 | uint64_t min, max, offset; |
| 5604 | char flag_r, flag_w, flag_x, flag_p; |
| 5605 | char path[512] = ""; |
| 5606 | fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d" |
| 5607 | " %512s", &min, &max, &flag_r, &flag_w, &flag_x, |
| 5608 | &flag_p, &offset, &dev_maj, &dev_min, &inode, path); |
| 5609 | |
| 5610 | if ((fields < 10) || (fields > 11)) { |
| 5611 | continue; |
| 5612 | } |
Mikhail Ilyin | d67f4aa | 2014-08-05 17:33:51 +0400 | [diff] [blame] | 5613 | if (h2g_valid(min)) { |
| 5614 | int flags = page_get_flags(h2g(min)); |
| 5615 | max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX); |
| 5616 | if (page_check_range(h2g(min), max - min, flags) == -1) { |
| 5617 | continue; |
| 5618 | } |
| 5619 | if (h2g(min) == ts->info->stack_limit) { |
| 5620 | pstrcpy(path, sizeof(path), " [stack]"); |
| 5621 | } |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 5622 | dprintf(fd, TARGET_ABI_FMT_lx "-" TARGET_ABI_FMT_lx |
Christophe Lyon | e24fed4 | 2013-04-02 14:03:38 +0200 | [diff] [blame] | 5623 | " %c%c%c%c %08" PRIx64 " %02x:%02x %d %s%s\n", |
Mikhail Ilyin | d67f4aa | 2014-08-05 17:33:51 +0400 | [diff] [blame] | 5624 | h2g(min), h2g(max - 1) + 1, flag_r, flag_w, |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 5625 | flag_x, flag_p, offset, dev_maj, dev_min, inode, |
Christophe Lyon | e24fed4 | 2013-04-02 14:03:38 +0200 | [diff] [blame] | 5626 | path[0] ? " " : "", path); |
Alexander Graf | 1a49ef2 | 2012-05-01 16:30:28 +0100 | [diff] [blame] | 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | free(line); |
| 5631 | fclose(fp); |
| 5632 | |
Alexander Graf | 36c08d4 | 2011-11-02 20:23:24 +0100 | [diff] [blame] | 5633 | return 0; |
| 5634 | } |
| 5635 | |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5636 | static int open_self_stat(void *cpu_env, int fd) |
| 5637 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 5638 | CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env); |
| 5639 | TaskState *ts = cpu->opaque; |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5640 | abi_ulong start_stack = ts->info->start_stack; |
| 5641 | int i; |
| 5642 | |
| 5643 | for (i = 0; i < 44; i++) { |
| 5644 | char buf[128]; |
| 5645 | int len; |
| 5646 | uint64_t val = 0; |
| 5647 | |
Fabio Erculiani | e0e65be | 2012-01-03 09:38:34 +0000 | [diff] [blame] | 5648 | if (i == 0) { |
| 5649 | /* pid */ |
| 5650 | val = getpid(); |
| 5651 | snprintf(buf, sizeof(buf), "%"PRId64 " ", val); |
| 5652 | } else if (i == 1) { |
| 5653 | /* app name */ |
| 5654 | snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]); |
| 5655 | } else if (i == 27) { |
| 5656 | /* stack bottom */ |
| 5657 | val = start_stack; |
| 5658 | snprintf(buf, sizeof(buf), "%"PRId64 " ", val); |
| 5659 | } else { |
| 5660 | /* for the rest, there is MasterCard */ |
| 5661 | snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' '); |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5662 | } |
Fabio Erculiani | e0e65be | 2012-01-03 09:38:34 +0000 | [diff] [blame] | 5663 | |
Alexander Graf | 480b8e7 | 2011-11-02 20:23:25 +0100 | [diff] [blame] | 5664 | len = strlen(buf); |
| 5665 | if (write(fd, buf, len) != len) { |
| 5666 | return -1; |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | return 0; |
| 5671 | } |
| 5672 | |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5673 | static int open_self_auxv(void *cpu_env, int fd) |
| 5674 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 5675 | CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env); |
| 5676 | TaskState *ts = cpu->opaque; |
Alexander Graf | 257450e | 2011-11-02 20:23:26 +0100 | [diff] [blame] | 5677 | abi_ulong auxv = ts->info->saved_auxv; |
| 5678 | abi_ulong len = ts->info->auxv_len; |
| 5679 | char *ptr; |
| 5680 | |
| 5681 | /* |
| 5682 | * Auxiliary vector is stored in target process stack. |
| 5683 | * read in whole auxv vector and copy it to file |
| 5684 | */ |
| 5685 | ptr = lock_user(VERIFY_READ, auxv, len, 0); |
| 5686 | if (ptr != NULL) { |
| 5687 | while (len > 0) { |
| 5688 | ssize_t r; |
| 5689 | r = write(fd, ptr, len); |
| 5690 | if (r <= 0) { |
| 5691 | break; |
| 5692 | } |
| 5693 | len -= r; |
| 5694 | ptr += r; |
| 5695 | } |
| 5696 | lseek(fd, 0, SEEK_SET); |
| 5697 | unlock_user(ptr, auxv, len); |
| 5698 | } |
| 5699 | |
| 5700 | return 0; |
| 5701 | } |
| 5702 | |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 5703 | static int is_proc_myself(const char *filename, const char *entry) |
| 5704 | { |
| 5705 | if (!strncmp(filename, "/proc/", strlen("/proc/"))) { |
| 5706 | filename += strlen("/proc/"); |
| 5707 | if (!strncmp(filename, "self/", strlen("self/"))) { |
| 5708 | filename += strlen("self/"); |
| 5709 | } else if (*filename >= '1' && *filename <= '9') { |
| 5710 | char myself[80]; |
| 5711 | snprintf(myself, sizeof(myself), "%d/", getpid()); |
| 5712 | if (!strncmp(filename, myself, strlen(myself))) { |
| 5713 | filename += strlen(myself); |
| 5714 | } else { |
| 5715 | return 0; |
| 5716 | } |
| 5717 | } else { |
| 5718 | return 0; |
| 5719 | } |
| 5720 | if (!strcmp(filename, entry)) { |
| 5721 | return 1; |
| 5722 | } |
| 5723 | } |
| 5724 | return 0; |
| 5725 | } |
| 5726 | |
Laurent Vivier | de6b993 | 2013-08-30 01:46:40 +0200 | [diff] [blame] | 5727 | #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
| 5728 | static int is_proc(const char *filename, const char *entry) |
| 5729 | { |
| 5730 | return strcmp(filename, entry) == 0; |
| 5731 | } |
| 5732 | |
| 5733 | static int open_net_route(void *cpu_env, int fd) |
| 5734 | { |
| 5735 | FILE *fp; |
| 5736 | char *line = NULL; |
| 5737 | size_t len = 0; |
| 5738 | ssize_t read; |
| 5739 | |
| 5740 | fp = fopen("/proc/net/route", "r"); |
| 5741 | if (fp == NULL) { |
| 5742 | return -EACCES; |
| 5743 | } |
| 5744 | |
| 5745 | /* read header */ |
| 5746 | |
| 5747 | read = getline(&line, &len, fp); |
| 5748 | dprintf(fd, "%s", line); |
| 5749 | |
| 5750 | /* read routes */ |
| 5751 | |
| 5752 | while ((read = getline(&line, &len, fp)) != -1) { |
| 5753 | char iface[16]; |
| 5754 | uint32_t dest, gw, mask; |
| 5755 | unsigned int flags, refcnt, use, metric, mtu, window, irtt; |
| 5756 | sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n", |
| 5757 | iface, &dest, &gw, &flags, &refcnt, &use, &metric, |
| 5758 | &mask, &mtu, &window, &irtt); |
| 5759 | dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n", |
| 5760 | iface, tswap32(dest), tswap32(gw), flags, refcnt, use, |
| 5761 | metric, tswap32(mask), mtu, window, irtt); |
| 5762 | } |
| 5763 | |
| 5764 | free(line); |
| 5765 | fclose(fp); |
| 5766 | |
| 5767 | return 0; |
| 5768 | } |
| 5769 | #endif |
| 5770 | |
Riku Voipio | 0b2effd | 2014-08-06 10:36:37 +0300 | [diff] [blame] | 5771 | static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, mode_t mode) |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5772 | { |
| 5773 | struct fake_open { |
| 5774 | const char *filename; |
| 5775 | int (*fill)(void *cpu_env, int fd); |
Laurent Vivier | de6b993 | 2013-08-30 01:46:40 +0200 | [diff] [blame] | 5776 | int (*cmp)(const char *s1, const char *s2); |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5777 | }; |
| 5778 | const struct fake_open *fake_open; |
| 5779 | static const struct fake_open fakes[] = { |
Laurent Vivier | de6b993 | 2013-08-30 01:46:40 +0200 | [diff] [blame] | 5780 | { "maps", open_self_maps, is_proc_myself }, |
| 5781 | { "stat", open_self_stat, is_proc_myself }, |
| 5782 | { "auxv", open_self_auxv, is_proc_myself }, |
Wim Vander Schelden | 76b9424 | 2014-06-18 11:02:39 +0200 | [diff] [blame] | 5783 | { "cmdline", open_self_cmdline, is_proc_myself }, |
Laurent Vivier | de6b993 | 2013-08-30 01:46:40 +0200 | [diff] [blame] | 5784 | #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
| 5785 | { "/proc/net/route", open_net_route, is_proc }, |
| 5786 | #endif |
| 5787 | { NULL, NULL, NULL } |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5788 | }; |
| 5789 | |
Maxim Ostapenko | aa07f5e | 2014-05-02 11:17:07 +0300 | [diff] [blame] | 5790 | if (is_proc_myself(pathname, "exe")) { |
| 5791 | int execfd = qemu_getauxval(AT_EXECFD); |
Riku Voipio | 0b2effd | 2014-08-06 10:36:37 +0300 | [diff] [blame] | 5792 | return execfd ? execfd : get_errno(sys_openat(dirfd, exec_path, flags, mode)); |
Maxim Ostapenko | aa07f5e | 2014-05-02 11:17:07 +0300 | [diff] [blame] | 5793 | } |
| 5794 | |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5795 | for (fake_open = fakes; fake_open->filename; fake_open++) { |
Laurent Vivier | de6b993 | 2013-08-30 01:46:40 +0200 | [diff] [blame] | 5796 | if (fake_open->cmp(pathname, fake_open->filename)) { |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5797 | break; |
| 5798 | } |
| 5799 | } |
| 5800 | |
| 5801 | if (fake_open->filename) { |
| 5802 | const char *tmpdir; |
| 5803 | char filename[PATH_MAX]; |
| 5804 | int fd, r; |
| 5805 | |
| 5806 | /* create temporary file to map stat to */ |
| 5807 | tmpdir = getenv("TMPDIR"); |
| 5808 | if (!tmpdir) |
| 5809 | tmpdir = "/tmp"; |
| 5810 | snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir); |
| 5811 | fd = mkstemp(filename); |
| 5812 | if (fd < 0) { |
| 5813 | return fd; |
| 5814 | } |
| 5815 | unlink(filename); |
| 5816 | |
| 5817 | if ((r = fake_open->fill(cpu_env, fd))) { |
| 5818 | close(fd); |
| 5819 | return r; |
| 5820 | } |
| 5821 | lseek(fd, 0, SEEK_SET); |
| 5822 | |
| 5823 | return fd; |
| 5824 | } |
| 5825 | |
Riku Voipio | 0b2effd | 2014-08-06 10:36:37 +0300 | [diff] [blame] | 5826 | return get_errno(sys_openat(dirfd, path(pathname), flags, mode)); |
Alexander Graf | 3be14d0 | 2011-11-02 20:23:23 +0100 | [diff] [blame] | 5827 | } |
| 5828 | |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 5829 | #define TIMER_MAGIC 0x0caf0000 |
| 5830 | #define TIMER_MAGIC_MASK 0xffff0000 |
| 5831 | |
| 5832 | /* Convert QEMU provided timer ID back to internal 16bit index format */ |
| 5833 | static target_timer_t get_timer_id(abi_long arg) |
| 5834 | { |
| 5835 | target_timer_t timerid = arg; |
| 5836 | |
| 5837 | if ((timerid & TIMER_MAGIC_MASK) != TIMER_MAGIC) { |
| 5838 | return -TARGET_EINVAL; |
| 5839 | } |
| 5840 | |
| 5841 | timerid &= 0xffff; |
| 5842 | |
| 5843 | if (timerid >= ARRAY_SIZE(g_posix_timers)) { |
| 5844 | return -TARGET_EINVAL; |
| 5845 | } |
| 5846 | |
| 5847 | return timerid; |
| 5848 | } |
| 5849 | |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 5850 | /* do_syscall() should always have a single exit point at the end so |
| 5851 | that actions, such as logging of syscall results, can be performed. |
| 5852 | All errnos that do_syscall() returns must be -TARGET_<errcode>. */ |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5853 | abi_long do_syscall(void *cpu_env, int num, abi_long arg1, |
| 5854 | abi_long arg2, abi_long arg3, abi_long arg4, |
Peter Maydell | 5945cfc | 2011-06-16 17:37:13 +0100 | [diff] [blame] | 5855 | abi_long arg5, abi_long arg6, abi_long arg7, |
| 5856 | abi_long arg8) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5857 | { |
Andreas Färber | 182735e | 2013-05-29 22:29:20 +0200 | [diff] [blame] | 5858 | CPUState *cpu = ENV_GET_CPU(cpu_env); |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 5859 | abi_long ret; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5860 | struct stat st; |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 5861 | struct statfs stfs; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5862 | void *p; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 5863 | |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 5864 | #ifdef DEBUG |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 5865 | gemu_log("syscall %d", num); |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 5866 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 5867 | if(do_strace) |
| 5868 | print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
| 5869 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5870 | switch(num) { |
| 5871 | case TARGET_NR_exit: |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5872 | /* In old applications this may be used to implement _exit(2). |
| 5873 | However in threaded applictions it is used for thread termination, |
| 5874 | and _exit_group is used for application termination. |
| 5875 | Do thread termination if we have more then one thread. */ |
| 5876 | /* FIXME: This probably breaks if a signal arrives. We should probably |
| 5877 | be disabling signals. */ |
Andreas Färber | bdc4464 | 2013-06-24 23:50:24 +0200 | [diff] [blame] | 5878 | if (CPU_NEXT(first_cpu)) { |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5879 | TaskState *ts; |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5880 | |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5881 | cpu_list_lock(); |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5882 | /* Remove the CPU from the list. */ |
Andreas Färber | bdc4464 | 2013-06-24 23:50:24 +0200 | [diff] [blame] | 5883 | QTAILQ_REMOVE(&cpus, cpu, node); |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5884 | cpu_list_unlock(); |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 5885 | ts = cpu->opaque; |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5886 | if (ts->child_tidptr) { |
| 5887 | put_user_u32(0, ts->child_tidptr); |
| 5888 | sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX, |
| 5889 | NULL, NULL, 0); |
| 5890 | } |
Andreas Färber | a2247f8 | 2013-06-09 19:47:04 +0200 | [diff] [blame] | 5891 | thread_cpu = NULL; |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 5892 | object_unref(OBJECT(cpu)); |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5893 | g_free(ts); |
Emilio G. Cota | 7090376 | 2015-08-23 20:23:41 -0400 | [diff] [blame] | 5894 | rcu_unregister_thread(); |
Andreas Färber | 9b056fc | 2013-06-24 23:53:10 +0200 | [diff] [blame] | 5895 | pthread_exit(NULL); |
| 5896 | } |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 5897 | #ifdef TARGET_GPROF |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 5898 | _mcleanup(); |
| 5899 | #endif |
bellard | e900967 | 2005-04-26 20:42:36 +0000 | [diff] [blame] | 5900 | gdb_exit(cpu_env, arg1); |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 5901 | _exit(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5902 | ret = 0; /* avoid warning */ |
| 5903 | break; |
| 5904 | case TARGET_NR_read: |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 5905 | if (arg3 == 0) |
| 5906 | ret = 0; |
| 5907 | else { |
| 5908 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 5909 | goto efault; |
| 5910 | ret = get_errno(read(arg1, p, arg3)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5911 | if (ret >= 0 && |
Laurent Vivier | 5d4d366 | 2015-10-28 21:40:43 +0100 | [diff] [blame] | 5912 | fd_trans_host_to_target_data(arg1)) { |
| 5913 | ret = fd_trans_host_to_target_data(arg1)(p, ret); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5914 | } |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 5915 | unlock_user(p, arg2, ret); |
| 5916 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5917 | break; |
| 5918 | case TARGET_NR_write: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5919 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 5920 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5921 | ret = get_errno(write(arg1, p, arg3)); |
| 5922 | unlock_user(p, arg2, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5923 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 5924 | #ifdef TARGET_NR_open |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5925 | case TARGET_NR_open: |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5926 | if (!(p = lock_user_string(arg1))) |
| 5927 | goto efault; |
Riku Voipio | 0b2effd | 2014-08-06 10:36:37 +0300 | [diff] [blame] | 5928 | ret = get_errno(do_openat(cpu_env, AT_FDCWD, p, |
| 5929 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
| 5930 | arg3)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5931 | fd_trans_unregister(ret); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5932 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5933 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 5934 | #endif |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 5935 | case TARGET_NR_openat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5936 | if (!(p = lock_user_string(arg2))) |
| 5937 | goto efault; |
Riku Voipio | 0b2effd | 2014-08-06 10:36:37 +0300 | [diff] [blame] | 5938 | ret = get_errno(do_openat(cpu_env, arg1, p, |
| 5939 | target_to_host_bitmask(arg3, fcntl_flags_tbl), |
| 5940 | arg4)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5941 | fd_trans_unregister(ret); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5942 | unlock_user(p, arg2, 0); |
ths | 8242483 | 2007-09-24 09:21:55 +0000 | [diff] [blame] | 5943 | break; |
Laurent Vivier | 0f0426f | 2015-09-01 22:27:33 +0200 | [diff] [blame] | 5944 | #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) |
| 5945 | case TARGET_NR_name_to_handle_at: |
| 5946 | ret = do_name_to_handle_at(arg1, arg2, arg3, arg4, arg5); |
| 5947 | break; |
| 5948 | #endif |
| 5949 | #if defined(TARGET_NR_open_by_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) |
| 5950 | case TARGET_NR_open_by_handle_at: |
| 5951 | ret = do_open_by_handle_at(arg1, arg2, arg3); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5952 | fd_trans_unregister(ret); |
Laurent Vivier | 0f0426f | 2015-09-01 22:27:33 +0200 | [diff] [blame] | 5953 | break; |
| 5954 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5955 | case TARGET_NR_close: |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5956 | fd_trans_unregister(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5957 | ret = get_errno(close(arg1)); |
| 5958 | break; |
| 5959 | case TARGET_NR_brk: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5960 | ret = do_brk(arg1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5961 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 5962 | #ifdef TARGET_NR_fork |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5963 | case TARGET_NR_fork: |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 5964 | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0, 0, 0, 0)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5965 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 5966 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5967 | #ifdef TARGET_NR_waitpid |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5968 | case TARGET_NR_waitpid: |
| 5969 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5970 | int status; |
| 5971 | ret = get_errno(waitpid(arg1, &status, arg3)); |
Alexander Graf | 5379557 | 2011-11-24 00:44:43 +0100 | [diff] [blame] | 5972 | if (!is_error(ret) && arg2 && ret |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 5973 | && put_user_s32(host_to_target_waitstatus(status), arg2)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 5974 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5975 | } |
| 5976 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 5977 | #endif |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5978 | #ifdef TARGET_NR_waitid |
| 5979 | case TARGET_NR_waitid: |
| 5980 | { |
| 5981 | siginfo_t info; |
| 5982 | info.si_pid = 0; |
| 5983 | ret = get_errno(waitid(arg1, arg2, &info, arg4)); |
| 5984 | if (!is_error(ret) && arg3 && info.si_pid != 0) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5985 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0))) |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5986 | goto efault; |
| 5987 | host_to_target_siginfo(p, &info); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 5988 | unlock_user(p, arg3, sizeof(target_siginfo_t)); |
pbrook | f0cbb61 | 2008-05-30 18:20:05 +0000 | [diff] [blame] | 5989 | } |
| 5990 | } |
| 5991 | break; |
| 5992 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 5993 | #ifdef TARGET_NR_creat /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 5994 | case TARGET_NR_creat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 5995 | if (!(p = lock_user_string(arg1))) |
| 5996 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5997 | ret = get_errno(creat(p, arg2)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 5998 | fd_trans_unregister(ret); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 5999 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6000 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6001 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6002 | #ifdef TARGET_NR_link |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6003 | case TARGET_NR_link: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6004 | { |
| 6005 | void * p2; |
| 6006 | p = lock_user_string(arg1); |
| 6007 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6008 | if (!p || !p2) |
| 6009 | ret = -TARGET_EFAULT; |
| 6010 | else |
| 6011 | ret = get_errno(link(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6012 | unlock_user(p2, arg2, 0); |
| 6013 | unlock_user(p, arg1, 0); |
| 6014 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6015 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6016 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6017 | #if defined(TARGET_NR_linkat) |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 6018 | case TARGET_NR_linkat: |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 6019 | { |
| 6020 | void * p2 = NULL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6021 | if (!arg2 || !arg4) |
| 6022 | goto efault; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 6023 | p = lock_user_string(arg2); |
| 6024 | p2 = lock_user_string(arg4); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6025 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6026 | ret = -TARGET_EFAULT; |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 6027 | else |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6028 | ret = get_errno(linkat(arg1, p, arg3, p2, arg5)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6029 | unlock_user(p, arg2, 0); |
| 6030 | unlock_user(p2, arg4, 0); |
ths | 64f0ce4 | 2007-09-24 09:25:06 +0000 | [diff] [blame] | 6031 | } |
| 6032 | break; |
| 6033 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6034 | #ifdef TARGET_NR_unlink |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6035 | case TARGET_NR_unlink: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6036 | if (!(p = lock_user_string(arg1))) |
| 6037 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6038 | ret = get_errno(unlink(p)); |
| 6039 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6040 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6041 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6042 | #if defined(TARGET_NR_unlinkat) |
ths | 8170f56 | 2007-09-24 09:24:11 +0000 | [diff] [blame] | 6043 | case TARGET_NR_unlinkat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6044 | if (!(p = lock_user_string(arg2))) |
| 6045 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6046 | ret = get_errno(unlinkat(arg1, p, arg3)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6047 | unlock_user(p, arg2, 0); |
balrog | ed494d8 | 2007-12-11 23:23:52 +0000 | [diff] [blame] | 6048 | break; |
balrog | b7d35e6 | 2007-12-12 00:40:24 +0000 | [diff] [blame] | 6049 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6050 | case TARGET_NR_execve: |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6051 | { |
| 6052 | char **argp, **envp; |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 6053 | int argc, envc; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6054 | abi_ulong gp; |
| 6055 | abi_ulong guest_argp; |
| 6056 | abi_ulong guest_envp; |
| 6057 | abi_ulong addr; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6058 | char **q; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 6059 | int total_size = 0; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6060 | |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 6061 | argc = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6062 | guest_argp = arg2; |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 6063 | for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) { |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 6064 | if (get_user_ual(addr, gp)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6065 | goto efault; |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 6066 | if (!addr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6067 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6068 | argc++; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6069 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 6070 | envc = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6071 | guest_envp = arg3; |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 6072 | for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) { |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 6073 | if (get_user_ual(addr, gp)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6074 | goto efault; |
ths | 03aa197 | 2007-12-02 06:28:08 +0000 | [diff] [blame] | 6075 | if (!addr) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6076 | break; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6077 | envc++; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6078 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6079 | |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 6080 | argp = alloca((argc + 1) * sizeof(void *)); |
| 6081 | envp = alloca((envc + 1) * sizeof(void *)); |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6082 | |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 6083 | for (gp = guest_argp, q = argp; gp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6084 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6085 | if (get_user_ual(addr, gp)) |
| 6086 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6087 | if (!addr) |
| 6088 | break; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6089 | if (!(*q = lock_user_string(addr))) |
| 6090 | goto execve_efault; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 6091 | total_size += strlen(*q) + 1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6092 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 6093 | *q = NULL; |
| 6094 | |
pbrook | da94d26 | 2008-05-30 18:24:00 +0000 | [diff] [blame] | 6095 | for (gp = guest_envp, q = envp; gp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6096 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6097 | if (get_user_ual(addr, gp)) |
| 6098 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6099 | if (!addr) |
| 6100 | break; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6101 | if (!(*q = lock_user_string(addr))) |
| 6102 | goto execve_efault; |
Ulrich Hecht | a6f79cc | 2012-01-31 12:43:16 +0100 | [diff] [blame] | 6103 | total_size += strlen(*q) + 1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6104 | } |
bellard | f7341ff | 2003-03-30 21:00:25 +0000 | [diff] [blame] | 6105 | *q = NULL; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6106 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6107 | if (!(p = lock_user_string(arg1))) |
| 6108 | goto execve_efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6109 | ret = get_errno(execve(p, argp, envp)); |
| 6110 | unlock_user(p, arg1, 0); |
| 6111 | |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6112 | goto execve_end; |
| 6113 | |
| 6114 | execve_efault: |
| 6115 | ret = -TARGET_EFAULT; |
| 6116 | |
| 6117 | execve_end: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6118 | for (gp = guest_argp, q = argp; *q; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6119 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6120 | if (get_user_ual(addr, gp) |
| 6121 | || !addr) |
| 6122 | break; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6123 | unlock_user(*q, addr, 0); |
| 6124 | } |
| 6125 | for (gp = guest_envp, q = envp; *q; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6126 | gp += sizeof(abi_ulong), q++) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6127 | if (get_user_ual(addr, gp) |
| 6128 | || !addr) |
| 6129 | break; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6130 | unlock_user(*q, addr, 0); |
| 6131 | } |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 6132 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6133 | break; |
| 6134 | case TARGET_NR_chdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6135 | if (!(p = lock_user_string(arg1))) |
| 6136 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6137 | ret = get_errno(chdir(p)); |
| 6138 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6139 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 6140 | #ifdef TARGET_NR_time |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6141 | case TARGET_NR_time: |
| 6142 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6143 | time_t host_time; |
| 6144 | ret = get_errno(time(&host_time)); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6145 | if (!is_error(ret) |
| 6146 | && arg1 |
| 6147 | && put_user_sal(host_time, arg1)) |
| 6148 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6149 | } |
| 6150 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 6151 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6152 | #ifdef TARGET_NR_mknod |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6153 | case TARGET_NR_mknod: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6154 | if (!(p = lock_user_string(arg1))) |
| 6155 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6156 | ret = get_errno(mknod(p, arg2, arg3)); |
| 6157 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6158 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6159 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6160 | #if defined(TARGET_NR_mknodat) |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 6161 | case TARGET_NR_mknodat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6162 | if (!(p = lock_user_string(arg2))) |
| 6163 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6164 | ret = get_errno(mknodat(arg1, p, arg3, arg4)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6165 | unlock_user(p, arg2, 0); |
ths | 75ac37a | 2007-09-24 09:23:05 +0000 | [diff] [blame] | 6166 | break; |
| 6167 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6168 | #ifdef TARGET_NR_chmod |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6169 | case TARGET_NR_chmod: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6170 | if (!(p = lock_user_string(arg1))) |
| 6171 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6172 | ret = get_errno(chmod(p, arg2)); |
| 6173 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6174 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6175 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6176 | #ifdef TARGET_NR_break |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6177 | case TARGET_NR_break: |
| 6178 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6179 | #endif |
| 6180 | #ifdef TARGET_NR_oldstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6181 | case TARGET_NR_oldstat: |
| 6182 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6183 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6184 | case TARGET_NR_lseek: |
| 6185 | ret = get_errno(lseek(arg1, arg2, arg3)); |
| 6186 | break; |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 6187 | #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA) |
| 6188 | /* Alpha specific */ |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6189 | case TARGET_NR_getxpid: |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 6190 | ((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid(); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6191 | ret = get_errno(getpid()); |
| 6192 | break; |
Richard Henderson | 9231733 | 2010-05-03 10:07:53 -0700 | [diff] [blame] | 6193 | #endif |
| 6194 | #ifdef TARGET_NR_getpid |
| 6195 | case TARGET_NR_getpid: |
| 6196 | ret = get_errno(getpid()); |
| 6197 | break; |
| 6198 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6199 | case TARGET_NR_mount: |
Paul Burton | 356d771 | 2014-06-22 11:25:37 +0100 | [diff] [blame] | 6200 | { |
| 6201 | /* need to look at the data field */ |
| 6202 | void *p2, *p3; |
| 6203 | |
| 6204 | if (arg1) { |
| 6205 | p = lock_user_string(arg1); |
| 6206 | if (!p) { |
| 6207 | goto efault; |
| 6208 | } |
| 6209 | } else { |
| 6210 | p = NULL; |
| 6211 | } |
| 6212 | |
| 6213 | p2 = lock_user_string(arg2); |
| 6214 | if (!p2) { |
| 6215 | if (arg1) { |
| 6216 | unlock_user(p, arg1, 0); |
| 6217 | } |
| 6218 | goto efault; |
| 6219 | } |
| 6220 | |
| 6221 | if (arg3) { |
| 6222 | p3 = lock_user_string(arg3); |
| 6223 | if (!p3) { |
| 6224 | if (arg1) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6225 | unlock_user(p, arg1, 0); |
Paul Burton | 356d771 | 2014-06-22 11:25:37 +0100 | [diff] [blame] | 6226 | } |
| 6227 | unlock_user(p2, arg2, 0); |
| 6228 | goto efault; |
| 6229 | } |
| 6230 | } else { |
| 6231 | p3 = NULL; |
| 6232 | } |
| 6233 | |
| 6234 | /* FIXME - arg5 should be locked, but it isn't clear how to |
| 6235 | * do that since it's not guaranteed to be a NULL-terminated |
| 6236 | * string. |
| 6237 | */ |
| 6238 | if (!arg5) { |
| 6239 | ret = mount(p, p2, p3, (unsigned long)arg4, NULL); |
| 6240 | } else { |
| 6241 | ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5)); |
| 6242 | } |
| 6243 | ret = get_errno(ret); |
| 6244 | |
| 6245 | if (arg1) { |
| 6246 | unlock_user(p, arg1, 0); |
| 6247 | } |
| 6248 | unlock_user(p2, arg2, 0); |
| 6249 | if (arg3) { |
| 6250 | unlock_user(p3, arg3, 0); |
| 6251 | } |
| 6252 | } |
| 6253 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6254 | #ifdef TARGET_NR_umount |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6255 | case TARGET_NR_umount: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6256 | if (!(p = lock_user_string(arg1))) |
| 6257 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6258 | ret = get_errno(umount(p)); |
| 6259 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6260 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6261 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6262 | #ifdef TARGET_NR_stime /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6263 | case TARGET_NR_stime: |
| 6264 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6265 | time_t host_time; |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 6266 | if (get_user_sal(host_time, arg1)) |
| 6267 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6268 | ret = get_errno(stime(&host_time)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6269 | } |
| 6270 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6271 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6272 | case TARGET_NR_ptrace: |
| 6273 | goto unimplemented; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6274 | #ifdef TARGET_NR_alarm /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6275 | case TARGET_NR_alarm: |
| 6276 | ret = alarm(arg1); |
| 6277 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6278 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6279 | #ifdef TARGET_NR_oldfstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6280 | case TARGET_NR_oldfstat: |
| 6281 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6282 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6283 | #ifdef TARGET_NR_pause /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6284 | case TARGET_NR_pause: |
| 6285 | ret = get_errno(pause()); |
| 6286 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6287 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6288 | #ifdef TARGET_NR_utime |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6289 | case TARGET_NR_utime: |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6290 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6291 | struct utimbuf tbuf, *host_tbuf; |
| 6292 | struct target_utimbuf *target_tbuf; |
| 6293 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6294 | if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1)) |
| 6295 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6296 | tbuf.actime = tswapal(target_tbuf->actime); |
| 6297 | tbuf.modtime = tswapal(target_tbuf->modtime); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6298 | unlock_user_struct(target_tbuf, arg2, 0); |
| 6299 | host_tbuf = &tbuf; |
bellard | f72e8ff | 2004-05-03 19:23:07 +0000 | [diff] [blame] | 6300 | } else { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6301 | host_tbuf = NULL; |
bellard | f72e8ff | 2004-05-03 19:23:07 +0000 | [diff] [blame] | 6302 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6303 | if (!(p = lock_user_string(arg1))) |
| 6304 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6305 | ret = get_errno(utime(p, host_tbuf)); |
| 6306 | unlock_user(p, arg1, 0); |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6307 | } |
| 6308 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6309 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6310 | #ifdef TARGET_NR_utimes |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 6311 | case TARGET_NR_utimes: |
| 6312 | { |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 6313 | struct timeval *tvp, tv[2]; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6314 | if (arg2) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6315 | if (copy_from_user_timeval(&tv[0], arg2) |
| 6316 | || copy_from_user_timeval(&tv[1], |
| 6317 | arg2 + sizeof(struct target_timeval))) |
| 6318 | goto efault; |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 6319 | tvp = tv; |
| 6320 | } else { |
| 6321 | tvp = NULL; |
| 6322 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6323 | if (!(p = lock_user_string(arg1))) |
| 6324 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6325 | ret = get_errno(utimes(p, tvp)); |
| 6326 | unlock_user(p, arg1, 0); |
bellard | 978a66f | 2004-12-06 22:58:05 +0000 | [diff] [blame] | 6327 | } |
| 6328 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6329 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6330 | #if defined(TARGET_NR_futimesat) |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 6331 | case TARGET_NR_futimesat: |
| 6332 | { |
| 6333 | struct timeval *tvp, tv[2]; |
| 6334 | if (arg3) { |
| 6335 | if (copy_from_user_timeval(&tv[0], arg3) |
| 6336 | || copy_from_user_timeval(&tv[1], |
| 6337 | arg3 + sizeof(struct target_timeval))) |
| 6338 | goto efault; |
| 6339 | tvp = tv; |
| 6340 | } else { |
| 6341 | tvp = NULL; |
| 6342 | } |
| 6343 | if (!(p = lock_user_string(arg2))) |
| 6344 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6345 | ret = get_errno(futimesat(arg1, path(p), tvp)); |
balrog | ac8a655 | 2008-09-20 02:25:39 +0000 | [diff] [blame] | 6346 | unlock_user(p, arg2, 0); |
| 6347 | } |
| 6348 | break; |
| 6349 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6350 | #ifdef TARGET_NR_stty |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6351 | case TARGET_NR_stty: |
| 6352 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6353 | #endif |
| 6354 | #ifdef TARGET_NR_gtty |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6355 | case TARGET_NR_gtty: |
| 6356 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6357 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6358 | #ifdef TARGET_NR_access |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6359 | case TARGET_NR_access: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6360 | if (!(p = lock_user_string(arg1))) |
| 6361 | goto efault; |
Ulrich Hecht | 719f908 | 2009-07-03 17:09:29 +0200 | [diff] [blame] | 6362 | ret = get_errno(access(path(p), arg2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6363 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6364 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6365 | #endif |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 6366 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
| 6367 | case TARGET_NR_faccessat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6368 | if (!(p = lock_user_string(arg2))) |
| 6369 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6370 | ret = get_errno(faccessat(arg1, p, arg3, 0)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6371 | unlock_user(p, arg2, 0); |
ths | 92a34c1 | 2007-09-24 09:27:49 +0000 | [diff] [blame] | 6372 | break; |
| 6373 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6374 | #ifdef TARGET_NR_nice /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6375 | case TARGET_NR_nice: |
| 6376 | ret = get_errno(nice(arg1)); |
| 6377 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6378 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6379 | #ifdef TARGET_NR_ftime |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6380 | case TARGET_NR_ftime: |
| 6381 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6382 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6383 | case TARGET_NR_sync: |
bellard | 04369ff | 2003-03-20 22:33:23 +0000 | [diff] [blame] | 6384 | sync(); |
| 6385 | ret = 0; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6386 | break; |
| 6387 | case TARGET_NR_kill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 6388 | ret = get_errno(kill(arg1, target_to_host_signal(arg2))); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6389 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6390 | #ifdef TARGET_NR_rename |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6391 | case TARGET_NR_rename: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6392 | { |
| 6393 | void *p2; |
| 6394 | p = lock_user_string(arg1); |
| 6395 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6396 | if (!p || !p2) |
| 6397 | ret = -TARGET_EFAULT; |
| 6398 | else |
| 6399 | ret = get_errno(rename(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6400 | unlock_user(p2, arg2, 0); |
| 6401 | unlock_user(p, arg1, 0); |
| 6402 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6403 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6404 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6405 | #if defined(TARGET_NR_renameat) |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 6406 | case TARGET_NR_renameat: |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 6407 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6408 | void *p2; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 6409 | p = lock_user_string(arg2); |
| 6410 | p2 = lock_user_string(arg4); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6411 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6412 | ret = -TARGET_EFAULT; |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 6413 | else |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6414 | ret = get_errno(renameat(arg1, p, arg3, p2)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6415 | unlock_user(p2, arg4, 0); |
| 6416 | unlock_user(p, arg2, 0); |
ths | 722183f | 2007-09-24 09:24:37 +0000 | [diff] [blame] | 6417 | } |
| 6418 | break; |
| 6419 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6420 | #ifdef TARGET_NR_mkdir |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6421 | case TARGET_NR_mkdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6422 | if (!(p = lock_user_string(arg1))) |
| 6423 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6424 | ret = get_errno(mkdir(p, arg2)); |
| 6425 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6426 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6427 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6428 | #if defined(TARGET_NR_mkdirat) |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 6429 | case TARGET_NR_mkdirat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6430 | if (!(p = lock_user_string(arg2))) |
| 6431 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 6432 | ret = get_errno(mkdirat(arg1, p, arg3)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6433 | unlock_user(p, arg2, 0); |
ths | 4472ad0 | 2007-09-24 09:22:32 +0000 | [diff] [blame] | 6434 | break; |
| 6435 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6436 | #ifdef TARGET_NR_rmdir |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6437 | case TARGET_NR_rmdir: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6438 | if (!(p = lock_user_string(arg1))) |
| 6439 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6440 | ret = get_errno(rmdir(p)); |
| 6441 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6442 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6443 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6444 | case TARGET_NR_dup: |
| 6445 | ret = get_errno(dup(arg1)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 6446 | if (ret >= 0) { |
| 6447 | fd_trans_dup(arg1, ret); |
| 6448 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6449 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6450 | #ifdef TARGET_NR_pipe |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6451 | case TARGET_NR_pipe: |
Richard Henderson | fb41a66 | 2010-05-03 10:07:52 -0700 | [diff] [blame] | 6452 | ret = do_pipe(cpu_env, arg1, 0, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6453 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6454 | #endif |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 6455 | #ifdef TARGET_NR_pipe2 |
| 6456 | case TARGET_NR_pipe2: |
Richard Henderson | e7ea6cb | 2012-06-01 18:48:39 -0700 | [diff] [blame] | 6457 | ret = do_pipe(cpu_env, arg1, |
| 6458 | target_to_host_bitmask(arg2, fcntl_flags_tbl), 1); |
Riku Voipio | 099d6b0 | 2009-05-05 12:10:04 +0300 | [diff] [blame] | 6459 | break; |
| 6460 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6461 | case TARGET_NR_times: |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 6462 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6463 | struct target_tms *tmsp; |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 6464 | struct tms tms; |
| 6465 | ret = get_errno(times(&tms)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6466 | if (arg1) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6467 | tmsp = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_tms), 0); |
| 6468 | if (!tmsp) |
| 6469 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 6470 | tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime)); |
| 6471 | tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime)); |
| 6472 | tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime)); |
| 6473 | tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime)); |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 6474 | } |
bellard | c596ed1 | 2003-07-13 17:32:31 +0000 | [diff] [blame] | 6475 | if (!is_error(ret)) |
| 6476 | ret = host_to_target_clock_t(ret); |
bellard | 32f36bc | 2003-03-30 21:29:48 +0000 | [diff] [blame] | 6477 | } |
| 6478 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6479 | #ifdef TARGET_NR_prof |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6480 | case TARGET_NR_prof: |
| 6481 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6482 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6483 | #ifdef TARGET_NR_signal |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6484 | case TARGET_NR_signal: |
| 6485 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6486 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6487 | case TARGET_NR_acct: |
aurel32 | 38d840e | 2009-01-30 19:48:17 +0000 | [diff] [blame] | 6488 | if (arg1 == 0) { |
| 6489 | ret = get_errno(acct(NULL)); |
| 6490 | } else { |
| 6491 | if (!(p = lock_user_string(arg1))) |
| 6492 | goto efault; |
| 6493 | ret = get_errno(acct(path(p))); |
| 6494 | unlock_user(p, arg1, 0); |
| 6495 | } |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 6496 | break; |
Richard Henderson | 8070e7b | 2013-07-24 09:50:00 -1000 | [diff] [blame] | 6497 | #ifdef TARGET_NR_umount2 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6498 | case TARGET_NR_umount2: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6499 | if (!(p = lock_user_string(arg1))) |
| 6500 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6501 | ret = get_errno(umount2(p, arg2)); |
| 6502 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6503 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6504 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6505 | #ifdef TARGET_NR_lock |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6506 | case TARGET_NR_lock: |
| 6507 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6508 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6509 | case TARGET_NR_ioctl: |
| 6510 | ret = do_ioctl(arg1, arg2, arg3); |
| 6511 | break; |
| 6512 | case TARGET_NR_fcntl: |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 6513 | ret = do_fcntl(arg1, arg2, arg3); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6514 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6515 | #ifdef TARGET_NR_mpx |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6516 | case TARGET_NR_mpx: |
| 6517 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6518 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6519 | case TARGET_NR_setpgid: |
| 6520 | ret = get_errno(setpgid(arg1, arg2)); |
| 6521 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6522 | #ifdef TARGET_NR_ulimit |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6523 | case TARGET_NR_ulimit: |
| 6524 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6525 | #endif |
| 6526 | #ifdef TARGET_NR_oldolduname |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6527 | case TARGET_NR_oldolduname: |
| 6528 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 6529 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6530 | case TARGET_NR_umask: |
| 6531 | ret = get_errno(umask(arg1)); |
| 6532 | break; |
| 6533 | case TARGET_NR_chroot: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6534 | if (!(p = lock_user_string(arg1))) |
| 6535 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6536 | ret = get_errno(chroot(p)); |
| 6537 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6538 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6539 | #ifdef TARGET_NR_ustat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6540 | case TARGET_NR_ustat: |
| 6541 | goto unimplemented; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6542 | #endif |
| 6543 | #ifdef TARGET_NR_dup2 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6544 | case TARGET_NR_dup2: |
| 6545 | ret = get_errno(dup2(arg1, arg2)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 6546 | if (ret >= 0) { |
| 6547 | fd_trans_dup(arg1, arg2); |
| 6548 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6549 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6550 | #endif |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 6551 | #if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) |
| 6552 | case TARGET_NR_dup3: |
| 6553 | ret = get_errno(dup3(arg1, arg2, arg3)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 6554 | if (ret >= 0) { |
| 6555 | fd_trans_dup(arg1, arg2); |
| 6556 | } |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 6557 | break; |
| 6558 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6559 | #ifdef TARGET_NR_getppid /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6560 | case TARGET_NR_getppid: |
| 6561 | ret = get_errno(getppid()); |
| 6562 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6563 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6564 | #ifdef TARGET_NR_getpgrp |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6565 | case TARGET_NR_getpgrp: |
| 6566 | ret = get_errno(getpgrp()); |
| 6567 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 6568 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6569 | case TARGET_NR_setsid: |
| 6570 | ret = get_errno(setsid()); |
| 6571 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6572 | #ifdef TARGET_NR_sigaction |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6573 | case TARGET_NR_sigaction: |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6574 | { |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 6575 | #if defined(TARGET_ALPHA) |
| 6576 | struct target_sigaction act, oact, *pact = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6577 | struct target_old_sigaction *old_act; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6578 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6579 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 6580 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6581 | act._sa_handler = old_act->_sa_handler; |
| 6582 | target_siginitset(&act.sa_mask, old_act->sa_mask); |
| 6583 | act.sa_flags = old_act->sa_flags; |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 6584 | act.sa_restorer = 0; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6585 | unlock_user_struct(old_act, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6586 | pact = &act; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6587 | } |
| 6588 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6589 | if (!is_error(ret) && arg3) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6590 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 6591 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6592 | old_act->_sa_handler = oact._sa_handler; |
| 6593 | old_act->sa_mask = oact.sa_mask.sig[0]; |
| 6594 | old_act->sa_flags = oact.sa_flags; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6595 | unlock_user_struct(old_act, arg3, 1); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6596 | } |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 6597 | #elif defined(TARGET_MIPS) |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 6598 | struct target_sigaction act, oact, *pact, *old_act; |
| 6599 | |
| 6600 | if (arg2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6601 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 6602 | goto efault; |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 6603 | act._sa_handler = old_act->_sa_handler; |
| 6604 | target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]); |
| 6605 | act.sa_flags = old_act->sa_flags; |
| 6606 | unlock_user_struct(old_act, arg2, 0); |
| 6607 | pact = &act; |
| 6608 | } else { |
| 6609 | pact = NULL; |
| 6610 | } |
| 6611 | |
| 6612 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 6613 | |
| 6614 | if (!is_error(ret) && arg3) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6615 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 6616 | goto efault; |
bellard | 106ec87 | 2006-06-27 21:08:10 +0000 | [diff] [blame] | 6617 | old_act->_sa_handler = oact._sa_handler; |
| 6618 | old_act->sa_flags = oact.sa_flags; |
| 6619 | old_act->sa_mask.sig[0] = oact.sa_mask.sig[0]; |
| 6620 | old_act->sa_mask.sig[1] = 0; |
| 6621 | old_act->sa_mask.sig[2] = 0; |
| 6622 | old_act->sa_mask.sig[3] = 0; |
| 6623 | unlock_user_struct(old_act, arg3, 1); |
| 6624 | } |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 6625 | #else |
| 6626 | struct target_old_sigaction *old_act; |
| 6627 | struct target_sigaction act, oact, *pact; |
| 6628 | if (arg2) { |
| 6629 | if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) |
| 6630 | goto efault; |
| 6631 | act._sa_handler = old_act->_sa_handler; |
| 6632 | target_siginitset(&act.sa_mask, old_act->sa_mask); |
| 6633 | act.sa_flags = old_act->sa_flags; |
| 6634 | act.sa_restorer = old_act->sa_restorer; |
| 6635 | unlock_user_struct(old_act, arg2, 0); |
| 6636 | pact = &act; |
| 6637 | } else { |
| 6638 | pact = NULL; |
| 6639 | } |
| 6640 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 6641 | if (!is_error(ret) && arg3) { |
| 6642 | if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) |
| 6643 | goto efault; |
| 6644 | old_act->_sa_handler = oact._sa_handler; |
| 6645 | old_act->sa_mask = oact.sa_mask.sig[0]; |
| 6646 | old_act->sa_flags = oact.sa_flags; |
| 6647 | old_act->sa_restorer = oact.sa_restorer; |
| 6648 | unlock_user_struct(old_act, arg3, 1); |
| 6649 | } |
ths | 388bb21 | 2007-05-13 13:58:00 +0000 | [diff] [blame] | 6650 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6651 | } |
| 6652 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6653 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6654 | case TARGET_NR_rt_sigaction: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6655 | { |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 6656 | #if defined(TARGET_ALPHA) |
| 6657 | struct target_sigaction act, oact, *pact = 0; |
| 6658 | struct target_rt_sigaction *rt_act; |
| 6659 | /* ??? arg4 == sizeof(sigset_t). */ |
| 6660 | if (arg2) { |
| 6661 | if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1)) |
| 6662 | goto efault; |
| 6663 | act._sa_handler = rt_act->_sa_handler; |
| 6664 | act.sa_mask = rt_act->sa_mask; |
| 6665 | act.sa_flags = rt_act->sa_flags; |
| 6666 | act.sa_restorer = arg5; |
| 6667 | unlock_user_struct(rt_act, arg2, 0); |
| 6668 | pact = &act; |
| 6669 | } |
| 6670 | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
| 6671 | if (!is_error(ret) && arg3) { |
| 6672 | if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0)) |
| 6673 | goto efault; |
| 6674 | rt_act->_sa_handler = oact._sa_handler; |
| 6675 | rt_act->sa_mask = oact.sa_mask; |
| 6676 | rt_act->sa_flags = oact.sa_flags; |
| 6677 | unlock_user_struct(rt_act, arg3, 1); |
| 6678 | } |
| 6679 | #else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6680 | struct target_sigaction *act; |
| 6681 | struct target_sigaction *oact; |
| 6682 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6683 | if (arg2) { |
| 6684 | if (!lock_user_struct(VERIFY_READ, act, arg2, 1)) |
| 6685 | goto efault; |
| 6686 | } else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6687 | act = NULL; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6688 | if (arg3) { |
| 6689 | if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) { |
| 6690 | ret = -TARGET_EFAULT; |
| 6691 | goto rt_sigaction_fail; |
| 6692 | } |
| 6693 | } else |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6694 | oact = NULL; |
| 6695 | ret = get_errno(do_sigaction(arg1, act, oact)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6696 | rt_sigaction_fail: |
| 6697 | if (act) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6698 | unlock_user_struct(act, arg2, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6699 | if (oact) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6700 | unlock_user_struct(oact, arg3, 1); |
Richard Henderson | 6049f4f | 2009-12-27 18:30:03 -0800 | [diff] [blame] | 6701 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6702 | } |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6703 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6704 | #ifdef TARGET_NR_sgetmask /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6705 | case TARGET_NR_sgetmask: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6706 | { |
| 6707 | sigset_t cur_set; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6708 | abi_ulong target_set; |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 6709 | do_sigprocmask(0, NULL, &cur_set); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6710 | host_to_target_old_sigset(&target_set, &cur_set); |
| 6711 | ret = target_set; |
| 6712 | } |
| 6713 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6714 | #endif |
| 6715 | #ifdef TARGET_NR_ssetmask /* not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6716 | case TARGET_NR_ssetmask: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6717 | { |
| 6718 | sigset_t set, oset, cur_set; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 6719 | abi_ulong target_set = arg1; |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 6720 | do_sigprocmask(0, NULL, &cur_set); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6721 | target_to_host_old_sigset(&set, &target_set); |
| 6722 | sigorset(&set, &set, &cur_set); |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 6723 | do_sigprocmask(SIG_SETMASK, &set, &oset); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6724 | host_to_target_old_sigset(&target_set, &oset); |
| 6725 | ret = target_set; |
| 6726 | } |
| 6727 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 6728 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6729 | #ifdef TARGET_NR_sigprocmask |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6730 | case TARGET_NR_sigprocmask: |
| 6731 | { |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6732 | #if defined(TARGET_ALPHA) |
| 6733 | sigset_t set, oldset; |
| 6734 | abi_ulong mask; |
| 6735 | int how; |
| 6736 | |
| 6737 | switch (arg1) { |
| 6738 | case TARGET_SIG_BLOCK: |
| 6739 | how = SIG_BLOCK; |
| 6740 | break; |
| 6741 | case TARGET_SIG_UNBLOCK: |
| 6742 | how = SIG_UNBLOCK; |
| 6743 | break; |
| 6744 | case TARGET_SIG_SETMASK: |
| 6745 | how = SIG_SETMASK; |
| 6746 | break; |
| 6747 | default: |
| 6748 | ret = -TARGET_EINVAL; |
| 6749 | goto fail; |
| 6750 | } |
| 6751 | mask = arg2; |
| 6752 | target_to_host_old_sigset(&set, &mask); |
| 6753 | |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 6754 | ret = get_errno(do_sigprocmask(how, &set, &oldset)); |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6755 | if (!is_error(ret)) { |
| 6756 | host_to_target_old_sigset(&mask, &oldset); |
| 6757 | ret = mask; |
Richard Henderson | 0229f5a | 2012-06-07 15:02:49 -0700 | [diff] [blame] | 6758 | ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; /* force no error */ |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6759 | } |
| 6760 | #else |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6761 | sigset_t set, oldset, *set_ptr; |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6762 | int how; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6763 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6764 | if (arg2) { |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6765 | switch (arg1) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6766 | case TARGET_SIG_BLOCK: |
| 6767 | how = SIG_BLOCK; |
| 6768 | break; |
| 6769 | case TARGET_SIG_UNBLOCK: |
| 6770 | how = SIG_UNBLOCK; |
| 6771 | break; |
| 6772 | case TARGET_SIG_SETMASK: |
| 6773 | how = SIG_SETMASK; |
| 6774 | break; |
| 6775 | default: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6776 | ret = -TARGET_EINVAL; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6777 | goto fail; |
| 6778 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6779 | if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6780 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6781 | target_to_host_old_sigset(&set, p); |
| 6782 | unlock_user(p, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6783 | set_ptr = &set; |
| 6784 | } else { |
| 6785 | how = 0; |
| 6786 | set_ptr = NULL; |
| 6787 | } |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 6788 | ret = get_errno(do_sigprocmask(how, set_ptr, &oldset)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6789 | if (!is_error(ret) && arg3) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6790 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6791 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6792 | host_to_target_old_sigset(p, &oldset); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6793 | unlock_user(p, arg3, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6794 | } |
Richard Henderson | a5b3b13 | 2010-05-03 10:07:55 -0700 | [diff] [blame] | 6795 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6796 | } |
| 6797 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6798 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6799 | case TARGET_NR_rt_sigprocmask: |
| 6800 | { |
| 6801 | int how = arg1; |
| 6802 | sigset_t set, oldset, *set_ptr; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6803 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6804 | if (arg2) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6805 | switch(how) { |
| 6806 | case TARGET_SIG_BLOCK: |
| 6807 | how = SIG_BLOCK; |
| 6808 | break; |
| 6809 | case TARGET_SIG_UNBLOCK: |
| 6810 | how = SIG_UNBLOCK; |
| 6811 | break; |
| 6812 | case TARGET_SIG_SETMASK: |
| 6813 | how = SIG_SETMASK; |
| 6814 | break; |
| 6815 | default: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 6816 | ret = -TARGET_EINVAL; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6817 | goto fail; |
| 6818 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6819 | if (!(p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6820 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6821 | target_to_host_sigset(&set, p); |
| 6822 | unlock_user(p, arg2, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6823 | set_ptr = &set; |
| 6824 | } else { |
| 6825 | how = 0; |
| 6826 | set_ptr = NULL; |
| 6827 | } |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 6828 | ret = get_errno(do_sigprocmask(how, set_ptr, &oldset)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6829 | if (!is_error(ret) && arg3) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6830 | if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6831 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6832 | host_to_target_sigset(p, &oldset); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6833 | unlock_user(p, arg3, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6834 | } |
| 6835 | } |
| 6836 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6837 | #ifdef TARGET_NR_sigpending |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6838 | case TARGET_NR_sigpending: |
| 6839 | { |
| 6840 | sigset_t set; |
| 6841 | ret = get_errno(sigpending(&set)); |
| 6842 | if (!is_error(ret)) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6843 | if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6844 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6845 | host_to_target_old_sigset(p, &set); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6846 | unlock_user(p, arg1, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6847 | } |
| 6848 | } |
| 6849 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6850 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6851 | case TARGET_NR_rt_sigpending: |
| 6852 | { |
| 6853 | sigset_t set; |
| 6854 | ret = get_errno(sigpending(&set)); |
| 6855 | if (!is_error(ret)) { |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6856 | if (!(p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6857 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6858 | host_to_target_sigset(p, &set); |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6859 | unlock_user(p, arg1, sizeof(target_sigset_t)); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6860 | } |
| 6861 | } |
| 6862 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6863 | #ifdef TARGET_NR_sigsuspend |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6864 | case TARGET_NR_sigsuspend: |
| 6865 | { |
| 6866 | sigset_t set; |
Richard Henderson | f43ce12 | 2010-05-03 10:07:54 -0700 | [diff] [blame] | 6867 | #if defined(TARGET_ALPHA) |
| 6868 | abi_ulong mask = arg1; |
| 6869 | target_to_host_old_sigset(&set, &mask); |
| 6870 | #else |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6871 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6872 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6873 | target_to_host_old_sigset(&set, p); |
| 6874 | unlock_user(p, arg1, 0); |
Richard Henderson | f43ce12 | 2010-05-03 10:07:54 -0700 | [diff] [blame] | 6875 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6876 | ret = get_errno(sigsuspend(&set)); |
| 6877 | } |
| 6878 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6879 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6880 | case TARGET_NR_rt_sigsuspend: |
| 6881 | { |
| 6882 | sigset_t set; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6883 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6884 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6885 | target_to_host_sigset(&set, p); |
| 6886 | unlock_user(p, arg1, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6887 | ret = get_errno(sigsuspend(&set)); |
| 6888 | } |
| 6889 | break; |
| 6890 | case TARGET_NR_rt_sigtimedwait: |
| 6891 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6892 | sigset_t set; |
| 6893 | struct timespec uts, *puts; |
| 6894 | siginfo_t uinfo; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6895 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6896 | if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6897 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6898 | target_to_host_sigset(&set, p); |
| 6899 | unlock_user(p, arg1, 0); |
| 6900 | if (arg3) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6901 | puts = &uts; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6902 | target_to_host_timespec(puts, arg3); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6903 | } else { |
| 6904 | puts = NULL; |
| 6905 | } |
| 6906 | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); |
Petar Jovanovic | 974a196 | 2014-03-03 15:07:41 +0100 | [diff] [blame] | 6907 | if (!is_error(ret)) { |
| 6908 | if (arg2) { |
| 6909 | p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t), |
| 6910 | 0); |
| 6911 | if (!p) { |
| 6912 | goto efault; |
| 6913 | } |
| 6914 | host_to_target_siginfo(p, &uinfo); |
| 6915 | unlock_user(p, arg2, sizeof(target_siginfo_t)); |
| 6916 | } |
| 6917 | ret = host_to_target_signal(ret); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6918 | } |
| 6919 | } |
| 6920 | break; |
| 6921 | case TARGET_NR_rt_sigqueueinfo: |
| 6922 | { |
| 6923 | siginfo_t uinfo; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 6924 | if (!(p = lock_user(VERIFY_READ, arg3, sizeof(target_sigset_t), 1))) |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6925 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6926 | target_to_host_siginfo(&uinfo, p); |
| 6927 | unlock_user(p, arg1, 0); |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6928 | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); |
| 6929 | } |
| 6930 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6931 | #ifdef TARGET_NR_sigreturn |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6932 | case TARGET_NR_sigreturn: |
| 6933 | /* NOTE: ret is eax, so not transcoding must be done */ |
| 6934 | ret = do_sigreturn(cpu_env); |
| 6935 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 6936 | #endif |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 6937 | case TARGET_NR_rt_sigreturn: |
| 6938 | /* NOTE: ret is eax, so not transcoding must be done */ |
| 6939 | ret = do_rt_sigreturn(cpu_env); |
| 6940 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6941 | case TARGET_NR_sethostname: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6942 | if (!(p = lock_user_string(arg1))) |
| 6943 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6944 | ret = get_errno(sethostname(p, arg2)); |
| 6945 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6946 | break; |
| 6947 | case TARGET_NR_setrlimit: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6948 | { |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 6949 | int resource = target_to_host_resource(arg1); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6950 | struct target_rlimit *target_rlim; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6951 | struct rlimit rlim; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6952 | if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)) |
| 6953 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 6954 | rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur); |
| 6955 | rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6956 | unlock_user_struct(target_rlim, arg2, 0); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6957 | ret = get_errno(setrlimit(resource, &rlim)); |
| 6958 | } |
| 6959 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6960 | case TARGET_NR_getrlimit: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6961 | { |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 6962 | int resource = target_to_host_resource(arg1); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6963 | struct target_rlimit *target_rlim; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6964 | struct rlimit rlim; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 6965 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6966 | ret = get_errno(getrlimit(resource, &rlim)); |
| 6967 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 6968 | if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) |
| 6969 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 6970 | target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); |
| 6971 | target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 6972 | unlock_user_struct(target_rlim, arg2, 1); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 6973 | } |
| 6974 | } |
| 6975 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6976 | case TARGET_NR_getrusage: |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6977 | { |
| 6978 | struct rusage rusage; |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6979 | ret = get_errno(getrusage(arg1, &rusage)); |
| 6980 | if (!is_error(ret)) { |
Petar Jovanovic | a39fb27 | 2014-04-08 19:24:30 +0200 | [diff] [blame] | 6981 | ret = host_to_target_rusage(arg2, &rusage); |
bellard | b409186 | 2003-05-16 15:39:34 +0000 | [diff] [blame] | 6982 | } |
| 6983 | } |
| 6984 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6985 | case TARGET_NR_gettimeofday: |
| 6986 | { |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6987 | struct timeval tv; |
| 6988 | ret = get_errno(gettimeofday(&tv, NULL)); |
| 6989 | if (!is_error(ret)) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 6990 | if (copy_to_user_timeval(arg1, &tv)) |
| 6991 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 6992 | } |
| 6993 | } |
| 6994 | break; |
| 6995 | case TARGET_NR_settimeofday: |
| 6996 | { |
Paul Burton | b67d803 | 2014-06-22 11:25:41 +0100 | [diff] [blame] | 6997 | struct timeval tv, *ptv = NULL; |
Paul Burton | ef4467e | 2014-06-22 11:25:40 +0100 | [diff] [blame] | 6998 | struct timezone tz, *ptz = NULL; |
| 6999 | |
Paul Burton | b67d803 | 2014-06-22 11:25:41 +0100 | [diff] [blame] | 7000 | if (arg1) { |
| 7001 | if (copy_from_user_timeval(&tv, arg1)) { |
| 7002 | goto efault; |
| 7003 | } |
| 7004 | ptv = &tv; |
| 7005 | } |
Paul Burton | ef4467e | 2014-06-22 11:25:40 +0100 | [diff] [blame] | 7006 | |
| 7007 | if (arg2) { |
| 7008 | if (copy_from_user_timezone(&tz, arg2)) { |
| 7009 | goto efault; |
| 7010 | } |
| 7011 | ptz = &tz; |
| 7012 | } |
| 7013 | |
Paul Burton | b67d803 | 2014-06-22 11:25:41 +0100 | [diff] [blame] | 7014 | ret = get_errno(settimeofday(ptv, ptz)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7015 | } |
| 7016 | break; |
Laurent Vivier | 9468a5d | 2013-01-10 22:30:50 +0100 | [diff] [blame] | 7017 | #if defined(TARGET_NR_select) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7018 | case TARGET_NR_select: |
Laurent Vivier | 9468a5d | 2013-01-10 22:30:50 +0100 | [diff] [blame] | 7019 | #if defined(TARGET_S390X) || defined(TARGET_ALPHA) |
| 7020 | ret = do_select(arg1, arg2, arg3, arg4, arg5); |
| 7021 | #else |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 7022 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7023 | struct target_sel_arg_struct *sel; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7024 | abi_ulong inp, outp, exp, tvp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7025 | long nsel; |
| 7026 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7027 | if (!lock_user_struct(VERIFY_READ, sel, arg1, 1)) |
| 7028 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 7029 | nsel = tswapal(sel->n); |
| 7030 | inp = tswapal(sel->inp); |
| 7031 | outp = tswapal(sel->outp); |
| 7032 | exp = tswapal(sel->exp); |
| 7033 | tvp = tswapal(sel->tvp); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7034 | unlock_user_struct(sel, arg1, 0); |
| 7035 | ret = do_select(nsel, inp, outp, exp, tvp); |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 7036 | } |
Laurent Vivier | 9468a5d | 2013-01-10 22:30:50 +0100 | [diff] [blame] | 7037 | #endif |
bellard | f2674e3 | 2003-07-09 12:26:09 +0000 | [diff] [blame] | 7038 | break; |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 7039 | #endif |
Riku Voipio | 9e42382 | 2010-05-07 12:28:05 +0000 | [diff] [blame] | 7040 | #ifdef TARGET_NR_pselect6 |
| 7041 | case TARGET_NR_pselect6: |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 7042 | { |
| 7043 | abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr; |
| 7044 | fd_set rfds, wfds, efds; |
| 7045 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
| 7046 | struct timespec ts, *ts_ptr; |
| 7047 | |
| 7048 | /* |
| 7049 | * The 6th arg is actually two args smashed together, |
| 7050 | * so we cannot use the C library. |
| 7051 | */ |
| 7052 | sigset_t set; |
| 7053 | struct { |
| 7054 | sigset_t *set; |
| 7055 | size_t size; |
| 7056 | } sig, *sig_ptr; |
| 7057 | |
| 7058 | abi_ulong arg_sigset, arg_sigsize, *arg7; |
| 7059 | target_sigset_t *target_sigset; |
| 7060 | |
| 7061 | n = arg1; |
| 7062 | rfd_addr = arg2; |
| 7063 | wfd_addr = arg3; |
| 7064 | efd_addr = arg4; |
| 7065 | ts_addr = arg5; |
| 7066 | |
| 7067 | ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); |
| 7068 | if (ret) { |
| 7069 | goto fail; |
| 7070 | } |
| 7071 | ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n); |
| 7072 | if (ret) { |
| 7073 | goto fail; |
| 7074 | } |
| 7075 | ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n); |
| 7076 | if (ret) { |
| 7077 | goto fail; |
| 7078 | } |
| 7079 | |
| 7080 | /* |
| 7081 | * This takes a timespec, and not a timeval, so we cannot |
| 7082 | * use the do_select() helper ... |
| 7083 | */ |
| 7084 | if (ts_addr) { |
| 7085 | if (target_to_host_timespec(&ts, ts_addr)) { |
| 7086 | goto efault; |
| 7087 | } |
| 7088 | ts_ptr = &ts; |
| 7089 | } else { |
| 7090 | ts_ptr = NULL; |
| 7091 | } |
| 7092 | |
| 7093 | /* Extract the two packed args for the sigset */ |
| 7094 | if (arg6) { |
| 7095 | sig_ptr = &sig; |
| 7096 | sig.size = _NSIG / 8; |
| 7097 | |
| 7098 | arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1); |
| 7099 | if (!arg7) { |
| 7100 | goto efault; |
| 7101 | } |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 7102 | arg_sigset = tswapal(arg7[0]); |
| 7103 | arg_sigsize = tswapal(arg7[1]); |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 7104 | unlock_user(arg7, arg6, 0); |
| 7105 | |
| 7106 | if (arg_sigset) { |
| 7107 | sig.set = &set; |
Peter Maydell | 8f04eeb | 2011-06-28 12:21:57 +0100 | [diff] [blame] | 7108 | if (arg_sigsize != sizeof(*target_sigset)) { |
| 7109 | /* Like the kernel, we enforce correct size sigsets */ |
| 7110 | ret = -TARGET_EINVAL; |
| 7111 | goto fail; |
| 7112 | } |
Mike Frysinger | 055e090 | 2011-06-03 17:01:49 -0400 | [diff] [blame] | 7113 | target_sigset = lock_user(VERIFY_READ, arg_sigset, |
| 7114 | sizeof(*target_sigset), 1); |
| 7115 | if (!target_sigset) { |
| 7116 | goto efault; |
| 7117 | } |
| 7118 | target_to_host_sigset(&set, target_sigset); |
| 7119 | unlock_user(target_sigset, arg_sigset, 0); |
| 7120 | } else { |
| 7121 | sig.set = NULL; |
| 7122 | } |
| 7123 | } else { |
| 7124 | sig_ptr = NULL; |
| 7125 | } |
| 7126 | |
| 7127 | ret = get_errno(sys_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, |
| 7128 | ts_ptr, sig_ptr)); |
| 7129 | |
| 7130 | if (!is_error(ret)) { |
| 7131 | if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) |
| 7132 | goto efault; |
| 7133 | if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n)) |
| 7134 | goto efault; |
| 7135 | if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) |
| 7136 | goto efault; |
| 7137 | |
| 7138 | if (ts_addr && host_to_target_timespec(ts_addr, &ts)) |
| 7139 | goto efault; |
| 7140 | } |
| 7141 | } |
| 7142 | break; |
Riku Voipio | 9e42382 | 2010-05-07 12:28:05 +0000 | [diff] [blame] | 7143 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7144 | #ifdef TARGET_NR_symlink |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7145 | case TARGET_NR_symlink: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7146 | { |
| 7147 | void *p2; |
| 7148 | p = lock_user_string(arg1); |
| 7149 | p2 = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7150 | if (!p || !p2) |
| 7151 | ret = -TARGET_EFAULT; |
| 7152 | else |
| 7153 | ret = get_errno(symlink(p, p2)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7154 | unlock_user(p2, arg2, 0); |
| 7155 | unlock_user(p, arg1, 0); |
| 7156 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7157 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7158 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7159 | #if defined(TARGET_NR_symlinkat) |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 7160 | case TARGET_NR_symlinkat: |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 7161 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7162 | void *p2; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 7163 | p = lock_user_string(arg1); |
| 7164 | p2 = lock_user_string(arg3); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7165 | if (!p || !p2) |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7166 | ret = -TARGET_EFAULT; |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 7167 | else |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7168 | ret = get_errno(symlinkat(p, arg2, p2)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7169 | unlock_user(p2, arg3, 0); |
| 7170 | unlock_user(p, arg1, 0); |
ths | f0b6243 | 2007-09-24 09:25:40 +0000 | [diff] [blame] | 7171 | } |
| 7172 | break; |
| 7173 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7174 | #ifdef TARGET_NR_oldlstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7175 | case TARGET_NR_oldlstat: |
| 7176 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7177 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7178 | #ifdef TARGET_NR_readlink |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7179 | case TARGET_NR_readlink: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7180 | { |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 7181 | void *p2; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7182 | p = lock_user_string(arg1); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7183 | p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 7184 | if (!p || !p2) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7185 | ret = -TARGET_EFAULT; |
Mike Frysinger | f17f498 | 2014-08-08 09:40:25 +0900 | [diff] [blame] | 7186 | } else if (!arg3) { |
| 7187 | /* Short circuit this for the magic exe check. */ |
| 7188 | ret = -TARGET_EINVAL; |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 7189 | } else if (is_proc_myself((const char *)p, "exe")) { |
| 7190 | char real[PATH_MAX], *temp; |
| 7191 | temp = realpath(exec_path, real); |
Mike Frysinger | f17f498 | 2014-08-08 09:40:25 +0900 | [diff] [blame] | 7192 | /* Return value is # of bytes that we wrote to the buffer. */ |
| 7193 | if (temp == NULL) { |
| 7194 | ret = get_errno(-1); |
| 7195 | } else { |
| 7196 | /* Don't worry about sign mismatch as earlier mapping |
| 7197 | * logic would have thrown a bad address error. */ |
| 7198 | ret = MIN(strlen(real), arg3); |
| 7199 | /* We cannot NUL terminate the string. */ |
| 7200 | memcpy(p2, real, ret); |
| 7201 | } |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 7202 | } else { |
| 7203 | ret = get_errno(readlink(path(p), p2, arg3)); |
aurel32 | d088d66 | 2009-01-30 20:09:01 +0000 | [diff] [blame] | 7204 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7205 | unlock_user(p2, arg2, ret); |
| 7206 | unlock_user(p, arg1, 0); |
| 7207 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7208 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7209 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7210 | #if defined(TARGET_NR_readlinkat) |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 7211 | case TARGET_NR_readlinkat: |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 7212 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7213 | void *p2; |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 7214 | p = lock_user_string(arg2); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7215 | p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 7216 | if (!p || !p2) { |
| 7217 | ret = -TARGET_EFAULT; |
| 7218 | } else if (is_proc_myself((const char *)p, "exe")) { |
| 7219 | char real[PATH_MAX], *temp; |
| 7220 | temp = realpath(exec_path, real); |
| 7221 | ret = temp == NULL ? get_errno(-1) : strlen(real) ; |
| 7222 | snprintf((char *)p2, arg4, "%s", real); |
| 7223 | } else { |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7224 | ret = get_errno(readlinkat(arg1, path(p), p2, arg4)); |
Andreas Schwab | 463d8e7 | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 7225 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7226 | unlock_user(p2, arg3, ret); |
| 7227 | unlock_user(p, arg2, 0); |
ths | 5e0ccb1 | 2007-09-24 09:26:10 +0000 | [diff] [blame] | 7228 | } |
| 7229 | break; |
| 7230 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7231 | #ifdef TARGET_NR_uselib |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7232 | case TARGET_NR_uselib: |
| 7233 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7234 | #endif |
| 7235 | #ifdef TARGET_NR_swapon |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7236 | case TARGET_NR_swapon: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7237 | if (!(p = lock_user_string(arg1))) |
| 7238 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7239 | ret = get_errno(swapon(p, arg2)); |
| 7240 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7241 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7242 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7243 | case TARGET_NR_reboot: |
Laurent Vivier | c07ecc6 | 2013-01-07 11:40:06 +0000 | [diff] [blame] | 7244 | if (arg3 == LINUX_REBOOT_CMD_RESTART2) { |
| 7245 | /* arg4 must be ignored in all other cases */ |
| 7246 | p = lock_user_string(arg4); |
| 7247 | if (!p) { |
| 7248 | goto efault; |
| 7249 | } |
| 7250 | ret = get_errno(reboot(arg1, arg2, arg3, p)); |
| 7251 | unlock_user(p, arg4, 0); |
| 7252 | } else { |
| 7253 | ret = get_errno(reboot(arg1, arg2, arg3, NULL)); |
| 7254 | } |
Alexander Graf | 0f6b4d2 | 2011-09-27 14:39:42 +0200 | [diff] [blame] | 7255 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7256 | #ifdef TARGET_NR_readdir |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7257 | case TARGET_NR_readdir: |
| 7258 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7259 | #endif |
| 7260 | #ifdef TARGET_NR_mmap |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7261 | case TARGET_NR_mmap: |
Alexander Graf | 0970119 | 2013-09-03 20:12:15 +0100 | [diff] [blame] | 7262 | #if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \ |
| 7263 | (defined(TARGET_ARM) && defined(TARGET_ABI32)) || \ |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7264 | defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \ |
| 7265 | || defined(TARGET_S390X) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7266 | { |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7267 | abi_ulong *v; |
| 7268 | abi_ulong v1, v2, v3, v4, v5, v6; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7269 | if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1))) |
| 7270 | goto efault; |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 7271 | v1 = tswapal(v[0]); |
| 7272 | v2 = tswapal(v[1]); |
| 7273 | v3 = tswapal(v[2]); |
| 7274 | v4 = tswapal(v[3]); |
| 7275 | v5 = tswapal(v[4]); |
| 7276 | v6 = tswapal(v[5]); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7277 | unlock_user(v, arg1, 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7278 | ret = get_errno(target_mmap(v1, v2, v3, |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 7279 | target_to_host_bitmask(v4, mmap_flags_tbl), |
| 7280 | v5, v6)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7281 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7282 | #else |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7283 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
| 7284 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 7285 | arg5, |
| 7286 | arg6)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7287 | #endif |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 7288 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7289 | #endif |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7290 | #ifdef TARGET_NR_mmap2 |
bellard | 6fb883e | 2003-07-09 17:12:39 +0000 | [diff] [blame] | 7291 | case TARGET_NR_mmap2: |
pbrook | bb7ec04 | 2008-03-25 22:28:25 +0000 | [diff] [blame] | 7292 | #ifndef MMAP_SHIFT |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 7293 | #define MMAP_SHIFT 12 |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 7294 | #endif |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 7295 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
| 7296 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
bellard | 5286db7 | 2003-06-05 00:57:30 +0000 | [diff] [blame] | 7297 | arg5, |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 7298 | arg6 << MMAP_SHIFT)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7299 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 7300 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7301 | case TARGET_NR_munmap: |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 7302 | ret = get_errno(target_munmap(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7303 | break; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7304 | case TARGET_NR_mprotect: |
Paul Brook | 97374d3 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 7305 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 7306 | TaskState *ts = cpu->opaque; |
Paul Brook | 97374d3 | 2010-06-16 13:03:51 +0100 | [diff] [blame] | 7307 | /* Special hack to detect libc making the stack executable. */ |
| 7308 | if ((arg3 & PROT_GROWSDOWN) |
| 7309 | && arg1 >= ts->info->stack_limit |
| 7310 | && arg1 <= ts->info->start_stack) { |
| 7311 | arg3 &= ~PROT_GROWSDOWN; |
| 7312 | arg2 = arg2 + arg1 - ts->info->stack_limit; |
| 7313 | arg1 = ts->info->stack_limit; |
| 7314 | } |
| 7315 | } |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 7316 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7317 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7318 | #ifdef TARGET_NR_mremap |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7319 | case TARGET_NR_mremap: |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 7320 | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7321 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7322 | #endif |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7323 | /* ??? msync/mlock/munlock are broken for softmmu. */ |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7324 | #ifdef TARGET_NR_msync |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7325 | case TARGET_NR_msync: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7326 | ret = get_errno(msync(g2h(arg1), arg2, arg3)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7327 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7328 | #endif |
| 7329 | #ifdef TARGET_NR_mlock |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7330 | case TARGET_NR_mlock: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7331 | ret = get_errno(mlock(g2h(arg1), arg2)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7332 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7333 | #endif |
| 7334 | #ifdef TARGET_NR_munlock |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7335 | case TARGET_NR_munlock: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7336 | ret = get_errno(munlock(g2h(arg1), arg2)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7337 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7338 | #endif |
| 7339 | #ifdef TARGET_NR_mlockall |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7340 | case TARGET_NR_mlockall: |
Tom Musta | 6f6a403 | 2014-08-12 13:53:42 -0500 | [diff] [blame] | 7341 | ret = get_errno(mlockall(target_to_host_mlockall_arg(arg1))); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7342 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7343 | #endif |
| 7344 | #ifdef TARGET_NR_munlockall |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 7345 | case TARGET_NR_munlockall: |
| 7346 | ret = get_errno(munlockall()); |
| 7347 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7348 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7349 | case TARGET_NR_truncate: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7350 | if (!(p = lock_user_string(arg1))) |
| 7351 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7352 | ret = get_errno(truncate(p, arg2)); |
| 7353 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7354 | break; |
| 7355 | case TARGET_NR_ftruncate: |
| 7356 | ret = get_errno(ftruncate(arg1, arg2)); |
| 7357 | break; |
| 7358 | case TARGET_NR_fchmod: |
| 7359 | ret = get_errno(fchmod(arg1, arg2)); |
| 7360 | break; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7361 | #if defined(TARGET_NR_fchmodat) |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 7362 | case TARGET_NR_fchmodat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7363 | if (!(p = lock_user_string(arg2))) |
| 7364 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7365 | ret = get_errno(fchmodat(arg1, p, arg3, 0)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7366 | unlock_user(p, arg2, 0); |
ths | 814d797 | 2007-09-24 09:26:51 +0000 | [diff] [blame] | 7367 | break; |
| 7368 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7369 | case TARGET_NR_getpriority: |
Richard Henderson | 95c0982 | 2012-06-07 15:14:50 -0700 | [diff] [blame] | 7370 | /* Note that negative values are valid for getpriority, so we must |
| 7371 | differentiate based on errno settings. */ |
| 7372 | errno = 0; |
| 7373 | ret = getpriority(arg1, arg2); |
| 7374 | if (ret == -1 && errno != 0) { |
| 7375 | ret = -host_to_target_errno(errno); |
| 7376 | break; |
| 7377 | } |
| 7378 | #ifdef TARGET_ALPHA |
| 7379 | /* Return value is the unbiased priority. Signal no error. */ |
| 7380 | ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; |
| 7381 | #else |
| 7382 | /* Return value is a biased priority to avoid negative numbers. */ |
| 7383 | ret = 20 - ret; |
| 7384 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7385 | break; |
| 7386 | case TARGET_NR_setpriority: |
| 7387 | ret = get_errno(setpriority(arg1, arg2, arg3)); |
| 7388 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7389 | #ifdef TARGET_NR_profil |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7390 | case TARGET_NR_profil: |
| 7391 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7392 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7393 | case TARGET_NR_statfs: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7394 | if (!(p = lock_user_string(arg1))) |
| 7395 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7396 | ret = get_errno(statfs(path(p), &stfs)); |
| 7397 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7398 | convert_statfs: |
| 7399 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7400 | struct target_statfs *target_stfs; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7401 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7402 | if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg2, 0)) |
| 7403 | goto efault; |
| 7404 | __put_user(stfs.f_type, &target_stfs->f_type); |
| 7405 | __put_user(stfs.f_bsize, &target_stfs->f_bsize); |
| 7406 | __put_user(stfs.f_blocks, &target_stfs->f_blocks); |
| 7407 | __put_user(stfs.f_bfree, &target_stfs->f_bfree); |
| 7408 | __put_user(stfs.f_bavail, &target_stfs->f_bavail); |
| 7409 | __put_user(stfs.f_files, &target_stfs->f_files); |
| 7410 | __put_user(stfs.f_ffree, &target_stfs->f_ffree); |
| 7411 | __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
| 7412 | __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); |
| 7413 | __put_user(stfs.f_namelen, &target_stfs->f_namelen); |
Alexander Graf | 229d337 | 2012-09-19 04:39:53 +0200 | [diff] [blame] | 7414 | __put_user(stfs.f_frsize, &target_stfs->f_frsize); |
| 7415 | memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7416 | unlock_user_struct(target_stfs, arg2, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7417 | } |
| 7418 | break; |
| 7419 | case TARGET_NR_fstatfs: |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 7420 | ret = get_errno(fstatfs(arg1, &stfs)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7421 | goto convert_statfs; |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 7422 | #ifdef TARGET_NR_statfs64 |
| 7423 | case TARGET_NR_statfs64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7424 | if (!(p = lock_user_string(arg1))) |
| 7425 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7426 | ret = get_errno(statfs(path(p), &stfs)); |
| 7427 | unlock_user(p, arg1, 0); |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 7428 | convert_statfs64: |
| 7429 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7430 | struct target_statfs64 *target_stfs; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7431 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7432 | if (!lock_user_struct(VERIFY_WRITE, target_stfs, arg3, 0)) |
| 7433 | goto efault; |
| 7434 | __put_user(stfs.f_type, &target_stfs->f_type); |
| 7435 | __put_user(stfs.f_bsize, &target_stfs->f_bsize); |
| 7436 | __put_user(stfs.f_blocks, &target_stfs->f_blocks); |
| 7437 | __put_user(stfs.f_bfree, &target_stfs->f_bfree); |
| 7438 | __put_user(stfs.f_bavail, &target_stfs->f_bavail); |
| 7439 | __put_user(stfs.f_files, &target_stfs->f_files); |
| 7440 | __put_user(stfs.f_ffree, &target_stfs->f_ffree); |
| 7441 | __put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
| 7442 | __put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); |
| 7443 | __put_user(stfs.f_namelen, &target_stfs->f_namelen); |
Alexander Graf | 229d337 | 2012-09-19 04:39:53 +0200 | [diff] [blame] | 7444 | __put_user(stfs.f_frsize, &target_stfs->f_frsize); |
| 7445 | memset(target_stfs->f_spare, 0, sizeof(target_stfs->f_spare)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7446 | unlock_user_struct(target_stfs, arg3, 1); |
bellard | 56c8f68 | 2005-11-28 22:28:41 +0000 | [diff] [blame] | 7447 | } |
| 7448 | break; |
| 7449 | case TARGET_NR_fstatfs64: |
| 7450 | ret = get_errno(fstatfs(arg1, &stfs)); |
| 7451 | goto convert_statfs64; |
| 7452 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7453 | #ifdef TARGET_NR_ioperm |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7454 | case TARGET_NR_ioperm: |
| 7455 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7456 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7457 | #ifdef TARGET_NR_socketcall |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7458 | case TARGET_NR_socketcall: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7459 | ret = do_socketcall(arg1, arg2); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7460 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7461 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7462 | #ifdef TARGET_NR_accept |
| 7463 | case TARGET_NR_accept: |
Peter Maydell | a94b498 | 2013-02-08 04:35:04 +0000 | [diff] [blame] | 7464 | ret = do_accept4(arg1, arg2, arg3, 0); |
| 7465 | break; |
| 7466 | #endif |
| 7467 | #ifdef TARGET_NR_accept4 |
| 7468 | case TARGET_NR_accept4: |
| 7469 | #ifdef CONFIG_ACCEPT4 |
| 7470 | ret = do_accept4(arg1, arg2, arg3, arg4); |
| 7471 | #else |
| 7472 | goto unimplemented; |
| 7473 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7474 | break; |
| 7475 | #endif |
| 7476 | #ifdef TARGET_NR_bind |
| 7477 | case TARGET_NR_bind: |
| 7478 | ret = do_bind(arg1, arg2, arg3); |
| 7479 | break; |
| 7480 | #endif |
| 7481 | #ifdef TARGET_NR_connect |
| 7482 | case TARGET_NR_connect: |
| 7483 | ret = do_connect(arg1, arg2, arg3); |
| 7484 | break; |
| 7485 | #endif |
| 7486 | #ifdef TARGET_NR_getpeername |
| 7487 | case TARGET_NR_getpeername: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7488 | ret = do_getpeername(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7489 | break; |
| 7490 | #endif |
| 7491 | #ifdef TARGET_NR_getsockname |
| 7492 | case TARGET_NR_getsockname: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7493 | ret = do_getsockname(arg1, arg2, arg3); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7494 | break; |
| 7495 | #endif |
| 7496 | #ifdef TARGET_NR_getsockopt |
| 7497 | case TARGET_NR_getsockopt: |
| 7498 | ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5); |
| 7499 | break; |
| 7500 | #endif |
| 7501 | #ifdef TARGET_NR_listen |
| 7502 | case TARGET_NR_listen: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7503 | ret = get_errno(listen(arg1, arg2)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7504 | break; |
| 7505 | #endif |
| 7506 | #ifdef TARGET_NR_recv |
| 7507 | case TARGET_NR_recv: |
pbrook | 214201b | 2007-03-17 01:27:24 +0000 | [diff] [blame] | 7508 | ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7509 | break; |
| 7510 | #endif |
| 7511 | #ifdef TARGET_NR_recvfrom |
| 7512 | case TARGET_NR_recvfrom: |
pbrook | 214201b | 2007-03-17 01:27:24 +0000 | [diff] [blame] | 7513 | ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7514 | break; |
| 7515 | #endif |
| 7516 | #ifdef TARGET_NR_recvmsg |
| 7517 | case TARGET_NR_recvmsg: |
| 7518 | ret = do_sendrecvmsg(arg1, arg2, arg3, 0); |
| 7519 | break; |
| 7520 | #endif |
| 7521 | #ifdef TARGET_NR_send |
| 7522 | case TARGET_NR_send: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7523 | ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7524 | break; |
| 7525 | #endif |
| 7526 | #ifdef TARGET_NR_sendmsg |
| 7527 | case TARGET_NR_sendmsg: |
| 7528 | ret = do_sendrecvmsg(arg1, arg2, arg3, 1); |
| 7529 | break; |
| 7530 | #endif |
Alexander Graf | f19e00d | 2014-03-02 19:36:42 +0000 | [diff] [blame] | 7531 | #ifdef TARGET_NR_sendmmsg |
| 7532 | case TARGET_NR_sendmmsg: |
| 7533 | ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1); |
| 7534 | break; |
| 7535 | case TARGET_NR_recvmmsg: |
| 7536 | ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0); |
| 7537 | break; |
| 7538 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7539 | #ifdef TARGET_NR_sendto |
| 7540 | case TARGET_NR_sendto: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7541 | ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7542 | break; |
| 7543 | #endif |
| 7544 | #ifdef TARGET_NR_shutdown |
| 7545 | case TARGET_NR_shutdown: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7546 | ret = get_errno(shutdown(arg1, arg2)); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7547 | break; |
| 7548 | #endif |
Laurent Vivier | f894efd | 2016-02-21 10:56:23 +0100 | [diff] [blame] | 7549 | #if defined(TARGET_NR_getrandom) && defined(__NR_getrandom) |
| 7550 | case TARGET_NR_getrandom: |
| 7551 | p = lock_user(VERIFY_WRITE, arg1, arg2, 0); |
| 7552 | if (!p) { |
| 7553 | goto efault; |
| 7554 | } |
| 7555 | ret = get_errno(getrandom(p, arg2, arg3)); |
| 7556 | unlock_user(p, arg1, ret); |
| 7557 | break; |
| 7558 | #endif |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7559 | #ifdef TARGET_NR_socket |
| 7560 | case TARGET_NR_socket: |
| 7561 | ret = do_socket(arg1, arg2, arg3); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 7562 | fd_trans_unregister(ret); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7563 | break; |
| 7564 | #endif |
| 7565 | #ifdef TARGET_NR_socketpair |
| 7566 | case TARGET_NR_socketpair: |
pbrook | 1be9e1d | 2006-11-19 15:26:04 +0000 | [diff] [blame] | 7567 | ret = do_socketpair(arg1, arg2, arg3, arg4); |
bellard | 3532fa7 | 2006-06-24 15:06:03 +0000 | [diff] [blame] | 7568 | break; |
| 7569 | #endif |
| 7570 | #ifdef TARGET_NR_setsockopt |
| 7571 | case TARGET_NR_setsockopt: |
| 7572 | ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); |
| 7573 | break; |
| 7574 | #endif |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 7575 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7576 | case TARGET_NR_syslog: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7577 | if (!(p = lock_user_string(arg2))) |
| 7578 | goto efault; |
ths | e557448 | 2007-02-11 20:03:13 +0000 | [diff] [blame] | 7579 | ret = get_errno(sys_syslog((int)arg1, p, (int)arg3)); |
| 7580 | unlock_user(p, arg2, 0); |
ths | 7494b0f | 2007-02-11 18:26:53 +0000 | [diff] [blame] | 7581 | break; |
| 7582 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7583 | case TARGET_NR_setitimer: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7584 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7585 | struct itimerval value, ovalue, *pvalue; |
| 7586 | |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7587 | if (arg2) { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7588 | pvalue = &value; |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 7589 | if (copy_from_user_timeval(&pvalue->it_interval, arg2) |
| 7590 | || copy_from_user_timeval(&pvalue->it_value, |
| 7591 | arg2 + sizeof(struct target_timeval))) |
| 7592 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7593 | } else { |
| 7594 | pvalue = NULL; |
| 7595 | } |
| 7596 | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7597 | if (!is_error(ret) && arg3) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 7598 | if (copy_to_user_timeval(arg3, |
| 7599 | &ovalue.it_interval) |
| 7600 | || copy_to_user_timeval(arg3 + sizeof(struct target_timeval), |
| 7601 | &ovalue.it_value)) |
| 7602 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7603 | } |
| 7604 | } |
| 7605 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7606 | case TARGET_NR_getitimer: |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7607 | { |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7608 | struct itimerval value; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7609 | |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7610 | ret = get_errno(getitimer(arg1, &value)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7611 | if (!is_error(ret) && arg2) { |
ths | 788f5ec | 2007-12-09 02:37:05 +0000 | [diff] [blame] | 7612 | if (copy_to_user_timeval(arg2, |
| 7613 | &value.it_interval) |
| 7614 | || copy_to_user_timeval(arg2 + sizeof(struct target_timeval), |
| 7615 | &value.it_value)) |
| 7616 | goto efault; |
bellard | 66fb976 | 2003-03-23 01:06:05 +0000 | [diff] [blame] | 7617 | } |
| 7618 | } |
| 7619 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7620 | #ifdef TARGET_NR_stat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7621 | case TARGET_NR_stat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7622 | if (!(p = lock_user_string(arg1))) |
| 7623 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7624 | ret = get_errno(stat(path(p), &st)); |
| 7625 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7626 | goto do_stat; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7627 | #endif |
| 7628 | #ifdef TARGET_NR_lstat |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7629 | case TARGET_NR_lstat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7630 | if (!(p = lock_user_string(arg1))) |
| 7631 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7632 | ret = get_errno(lstat(path(p), &st)); |
| 7633 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7634 | goto do_stat; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7635 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7636 | case TARGET_NR_fstat: |
| 7637 | { |
| 7638 | ret = get_errno(fstat(arg1, &st)); |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7639 | #if defined(TARGET_NR_stat) || defined(TARGET_NR_lstat) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7640 | do_stat: |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7641 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7642 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7643 | struct target_stat *target_st; |
ths | e358465 | 2007-06-01 11:49:38 +0000 | [diff] [blame] | 7644 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7645 | if (!lock_user_struct(VERIFY_WRITE, target_st, arg2, 0)) |
| 7646 | goto efault; |
Ulrich Hecht | 1272791 | 2009-07-24 19:10:32 +0200 | [diff] [blame] | 7647 | memset(target_st, 0, sizeof(*target_st)); |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 7648 | __put_user(st.st_dev, &target_st->st_dev); |
| 7649 | __put_user(st.st_ino, &target_st->st_ino); |
| 7650 | __put_user(st.st_mode, &target_st->st_mode); |
| 7651 | __put_user(st.st_uid, &target_st->st_uid); |
| 7652 | __put_user(st.st_gid, &target_st->st_gid); |
| 7653 | __put_user(st.st_nlink, &target_st->st_nlink); |
| 7654 | __put_user(st.st_rdev, &target_st->st_rdev); |
| 7655 | __put_user(st.st_size, &target_st->st_size); |
| 7656 | __put_user(st.st_blksize, &target_st->st_blksize); |
| 7657 | __put_user(st.st_blocks, &target_st->st_blocks); |
| 7658 | __put_user(st.st_atime, &target_st->target_st_atime); |
| 7659 | __put_user(st.st_mtime, &target_st->target_st_mtime); |
| 7660 | __put_user(st.st_ctime, &target_st->target_st_ctime); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7661 | unlock_user_struct(target_st, arg2, 1); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7662 | } |
| 7663 | } |
| 7664 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7665 | #ifdef TARGET_NR_olduname |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7666 | case TARGET_NR_olduname: |
| 7667 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7668 | #endif |
| 7669 | #ifdef TARGET_NR_iopl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7670 | case TARGET_NR_iopl: |
| 7671 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7672 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7673 | case TARGET_NR_vhangup: |
| 7674 | ret = get_errno(vhangup()); |
| 7675 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7676 | #ifdef TARGET_NR_idle |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7677 | case TARGET_NR_idle: |
| 7678 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 7679 | #endif |
bellard | 42ad6ae | 2005-01-03 22:48:11 +0000 | [diff] [blame] | 7680 | #ifdef TARGET_NR_syscall |
| 7681 | case TARGET_NR_syscall: |
Peter Maydell | 5945cfc | 2011-06-16 17:37:13 +0100 | [diff] [blame] | 7682 | ret = do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, |
| 7683 | arg6, arg7, arg8, 0); |
| 7684 | break; |
bellard | 42ad6ae | 2005-01-03 22:48:11 +0000 | [diff] [blame] | 7685 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7686 | case TARGET_NR_wait4: |
| 7687 | { |
| 7688 | int status; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7689 | abi_long status_ptr = arg2; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7690 | struct rusage rusage, *rusage_ptr; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7691 | abi_ulong target_rusage = arg4; |
Petar Jovanovic | a39fb27 | 2014-04-08 19:24:30 +0200 | [diff] [blame] | 7692 | abi_long rusage_err; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7693 | if (target_rusage) |
| 7694 | rusage_ptr = &rusage; |
| 7695 | else |
| 7696 | rusage_ptr = NULL; |
| 7697 | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); |
| 7698 | if (!is_error(ret)) { |
Alexander Graf | 5379557 | 2011-11-24 00:44:43 +0100 | [diff] [blame] | 7699 | if (status_ptr && ret) { |
pbrook | 1d9d8b5 | 2009-04-16 15:17:02 +0000 | [diff] [blame] | 7700 | status = host_to_target_waitstatus(status); |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 7701 | if (put_user_s32(status, status_ptr)) |
| 7702 | goto efault; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7703 | } |
Petar Jovanovic | a39fb27 | 2014-04-08 19:24:30 +0200 | [diff] [blame] | 7704 | if (target_rusage) { |
| 7705 | rusage_err = host_to_target_rusage(target_rusage, &rusage); |
| 7706 | if (rusage_err) { |
| 7707 | ret = rusage_err; |
| 7708 | } |
| 7709 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7710 | } |
| 7711 | } |
| 7712 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7713 | #ifdef TARGET_NR_swapoff |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7714 | case TARGET_NR_swapoff: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7715 | if (!(p = lock_user_string(arg1))) |
| 7716 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7717 | ret = get_errno(swapoff(p)); |
| 7718 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7719 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7720 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7721 | case TARGET_NR_sysinfo: |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 7722 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7723 | struct target_sysinfo *target_value; |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 7724 | struct sysinfo value; |
| 7725 | ret = get_errno(sysinfo(&value)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7726 | if (!is_error(ret) && arg1) |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 7727 | { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7728 | if (!lock_user_struct(VERIFY_WRITE, target_value, arg1, 0)) |
| 7729 | goto efault; |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 7730 | __put_user(value.uptime, &target_value->uptime); |
| 7731 | __put_user(value.loads[0], &target_value->loads[0]); |
| 7732 | __put_user(value.loads[1], &target_value->loads[1]); |
| 7733 | __put_user(value.loads[2], &target_value->loads[2]); |
| 7734 | __put_user(value.totalram, &target_value->totalram); |
| 7735 | __put_user(value.freeram, &target_value->freeram); |
| 7736 | __put_user(value.sharedram, &target_value->sharedram); |
| 7737 | __put_user(value.bufferram, &target_value->bufferram); |
| 7738 | __put_user(value.totalswap, &target_value->totalswap); |
| 7739 | __put_user(value.freeswap, &target_value->freeswap); |
| 7740 | __put_user(value.procs, &target_value->procs); |
| 7741 | __put_user(value.totalhigh, &target_value->totalhigh); |
| 7742 | __put_user(value.freehigh, &target_value->freehigh); |
| 7743 | __put_user(value.mem_unit, &target_value->mem_unit); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7744 | unlock_user_struct(target_value, arg1, 1); |
bellard | a5448a7 | 2004-06-19 16:59:03 +0000 | [diff] [blame] | 7745 | } |
| 7746 | } |
| 7747 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7748 | #ifdef TARGET_NR_ipc |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7749 | case TARGET_NR_ipc: |
bellard | 8853f86 | 2004-02-22 14:57:26 +0000 | [diff] [blame] | 7750 | ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6); |
| 7751 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7752 | #endif |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 7753 | #ifdef TARGET_NR_semget |
| 7754 | case TARGET_NR_semget: |
| 7755 | ret = get_errno(semget(arg1, arg2, arg3)); |
| 7756 | break; |
| 7757 | #endif |
| 7758 | #ifdef TARGET_NR_semop |
| 7759 | case TARGET_NR_semop: |
Petar Jovanovic | c7128c9 | 2013-03-21 07:57:36 +0000 | [diff] [blame] | 7760 | ret = do_semop(arg1, arg2, arg3); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 7761 | break; |
| 7762 | #endif |
| 7763 | #ifdef TARGET_NR_semctl |
| 7764 | case TARGET_NR_semctl: |
Stefan Weil | d1c002b | 2015-02-08 15:40:58 +0100 | [diff] [blame] | 7765 | ret = do_semctl(arg1, arg2, arg3, arg4); |
aurel32 | e528908 | 2009-04-18 16:16:12 +0000 | [diff] [blame] | 7766 | break; |
| 7767 | #endif |
aurel32 | eeb438c | 2008-10-13 21:08:55 +0000 | [diff] [blame] | 7768 | #ifdef TARGET_NR_msgctl |
| 7769 | case TARGET_NR_msgctl: |
| 7770 | ret = do_msgctl(arg1, arg2, arg3); |
| 7771 | break; |
| 7772 | #endif |
| 7773 | #ifdef TARGET_NR_msgget |
| 7774 | case TARGET_NR_msgget: |
| 7775 | ret = get_errno(msgget(arg1, arg2)); |
| 7776 | break; |
| 7777 | #endif |
| 7778 | #ifdef TARGET_NR_msgrcv |
| 7779 | case TARGET_NR_msgrcv: |
| 7780 | ret = do_msgrcv(arg1, arg2, arg3, arg4, arg5); |
| 7781 | break; |
| 7782 | #endif |
| 7783 | #ifdef TARGET_NR_msgsnd |
| 7784 | case TARGET_NR_msgsnd: |
| 7785 | ret = do_msgsnd(arg1, arg2, arg3, arg4); |
| 7786 | break; |
| 7787 | #endif |
Riku Voipio | 88a8c98 | 2009-04-03 10:42:00 +0300 | [diff] [blame] | 7788 | #ifdef TARGET_NR_shmget |
| 7789 | case TARGET_NR_shmget: |
| 7790 | ret = get_errno(shmget(arg1, arg2, arg3)); |
| 7791 | break; |
| 7792 | #endif |
| 7793 | #ifdef TARGET_NR_shmctl |
| 7794 | case TARGET_NR_shmctl: |
| 7795 | ret = do_shmctl(arg1, arg2, arg3); |
| 7796 | break; |
| 7797 | #endif |
| 7798 | #ifdef TARGET_NR_shmat |
| 7799 | case TARGET_NR_shmat: |
| 7800 | ret = do_shmat(arg1, arg2, arg3); |
| 7801 | break; |
| 7802 | #endif |
| 7803 | #ifdef TARGET_NR_shmdt |
| 7804 | case TARGET_NR_shmdt: |
| 7805 | ret = do_shmdt(arg1); |
| 7806 | break; |
| 7807 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7808 | case TARGET_NR_fsync: |
| 7809 | ret = get_errno(fsync(arg1)); |
| 7810 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7811 | case TARGET_NR_clone: |
Peter Maydell | 4ce6243 | 2013-07-16 18:44:57 +0100 | [diff] [blame] | 7812 | /* Linux manages to have three different orderings for its |
| 7813 | * arguments to clone(); the BACKWARDS and BACKWARDS2 defines |
| 7814 | * match the kernel's CONFIG_CLONE_* settings. |
| 7815 | * Microblaze is further special in that it uses a sixth |
| 7816 | * implicit argument to clone for the TLS pointer. |
| 7817 | */ |
| 7818 | #if defined(TARGET_MICROBLAZE) |
Edgar E. Iglesias | a5b3bdc | 2012-04-26 14:17:41 +0200 | [diff] [blame] | 7819 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5)); |
Peter Maydell | 4ce6243 | 2013-07-16 18:44:57 +0100 | [diff] [blame] | 7820 | #elif defined(TARGET_CLONE_BACKWARDS) |
| 7821 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5)); |
| 7822 | #elif defined(TARGET_CLONE_BACKWARDS2) |
Ulrich Hecht | a4c075f | 2009-07-24 16:57:31 +0200 | [diff] [blame] | 7823 | ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4)); |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 7824 | #else |
Peter Maydell | 4ce6243 | 2013-07-16 18:44:57 +0100 | [diff] [blame] | 7825 | ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4)); |
aurel32 | 0b6d3ae | 2008-09-15 07:43:43 +0000 | [diff] [blame] | 7826 | #endif |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7827 | break; |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 7828 | #ifdef __NR_exit_group |
| 7829 | /* new thread calls */ |
| 7830 | case TARGET_NR_exit_group: |
Juan Quintela | 9788c9c | 2009-07-27 16:13:02 +0200 | [diff] [blame] | 7831 | #ifdef TARGET_GPROF |
aurel32 | 6d946cd | 2008-11-06 16:15:18 +0000 | [diff] [blame] | 7832 | _mcleanup(); |
| 7833 | #endif |
bellard | e900967 | 2005-04-26 20:42:36 +0000 | [diff] [blame] | 7834 | gdb_exit(cpu_env, arg1); |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 7835 | ret = get_errno(exit_group(arg1)); |
| 7836 | break; |
| 7837 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7838 | case TARGET_NR_setdomainname: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7839 | if (!(p = lock_user_string(arg1))) |
| 7840 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7841 | ret = get_errno(setdomainname(p, arg2)); |
| 7842 | unlock_user(p, arg1, 0); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7843 | break; |
| 7844 | case TARGET_NR_uname: |
| 7845 | /* no need to transcode because we use the linux syscall */ |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 7846 | { |
| 7847 | struct new_utsname * buf; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7848 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7849 | if (!lock_user_struct(VERIFY_WRITE, buf, arg1, 0)) |
| 7850 | goto efault; |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 7851 | ret = get_errno(sys_uname(buf)); |
| 7852 | if (!is_error(ret)) { |
| 7853 | /* Overrite the native machine name with whatever is being |
| 7854 | emulated. */ |
LoĂŻc Minier | da79030 | 2009-12-29 22:06:13 +0100 | [diff] [blame] | 7855 | strcpy (buf->machine, cpu_to_uname_machine(cpu_env)); |
pbrook | c593722 | 2006-05-14 11:30:38 +0000 | [diff] [blame] | 7856 | /* Allow the user to override the reported release. */ |
| 7857 | if (qemu_uname_release && *qemu_uname_release) |
| 7858 | strcpy (buf->release, qemu_uname_release); |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 7859 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7860 | unlock_user_struct(buf, arg1, 1); |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 7861 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7862 | break; |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 7863 | #ifdef TARGET_I386 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7864 | case TARGET_NR_modify_ldt: |
bellard | 03acab6 | 2007-11-11 14:57:14 +0000 | [diff] [blame] | 7865 | ret = do_modify_ldt(cpu_env, arg1, arg2, arg3); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7866 | break; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 7867 | #if !defined(TARGET_X86_64) |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 7868 | case TARGET_NR_vm86old: |
| 7869 | goto unimplemented; |
| 7870 | case TARGET_NR_vm86: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7871 | ret = do_vm86(cpu_env, arg1, arg2); |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 7872 | break; |
| 7873 | #endif |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 7874 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7875 | case TARGET_NR_adjtimex: |
| 7876 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7877 | #ifdef TARGET_NR_create_module |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7878 | case TARGET_NR_create_module: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7879 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7880 | case TARGET_NR_init_module: |
| 7881 | case TARGET_NR_delete_module: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7882 | #ifdef TARGET_NR_get_kernel_syms |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7883 | case TARGET_NR_get_kernel_syms: |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7884 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7885 | goto unimplemented; |
| 7886 | case TARGET_NR_quotactl: |
| 7887 | goto unimplemented; |
| 7888 | case TARGET_NR_getpgid: |
| 7889 | ret = get_errno(getpgid(arg1)); |
| 7890 | break; |
| 7891 | case TARGET_NR_fchdir: |
| 7892 | ret = get_errno(fchdir(arg1)); |
| 7893 | break; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 7894 | #ifdef TARGET_NR_bdflush /* not on x86_64 */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7895 | case TARGET_NR_bdflush: |
| 7896 | goto unimplemented; |
j_mayer | 84409dd | 2007-04-06 08:56:50 +0000 | [diff] [blame] | 7897 | #endif |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7898 | #ifdef TARGET_NR_sysfs |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7899 | case TARGET_NR_sysfs: |
| 7900 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7901 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7902 | case TARGET_NR_personality: |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 7903 | ret = get_errno(personality(arg1)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7904 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7905 | #ifdef TARGET_NR_afs_syscall |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7906 | case TARGET_NR_afs_syscall: |
| 7907 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 7908 | #endif |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7909 | #ifdef TARGET_NR__llseek /* Not on alpha */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7910 | case TARGET_NR__llseek: |
| 7911 | { |
| 7912 | int64_t res; |
Peter Maydell | 0c1592d | 2011-02-22 13:02:26 +0000 | [diff] [blame] | 7913 | #if !defined(__NR_llseek) |
| 7914 | res = lseek(arg1, ((uint64_t)arg2 << 32) | arg3, arg5); |
| 7915 | if (res == -1) { |
| 7916 | ret = get_errno(res); |
| 7917 | } else { |
| 7918 | ret = 0; |
| 7919 | } |
| 7920 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7921 | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 7922 | #endif |
Peter Maydell | 0c1592d | 2011-02-22 13:02:26 +0000 | [diff] [blame] | 7923 | if ((ret == 0) && put_user_s64(res, arg4)) { |
| 7924 | goto efault; |
| 7925 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7926 | } |
| 7927 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 7928 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 7929 | #ifdef TARGET_NR_getdents |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7930 | case TARGET_NR_getdents: |
Peter Maydell | 3307e23 | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 7931 | #ifdef __NR_getdents |
Ulrich Hecht | d83c873 | 2009-07-24 19:10:28 +0200 | [diff] [blame] | 7932 | #if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7933 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 7934 | struct target_dirent *target_dirp; |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7935 | struct linux_dirent *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7936 | abi_long count = arg3; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7937 | |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 7938 | dirp = g_try_malloc(count); |
| 7939 | if (!dirp) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7940 | ret = -TARGET_ENOMEM; |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 7941 | goto fail; |
| 7942 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 7943 | |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7944 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
| 7945 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7946 | struct linux_dirent *de; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7947 | struct target_dirent *tde; |
| 7948 | int len = ret; |
| 7949 | int reclen, treclen; |
| 7950 | int count1, tnamelen; |
| 7951 | |
| 7952 | count1 = 0; |
| 7953 | de = dirp; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7954 | if (!(target_dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7955 | goto efault; |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7956 | tde = target_dirp; |
| 7957 | while (len > 0) { |
| 7958 | reclen = de->d_reclen; |
Dmitry V. Levin | 333858b | 2012-08-21 02:13:12 +0400 | [diff] [blame] | 7959 | tnamelen = reclen - offsetof(struct linux_dirent, d_name); |
| 7960 | assert(tnamelen >= 0); |
| 7961 | treclen = tnamelen + offsetof(struct target_dirent, d_name); |
| 7962 | assert(count1 + treclen <= count); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7963 | tde->d_reclen = tswap16(treclen); |
Matthias Braun | cbb21ee | 2011-08-12 19:57:41 +0200 | [diff] [blame] | 7964 | tde->d_ino = tswapal(de->d_ino); |
| 7965 | tde->d_off = tswapal(de->d_off); |
Dmitry V. Levin | 333858b | 2012-08-21 02:13:12 +0400 | [diff] [blame] | 7966 | memcpy(tde->d_name, de->d_name, tnamelen); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7967 | de = (struct linux_dirent *)((char *)de + reclen); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7968 | len -= reclen; |
j_mayer | 1c5bf3b | 2007-04-14 12:17:59 +0000 | [diff] [blame] | 7969 | tde = (struct target_dirent *)((char *)tde + treclen); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7970 | count1 += treclen; |
| 7971 | } |
| 7972 | ret = count1; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7973 | unlock_user(target_dirp, arg2, ret); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7974 | } |
Harmandeep Kaur | 0e173b2 | 2015-10-06 21:47:12 +0530 | [diff] [blame] | 7975 | g_free(dirp); |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 7976 | } |
| 7977 | #else |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7978 | { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7979 | struct linux_dirent *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 7980 | abi_long count = arg3; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 7981 | |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 7982 | if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 7983 | goto efault; |
bellard | 72f0390 | 2003-02-18 23:33:18 +0000 | [diff] [blame] | 7984 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7985 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7986 | struct linux_dirent *de; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7987 | int len = ret; |
| 7988 | int reclen; |
| 7989 | de = dirp; |
| 7990 | while (len > 0) { |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7991 | reclen = de->d_reclen; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7992 | if (reclen > len) |
| 7993 | break; |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 7994 | de->d_reclen = tswap16(reclen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7995 | tswapls(&de->d_ino); |
| 7996 | tswapls(&de->d_off); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 7997 | de = (struct linux_dirent *)((char *)de + reclen); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 7998 | len -= reclen; |
| 7999 | } |
| 8000 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8001 | unlock_user(dirp, arg2, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8002 | } |
bellard | 4add45b | 2003-06-05 01:52:59 +0000 | [diff] [blame] | 8003 | #endif |
Peter Maydell | 3307e23 | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 8004 | #else |
| 8005 | /* Implement getdents in terms of getdents64 */ |
| 8006 | { |
| 8007 | struct linux_dirent64 *dirp; |
| 8008 | abi_long count = arg3; |
| 8009 | |
| 8010 | dirp = lock_user(VERIFY_WRITE, arg2, count, 0); |
| 8011 | if (!dirp) { |
| 8012 | goto efault; |
| 8013 | } |
| 8014 | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
| 8015 | if (!is_error(ret)) { |
| 8016 | /* Convert the dirent64 structs to target dirent. We do this |
| 8017 | * in-place, since we can guarantee that a target_dirent is no |
| 8018 | * larger than a dirent64; however this means we have to be |
| 8019 | * careful to read everything before writing in the new format. |
| 8020 | */ |
| 8021 | struct linux_dirent64 *de; |
| 8022 | struct target_dirent *tde; |
| 8023 | int len = ret; |
| 8024 | int tlen = 0; |
| 8025 | |
| 8026 | de = dirp; |
| 8027 | tde = (struct target_dirent *)dirp; |
| 8028 | while (len > 0) { |
| 8029 | int namelen, treclen; |
| 8030 | int reclen = de->d_reclen; |
| 8031 | uint64_t ino = de->d_ino; |
| 8032 | int64_t off = de->d_off; |
| 8033 | uint8_t type = de->d_type; |
| 8034 | |
| 8035 | namelen = strlen(de->d_name); |
| 8036 | treclen = offsetof(struct target_dirent, d_name) |
| 8037 | + namelen + 2; |
| 8038 | treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long)); |
| 8039 | |
| 8040 | memmove(tde->d_name, de->d_name, namelen + 1); |
| 8041 | tde->d_ino = tswapal(ino); |
| 8042 | tde->d_off = tswapal(off); |
| 8043 | tde->d_reclen = tswap16(treclen); |
| 8044 | /* The target_dirent type is in what was formerly a padding |
| 8045 | * byte at the end of the structure: |
| 8046 | */ |
| 8047 | *(((char *)tde) + treclen - 1) = type; |
| 8048 | |
| 8049 | de = (struct linux_dirent64 *)((char *)de + reclen); |
| 8050 | tde = (struct target_dirent *)((char *)tde + treclen); |
| 8051 | len -= reclen; |
| 8052 | tlen += treclen; |
| 8053 | } |
| 8054 | ret = tlen; |
| 8055 | } |
| 8056 | unlock_user(dirp, arg2, ret); |
| 8057 | } |
| 8058 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8059 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8060 | #endif /* TARGET_NR_getdents */ |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 8061 | #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 8062 | case TARGET_NR_getdents64: |
| 8063 | { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 8064 | struct linux_dirent64 *dirp; |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 8065 | abi_long count = arg3; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8066 | if (!(dirp = lock_user(VERIFY_WRITE, arg2, count, 0))) |
| 8067 | goto efault; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 8068 | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
| 8069 | if (!is_error(ret)) { |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 8070 | struct linux_dirent64 *de; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 8071 | int len = ret; |
| 8072 | int reclen; |
| 8073 | de = dirp; |
| 8074 | while (len > 0) { |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 8075 | reclen = de->d_reclen; |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 8076 | if (reclen > len) |
| 8077 | break; |
bellard | 8083a3e | 2003-03-24 23:12:16 +0000 | [diff] [blame] | 8078 | de->d_reclen = tswap16(reclen); |
bellard | 8582a53 | 2007-11-11 23:11:36 +0000 | [diff] [blame] | 8079 | tswap64s((uint64_t *)&de->d_ino); |
| 8080 | tswap64s((uint64_t *)&de->d_off); |
aurel32 | 6556a83 | 2008-10-13 21:08:17 +0000 | [diff] [blame] | 8081 | de = (struct linux_dirent64 *)((char *)de + reclen); |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 8082 | len -= reclen; |
| 8083 | } |
| 8084 | } |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8085 | unlock_user(dirp, arg2, ret); |
bellard | dab2ed9 | 2003-03-22 15:23:14 +0000 | [diff] [blame] | 8086 | } |
| 8087 | break; |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 8088 | #endif /* TARGET_NR_getdents64 */ |
Laurent Vivier | 9468a5d | 2013-01-10 22:30:50 +0100 | [diff] [blame] | 8089 | #if defined(TARGET_NR__newselect) |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8090 | case TARGET_NR__newselect: |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8091 | ret = do_select(arg1, arg2, arg3, arg4, arg5); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8092 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8093 | #endif |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 8094 | #if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) |
| 8095 | # ifdef TARGET_NR_poll |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8096 | case TARGET_NR_poll: |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 8097 | # endif |
| 8098 | # ifdef TARGET_NR_ppoll |
| 8099 | case TARGET_NR_ppoll: |
| 8100 | # endif |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8101 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8102 | struct target_pollfd *target_pfd; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8103 | unsigned int nfds = arg2; |
| 8104 | int timeout = arg3; |
| 8105 | struct pollfd *pfd; |
bellard | 7854b05 | 2003-03-29 17:22:23 +0000 | [diff] [blame] | 8106 | unsigned int i; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8107 | |
Laurent Vivier | 3e24bb3 | 2015-10-06 01:20:48 +0200 | [diff] [blame] | 8108 | pfd = NULL; |
| 8109 | target_pfd = NULL; |
| 8110 | if (nfds) { |
| 8111 | target_pfd = lock_user(VERIFY_WRITE, arg1, |
| 8112 | sizeof(struct target_pollfd) * nfds, 1); |
| 8113 | if (!target_pfd) { |
| 8114 | goto efault; |
| 8115 | } |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 8116 | |
Laurent Vivier | 3e24bb3 | 2015-10-06 01:20:48 +0200 | [diff] [blame] | 8117 | pfd = alloca(sizeof(struct pollfd) * nfds); |
| 8118 | for (i = 0; i < nfds; i++) { |
| 8119 | pfd[i].fd = tswap32(target_pfd[i].fd); |
| 8120 | pfd[i].events = tswap16(target_pfd[i].events); |
| 8121 | } |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8122 | } |
Mike Frysinger | d8035d4 | 2011-02-07 01:05:51 -0500 | [diff] [blame] | 8123 | |
| 8124 | # ifdef TARGET_NR_ppoll |
| 8125 | if (num == TARGET_NR_ppoll) { |
| 8126 | struct timespec _timeout_ts, *timeout_ts = &_timeout_ts; |
| 8127 | target_sigset_t *target_set; |
| 8128 | sigset_t _set, *set = &_set; |
| 8129 | |
| 8130 | if (arg3) { |
| 8131 | if (target_to_host_timespec(timeout_ts, arg3)) { |
| 8132 | unlock_user(target_pfd, arg1, 0); |
| 8133 | goto efault; |
| 8134 | } |
| 8135 | } else { |
| 8136 | timeout_ts = NULL; |
| 8137 | } |
| 8138 | |
| 8139 | if (arg4) { |
| 8140 | target_set = lock_user(VERIFY_READ, arg4, sizeof(target_sigset_t), 1); |
| 8141 | if (!target_set) { |
| 8142 | unlock_user(target_pfd, arg1, 0); |
| 8143 | goto efault; |
| 8144 | } |
| 8145 | target_to_host_sigset(set, target_set); |
| 8146 | } else { |
| 8147 | set = NULL; |
| 8148 | } |
| 8149 | |
| 8150 | ret = get_errno(sys_ppoll(pfd, nfds, timeout_ts, set, _NSIG/8)); |
| 8151 | |
| 8152 | if (!is_error(ret) && arg3) { |
| 8153 | host_to_target_timespec(arg3, timeout_ts); |
| 8154 | } |
| 8155 | if (arg4) { |
| 8156 | unlock_user(target_set, arg4, 0); |
| 8157 | } |
| 8158 | } else |
| 8159 | # endif |
| 8160 | ret = get_errno(poll(pfd, nfds, timeout)); |
| 8161 | |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8162 | if (!is_error(ret)) { |
| 8163 | for(i = 0; i < nfds; i++) { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8164 | target_pfd[i].revents = tswap16(pfd[i].revents); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8165 | } |
| 8166 | } |
Peter Maydell | 30cb4cd | 2011-02-25 10:27:40 +0000 | [diff] [blame] | 8167 | unlock_user(target_pfd, arg1, sizeof(struct target_pollfd) * nfds); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8168 | } |
| 8169 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8170 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8171 | case TARGET_NR_flock: |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 8172 | /* NOTE: the flock constant seems to be the same for every |
| 8173 | Linux platform */ |
| 8174 | ret = get_errno(flock(arg1, arg2)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8175 | break; |
| 8176 | case TARGET_NR_readv: |
| 8177 | { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 8178 | struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0); |
| 8179 | if (vec != NULL) { |
| 8180 | ret = get_errno(readv(arg1, vec, arg3)); |
| 8181 | unlock_iovec(vec, arg2, arg3, 1); |
| 8182 | } else { |
| 8183 | ret = -host_to_target_errno(errno); |
| 8184 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8185 | } |
| 8186 | break; |
| 8187 | case TARGET_NR_writev: |
| 8188 | { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 8189 | struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1); |
| 8190 | if (vec != NULL) { |
| 8191 | ret = get_errno(writev(arg1, vec, arg3)); |
| 8192 | unlock_iovec(vec, arg2, arg3, 0); |
| 8193 | } else { |
| 8194 | ret = -host_to_target_errno(errno); |
| 8195 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8196 | } |
| 8197 | break; |
| 8198 | case TARGET_NR_getsid: |
| 8199 | ret = get_errno(getsid(arg1)); |
| 8200 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 8201 | #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */ |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8202 | case TARGET_NR_fdatasync: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8203 | ret = get_errno(fdatasync(arg1)); |
| 8204 | break; |
j_mayer | 7a3148a | 2007-04-05 07:13:51 +0000 | [diff] [blame] | 8205 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8206 | #ifdef TARGET_NR__sysctl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8207 | case TARGET_NR__sysctl: |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 8208 | /* We don't implement this, but ENOTDIR is always a safe |
bellard | 29e619b | 2004-09-13 21:41:04 +0000 | [diff] [blame] | 8209 | return value. */ |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 8210 | ret = -TARGET_ENOTDIR; |
| 8211 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8212 | #endif |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 8213 | case TARGET_NR_sched_getaffinity: |
| 8214 | { |
| 8215 | unsigned int mask_size; |
| 8216 | unsigned long *mask; |
| 8217 | |
| 8218 | /* |
| 8219 | * sched_getaffinity needs multiples of ulong, so need to take |
| 8220 | * care of mismatches between target ulong and host ulong sizes. |
| 8221 | */ |
| 8222 | if (arg2 & (sizeof(abi_ulong) - 1)) { |
| 8223 | ret = -TARGET_EINVAL; |
| 8224 | break; |
| 8225 | } |
| 8226 | mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); |
| 8227 | |
| 8228 | mask = alloca(mask_size); |
| 8229 | ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); |
| 8230 | |
| 8231 | if (!is_error(ret)) { |
Peter Maydell | be3bd28 | 2014-05-15 14:40:23 +0100 | [diff] [blame] | 8232 | if (ret > arg2) { |
| 8233 | /* More data returned than the caller's buffer will fit. |
| 8234 | * This only happens if sizeof(abi_long) < sizeof(long) |
| 8235 | * and the caller passed us a buffer holding an odd number |
| 8236 | * of abi_longs. If the host kernel is actually using the |
| 8237 | * extra 4 bytes then fail EINVAL; otherwise we can just |
| 8238 | * ignore them and only copy the interesting part. |
| 8239 | */ |
| 8240 | int numcpus = sysconf(_SC_NPROCESSORS_CONF); |
| 8241 | if (numcpus > arg2 * 8) { |
| 8242 | ret = -TARGET_EINVAL; |
| 8243 | break; |
| 8244 | } |
| 8245 | ret = arg2; |
| 8246 | } |
| 8247 | |
Mike McCormack | cd18f05 | 2011-04-18 14:43:36 +0900 | [diff] [blame] | 8248 | if (copy_to_user(arg3, mask, ret)) { |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 8249 | goto efault; |
| 8250 | } |
Mike Frysinger | 737de1d | 2011-02-07 01:05:55 -0500 | [diff] [blame] | 8251 | } |
| 8252 | } |
| 8253 | break; |
| 8254 | case TARGET_NR_sched_setaffinity: |
| 8255 | { |
| 8256 | unsigned int mask_size; |
| 8257 | unsigned long *mask; |
| 8258 | |
| 8259 | /* |
| 8260 | * sched_setaffinity needs multiples of ulong, so need to take |
| 8261 | * care of mismatches between target ulong and host ulong sizes. |
| 8262 | */ |
| 8263 | if (arg2 & (sizeof(abi_ulong) - 1)) { |
| 8264 | ret = -TARGET_EINVAL; |
| 8265 | break; |
| 8266 | } |
| 8267 | mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); |
| 8268 | |
| 8269 | mask = alloca(mask_size); |
| 8270 | if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) { |
| 8271 | goto efault; |
| 8272 | } |
| 8273 | memcpy(mask, p, arg2); |
| 8274 | unlock_user_struct(p, arg2, 0); |
| 8275 | |
| 8276 | ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask)); |
| 8277 | } |
| 8278 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8279 | case TARGET_NR_sched_setparam: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8280 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8281 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8282 | struct sched_param schp; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8283 | |
Tom Musta | a1d5c5b | 2014-08-12 13:53:38 -0500 | [diff] [blame] | 8284 | if (arg2 == 0) { |
| 8285 | return -TARGET_EINVAL; |
| 8286 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8287 | if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1)) |
| 8288 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8289 | schp.sched_priority = tswap32(target_schp->sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8290 | unlock_user_struct(target_schp, arg2, 0); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8291 | ret = get_errno(sched_setparam(arg1, &schp)); |
| 8292 | } |
| 8293 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8294 | case TARGET_NR_sched_getparam: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8295 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8296 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8297 | struct sched_param schp; |
Tom Musta | a1d5c5b | 2014-08-12 13:53:38 -0500 | [diff] [blame] | 8298 | |
| 8299 | if (arg2 == 0) { |
| 8300 | return -TARGET_EINVAL; |
| 8301 | } |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8302 | ret = get_errno(sched_getparam(arg1, &schp)); |
| 8303 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8304 | if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0)) |
| 8305 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8306 | target_schp->sched_priority = tswap32(schp.sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8307 | unlock_user_struct(target_schp, arg2, 1); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8308 | } |
| 8309 | } |
| 8310 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8311 | case TARGET_NR_sched_setscheduler: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8312 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8313 | struct sched_param *target_schp; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8314 | struct sched_param schp; |
Tom Musta | a1d5c5b | 2014-08-12 13:53:38 -0500 | [diff] [blame] | 8315 | if (arg3 == 0) { |
| 8316 | return -TARGET_EINVAL; |
| 8317 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8318 | if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1)) |
| 8319 | goto efault; |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8320 | schp.sched_priority = tswap32(target_schp->sched_priority); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8321 | unlock_user_struct(target_schp, arg3, 0); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8322 | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); |
| 8323 | } |
| 8324 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8325 | case TARGET_NR_sched_getscheduler: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8326 | ret = get_errno(sched_getscheduler(arg1)); |
| 8327 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8328 | case TARGET_NR_sched_yield: |
| 8329 | ret = get_errno(sched_yield()); |
| 8330 | break; |
| 8331 | case TARGET_NR_sched_get_priority_max: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8332 | ret = get_errno(sched_get_priority_max(arg1)); |
| 8333 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8334 | case TARGET_NR_sched_get_priority_min: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8335 | ret = get_errno(sched_get_priority_min(arg1)); |
| 8336 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8337 | case TARGET_NR_sched_rr_get_interval: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8338 | { |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8339 | struct timespec ts; |
| 8340 | ret = get_errno(sched_rr_get_interval(arg1, &ts)); |
| 8341 | if (!is_error(ret)) { |
Tom Musta | d4290c4 | 2014-08-12 13:53:39 -0500 | [diff] [blame] | 8342 | ret = host_to_target_timespec(arg2, &ts); |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8343 | } |
| 8344 | } |
| 8345 | break; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8346 | case TARGET_NR_nanosleep: |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 8347 | { |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 8348 | struct timespec req, rem; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8349 | target_to_host_timespec(&req, arg1); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 8350 | ret = get_errno(nanosleep(&req, &rem)); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8351 | if (is_error(ret) && arg2) { |
| 8352 | host_to_target_timespec(arg2, &rem); |
bellard | 1b6b029 | 2003-03-22 17:31:38 +0000 | [diff] [blame] | 8353 | } |
| 8354 | } |
| 8355 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8356 | #ifdef TARGET_NR_query_module |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8357 | case TARGET_NR_query_module: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8358 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8359 | #endif |
| 8360 | #ifdef TARGET_NR_nfsservctl |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8361 | case TARGET_NR_nfsservctl: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8362 | goto unimplemented; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 8363 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8364 | case TARGET_NR_prctl: |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 8365 | switch (arg1) { |
| 8366 | case PR_GET_PDEATHSIG: |
| 8367 | { |
| 8368 | int deathsig; |
| 8369 | ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5)); |
| 8370 | if (!is_error(ret) && arg2 |
| 8371 | && put_user_ual(deathsig, arg2)) { |
| 8372 | goto efault; |
ths | e557448 | 2007-02-11 20:03:13 +0000 | [diff] [blame] | 8373 | } |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 8374 | break; |
| 8375 | } |
Peter Maydell | db9526b | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 8376 | #ifdef PR_GET_NAME |
| 8377 | case PR_GET_NAME: |
| 8378 | { |
| 8379 | void *name = lock_user(VERIFY_WRITE, arg2, 16, 1); |
| 8380 | if (!name) { |
| 8381 | goto efault; |
| 8382 | } |
| 8383 | ret = get_errno(prctl(arg1, (unsigned long)name, |
| 8384 | arg3, arg4, arg5)); |
| 8385 | unlock_user(name, arg2, 16); |
| 8386 | break; |
| 8387 | } |
| 8388 | case PR_SET_NAME: |
| 8389 | { |
| 8390 | void *name = lock_user(VERIFY_READ, arg2, 16, 1); |
| 8391 | if (!name) { |
| 8392 | goto efault; |
| 8393 | } |
| 8394 | ret = get_errno(prctl(arg1, (unsigned long)name, |
| 8395 | arg3, arg4, arg5)); |
| 8396 | unlock_user(name, arg2, 0); |
| 8397 | break; |
| 8398 | } |
| 8399 | #endif |
Peter Maydell | 1e6722f | 2012-02-03 14:48:03 +0000 | [diff] [blame] | 8400 | default: |
| 8401 | /* Most prctl options have no pointer arguments */ |
| 8402 | ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5)); |
| 8403 | break; |
| 8404 | } |
ths | 39b9aae | 2007-02-11 18:36:44 +0000 | [diff] [blame] | 8405 | break; |
bellard | d2fd1af | 2007-11-14 18:08:56 +0000 | [diff] [blame] | 8406 | #ifdef TARGET_NR_arch_prctl |
| 8407 | case TARGET_NR_arch_prctl: |
| 8408 | #if defined(TARGET_I386) && !defined(TARGET_ABI32) |
| 8409 | ret = do_arch_prctl(cpu_env, arg1, arg2); |
| 8410 | break; |
| 8411 | #else |
| 8412 | goto unimplemented; |
| 8413 | #endif |
| 8414 | #endif |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 8415 | #ifdef TARGET_NR_pread64 |
| 8416 | case TARGET_NR_pread64: |
Alexander Graf | ae017a5 | 2012-09-29 15:32:39 +0000 | [diff] [blame] | 8417 | if (regpairs_aligned(cpu_env)) { |
| 8418 | arg4 = arg5; |
| 8419 | arg5 = arg6; |
| 8420 | } |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 8421 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
| 8422 | goto efault; |
| 8423 | ret = get_errno(pread64(arg1, p, arg3, target_offset64(arg4, arg5))); |
| 8424 | unlock_user(p, arg2, ret); |
| 8425 | break; |
| 8426 | case TARGET_NR_pwrite64: |
Alexander Graf | ae017a5 | 2012-09-29 15:32:39 +0000 | [diff] [blame] | 8427 | if (regpairs_aligned(cpu_env)) { |
| 8428 | arg4 = arg5; |
| 8429 | arg5 = arg6; |
| 8430 | } |
aurel32 | f2c7ba1 | 2008-03-28 22:32:06 +0000 | [diff] [blame] | 8431 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
| 8432 | goto efault; |
| 8433 | ret = get_errno(pwrite64(arg1, p, arg3, target_offset64(arg4, arg5))); |
| 8434 | unlock_user(p, arg2, 0); |
| 8435 | break; |
| 8436 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8437 | case TARGET_NR_getcwd: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8438 | if (!(p = lock_user(VERIFY_WRITE, arg1, arg2, 0))) |
| 8439 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8440 | ret = get_errno(sys_getcwd1(p, arg2)); |
| 8441 | unlock_user(p, arg1, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8442 | break; |
| 8443 | case TARGET_NR_capget: |
| 8444 | case TARGET_NR_capset: |
Peter Maydell | e0eb210 | 2014-03-17 12:15:35 +0000 | [diff] [blame] | 8445 | { |
| 8446 | struct target_user_cap_header *target_header; |
| 8447 | struct target_user_cap_data *target_data = NULL; |
| 8448 | struct __user_cap_header_struct header; |
| 8449 | struct __user_cap_data_struct data[2]; |
| 8450 | struct __user_cap_data_struct *dataptr = NULL; |
| 8451 | int i, target_datalen; |
| 8452 | int data_items = 1; |
| 8453 | |
| 8454 | if (!lock_user_struct(VERIFY_WRITE, target_header, arg1, 1)) { |
| 8455 | goto efault; |
| 8456 | } |
| 8457 | header.version = tswap32(target_header->version); |
| 8458 | header.pid = tswap32(target_header->pid); |
| 8459 | |
Peter Maydell | ec86487 | 2014-03-19 16:07:30 +0000 | [diff] [blame] | 8460 | if (header.version != _LINUX_CAPABILITY_VERSION) { |
Peter Maydell | e0eb210 | 2014-03-17 12:15:35 +0000 | [diff] [blame] | 8461 | /* Version 2 and up takes pointer to two user_data structs */ |
| 8462 | data_items = 2; |
| 8463 | } |
| 8464 | |
| 8465 | target_datalen = sizeof(*target_data) * data_items; |
| 8466 | |
| 8467 | if (arg2) { |
| 8468 | if (num == TARGET_NR_capget) { |
| 8469 | target_data = lock_user(VERIFY_WRITE, arg2, target_datalen, 0); |
| 8470 | } else { |
| 8471 | target_data = lock_user(VERIFY_READ, arg2, target_datalen, 1); |
| 8472 | } |
| 8473 | if (!target_data) { |
| 8474 | unlock_user_struct(target_header, arg1, 0); |
| 8475 | goto efault; |
| 8476 | } |
| 8477 | |
| 8478 | if (num == TARGET_NR_capset) { |
| 8479 | for (i = 0; i < data_items; i++) { |
| 8480 | data[i].effective = tswap32(target_data[i].effective); |
| 8481 | data[i].permitted = tswap32(target_data[i].permitted); |
| 8482 | data[i].inheritable = tswap32(target_data[i].inheritable); |
| 8483 | } |
| 8484 | } |
| 8485 | |
| 8486 | dataptr = data; |
| 8487 | } |
| 8488 | |
| 8489 | if (num == TARGET_NR_capget) { |
| 8490 | ret = get_errno(capget(&header, dataptr)); |
| 8491 | } else { |
| 8492 | ret = get_errno(capset(&header, dataptr)); |
| 8493 | } |
| 8494 | |
| 8495 | /* The kernel always updates version for both capget and capset */ |
| 8496 | target_header->version = tswap32(header.version); |
| 8497 | unlock_user_struct(target_header, arg1, 1); |
| 8498 | |
| 8499 | if (arg2) { |
| 8500 | if (num == TARGET_NR_capget) { |
| 8501 | for (i = 0; i < data_items; i++) { |
| 8502 | target_data[i].effective = tswap32(data[i].effective); |
| 8503 | target_data[i].permitted = tswap32(data[i].permitted); |
| 8504 | target_data[i].inheritable = tswap32(data[i].inheritable); |
| 8505 | } |
| 8506 | unlock_user(target_data, arg2, target_datalen); |
| 8507 | } else { |
| 8508 | unlock_user(target_data, arg2, 0); |
| 8509 | } |
| 8510 | } |
| 8511 | break; |
| 8512 | } |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8513 | case TARGET_NR_sigaltstack: |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 8514 | ret = do_sigaltstack(arg1, arg2, get_sp_from_cpustate((CPUArchState *)cpu_env)); |
ths | a04e134 | 2007-09-27 13:57:58 +0000 | [diff] [blame] | 8515 | break; |
Peter Maydell | a8fd1ab | 2013-02-08 07:31:55 +0000 | [diff] [blame] | 8516 | |
| 8517 | #ifdef CONFIG_SENDFILE |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8518 | case TARGET_NR_sendfile: |
Peter Maydell | a8fd1ab | 2013-02-08 07:31:55 +0000 | [diff] [blame] | 8519 | { |
| 8520 | off_t *offp = NULL; |
| 8521 | off_t off; |
| 8522 | if (arg3) { |
| 8523 | ret = get_user_sal(off, arg3); |
| 8524 | if (is_error(ret)) { |
| 8525 | break; |
| 8526 | } |
| 8527 | offp = &off; |
| 8528 | } |
| 8529 | ret = get_errno(sendfile(arg1, arg2, offp, arg4)); |
| 8530 | if (!is_error(ret) && arg3) { |
| 8531 | abi_long ret2 = put_user_sal(off, arg3); |
| 8532 | if (is_error(ret2)) { |
| 8533 | ret = ret2; |
| 8534 | } |
| 8535 | } |
| 8536 | break; |
| 8537 | } |
| 8538 | #ifdef TARGET_NR_sendfile64 |
| 8539 | case TARGET_NR_sendfile64: |
| 8540 | { |
| 8541 | off_t *offp = NULL; |
| 8542 | off_t off; |
| 8543 | if (arg3) { |
| 8544 | ret = get_user_s64(off, arg3); |
| 8545 | if (is_error(ret)) { |
| 8546 | break; |
| 8547 | } |
| 8548 | offp = &off; |
| 8549 | } |
| 8550 | ret = get_errno(sendfile(arg1, arg2, offp, arg4)); |
| 8551 | if (!is_error(ret) && arg3) { |
| 8552 | abi_long ret2 = put_user_s64(off, arg3); |
| 8553 | if (is_error(ret2)) { |
| 8554 | ret = ret2; |
| 8555 | } |
| 8556 | } |
| 8557 | break; |
| 8558 | } |
| 8559 | #endif |
| 8560 | #else |
| 8561 | case TARGET_NR_sendfile: |
Peter Maydell | 7edd2cf | 2013-04-21 13:30:03 +0100 | [diff] [blame] | 8562 | #ifdef TARGET_NR_sendfile64 |
Peter Maydell | a8fd1ab | 2013-02-08 07:31:55 +0000 | [diff] [blame] | 8563 | case TARGET_NR_sendfile64: |
| 8564 | #endif |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8565 | goto unimplemented; |
Peter Maydell | a8fd1ab | 2013-02-08 07:31:55 +0000 | [diff] [blame] | 8566 | #endif |
| 8567 | |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8568 | #ifdef TARGET_NR_getpmsg |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8569 | case TARGET_NR_getpmsg: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8570 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8571 | #endif |
| 8572 | #ifdef TARGET_NR_putpmsg |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8573 | case TARGET_NR_putpmsg: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 8574 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8575 | #endif |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 8576 | #ifdef TARGET_NR_vfork |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8577 | case TARGET_NR_vfork: |
pbrook | d865bab | 2008-06-07 22:12:17 +0000 | [diff] [blame] | 8578 | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, |
| 8579 | 0, 0, 0, 0)); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8580 | break; |
bellard | 048f6b4 | 2005-11-26 18:47:20 +0000 | [diff] [blame] | 8581 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8582 | #ifdef TARGET_NR_ugetrlimit |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8583 | case TARGET_NR_ugetrlimit: |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 8584 | { |
| 8585 | struct rlimit rlim; |
Wesley W. Terpstra | e22b701 | 2011-07-12 14:42:00 +0300 | [diff] [blame] | 8586 | int resource = target_to_host_resource(arg1); |
| 8587 | ret = get_errno(getrlimit(resource, &rlim)); |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 8588 | if (!is_error(ret)) { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8589 | struct target_rlimit *target_rlim; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8590 | if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)) |
| 8591 | goto efault; |
takasi-y@ops.dti.ne.jp | 81bbe90 | 2010-04-12 04:07:35 +0900 | [diff] [blame] | 8592 | target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur); |
| 8593 | target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8594 | unlock_user_struct(target_rlim, arg2, 1); |
bellard | 728584b | 2003-04-29 20:43:36 +0000 | [diff] [blame] | 8595 | } |
| 8596 | break; |
| 8597 | } |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 8598 | #endif |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8599 | #ifdef TARGET_NR_truncate64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8600 | case TARGET_NR_truncate64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8601 | if (!(p = lock_user_string(arg1))) |
| 8602 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8603 | ret = target_truncate64(cpu_env, p, arg2, arg3, arg4); |
| 8604 | unlock_user(p, arg1, 0); |
bellard | 667f38b | 2005-07-23 14:46:27 +0000 | [diff] [blame] | 8605 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8606 | #endif |
| 8607 | #ifdef TARGET_NR_ftruncate64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8608 | case TARGET_NR_ftruncate64: |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 8609 | ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4); |
bellard | 667f38b | 2005-07-23 14:46:27 +0000 | [diff] [blame] | 8610 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8611 | #endif |
| 8612 | #ifdef TARGET_NR_stat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8613 | case TARGET_NR_stat64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8614 | if (!(p = lock_user_string(arg1))) |
| 8615 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8616 | ret = get_errno(stat(path(p), &st)); |
| 8617 | unlock_user(p, arg1, 0); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 8618 | if (!is_error(ret)) |
| 8619 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 8620 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8621 | #endif |
| 8622 | #ifdef TARGET_NR_lstat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8623 | case TARGET_NR_lstat64: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8624 | if (!(p = lock_user_string(arg1))) |
| 8625 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8626 | ret = get_errno(lstat(path(p), &st)); |
| 8627 | unlock_user(p, arg1, 0); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 8628 | if (!is_error(ret)) |
| 8629 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 8630 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8631 | #endif |
| 8632 | #ifdef TARGET_NR_fstat64 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8633 | case TARGET_NR_fstat64: |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 8634 | ret = get_errno(fstat(arg1, &st)); |
| 8635 | if (!is_error(ret)) |
| 8636 | ret = host_to_target_stat64(cpu_env, arg2, &st); |
| 8637 | break; |
bellard | ec86b0f | 2003-04-11 00:15:04 +0000 | [diff] [blame] | 8638 | #endif |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 8639 | #if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 8640 | #ifdef TARGET_NR_fstatat64 |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 8641 | case TARGET_NR_fstatat64: |
aurel32 | 9d33b76 | 2009-04-08 23:07:05 +0000 | [diff] [blame] | 8642 | #endif |
| 8643 | #ifdef TARGET_NR_newfstatat |
| 8644 | case TARGET_NR_newfstatat: |
| 8645 | #endif |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 8646 | if (!(p = lock_user_string(arg2))) |
| 8647 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 8648 | ret = get_errno(fstatat(arg1, path(p), &st, arg4)); |
balrog | 6a24a77 | 2008-09-20 02:23:36 +0000 | [diff] [blame] | 8649 | if (!is_error(ret)) |
| 8650 | ret = host_to_target_stat64(cpu_env, arg3, &st); |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 8651 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8652 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8653 | #ifdef TARGET_NR_lchown |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8654 | case TARGET_NR_lchown: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8655 | if (!(p = lock_user_string(arg1))) |
| 8656 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8657 | ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3))); |
| 8658 | unlock_user(p, arg1, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8659 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8660 | #endif |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8661 | #ifdef TARGET_NR_getuid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8662 | case TARGET_NR_getuid: |
| 8663 | ret = get_errno(high2lowuid(getuid())); |
| 8664 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8665 | #endif |
| 8666 | #ifdef TARGET_NR_getgid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8667 | case TARGET_NR_getgid: |
| 8668 | ret = get_errno(high2lowgid(getgid())); |
| 8669 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8670 | #endif |
| 8671 | #ifdef TARGET_NR_geteuid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8672 | case TARGET_NR_geteuid: |
| 8673 | ret = get_errno(high2lowuid(geteuid())); |
| 8674 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8675 | #endif |
| 8676 | #ifdef TARGET_NR_getegid |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8677 | case TARGET_NR_getegid: |
| 8678 | ret = get_errno(high2lowgid(getegid())); |
| 8679 | break; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8680 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8681 | case TARGET_NR_setreuid: |
| 8682 | ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); |
| 8683 | break; |
| 8684 | case TARGET_NR_setregid: |
| 8685 | ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); |
| 8686 | break; |
| 8687 | case TARGET_NR_getgroups: |
| 8688 | { |
| 8689 | int gidsetsize = arg1; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8690 | target_id *target_grouplist; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8691 | gid_t *grouplist; |
| 8692 | int i; |
| 8693 | |
| 8694 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
| 8695 | ret = get_errno(getgroups(gidsetsize, grouplist)); |
balrog | cb3bc23 | 2008-09-20 02:08:13 +0000 | [diff] [blame] | 8696 | if (gidsetsize == 0) |
| 8697 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8698 | if (!is_error(ret)) { |
Andreas Schwab | 03903ff | 2013-04-09 05:41:33 +0000 | [diff] [blame] | 8699 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8700 | if (!target_grouplist) |
| 8701 | goto efault; |
balrog | a2155fc | 2008-09-20 02:12:08 +0000 | [diff] [blame] | 8702 | for(i = 0;i < ret; i++) |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8703 | target_grouplist[i] = tswapid(high2lowgid(grouplist[i])); |
Andreas Schwab | 03903ff | 2013-04-09 05:41:33 +0000 | [diff] [blame] | 8704 | unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id)); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8705 | } |
| 8706 | } |
| 8707 | break; |
| 8708 | case TARGET_NR_setgroups: |
| 8709 | { |
| 8710 | int gidsetsize = arg1; |
Riku Voipio | 0c866a7 | 2011-04-18 15:23:06 +0300 | [diff] [blame] | 8711 | target_id *target_grouplist; |
Dillon Amburgey | f2b79ce | 2013-02-02 18:04:48 -0500 | [diff] [blame] | 8712 | gid_t *grouplist = NULL; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8713 | int i; |
Dillon Amburgey | f2b79ce | 2013-02-02 18:04:48 -0500 | [diff] [blame] | 8714 | if (gidsetsize) { |
| 8715 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
Andreas Schwab | 03903ff | 2013-04-09 05:41:33 +0000 | [diff] [blame] | 8716 | target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1); |
Dillon Amburgey | f2b79ce | 2013-02-02 18:04:48 -0500 | [diff] [blame] | 8717 | if (!target_grouplist) { |
| 8718 | ret = -TARGET_EFAULT; |
| 8719 | goto fail; |
| 8720 | } |
| 8721 | for (i = 0; i < gidsetsize; i++) { |
| 8722 | grouplist[i] = low2highgid(tswapid(target_grouplist[i])); |
| 8723 | } |
| 8724 | unlock_user(target_grouplist, arg2, 0); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8725 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8726 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
| 8727 | } |
| 8728 | break; |
| 8729 | case TARGET_NR_fchown: |
| 8730 | ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3))); |
| 8731 | break; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 8732 | #if defined(TARGET_NR_fchownat) |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 8733 | case TARGET_NR_fchownat: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8734 | if (!(p = lock_user_string(arg2))) |
| 8735 | goto efault; |
Peter Maydell | c0d472b | 2013-06-12 16:20:21 +0100 | [diff] [blame] | 8736 | ret = get_errno(fchownat(arg1, p, low2highuid(arg3), |
| 8737 | low2highgid(arg4), arg5)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8738 | unlock_user(p, arg2, 0); |
ths | ccfa72b | 2007-09-24 09:23:34 +0000 | [diff] [blame] | 8739 | break; |
| 8740 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8741 | #ifdef TARGET_NR_setresuid |
| 8742 | case TARGET_NR_setresuid: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 8743 | ret = get_errno(setresuid(low2highuid(arg1), |
| 8744 | low2highuid(arg2), |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8745 | low2highuid(arg3))); |
| 8746 | break; |
| 8747 | #endif |
| 8748 | #ifdef TARGET_NR_getresuid |
| 8749 | case TARGET_NR_getresuid: |
| 8750 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8751 | uid_t ruid, euid, suid; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8752 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
| 8753 | if (!is_error(ret)) { |
Peter Maydell | 76ca310 | 2014-03-02 19:36:41 +0000 | [diff] [blame] | 8754 | if (put_user_id(high2lowuid(ruid), arg1) |
| 8755 | || put_user_id(high2lowuid(euid), arg2) |
| 8756 | || put_user_id(high2lowuid(suid), arg3)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 8757 | goto efault; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8758 | } |
| 8759 | } |
| 8760 | break; |
| 8761 | #endif |
| 8762 | #ifdef TARGET_NR_getresgid |
| 8763 | case TARGET_NR_setresgid: |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 8764 | ret = get_errno(setresgid(low2highgid(arg1), |
| 8765 | low2highgid(arg2), |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8766 | low2highgid(arg3))); |
| 8767 | break; |
| 8768 | #endif |
| 8769 | #ifdef TARGET_NR_getresgid |
| 8770 | case TARGET_NR_getresgid: |
| 8771 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8772 | gid_t rgid, egid, sgid; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8773 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
| 8774 | if (!is_error(ret)) { |
Peter Maydell | 76ca310 | 2014-03-02 19:36:41 +0000 | [diff] [blame] | 8775 | if (put_user_id(high2lowgid(rgid), arg1) |
| 8776 | || put_user_id(high2lowgid(egid), arg2) |
| 8777 | || put_user_id(high2lowgid(sgid), arg3)) |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 8778 | goto efault; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8779 | } |
| 8780 | } |
| 8781 | break; |
| 8782 | #endif |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8783 | #ifdef TARGET_NR_chown |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8784 | case TARGET_NR_chown: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8785 | if (!(p = lock_user_string(arg1))) |
| 8786 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8787 | ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3))); |
| 8788 | unlock_user(p, arg1, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8789 | break; |
Chen Gang | 704eff6 | 2015-08-21 05:37:33 +0800 | [diff] [blame] | 8790 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8791 | case TARGET_NR_setuid: |
| 8792 | ret = get_errno(setuid(low2highuid(arg1))); |
| 8793 | break; |
| 8794 | case TARGET_NR_setgid: |
| 8795 | ret = get_errno(setgid(low2highgid(arg1))); |
| 8796 | break; |
| 8797 | case TARGET_NR_setfsuid: |
| 8798 | ret = get_errno(setfsuid(arg1)); |
| 8799 | break; |
| 8800 | case TARGET_NR_setfsgid: |
| 8801 | ret = get_errno(setfsgid(arg1)); |
| 8802 | break; |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 8803 | |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8804 | #ifdef TARGET_NR_lchown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8805 | case TARGET_NR_lchown32: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 8806 | if (!(p = lock_user_string(arg1))) |
| 8807 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 8808 | ret = get_errno(lchown(p, arg2, arg3)); |
| 8809 | unlock_user(p, arg1, 0); |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8810 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8811 | #endif |
| 8812 | #ifdef TARGET_NR_getuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 8813 | case TARGET_NR_getuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 8814 | ret = get_errno(getuid()); |
| 8815 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8816 | #endif |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 8817 | |
| 8818 | #if defined(TARGET_NR_getxuid) && defined(TARGET_ALPHA) |
| 8819 | /* Alpha specific */ |
| 8820 | case TARGET_NR_getxuid: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8821 | { |
| 8822 | uid_t euid; |
| 8823 | euid=geteuid(); |
| 8824 | ((CPUAlphaState *)cpu_env)->ir[IR_A4]=euid; |
| 8825 | } |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 8826 | ret = get_errno(getuid()); |
| 8827 | break; |
| 8828 | #endif |
| 8829 | #if defined(TARGET_NR_getxgid) && defined(TARGET_ALPHA) |
| 8830 | /* Alpha specific */ |
| 8831 | case TARGET_NR_getxgid: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8832 | { |
| 8833 | uid_t egid; |
| 8834 | egid=getegid(); |
| 8835 | ((CPUAlphaState *)cpu_env)->ir[IR_A4]=egid; |
| 8836 | } |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 8837 | ret = get_errno(getgid()); |
| 8838 | break; |
| 8839 | #endif |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8840 | #if defined(TARGET_NR_osf_getsysinfo) && defined(TARGET_ALPHA) |
| 8841 | /* Alpha specific */ |
| 8842 | case TARGET_NR_osf_getsysinfo: |
| 8843 | ret = -TARGET_EOPNOTSUPP; |
| 8844 | switch (arg1) { |
| 8845 | case TARGET_GSI_IEEE_FP_CONTROL: |
| 8846 | { |
| 8847 | uint64_t swcr, fpcr = cpu_alpha_load_fpcr (cpu_env); |
| 8848 | |
| 8849 | /* Copied from linux ieee_fpcr_to_swcr. */ |
| 8850 | swcr = (fpcr >> 35) & SWCR_STATUS_MASK; |
| 8851 | swcr |= (fpcr >> 36) & SWCR_MAP_DMZ; |
| 8852 | swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV |
| 8853 | | SWCR_TRAP_ENABLE_DZE |
| 8854 | | SWCR_TRAP_ENABLE_OVF); |
| 8855 | swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF |
| 8856 | | SWCR_TRAP_ENABLE_INE); |
| 8857 | swcr |= (fpcr >> 47) & SWCR_MAP_UMZ; |
| 8858 | swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO; |
| 8859 | |
| 8860 | if (put_user_u64 (swcr, arg2)) |
| 8861 | goto efault; |
| 8862 | ret = 0; |
| 8863 | } |
| 8864 | break; |
| 8865 | |
| 8866 | /* case GSI_IEEE_STATE_AT_SIGNAL: |
| 8867 | -- Not implemented in linux kernel. |
| 8868 | case GSI_UACPROC: |
| 8869 | -- Retrieves current unaligned access state; not much used. |
| 8870 | case GSI_PROC_TYPE: |
| 8871 | -- Retrieves implver information; surely not used. |
| 8872 | case GSI_GET_HWRPB: |
| 8873 | -- Grabs a copy of the HWRPB; surely not used. |
| 8874 | */ |
| 8875 | } |
| 8876 | break; |
| 8877 | #endif |
| 8878 | #if defined(TARGET_NR_osf_setsysinfo) && defined(TARGET_ALPHA) |
| 8879 | /* Alpha specific */ |
| 8880 | case TARGET_NR_osf_setsysinfo: |
| 8881 | ret = -TARGET_EOPNOTSUPP; |
| 8882 | switch (arg1) { |
| 8883 | case TARGET_SSI_IEEE_FP_CONTROL: |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8884 | { |
| 8885 | uint64_t swcr, fpcr, orig_fpcr; |
| 8886 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 8887 | if (get_user_u64 (swcr, arg2)) { |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8888 | goto efault; |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 8889 | } |
| 8890 | orig_fpcr = cpu_alpha_load_fpcr(cpu_env); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8891 | fpcr = orig_fpcr & FPCR_DYN_MASK; |
| 8892 | |
| 8893 | /* Copied from linux ieee_swcr_to_fpcr. */ |
| 8894 | fpcr |= (swcr & SWCR_STATUS_MASK) << 35; |
| 8895 | fpcr |= (swcr & SWCR_MAP_DMZ) << 36; |
| 8896 | fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV |
| 8897 | | SWCR_TRAP_ENABLE_DZE |
| 8898 | | SWCR_TRAP_ENABLE_OVF)) << 48; |
| 8899 | fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF |
| 8900 | | SWCR_TRAP_ENABLE_INE)) << 57; |
| 8901 | fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0); |
| 8902 | fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41; |
| 8903 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 8904 | cpu_alpha_store_fpcr(cpu_env, fpcr); |
| 8905 | ret = 0; |
| 8906 | } |
| 8907 | break; |
| 8908 | |
| 8909 | case TARGET_SSI_IEEE_RAISE_EXCEPTION: |
| 8910 | { |
| 8911 | uint64_t exc, fpcr, orig_fpcr; |
| 8912 | int si_code; |
| 8913 | |
| 8914 | if (get_user_u64(exc, arg2)) { |
| 8915 | goto efault; |
| 8916 | } |
| 8917 | |
| 8918 | orig_fpcr = cpu_alpha_load_fpcr(cpu_env); |
| 8919 | |
| 8920 | /* We only add to the exception status here. */ |
| 8921 | fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35); |
| 8922 | |
| 8923 | cpu_alpha_store_fpcr(cpu_env, fpcr); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8924 | ret = 0; |
| 8925 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 8926 | /* Old exceptions are not signaled. */ |
| 8927 | fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8928 | |
Richard Henderson | 6e06d51 | 2012-06-01 09:08:21 -0700 | [diff] [blame] | 8929 | /* If any exceptions set by this call, |
| 8930 | and are unmasked, send a signal. */ |
| 8931 | si_code = 0; |
| 8932 | if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) { |
| 8933 | si_code = TARGET_FPE_FLTRES; |
| 8934 | } |
| 8935 | if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) { |
| 8936 | si_code = TARGET_FPE_FLTUND; |
| 8937 | } |
| 8938 | if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) { |
| 8939 | si_code = TARGET_FPE_FLTOVF; |
| 8940 | } |
| 8941 | if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) { |
| 8942 | si_code = TARGET_FPE_FLTDIV; |
| 8943 | } |
| 8944 | if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) { |
| 8945 | si_code = TARGET_FPE_FLTINV; |
| 8946 | } |
| 8947 | if (si_code != 0) { |
| 8948 | target_siginfo_t info; |
| 8949 | info.si_signo = SIGFPE; |
| 8950 | info.si_errno = 0; |
| 8951 | info.si_code = si_code; |
| 8952 | info._sifields._sigfault._addr |
| 8953 | = ((CPUArchState *)cpu_env)->pc; |
| 8954 | queue_signal((CPUArchState *)cpu_env, info.si_signo, &info); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8955 | } |
| 8956 | } |
| 8957 | break; |
| 8958 | |
| 8959 | /* case SSI_NVPAIRS: |
| 8960 | -- Used with SSIN_UACPROC to enable unaligned accesses. |
| 8961 | case SSI_IEEE_STATE_AT_SIGNAL: |
| 8962 | case SSI_IEEE_IGNORE_STATE_AT_SIGNAL: |
| 8963 | -- Not implemented in linux kernel |
| 8964 | */ |
| 8965 | } |
| 8966 | break; |
| 8967 | #endif |
| 8968 | #ifdef TARGET_NR_osf_sigprocmask |
| 8969 | /* Alpha specific. */ |
| 8970 | case TARGET_NR_osf_sigprocmask: |
| 8971 | { |
| 8972 | abi_ulong mask; |
Juan Quintela | bc088ba | 2011-06-16 17:37:10 +0100 | [diff] [blame] | 8973 | int how; |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8974 | sigset_t set, oldset; |
| 8975 | |
| 8976 | switch(arg1) { |
| 8977 | case TARGET_SIG_BLOCK: |
| 8978 | how = SIG_BLOCK; |
| 8979 | break; |
| 8980 | case TARGET_SIG_UNBLOCK: |
| 8981 | how = SIG_UNBLOCK; |
| 8982 | break; |
| 8983 | case TARGET_SIG_SETMASK: |
| 8984 | how = SIG_SETMASK; |
| 8985 | break; |
| 8986 | default: |
| 8987 | ret = -TARGET_EINVAL; |
| 8988 | goto fail; |
| 8989 | } |
| 8990 | mask = arg2; |
| 8991 | target_to_host_old_sigset(&set, &mask); |
Alex Barcelo | 1c27592 | 2014-03-14 14:36:55 +0000 | [diff] [blame] | 8992 | do_sigprocmask(how, &set, &oldset); |
Richard Henderson | ba0e276 | 2009-12-09 15:56:29 -0800 | [diff] [blame] | 8993 | host_to_target_old_sigset(&mask, &oldset); |
| 8994 | ret = mask; |
| 8995 | } |
| 8996 | break; |
| 8997 | #endif |
aurel32 | 64b4d28 | 2008-11-14 17:20:15 +0000 | [diff] [blame] | 8998 | |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 8999 | #ifdef TARGET_NR_getgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9000 | case TARGET_NR_getgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9001 | ret = get_errno(getgid()); |
| 9002 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9003 | #endif |
| 9004 | #ifdef TARGET_NR_geteuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9005 | case TARGET_NR_geteuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9006 | ret = get_errno(geteuid()); |
| 9007 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9008 | #endif |
| 9009 | #ifdef TARGET_NR_getegid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9010 | case TARGET_NR_getegid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9011 | ret = get_errno(getegid()); |
| 9012 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9013 | #endif |
| 9014 | #ifdef TARGET_NR_setreuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9015 | case TARGET_NR_setreuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9016 | ret = get_errno(setreuid(arg1, arg2)); |
| 9017 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9018 | #endif |
| 9019 | #ifdef TARGET_NR_setregid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9020 | case TARGET_NR_setregid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9021 | ret = get_errno(setregid(arg1, arg2)); |
| 9022 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9023 | #endif |
| 9024 | #ifdef TARGET_NR_getgroups32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9025 | case TARGET_NR_getgroups32: |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9026 | { |
| 9027 | int gidsetsize = arg1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9028 | uint32_t *target_grouplist; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9029 | gid_t *grouplist; |
| 9030 | int i; |
| 9031 | |
| 9032 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
| 9033 | ret = get_errno(getgroups(gidsetsize, grouplist)); |
balrog | cb3bc23 | 2008-09-20 02:08:13 +0000 | [diff] [blame] | 9034 | if (gidsetsize == 0) |
| 9035 | break; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9036 | if (!is_error(ret)) { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9037 | target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0); |
| 9038 | if (!target_grouplist) { |
| 9039 | ret = -TARGET_EFAULT; |
| 9040 | goto fail; |
| 9041 | } |
balrog | a2155fc | 2008-09-20 02:12:08 +0000 | [diff] [blame] | 9042 | for(i = 0;i < ret; i++) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9043 | target_grouplist[i] = tswap32(grouplist[i]); |
| 9044 | unlock_user(target_grouplist, arg2, gidsetsize * 4); |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9045 | } |
| 9046 | } |
| 9047 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9048 | #endif |
| 9049 | #ifdef TARGET_NR_setgroups32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9050 | case TARGET_NR_setgroups32: |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9051 | { |
| 9052 | int gidsetsize = arg1; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9053 | uint32_t *target_grouplist; |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9054 | gid_t *grouplist; |
| 9055 | int i; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 9056 | |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9057 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9058 | target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1); |
| 9059 | if (!target_grouplist) { |
| 9060 | ret = -TARGET_EFAULT; |
| 9061 | goto fail; |
| 9062 | } |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9063 | for(i = 0;i < gidsetsize; i++) |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9064 | grouplist[i] = tswap32(target_grouplist[i]); |
| 9065 | unlock_user(target_grouplist, arg2, 0); |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 9066 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
| 9067 | } |
| 9068 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9069 | #endif |
| 9070 | #ifdef TARGET_NR_fchown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9071 | case TARGET_NR_fchown32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9072 | ret = get_errno(fchown(arg1, arg2, arg3)); |
| 9073 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9074 | #endif |
| 9075 | #ifdef TARGET_NR_setresuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9076 | case TARGET_NR_setresuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9077 | ret = get_errno(setresuid(arg1, arg2, arg3)); |
| 9078 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9079 | #endif |
| 9080 | #ifdef TARGET_NR_getresuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9081 | case TARGET_NR_getresuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9082 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9083 | uid_t ruid, euid, suid; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9084 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
| 9085 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 9086 | if (put_user_u32(ruid, arg1) |
| 9087 | || put_user_u32(euid, arg2) |
| 9088 | || put_user_u32(suid, arg3)) |
| 9089 | goto efault; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9090 | } |
| 9091 | } |
| 9092 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9093 | #endif |
| 9094 | #ifdef TARGET_NR_setresgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9095 | case TARGET_NR_setresgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9096 | ret = get_errno(setresgid(arg1, arg2, arg3)); |
| 9097 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9098 | #endif |
| 9099 | #ifdef TARGET_NR_getresgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9100 | case TARGET_NR_getresgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9101 | { |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9102 | gid_t rgid, egid, sgid; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9103 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
| 9104 | if (!is_error(ret)) { |
bellard | 2f61969 | 2007-11-16 10:46:05 +0000 | [diff] [blame] | 9105 | if (put_user_u32(rgid, arg1) |
| 9106 | || put_user_u32(egid, arg2) |
| 9107 | || put_user_u32(sgid, arg3)) |
| 9108 | goto efault; |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9109 | } |
| 9110 | } |
| 9111 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9112 | #endif |
| 9113 | #ifdef TARGET_NR_chown32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9114 | case TARGET_NR_chown32: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9115 | if (!(p = lock_user_string(arg1))) |
| 9116 | goto efault; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9117 | ret = get_errno(chown(p, arg2, arg3)); |
| 9118 | unlock_user(p, arg1, 0); |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9119 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9120 | #endif |
| 9121 | #ifdef TARGET_NR_setuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9122 | case TARGET_NR_setuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9123 | ret = get_errno(setuid(arg1)); |
| 9124 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9125 | #endif |
| 9126 | #ifdef TARGET_NR_setgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9127 | case TARGET_NR_setgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9128 | ret = get_errno(setgid(arg1)); |
| 9129 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9130 | #endif |
| 9131 | #ifdef TARGET_NR_setfsuid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9132 | case TARGET_NR_setfsuid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9133 | ret = get_errno(setfsuid(arg1)); |
| 9134 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9135 | #endif |
| 9136 | #ifdef TARGET_NR_setfsgid32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9137 | case TARGET_NR_setfsgid32: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9138 | ret = get_errno(setfsgid(arg1)); |
| 9139 | break; |
bellard | a315a14 | 2005-01-30 22:59:18 +0000 | [diff] [blame] | 9140 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 9141 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9142 | case TARGET_NR_pivot_root: |
bellard | b03c60f | 2003-03-23 17:19:56 +0000 | [diff] [blame] | 9143 | goto unimplemented; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 9144 | #ifdef TARGET_NR_mincore |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9145 | case TARGET_NR_mincore: |
aurel32 | 04bb9ac | 2008-10-01 21:46:41 +0000 | [diff] [blame] | 9146 | { |
| 9147 | void *a; |
| 9148 | ret = -TARGET_EFAULT; |
| 9149 | if (!(a = lock_user(VERIFY_READ, arg1,arg2, 0))) |
| 9150 | goto efault; |
| 9151 | if (!(p = lock_user_string(arg3))) |
| 9152 | goto mincore_fail; |
| 9153 | ret = get_errno(mincore(a, arg2, p)); |
| 9154 | unlock_user(p, arg3, ret); |
| 9155 | mincore_fail: |
| 9156 | unlock_user(a, arg1, 0); |
| 9157 | } |
| 9158 | break; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 9159 | #endif |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 9160 | #ifdef TARGET_NR_arm_fadvise64_64 |
| 9161 | case TARGET_NR_arm_fadvise64_64: |
| 9162 | { |
| 9163 | /* |
| 9164 | * arm_fadvise64_64 looks like fadvise64_64 but |
| 9165 | * with different argument order |
| 9166 | */ |
| 9167 | abi_long temp; |
| 9168 | temp = arg3; |
| 9169 | arg3 = arg4; |
| 9170 | arg4 = temp; |
| 9171 | } |
| 9172 | #endif |
Ulrich Hecht | e72d2cc | 2009-07-24 19:10:31 +0200 | [diff] [blame] | 9173 | #if defined(TARGET_NR_fadvise64_64) || defined(TARGET_NR_arm_fadvise64_64) || defined(TARGET_NR_fadvise64) |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 9174 | #ifdef TARGET_NR_fadvise64_64 |
| 9175 | case TARGET_NR_fadvise64_64: |
| 9176 | #endif |
Ulrich Hecht | e72d2cc | 2009-07-24 19:10:31 +0200 | [diff] [blame] | 9177 | #ifdef TARGET_NR_fadvise64 |
| 9178 | case TARGET_NR_fadvise64: |
| 9179 | #endif |
| 9180 | #ifdef TARGET_S390X |
| 9181 | switch (arg4) { |
| 9182 | case 4: arg4 = POSIX_FADV_NOREUSE + 1; break; /* make sure it's an invalid value */ |
| 9183 | case 5: arg4 = POSIX_FADV_NOREUSE + 2; break; /* ditto */ |
| 9184 | case 6: arg4 = POSIX_FADV_DONTNEED; break; |
| 9185 | case 7: arg4 = POSIX_FADV_NOREUSE; break; |
| 9186 | default: break; |
| 9187 | } |
| 9188 | #endif |
| 9189 | ret = -posix_fadvise(arg1, arg2, arg3, arg4); |
aurel32 | 408321b | 2008-10-01 21:46:32 +0000 | [diff] [blame] | 9190 | break; |
| 9191 | #endif |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 9192 | #ifdef TARGET_NR_madvise |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9193 | case TARGET_NR_madvise: |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 9194 | /* A straight passthrough may not be safe because qemu sometimes |
Lei Li | d2d6b85 | 2013-05-20 17:20:50 +0800 | [diff] [blame] | 9195 | turns private file-backed mappings into anonymous mappings. |
pbrook | 2483668 | 2006-04-16 14:14:53 +0000 | [diff] [blame] | 9196 | This will break MADV_DONTNEED. |
| 9197 | This is a hint, so ignoring and returning success is ok. */ |
| 9198 | ret = get_errno(0); |
| 9199 | break; |
bellard | ffa65c3 | 2004-01-04 23:57:22 +0000 | [diff] [blame] | 9200 | #endif |
blueswir1 | 992f48a | 2007-10-14 16:27:31 +0000 | [diff] [blame] | 9201 | #if TARGET_ABI_BITS == 32 |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9202 | case TARGET_NR_fcntl64: |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9203 | { |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 9204 | int cmd; |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9205 | struct flock64 fl; |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9206 | struct target_flock64 *target_fl; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9207 | #ifdef TARGET_ARM |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9208 | struct target_eabi_flock64 *target_efl; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9209 | #endif |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9210 | |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 9211 | cmd = target_to_host_fcntl_cmd(arg2); |
Peter Maydell | 31b6319 | 2011-12-05 23:11:50 +0000 | [diff] [blame] | 9212 | if (cmd == -TARGET_EINVAL) { |
| 9213 | ret = cmd; |
| 9214 | break; |
| 9215 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 9216 | |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 9217 | switch(arg2) { |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 9218 | case TARGET_F_GETLK64: |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 9219 | #ifdef TARGET_ARM |
| 9220 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 9221 | if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) |
| 9222 | goto efault; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 9223 | fl.l_type = tswap16(target_efl->l_type); |
| 9224 | fl.l_whence = tswap16(target_efl->l_whence); |
| 9225 | fl.l_start = tswap64(target_efl->l_start); |
| 9226 | fl.l_len = tswap64(target_efl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 9227 | fl.l_pid = tswap32(target_efl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 9228 | unlock_user_struct(target_efl, arg3, 0); |
| 9229 | } else |
| 9230 | #endif |
| 9231 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 9232 | if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) |
| 9233 | goto efault; |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 9234 | fl.l_type = tswap16(target_fl->l_type); |
| 9235 | fl.l_whence = tswap16(target_fl->l_whence); |
| 9236 | fl.l_start = tswap64(target_fl->l_start); |
| 9237 | fl.l_len = tswap64(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 9238 | fl.l_pid = tswap32(target_fl->l_pid); |
ths | 5813427 | 2007-03-31 18:59:32 +0000 | [diff] [blame] | 9239 | unlock_user_struct(target_fl, arg3, 0); |
| 9240 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 9241 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9242 | if (ret == 0) { |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9243 | #ifdef TARGET_ARM |
| 9244 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 9245 | if (!lock_user_struct(VERIFY_WRITE, target_efl, arg3, 0)) |
| 9246 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9247 | target_efl->l_type = tswap16(fl.l_type); |
| 9248 | target_efl->l_whence = tswap16(fl.l_whence); |
| 9249 | target_efl->l_start = tswap64(fl.l_start); |
| 9250 | target_efl->l_len = tswap64(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 9251 | target_efl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9252 | unlock_user_struct(target_efl, arg3, 1); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9253 | } else |
| 9254 | #endif |
| 9255 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 9256 | if (!lock_user_struct(VERIFY_WRITE, target_fl, arg3, 0)) |
| 9257 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9258 | target_fl->l_type = tswap16(fl.l_type); |
| 9259 | target_fl->l_whence = tswap16(fl.l_whence); |
| 9260 | target_fl->l_start = tswap64(fl.l_start); |
| 9261 | target_fl->l_len = tswap64(fl.l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 9262 | target_fl->l_pid = tswap32(fl.l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9263 | unlock_user_struct(target_fl, arg3, 1); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9264 | } |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9265 | } |
| 9266 | break; |
| 9267 | |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 9268 | case TARGET_F_SETLK64: |
| 9269 | case TARGET_F_SETLKW64: |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9270 | #ifdef TARGET_ARM |
| 9271 | if (((CPUARMState *)cpu_env)->eabi) { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 9272 | if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) |
| 9273 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9274 | fl.l_type = tswap16(target_efl->l_type); |
| 9275 | fl.l_whence = tswap16(target_efl->l_whence); |
| 9276 | fl.l_start = tswap64(target_efl->l_start); |
| 9277 | fl.l_len = tswap64(target_efl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 9278 | fl.l_pid = tswap32(target_efl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9279 | unlock_user_struct(target_efl, arg3, 0); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9280 | } else |
| 9281 | #endif |
| 9282 | { |
bellard | 9ee1fa2 | 2007-11-11 15:11:19 +0000 | [diff] [blame] | 9283 | if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) |
| 9284 | goto efault; |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9285 | fl.l_type = tswap16(target_fl->l_type); |
| 9286 | fl.l_whence = tswap16(target_fl->l_whence); |
| 9287 | fl.l_start = tswap64(target_fl->l_start); |
| 9288 | fl.l_len = tswap64(target_fl->l_len); |
Ulrich Hecht | 7e22e54 | 2009-07-24 19:10:27 +0200 | [diff] [blame] | 9289 | fl.l_pid = tswap32(target_fl->l_pid); |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 9290 | unlock_user_struct(target_fl, arg3, 0); |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 9291 | } |
ths | b1e341e | 2007-03-20 21:50:52 +0000 | [diff] [blame] | 9292 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9293 | break; |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 9294 | default: |
Arnaud Patard (Rtp) | 5f10681 | 2009-06-03 14:35:04 +0200 | [diff] [blame] | 9295 | ret = do_fcntl(arg1, arg2, arg3); |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 9296 | break; |
| 9297 | } |
bellard | 77e4672 | 2003-04-29 20:39:06 +0000 | [diff] [blame] | 9298 | break; |
| 9299 | } |
bellard | 60cd49d | 2003-03-16 22:53:56 +0000 | [diff] [blame] | 9300 | #endif |
ths | 7d600c8 | 2006-12-08 01:32:58 +0000 | [diff] [blame] | 9301 | #ifdef TARGET_NR_cacheflush |
| 9302 | case TARGET_NR_cacheflush: |
| 9303 | /* self-modifying code is handled automatically, so nothing needed */ |
| 9304 | ret = 0; |
| 9305 | break; |
| 9306 | #endif |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 9307 | #ifdef TARGET_NR_security |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9308 | case TARGET_NR_security: |
| 9309 | goto unimplemented; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 9310 | #endif |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 9311 | #ifdef TARGET_NR_getpagesize |
| 9312 | case TARGET_NR_getpagesize: |
| 9313 | ret = TARGET_PAGE_SIZE; |
| 9314 | break; |
| 9315 | #endif |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9316 | case TARGET_NR_gettid: |
| 9317 | ret = get_errno(gettid()); |
| 9318 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 9319 | #ifdef TARGET_NR_readahead |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9320 | case TARGET_NR_readahead: |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 9321 | #if TARGET_ABI_BITS == 32 |
Riku Voipio | 48e515d | 2011-07-12 15:40:51 +0300 | [diff] [blame] | 9322 | if (regpairs_aligned(cpu_env)) { |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 9323 | arg2 = arg3; |
| 9324 | arg3 = arg4; |
| 9325 | arg4 = arg5; |
| 9326 | } |
aurel32 | 2054ac9 | 2008-10-13 21:08:07 +0000 | [diff] [blame] | 9327 | ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4)); |
| 9328 | #else |
| 9329 | ret = get_errno(readahead(arg1, arg2, arg3)); |
| 9330 | #endif |
| 9331 | break; |
ths | e5febef | 2007-04-01 18:31:35 +0000 | [diff] [blame] | 9332 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9333 | #ifdef CONFIG_ATTR |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 9334 | #ifdef TARGET_NR_setxattr |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 9335 | case TARGET_NR_listxattr: |
| 9336 | case TARGET_NR_llistxattr: |
Peter Maydell | fb5590f | 2011-12-14 15:37:19 +0000 | [diff] [blame] | 9337 | { |
| 9338 | void *p, *b = 0; |
| 9339 | if (arg2) { |
| 9340 | b = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 9341 | if (!b) { |
| 9342 | ret = -TARGET_EFAULT; |
| 9343 | break; |
| 9344 | } |
| 9345 | } |
| 9346 | p = lock_user_string(arg1); |
| 9347 | if (p) { |
| 9348 | if (num == TARGET_NR_listxattr) { |
| 9349 | ret = get_errno(listxattr(p, b, arg3)); |
| 9350 | } else { |
| 9351 | ret = get_errno(llistxattr(p, b, arg3)); |
| 9352 | } |
| 9353 | } else { |
| 9354 | ret = -TARGET_EFAULT; |
| 9355 | } |
| 9356 | unlock_user(p, arg1, 0); |
| 9357 | unlock_user(b, arg2, arg3); |
Arnaud Patard | 6f932f9 | 2009-04-21 21:04:18 +0300 | [diff] [blame] | 9358 | break; |
Peter Maydell | fb5590f | 2011-12-14 15:37:19 +0000 | [diff] [blame] | 9359 | } |
| 9360 | case TARGET_NR_flistxattr: |
| 9361 | { |
| 9362 | void *b = 0; |
| 9363 | if (arg2) { |
| 9364 | b = lock_user(VERIFY_WRITE, arg2, arg3, 0); |
| 9365 | if (!b) { |
| 9366 | ret = -TARGET_EFAULT; |
| 9367 | break; |
| 9368 | } |
| 9369 | } |
| 9370 | ret = get_errno(flistxattr(arg1, b, arg3)); |
| 9371 | unlock_user(b, arg2, arg3); |
| 9372 | break; |
| 9373 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9374 | case TARGET_NR_setxattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9375 | case TARGET_NR_lsetxattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9376 | { |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 9377 | void *p, *n, *v = 0; |
| 9378 | if (arg3) { |
| 9379 | v = lock_user(VERIFY_READ, arg3, arg4, 1); |
| 9380 | if (!v) { |
| 9381 | ret = -TARGET_EFAULT; |
| 9382 | break; |
| 9383 | } |
| 9384 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9385 | p = lock_user_string(arg1); |
| 9386 | n = lock_user_string(arg2); |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 9387 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9388 | if (num == TARGET_NR_setxattr) { |
| 9389 | ret = get_errno(setxattr(p, n, v, arg4, arg5)); |
| 9390 | } else { |
| 9391 | ret = get_errno(lsetxattr(p, n, v, arg4, arg5)); |
| 9392 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9393 | } else { |
| 9394 | ret = -TARGET_EFAULT; |
| 9395 | } |
| 9396 | unlock_user(p, arg1, 0); |
| 9397 | unlock_user(n, arg2, 0); |
| 9398 | unlock_user(v, arg3, 0); |
| 9399 | } |
| 9400 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9401 | case TARGET_NR_fsetxattr: |
| 9402 | { |
| 9403 | void *n, *v = 0; |
| 9404 | if (arg3) { |
| 9405 | v = lock_user(VERIFY_READ, arg3, arg4, 1); |
| 9406 | if (!v) { |
| 9407 | ret = -TARGET_EFAULT; |
| 9408 | break; |
| 9409 | } |
| 9410 | } |
| 9411 | n = lock_user_string(arg2); |
| 9412 | if (n) { |
| 9413 | ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5)); |
| 9414 | } else { |
| 9415 | ret = -TARGET_EFAULT; |
| 9416 | } |
| 9417 | unlock_user(n, arg2, 0); |
| 9418 | unlock_user(v, arg3, 0); |
| 9419 | } |
| 9420 | break; |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9421 | case TARGET_NR_getxattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9422 | case TARGET_NR_lgetxattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9423 | { |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 9424 | void *p, *n, *v = 0; |
| 9425 | if (arg3) { |
| 9426 | v = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 9427 | if (!v) { |
| 9428 | ret = -TARGET_EFAULT; |
| 9429 | break; |
| 9430 | } |
| 9431 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9432 | p = lock_user_string(arg1); |
| 9433 | n = lock_user_string(arg2); |
Peter Maydell | e3c33ec | 2011-12-14 15:37:17 +0000 | [diff] [blame] | 9434 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9435 | if (num == TARGET_NR_getxattr) { |
| 9436 | ret = get_errno(getxattr(p, n, v, arg4)); |
| 9437 | } else { |
| 9438 | ret = get_errno(lgetxattr(p, n, v, arg4)); |
| 9439 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9440 | } else { |
| 9441 | ret = -TARGET_EFAULT; |
| 9442 | } |
| 9443 | unlock_user(p, arg1, 0); |
| 9444 | unlock_user(n, arg2, 0); |
| 9445 | unlock_user(v, arg3, arg4); |
| 9446 | } |
| 9447 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9448 | case TARGET_NR_fgetxattr: |
| 9449 | { |
| 9450 | void *n, *v = 0; |
| 9451 | if (arg3) { |
| 9452 | v = lock_user(VERIFY_WRITE, arg3, arg4, 0); |
| 9453 | if (!v) { |
| 9454 | ret = -TARGET_EFAULT; |
| 9455 | break; |
| 9456 | } |
| 9457 | } |
| 9458 | n = lock_user_string(arg2); |
| 9459 | if (n) { |
| 9460 | ret = get_errno(fgetxattr(arg1, n, v, arg4)); |
| 9461 | } else { |
| 9462 | ret = -TARGET_EFAULT; |
| 9463 | } |
| 9464 | unlock_user(n, arg2, 0); |
| 9465 | unlock_user(v, arg3, arg4); |
| 9466 | } |
| 9467 | break; |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9468 | case TARGET_NR_removexattr: |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9469 | case TARGET_NR_lremovexattr: |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9470 | { |
| 9471 | void *p, *n; |
| 9472 | p = lock_user_string(arg1); |
| 9473 | n = lock_user_string(arg2); |
| 9474 | if (p && n) { |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9475 | if (num == TARGET_NR_removexattr) { |
| 9476 | ret = get_errno(removexattr(p, n)); |
| 9477 | } else { |
| 9478 | ret = get_errno(lremovexattr(p, n)); |
| 9479 | } |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9480 | } else { |
| 9481 | ret = -TARGET_EFAULT; |
| 9482 | } |
| 9483 | unlock_user(p, arg1, 0); |
| 9484 | unlock_user(n, arg2, 0); |
| 9485 | } |
| 9486 | break; |
Peter Maydell | 30297b5 | 2011-12-14 15:37:18 +0000 | [diff] [blame] | 9487 | case TARGET_NR_fremovexattr: |
| 9488 | { |
| 9489 | void *n; |
| 9490 | n = lock_user_string(arg2); |
| 9491 | if (n) { |
| 9492 | ret = get_errno(fremovexattr(arg1, n)); |
| 9493 | } else { |
| 9494 | ret = -TARGET_EFAULT; |
| 9495 | } |
| 9496 | unlock_user(n, arg2, 0); |
| 9497 | } |
| 9498 | break; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 9499 | #endif |
An-Cheng Huang | a790ae3 | 2011-08-09 12:34:06 -0700 | [diff] [blame] | 9500 | #endif /* CONFIG_ATTR */ |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 9501 | #ifdef TARGET_NR_set_thread_area |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 9502 | case TARGET_NR_set_thread_area: |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 9503 | #if defined(TARGET_MIPS) |
Petar Jovanovic | d279279 | 2014-06-18 17:48:20 +0200 | [diff] [blame] | 9504 | ((CPUMIPSState *) cpu_env)->active_tc.CP0_UserLocal = arg1; |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 9505 | ret = 0; |
| 9506 | break; |
edgar_igl | ef96779 | 2009-01-07 14:19:38 +0000 | [diff] [blame] | 9507 | #elif defined(TARGET_CRIS) |
| 9508 | if (arg1 & 0xff) |
| 9509 | ret = -TARGET_EINVAL; |
| 9510 | else { |
| 9511 | ((CPUCRISState *) cpu_env)->pregs[PR_PID] = arg1; |
| 9512 | ret = 0; |
| 9513 | } |
| 9514 | break; |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 9515 | #elif defined(TARGET_I386) && defined(TARGET_ABI32) |
| 9516 | ret = do_set_thread_area(cpu_env, arg1); |
| 9517 | break; |
Peter Maydell | 1ccd937 | 2013-07-16 18:44:55 +0100 | [diff] [blame] | 9518 | #elif defined(TARGET_M68K) |
| 9519 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 9520 | TaskState *ts = cpu->opaque; |
Peter Maydell | 1ccd937 | 2013-07-16 18:44:55 +0100 | [diff] [blame] | 9521 | ts->tp_value = arg1; |
Peter Maydell | 95c1eb1 | 2013-07-29 11:31:49 +0100 | [diff] [blame] | 9522 | ret = 0; |
Peter Maydell | 1ccd937 | 2013-07-16 18:44:55 +0100 | [diff] [blame] | 9523 | break; |
| 9524 | } |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 9525 | #else |
| 9526 | goto unimplemented_nowarn; |
| 9527 | #endif |
| 9528 | #endif |
| 9529 | #ifdef TARGET_NR_get_thread_area |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 9530 | case TARGET_NR_get_thread_area: |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 9531 | #if defined(TARGET_I386) && defined(TARGET_ABI32) |
| 9532 | ret = do_get_thread_area(cpu_env, arg1); |
Peter Maydell | d312bbe | 2013-07-16 18:44:56 +0100 | [diff] [blame] | 9533 | break; |
Peter Maydell | 1ccd937 | 2013-07-16 18:44:55 +0100 | [diff] [blame] | 9534 | #elif defined(TARGET_M68K) |
| 9535 | { |
Andreas Färber | 0429a97 | 2013-08-26 18:14:44 +0200 | [diff] [blame] | 9536 | TaskState *ts = cpu->opaque; |
Peter Maydell | 1ccd937 | 2013-07-16 18:44:55 +0100 | [diff] [blame] | 9537 | ret = ts->tp_value; |
| 9538 | break; |
| 9539 | } |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 9540 | #else |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 9541 | goto unimplemented_nowarn; |
bellard | ebc0548 | 2003-09-30 21:08:41 +0000 | [diff] [blame] | 9542 | #endif |
bellard | 8d18e89 | 2007-11-14 15:18:40 +0000 | [diff] [blame] | 9543 | #endif |
bellard | 48dc41e | 2006-06-21 18:15:50 +0000 | [diff] [blame] | 9544 | #ifdef TARGET_NR_getdomainname |
| 9545 | case TARGET_NR_getdomainname: |
| 9546 | goto unimplemented_nowarn; |
| 9547 | #endif |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 9548 | |
ths | b5906f9 | 2007-03-19 13:32:45 +0000 | [diff] [blame] | 9549 | #ifdef TARGET_NR_clock_gettime |
| 9550 | case TARGET_NR_clock_gettime: |
| 9551 | { |
| 9552 | struct timespec ts; |
| 9553 | ret = get_errno(clock_gettime(arg1, &ts)); |
| 9554 | if (!is_error(ret)) { |
| 9555 | host_to_target_timespec(arg2, &ts); |
| 9556 | } |
| 9557 | break; |
| 9558 | } |
| 9559 | #endif |
| 9560 | #ifdef TARGET_NR_clock_getres |
| 9561 | case TARGET_NR_clock_getres: |
| 9562 | { |
| 9563 | struct timespec ts; |
| 9564 | ret = get_errno(clock_getres(arg1, &ts)); |
| 9565 | if (!is_error(ret)) { |
| 9566 | host_to_target_timespec(arg2, &ts); |
| 9567 | } |
| 9568 | break; |
| 9569 | } |
| 9570 | #endif |
pbrook | 63d7651 | 2008-05-29 13:43:29 +0000 | [diff] [blame] | 9571 | #ifdef TARGET_NR_clock_nanosleep |
| 9572 | case TARGET_NR_clock_nanosleep: |
| 9573 | { |
| 9574 | struct timespec ts; |
| 9575 | target_to_host_timespec(&ts, arg3); |
| 9576 | ret = get_errno(clock_nanosleep(arg1, arg2, &ts, arg4 ? &ts : NULL)); |
| 9577 | if (arg4) |
| 9578 | host_to_target_timespec(arg4, &ts); |
Tom Musta | 8fbe8fd | 2014-08-12 13:53:41 -0500 | [diff] [blame] | 9579 | |
| 9580 | #if defined(TARGET_PPC) |
| 9581 | /* clock_nanosleep is odd in that it returns positive errno values. |
| 9582 | * On PPC, CR0 bit 3 should be set in such a situation. */ |
| 9583 | if (ret) { |
| 9584 | ((CPUPPCState *)cpu_env)->crf[0] |= 1; |
| 9585 | } |
| 9586 | #endif |
pbrook | 63d7651 | 2008-05-29 13:43:29 +0000 | [diff] [blame] | 9587 | break; |
| 9588 | } |
| 9589 | #endif |
ths | b5906f9 | 2007-03-19 13:32:45 +0000 | [diff] [blame] | 9590 | |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 9591 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
| 9592 | case TARGET_NR_set_tid_address: |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9593 | ret = get_errno(set_tid_address((int *)g2h(arg1))); |
| 9594 | break; |
ths | 6f5b89a | 2007-03-02 20:48:00 +0000 | [diff] [blame] | 9595 | #endif |
| 9596 | |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 9597 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 9598 | case TARGET_NR_tkill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 9599 | ret = get_errno(sys_tkill((int)arg1, target_to_host_signal(arg2))); |
ths | 4cae1d1 | 2007-07-12 11:06:53 +0000 | [diff] [blame] | 9600 | break; |
| 9601 | #endif |
| 9602 | |
ths | 3ae4320 | 2007-09-16 21:39:48 +0000 | [diff] [blame] | 9603 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 9604 | case TARGET_NR_tgkill: |
pbrook | 4cb0596 | 2008-05-30 18:05:19 +0000 | [diff] [blame] | 9605 | ret = get_errno(sys_tgkill((int)arg1, (int)arg2, |
| 9606 | target_to_host_signal(arg3))); |
ths | 7145557 | 2007-06-21 21:45:30 +0000 | [diff] [blame] | 9607 | break; |
| 9608 | #endif |
| 9609 | |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 9610 | #ifdef TARGET_NR_set_robust_list |
| 9611 | case TARGET_NR_set_robust_list: |
Peter Maydell | e9a970a | 2013-02-08 04:34:54 +0000 | [diff] [blame] | 9612 | case TARGET_NR_get_robust_list: |
| 9613 | /* The ABI for supporting robust futexes has userspace pass |
| 9614 | * the kernel a pointer to a linked list which is updated by |
| 9615 | * userspace after the syscall; the list is walked by the kernel |
| 9616 | * when the thread exits. Since the linked list in QEMU guest |
| 9617 | * memory isn't a valid linked list for the host and we have |
| 9618 | * no way to reliably intercept the thread-death event, we can't |
| 9619 | * support these. Silently return ENOSYS so that guest userspace |
| 9620 | * falls back to a non-robust futex implementation (which should |
| 9621 | * be OK except in the corner case of the guest crashing while |
| 9622 | * holding a mutex that is shared with another process via |
| 9623 | * shared memory). |
| 9624 | */ |
| 9625 | goto unimplemented_nowarn; |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 9626 | #endif |
| 9627 | |
Peter Maydell | 1acae9f | 2013-07-02 14:04:12 +0100 | [diff] [blame] | 9628 | #if defined(TARGET_NR_utimensat) |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 9629 | case TARGET_NR_utimensat: |
| 9630 | { |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 9631 | struct timespec *tsp, ts[2]; |
| 9632 | if (!arg3) { |
| 9633 | tsp = NULL; |
| 9634 | } else { |
| 9635 | target_to_host_timespec(ts, arg3); |
| 9636 | target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec)); |
| 9637 | tsp = ts; |
| 9638 | } |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 9639 | if (!arg2) |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 9640 | ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4)); |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 9641 | else { |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9642 | if (!(p = lock_user_string(arg2))) { |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 9643 | ret = -TARGET_EFAULT; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9644 | goto fail; |
| 9645 | } |
Riku Voipio | ebc996f | 2009-04-21 15:01:51 +0300 | [diff] [blame] | 9646 | ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4)); |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 9647 | unlock_user(p, arg2, 0); |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 9648 | } |
| 9649 | } |
| 9650 | break; |
| 9651 | #endif |
pbrook | bd0c566 | 2008-05-29 14:34:11 +0000 | [diff] [blame] | 9652 | case TARGET_NR_futex: |
| 9653 | ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6); |
| 9654 | break; |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 9655 | #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 9656 | case TARGET_NR_inotify_init: |
| 9657 | ret = get_errno(sys_inotify_init()); |
| 9658 | break; |
| 9659 | #endif |
Stefan Weil | a1606b0 | 2010-03-28 11:44:41 +0200 | [diff] [blame] | 9660 | #ifdef CONFIG_INOTIFY1 |
Riku Voipio | c05c7a7 | 2010-03-26 15:25:11 +0000 | [diff] [blame] | 9661 | #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1) |
| 9662 | case TARGET_NR_inotify_init1: |
| 9663 | ret = get_errno(sys_inotify_init1(arg1)); |
| 9664 | break; |
| 9665 | #endif |
Stefan Weil | a1606b0 | 2010-03-28 11:44:41 +0200 | [diff] [blame] | 9666 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 9667 | #if defined(TARGET_NR_inotify_add_watch) && defined(__NR_inotify_add_watch) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 9668 | case TARGET_NR_inotify_add_watch: |
| 9669 | p = lock_user_string(arg2); |
| 9670 | ret = get_errno(sys_inotify_add_watch(arg1, path(p), arg3)); |
| 9671 | unlock_user(p, arg2, 0); |
| 9672 | break; |
| 9673 | #endif |
aurel32 | dbfe4c3 | 2009-04-08 21:29:30 +0000 | [diff] [blame] | 9674 | #if defined(TARGET_NR_inotify_rm_watch) && defined(__NR_inotify_rm_watch) |
aurel32 | 39b5976 | 2008-10-01 21:46:50 +0000 | [diff] [blame] | 9675 | case TARGET_NR_inotify_rm_watch: |
| 9676 | ret = get_errno(sys_inotify_rm_watch(arg1, arg2)); |
| 9677 | break; |
| 9678 | #endif |
ths | 9007f0e | 2007-09-25 17:50:37 +0000 | [diff] [blame] | 9679 | |
Nathan Froyd | 8ec9cf8 | 2009-07-22 09:14:36 -0700 | [diff] [blame] | 9680 | #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open) |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 9681 | case TARGET_NR_mq_open: |
| 9682 | { |
Tom Musta | b6ce1f6 | 2014-08-12 13:53:36 -0500 | [diff] [blame] | 9683 | struct mq_attr posix_mq_attr, *attrp; |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 9684 | |
| 9685 | p = lock_user_string(arg1 - 1); |
Tom Musta | b6ce1f6 | 2014-08-12 13:53:36 -0500 | [diff] [blame] | 9686 | if (arg4 != 0) { |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 9687 | copy_from_user_mq_attr (&posix_mq_attr, arg4); |
Tom Musta | b6ce1f6 | 2014-08-12 13:53:36 -0500 | [diff] [blame] | 9688 | attrp = &posix_mq_attr; |
| 9689 | } else { |
| 9690 | attrp = 0; |
| 9691 | } |
| 9692 | ret = get_errno(mq_open(p, arg2, arg3, attrp)); |
aurel32 | 24e1003 | 2009-04-15 16:11:43 +0000 | [diff] [blame] | 9693 | unlock_user (p, arg1, 0); |
| 9694 | } |
| 9695 | break; |
| 9696 | |
| 9697 | case TARGET_NR_mq_unlink: |
| 9698 | p = lock_user_string(arg1 - 1); |
| 9699 | ret = get_errno(mq_unlink(p)); |
| 9700 | unlock_user (p, arg1, 0); |
| 9701 | break; |
| 9702 | |
| 9703 | case TARGET_NR_mq_timedsend: |
| 9704 | { |
| 9705 | struct timespec ts; |
| 9706 | |
| 9707 | p = lock_user (VERIFY_READ, arg2, arg3, 1); |
| 9708 | if (arg5 != 0) { |
| 9709 | target_to_host_timespec(&ts, arg5); |
| 9710 | ret = get_errno(mq_timedsend(arg1, p, arg3, arg4, &ts)); |
| 9711 | host_to_target_timespec(arg5, &ts); |
| 9712 | } |
| 9713 | else |
| 9714 | ret = get_errno(mq_send(arg1, p, arg3, arg4)); |
| 9715 | unlock_user (p, arg2, arg3); |
| 9716 | } |
| 9717 | break; |
| 9718 | |
| 9719 | case TARGET_NR_mq_timedreceive: |
| 9720 | { |
| 9721 | struct timespec ts; |
| 9722 | unsigned int prio; |
| 9723 | |
| 9724 | p = lock_user (VERIFY_READ, arg2, arg3, 1); |
| 9725 | if (arg5 != 0) { |
| 9726 | target_to_host_timespec(&ts, arg5); |
| 9727 | ret = get_errno(mq_timedreceive(arg1, p, arg3, &prio, &ts)); |
| 9728 | host_to_target_timespec(arg5, &ts); |
| 9729 | } |
| 9730 | else |
| 9731 | ret = get_errno(mq_receive(arg1, p, arg3, &prio)); |
| 9732 | unlock_user (p, arg2, arg3); |
| 9733 | if (arg4 != 0) |
| 9734 | put_user_u32(prio, arg4); |
| 9735 | } |
| 9736 | break; |
| 9737 | |
| 9738 | /* Not implemented for now... */ |
| 9739 | /* case TARGET_NR_mq_notify: */ |
| 9740 | /* break; */ |
| 9741 | |
| 9742 | case TARGET_NR_mq_getsetattr: |
| 9743 | { |
| 9744 | struct mq_attr posix_mq_attr_in, posix_mq_attr_out; |
| 9745 | ret = 0; |
| 9746 | if (arg3 != 0) { |
| 9747 | ret = mq_getattr(arg1, &posix_mq_attr_out); |
| 9748 | copy_to_user_mq_attr(arg3, &posix_mq_attr_out); |
| 9749 | } |
| 9750 | if (arg2 != 0) { |
| 9751 | copy_from_user_mq_attr(&posix_mq_attr_in, arg2); |
| 9752 | ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out); |
| 9753 | } |
| 9754 | |
| 9755 | } |
| 9756 | break; |
| 9757 | #endif |
| 9758 | |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 9759 | #ifdef CONFIG_SPLICE |
| 9760 | #ifdef TARGET_NR_tee |
| 9761 | case TARGET_NR_tee: |
| 9762 | { |
| 9763 | ret = get_errno(tee(arg1,arg2,arg3,arg4)); |
| 9764 | } |
| 9765 | break; |
| 9766 | #endif |
| 9767 | #ifdef TARGET_NR_splice |
| 9768 | case TARGET_NR_splice: |
| 9769 | { |
| 9770 | loff_t loff_in, loff_out; |
| 9771 | loff_t *ploff_in = NULL, *ploff_out = NULL; |
Andreas Schwab | 17644b3 | 2015-03-10 17:11:35 +0100 | [diff] [blame] | 9772 | if (arg2) { |
| 9773 | if (get_user_u64(loff_in, arg2)) { |
| 9774 | goto efault; |
| 9775 | } |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 9776 | ploff_in = &loff_in; |
| 9777 | } |
Andreas Schwab | 17644b3 | 2015-03-10 17:11:35 +0100 | [diff] [blame] | 9778 | if (arg4) { |
| 9779 | if (get_user_u64(loff_out, arg4)) { |
| 9780 | goto efault; |
| 9781 | } |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 9782 | ploff_out = &loff_out; |
| 9783 | } |
| 9784 | ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6)); |
Andreas Schwab | 17644b3 | 2015-03-10 17:11:35 +0100 | [diff] [blame] | 9785 | if (arg2) { |
| 9786 | if (put_user_u64(loff_in, arg2)) { |
| 9787 | goto efault; |
| 9788 | } |
| 9789 | } |
| 9790 | if (arg4) { |
| 9791 | if (put_user_u64(loff_out, arg4)) { |
| 9792 | goto efault; |
| 9793 | } |
| 9794 | } |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 9795 | } |
| 9796 | break; |
| 9797 | #endif |
| 9798 | #ifdef TARGET_NR_vmsplice |
| 9799 | case TARGET_NR_vmsplice: |
| 9800 | { |
Richard Henderson | f287b2c | 2012-09-15 13:20:25 -0700 | [diff] [blame] | 9801 | struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1); |
| 9802 | if (vec != NULL) { |
| 9803 | ret = get_errno(vmsplice(arg1, vec, arg3, arg4)); |
| 9804 | unlock_iovec(vec, arg2, arg3, 0); |
| 9805 | } else { |
| 9806 | ret = -host_to_target_errno(errno); |
| 9807 | } |
vibisreenivasan | 3ce34df | 2009-05-16 18:32:41 +0530 | [diff] [blame] | 9808 | } |
| 9809 | break; |
| 9810 | #endif |
| 9811 | #endif /* CONFIG_SPLICE */ |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 9812 | #ifdef CONFIG_EVENTFD |
| 9813 | #if defined(TARGET_NR_eventfd) |
| 9814 | case TARGET_NR_eventfd: |
| 9815 | ret = get_errno(eventfd(arg1, 0)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 9816 | fd_trans_unregister(ret); |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 9817 | break; |
| 9818 | #endif |
| 9819 | #if defined(TARGET_NR_eventfd2) |
| 9820 | case TARGET_NR_eventfd2: |
Petar Jovanovic | 5947c69 | 2013-04-08 20:26:10 +0200 | [diff] [blame] | 9821 | { |
| 9822 | int host_flags = arg2 & (~(TARGET_O_NONBLOCK | TARGET_O_CLOEXEC)); |
| 9823 | if (arg2 & TARGET_O_NONBLOCK) { |
| 9824 | host_flags |= O_NONBLOCK; |
| 9825 | } |
| 9826 | if (arg2 & TARGET_O_CLOEXEC) { |
| 9827 | host_flags |= O_CLOEXEC; |
| 9828 | } |
| 9829 | ret = get_errno(eventfd(arg1, host_flags)); |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 9830 | fd_trans_unregister(ret); |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 9831 | break; |
Petar Jovanovic | 5947c69 | 2013-04-08 20:26:10 +0200 | [diff] [blame] | 9832 | } |
Riku Voipio | c2882b9 | 2009-08-12 15:08:24 +0300 | [diff] [blame] | 9833 | #endif |
| 9834 | #endif /* CONFIG_EVENTFD */ |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 9835 | #if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate) |
| 9836 | case TARGET_NR_fallocate: |
Alexander Graf | 20249ae | 2012-02-06 21:37:07 +0100 | [diff] [blame] | 9837 | #if TARGET_ABI_BITS == 32 |
| 9838 | ret = get_errno(fallocate(arg1, arg2, target_offset64(arg3, arg4), |
| 9839 | target_offset64(arg5, arg6))); |
| 9840 | #else |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 9841 | ret = get_errno(fallocate(arg1, arg2, arg3, arg4)); |
Alexander Graf | 20249ae | 2012-02-06 21:37:07 +0100 | [diff] [blame] | 9842 | #endif |
Ulrich Hecht | d092793 | 2009-09-17 20:22:14 +0300 | [diff] [blame] | 9843 | break; |
| 9844 | #endif |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 9845 | #if defined(CONFIG_SYNC_FILE_RANGE) |
| 9846 | #if defined(TARGET_NR_sync_file_range) |
| 9847 | case TARGET_NR_sync_file_range: |
| 9848 | #if TARGET_ABI_BITS == 32 |
Riku Voipio | bfcedc5 | 2011-06-20 16:24:39 +0300 | [diff] [blame] | 9849 | #if defined(TARGET_MIPS) |
| 9850 | ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), |
| 9851 | target_offset64(arg5, arg6), arg7)); |
| 9852 | #else |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 9853 | ret = get_errno(sync_file_range(arg1, target_offset64(arg2, arg3), |
| 9854 | target_offset64(arg4, arg5), arg6)); |
Riku Voipio | bfcedc5 | 2011-06-20 16:24:39 +0300 | [diff] [blame] | 9855 | #endif /* !TARGET_MIPS */ |
Peter Maydell | c727f47 | 2011-01-06 11:05:10 +0000 | [diff] [blame] | 9856 | #else |
| 9857 | ret = get_errno(sync_file_range(arg1, arg2, arg3, arg4)); |
| 9858 | #endif |
| 9859 | break; |
| 9860 | #endif |
| 9861 | #if defined(TARGET_NR_sync_file_range2) |
| 9862 | case TARGET_NR_sync_file_range2: |
| 9863 | /* This is like sync_file_range but the arguments are reordered */ |
| 9864 | #if TARGET_ABI_BITS == 32 |
| 9865 | ret = get_errno(sync_file_range(arg1, target_offset64(arg3, arg4), |
| 9866 | target_offset64(arg5, arg6), arg2)); |
| 9867 | #else |
| 9868 | ret = get_errno(sync_file_range(arg1, arg3, arg4, arg2)); |
| 9869 | #endif |
| 9870 | break; |
| 9871 | #endif |
| 9872 | #endif |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 9873 | #if defined(TARGET_NR_signalfd4) |
| 9874 | case TARGET_NR_signalfd4: |
| 9875 | ret = do_signalfd4(arg1, arg2, arg4); |
| 9876 | break; |
| 9877 | #endif |
| 9878 | #if defined(TARGET_NR_signalfd) |
| 9879 | case TARGET_NR_signalfd: |
| 9880 | ret = do_signalfd4(arg1, arg2, 0); |
| 9881 | break; |
| 9882 | #endif |
Peter Maydell | 3b6edd1 | 2011-02-15 18:35:05 +0000 | [diff] [blame] | 9883 | #if defined(CONFIG_EPOLL) |
| 9884 | #if defined(TARGET_NR_epoll_create) |
| 9885 | case TARGET_NR_epoll_create: |
| 9886 | ret = get_errno(epoll_create(arg1)); |
| 9887 | break; |
| 9888 | #endif |
| 9889 | #if defined(TARGET_NR_epoll_create1) && defined(CONFIG_EPOLL_CREATE1) |
| 9890 | case TARGET_NR_epoll_create1: |
| 9891 | ret = get_errno(epoll_create1(arg1)); |
| 9892 | break; |
| 9893 | #endif |
| 9894 | #if defined(TARGET_NR_epoll_ctl) |
| 9895 | case TARGET_NR_epoll_ctl: |
| 9896 | { |
| 9897 | struct epoll_event ep; |
| 9898 | struct epoll_event *epp = 0; |
| 9899 | if (arg4) { |
| 9900 | struct target_epoll_event *target_ep; |
| 9901 | if (!lock_user_struct(VERIFY_READ, target_ep, arg4, 1)) { |
| 9902 | goto efault; |
| 9903 | } |
| 9904 | ep.events = tswap32(target_ep->events); |
| 9905 | /* The epoll_data_t union is just opaque data to the kernel, |
| 9906 | * so we transfer all 64 bits across and need not worry what |
| 9907 | * actual data type it is. |
| 9908 | */ |
| 9909 | ep.data.u64 = tswap64(target_ep->data.u64); |
| 9910 | unlock_user_struct(target_ep, arg4, 0); |
| 9911 | epp = &ep; |
| 9912 | } |
| 9913 | ret = get_errno(epoll_ctl(arg1, arg2, arg3, epp)); |
| 9914 | break; |
| 9915 | } |
| 9916 | #endif |
| 9917 | |
| 9918 | #if defined(TARGET_NR_epoll_pwait) && defined(CONFIG_EPOLL_PWAIT) |
| 9919 | #define IMPLEMENT_EPOLL_PWAIT |
| 9920 | #endif |
| 9921 | #if defined(TARGET_NR_epoll_wait) || defined(IMPLEMENT_EPOLL_PWAIT) |
| 9922 | #if defined(TARGET_NR_epoll_wait) |
| 9923 | case TARGET_NR_epoll_wait: |
| 9924 | #endif |
| 9925 | #if defined(IMPLEMENT_EPOLL_PWAIT) |
| 9926 | case TARGET_NR_epoll_pwait: |
| 9927 | #endif |
| 9928 | { |
| 9929 | struct target_epoll_event *target_ep; |
| 9930 | struct epoll_event *ep; |
| 9931 | int epfd = arg1; |
| 9932 | int maxevents = arg3; |
| 9933 | int timeout = arg4; |
| 9934 | |
| 9935 | target_ep = lock_user(VERIFY_WRITE, arg2, |
| 9936 | maxevents * sizeof(struct target_epoll_event), 1); |
| 9937 | if (!target_ep) { |
| 9938 | goto efault; |
| 9939 | } |
| 9940 | |
| 9941 | ep = alloca(maxevents * sizeof(struct epoll_event)); |
| 9942 | |
| 9943 | switch (num) { |
| 9944 | #if defined(IMPLEMENT_EPOLL_PWAIT) |
| 9945 | case TARGET_NR_epoll_pwait: |
| 9946 | { |
| 9947 | target_sigset_t *target_set; |
| 9948 | sigset_t _set, *set = &_set; |
| 9949 | |
| 9950 | if (arg5) { |
| 9951 | target_set = lock_user(VERIFY_READ, arg5, |
| 9952 | sizeof(target_sigset_t), 1); |
| 9953 | if (!target_set) { |
| 9954 | unlock_user(target_ep, arg2, 0); |
| 9955 | goto efault; |
| 9956 | } |
| 9957 | target_to_host_sigset(set, target_set); |
| 9958 | unlock_user(target_set, arg5, 0); |
| 9959 | } else { |
| 9960 | set = NULL; |
| 9961 | } |
| 9962 | |
| 9963 | ret = get_errno(epoll_pwait(epfd, ep, maxevents, timeout, set)); |
| 9964 | break; |
| 9965 | } |
| 9966 | #endif |
| 9967 | #if defined(TARGET_NR_epoll_wait) |
| 9968 | case TARGET_NR_epoll_wait: |
| 9969 | ret = get_errno(epoll_wait(epfd, ep, maxevents, timeout)); |
| 9970 | break; |
| 9971 | #endif |
| 9972 | default: |
| 9973 | ret = -TARGET_ENOSYS; |
| 9974 | } |
| 9975 | if (!is_error(ret)) { |
| 9976 | int i; |
| 9977 | for (i = 0; i < ret; i++) { |
| 9978 | target_ep[i].events = tswap32(ep[i].events); |
| 9979 | target_ep[i].data.u64 = tswap64(ep[i].data.u64); |
| 9980 | } |
| 9981 | } |
| 9982 | unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event)); |
| 9983 | break; |
| 9984 | } |
| 9985 | #endif |
| 9986 | #endif |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 9987 | #ifdef TARGET_NR_prlimit64 |
| 9988 | case TARGET_NR_prlimit64: |
| 9989 | { |
| 9990 | /* args: pid, resource number, ptr to new rlimit, ptr to old rlimit */ |
| 9991 | struct target_rlimit64 *target_rnew, *target_rold; |
| 9992 | struct host_rlimit64 rnew, rold, *rnewp = 0; |
Felix Janda | 9501801 | 2014-12-02 22:11:17 +0100 | [diff] [blame] | 9993 | int resource = target_to_host_resource(arg2); |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 9994 | if (arg3) { |
| 9995 | if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) { |
| 9996 | goto efault; |
| 9997 | } |
| 9998 | rnew.rlim_cur = tswap64(target_rnew->rlim_cur); |
| 9999 | rnew.rlim_max = tswap64(target_rnew->rlim_max); |
| 10000 | unlock_user_struct(target_rnew, arg3, 0); |
| 10001 | rnewp = &rnew; |
| 10002 | } |
| 10003 | |
Felix Janda | 9501801 | 2014-12-02 22:11:17 +0100 | [diff] [blame] | 10004 | ret = get_errno(sys_prlimit64(arg1, resource, rnewp, arg4 ? &rold : 0)); |
Peter Maydell | 163a05a | 2011-06-27 17:44:52 +0100 | [diff] [blame] | 10005 | if (!is_error(ret) && arg4) { |
| 10006 | if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) { |
| 10007 | goto efault; |
| 10008 | } |
| 10009 | target_rold->rlim_cur = tswap64(rold.rlim_cur); |
| 10010 | target_rold->rlim_max = tswap64(rold.rlim_max); |
| 10011 | unlock_user_struct(target_rold, arg4, 1); |
| 10012 | } |
| 10013 | break; |
| 10014 | } |
| 10015 | #endif |
Richard Henderson | 3d21d29 | 2012-09-15 13:20:46 -0700 | [diff] [blame] | 10016 | #ifdef TARGET_NR_gethostname |
| 10017 | case TARGET_NR_gethostname: |
| 10018 | { |
| 10019 | char *name = lock_user(VERIFY_WRITE, arg1, arg2, 0); |
| 10020 | if (name) { |
| 10021 | ret = get_errno(gethostname(name, arg2)); |
| 10022 | unlock_user(name, arg1, arg2); |
| 10023 | } else { |
| 10024 | ret = -TARGET_EFAULT; |
| 10025 | } |
| 10026 | break; |
| 10027 | } |
| 10028 | #endif |
Riku Voipio | 89aaf1a | 2013-07-24 09:44:26 +0300 | [diff] [blame] | 10029 | #ifdef TARGET_NR_atomic_cmpxchg_32 |
| 10030 | case TARGET_NR_atomic_cmpxchg_32: |
| 10031 | { |
| 10032 | /* should use start_exclusive from main.c */ |
| 10033 | abi_ulong mem_value; |
| 10034 | if (get_user_u32(mem_value, arg6)) { |
| 10035 | target_siginfo_t info; |
| 10036 | info.si_signo = SIGSEGV; |
| 10037 | info.si_errno = 0; |
| 10038 | info.si_code = TARGET_SEGV_MAPERR; |
| 10039 | info._sifields._sigfault._addr = arg6; |
| 10040 | queue_signal((CPUArchState *)cpu_env, info.si_signo, &info); |
| 10041 | ret = 0xdeadbeef; |
| 10042 | |
| 10043 | } |
| 10044 | if (mem_value == arg2) |
| 10045 | put_user_u32(arg1, arg6); |
| 10046 | ret = mem_value; |
| 10047 | break; |
| 10048 | } |
| 10049 | #endif |
| 10050 | #ifdef TARGET_NR_atomic_barrier |
| 10051 | case TARGET_NR_atomic_barrier: |
| 10052 | { |
| 10053 | /* Like the kernel implementation and the qemu arm barrier, no-op this? */ |
Peter Maydell | 3b899ea | 2014-03-12 13:06:01 +0000 | [diff] [blame] | 10054 | ret = 0; |
Riku Voipio | 89aaf1a | 2013-07-24 09:44:26 +0300 | [diff] [blame] | 10055 | break; |
| 10056 | } |
| 10057 | #endif |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10058 | |
| 10059 | #ifdef TARGET_NR_timer_create |
| 10060 | case TARGET_NR_timer_create: |
| 10061 | { |
| 10062 | /* args: clockid_t clockid, struct sigevent *sevp, timer_t *timerid */ |
| 10063 | |
| 10064 | struct sigevent host_sevp = { {0}, }, *phost_sevp = NULL; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10065 | |
| 10066 | int clkid = arg1; |
| 10067 | int timer_index = next_free_host_timer(); |
| 10068 | |
| 10069 | if (timer_index < 0) { |
| 10070 | ret = -TARGET_EAGAIN; |
| 10071 | } else { |
| 10072 | timer_t *phtimer = g_posix_timers + timer_index; |
| 10073 | |
| 10074 | if (arg2) { |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10075 | phost_sevp = &host_sevp; |
Peter Maydell | c065976 | 2014-08-09 15:42:32 +0100 | [diff] [blame] | 10076 | ret = target_to_host_sigevent(phost_sevp, arg2); |
| 10077 | if (ret != 0) { |
| 10078 | break; |
| 10079 | } |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10080 | } |
| 10081 | |
| 10082 | ret = get_errno(timer_create(clkid, phost_sevp, phtimer)); |
| 10083 | if (ret) { |
| 10084 | phtimer = NULL; |
| 10085 | } else { |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10086 | if (put_user(TIMER_MAGIC | timer_index, arg3, target_timer_t)) { |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10087 | goto efault; |
| 10088 | } |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10089 | } |
| 10090 | } |
| 10091 | break; |
| 10092 | } |
| 10093 | #endif |
| 10094 | |
| 10095 | #ifdef TARGET_NR_timer_settime |
| 10096 | case TARGET_NR_timer_settime: |
| 10097 | { |
| 10098 | /* args: timer_t timerid, int flags, const struct itimerspec *new_value, |
| 10099 | * struct itimerspec * old_value */ |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10100 | target_timer_t timerid = get_timer_id(arg1); |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10101 | |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10102 | if (timerid < 0) { |
| 10103 | ret = timerid; |
| 10104 | } else if (arg3 == 0) { |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10105 | ret = -TARGET_EINVAL; |
| 10106 | } else { |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10107 | timer_t htimer = g_posix_timers[timerid]; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10108 | struct itimerspec hspec_new = {{0},}, hspec_old = {{0},}; |
| 10109 | |
| 10110 | target_to_host_itimerspec(&hspec_new, arg3); |
| 10111 | ret = get_errno( |
| 10112 | timer_settime(htimer, arg2, &hspec_new, &hspec_old)); |
| 10113 | host_to_target_itimerspec(arg2, &hspec_old); |
| 10114 | } |
| 10115 | break; |
| 10116 | } |
| 10117 | #endif |
| 10118 | |
| 10119 | #ifdef TARGET_NR_timer_gettime |
| 10120 | case TARGET_NR_timer_gettime: |
| 10121 | { |
| 10122 | /* args: timer_t timerid, struct itimerspec *curr_value */ |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10123 | target_timer_t timerid = get_timer_id(arg1); |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10124 | |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10125 | if (timerid < 0) { |
| 10126 | ret = timerid; |
| 10127 | } else if (!arg2) { |
| 10128 | ret = -TARGET_EFAULT; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10129 | } else { |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10130 | timer_t htimer = g_posix_timers[timerid]; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10131 | struct itimerspec hspec; |
| 10132 | ret = get_errno(timer_gettime(htimer, &hspec)); |
| 10133 | |
| 10134 | if (host_to_target_itimerspec(arg2, &hspec)) { |
| 10135 | ret = -TARGET_EFAULT; |
| 10136 | } |
| 10137 | } |
| 10138 | break; |
| 10139 | } |
| 10140 | #endif |
| 10141 | |
| 10142 | #ifdef TARGET_NR_timer_getoverrun |
| 10143 | case TARGET_NR_timer_getoverrun: |
| 10144 | { |
| 10145 | /* args: timer_t timerid */ |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10146 | target_timer_t timerid = get_timer_id(arg1); |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10147 | |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10148 | if (timerid < 0) { |
| 10149 | ret = timerid; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10150 | } else { |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10151 | timer_t htimer = g_posix_timers[timerid]; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10152 | ret = get_errno(timer_getoverrun(htimer)); |
| 10153 | } |
Laurent Vivier | e36800c | 2015-10-02 14:48:09 +0200 | [diff] [blame] | 10154 | fd_trans_unregister(ret); |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10155 | break; |
| 10156 | } |
| 10157 | #endif |
| 10158 | |
| 10159 | #ifdef TARGET_NR_timer_delete |
| 10160 | case TARGET_NR_timer_delete: |
| 10161 | { |
| 10162 | /* args: timer_t timerid */ |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10163 | target_timer_t timerid = get_timer_id(arg1); |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10164 | |
Alexander Graf | aecc886 | 2014-11-10 21:33:03 +0100 | [diff] [blame] | 10165 | if (timerid < 0) { |
| 10166 | ret = timerid; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10167 | } else { |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10168 | timer_t htimer = g_posix_timers[timerid]; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10169 | ret = get_errno(timer_delete(htimer)); |
Alexander Graf | e52a99f | 2014-08-22 13:56:18 +0200 | [diff] [blame] | 10170 | g_posix_timers[timerid] = 0; |
Erik de Castro Lopo | f4f1e10 | 2013-11-29 18:39:23 +1100 | [diff] [blame] | 10171 | } |
| 10172 | break; |
| 10173 | } |
| 10174 | #endif |
| 10175 | |
Riku Voipio | 5183434 | 2014-06-22 11:25:42 +0100 | [diff] [blame] | 10176 | #if defined(TARGET_NR_timerfd_create) && defined(CONFIG_TIMERFD) |
| 10177 | case TARGET_NR_timerfd_create: |
| 10178 | ret = get_errno(timerfd_create(arg1, |
| 10179 | target_to_host_bitmask(arg2, fcntl_flags_tbl))); |
| 10180 | break; |
| 10181 | #endif |
| 10182 | |
| 10183 | #if defined(TARGET_NR_timerfd_gettime) && defined(CONFIG_TIMERFD) |
| 10184 | case TARGET_NR_timerfd_gettime: |
| 10185 | { |
| 10186 | struct itimerspec its_curr; |
| 10187 | |
| 10188 | ret = get_errno(timerfd_gettime(arg1, &its_curr)); |
| 10189 | |
| 10190 | if (arg2 && host_to_target_itimerspec(arg2, &its_curr)) { |
| 10191 | goto efault; |
| 10192 | } |
| 10193 | } |
| 10194 | break; |
| 10195 | #endif |
| 10196 | |
| 10197 | #if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD) |
| 10198 | case TARGET_NR_timerfd_settime: |
| 10199 | { |
| 10200 | struct itimerspec its_new, its_old, *p_new; |
| 10201 | |
| 10202 | if (arg3) { |
| 10203 | if (target_to_host_itimerspec(&its_new, arg3)) { |
| 10204 | goto efault; |
| 10205 | } |
| 10206 | p_new = &its_new; |
| 10207 | } else { |
| 10208 | p_new = NULL; |
| 10209 | } |
| 10210 | |
| 10211 | ret = get_errno(timerfd_settime(arg1, arg2, p_new, &its_old)); |
| 10212 | |
| 10213 | if (arg4 && host_to_target_itimerspec(arg4, &its_old)) { |
| 10214 | goto efault; |
| 10215 | } |
| 10216 | } |
| 10217 | break; |
| 10218 | #endif |
| 10219 | |
Paul Burton | ab31cda | 2014-06-22 11:25:43 +0100 | [diff] [blame] | 10220 | #if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get) |
| 10221 | case TARGET_NR_ioprio_get: |
| 10222 | ret = get_errno(ioprio_get(arg1, arg2)); |
| 10223 | break; |
| 10224 | #endif |
| 10225 | |
| 10226 | #if defined(TARGET_NR_ioprio_set) && defined(__NR_ioprio_set) |
| 10227 | case TARGET_NR_ioprio_set: |
| 10228 | ret = get_errno(ioprio_set(arg1, arg2, arg3)); |
| 10229 | break; |
| 10230 | #endif |
| 10231 | |
Riku Voipio | 9af5c90 | 2014-08-12 15:58:57 +0300 | [diff] [blame] | 10232 | #if defined(TARGET_NR_setns) && defined(CONFIG_SETNS) |
| 10233 | case TARGET_NR_setns: |
| 10234 | ret = get_errno(setns(arg1, arg2)); |
| 10235 | break; |
| 10236 | #endif |
| 10237 | #if defined(TARGET_NR_unshare) && defined(CONFIG_SETNS) |
| 10238 | case TARGET_NR_unshare: |
| 10239 | ret = get_errno(unshare(arg1)); |
| 10240 | break; |
| 10241 | #endif |
| 10242 | |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 10243 | default: |
| 10244 | unimplemented: |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 10245 | gemu_log("qemu: Unsupported syscall: %d\n", num); |
ths | 4f2b1fe | 2007-06-21 21:57:12 +0000 | [diff] [blame] | 10246 | #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list) |
bellard | 5cd4393 | 2003-03-29 16:54:36 +0000 | [diff] [blame] | 10247 | unimplemented_nowarn: |
bellard | 80a9d03 | 2005-01-03 23:31:27 +0000 | [diff] [blame] | 10248 | #endif |
ths | 0da46a6 | 2007-10-20 20:23:07 +0000 | [diff] [blame] | 10249 | ret = -TARGET_ENOSYS; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 10250 | break; |
| 10251 | } |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 10252 | fail: |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 10253 | #ifdef DEBUG |
Blue Swirl | 0bf9e31 | 2009-07-20 17:19:25 +0000 | [diff] [blame] | 10254 | gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret); |
bellard | c573ff6 | 2004-01-04 15:51:36 +0000 | [diff] [blame] | 10255 | #endif |
ths | b92c47c | 2007-11-01 00:07:38 +0000 | [diff] [blame] | 10256 | if(do_strace) |
| 10257 | print_syscall_ret(num, ret); |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 10258 | return ret; |
bellard | 579a97f | 2007-11-11 14:26:47 +0000 | [diff] [blame] | 10259 | efault: |
| 10260 | ret = -TARGET_EFAULT; |
| 10261 | goto fail; |
bellard | 31e31b8 | 2003-02-18 22:55:36 +0000 | [diff] [blame] | 10262 | } |