Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl> |
| 3 | * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl> |
| 4 | * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. The name of the author may not be used to endorse or promote products |
| 17 | * derived from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 32 | #include <fcntl.h> |
| 33 | #include <sys/file.h> |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 34 | #ifdef HAVE_SYS_EPOLL_H |
Denys Vlasenko | a6d91de | 2012-03-16 12:02:22 +0100 | [diff] [blame] | 35 | # include <sys/epoll.h> |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 36 | #endif |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 37 | #ifdef HAVE_LINUX_PERF_EVENT_H |
| 38 | # include <linux/perf_event.h> |
| 39 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 40 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 41 | static const struct xlat fcntlcmds[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 42 | XLAT(F_DUPFD), |
| 43 | XLAT(F_GETFD), |
| 44 | XLAT(F_SETFD), |
| 45 | XLAT(F_GETFL), |
| 46 | XLAT(F_SETFL), |
| 47 | XLAT(F_GETLK), |
| 48 | XLAT(F_SETLK), |
| 49 | XLAT(F_SETLKW), |
| 50 | XLAT(F_GETOWN), |
| 51 | XLAT(F_SETOWN), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 52 | #ifdef F_RSETLK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 53 | XLAT(F_RSETLK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 54 | #endif |
| 55 | #ifdef F_RSETLKW |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 56 | XLAT(F_RSETLKW), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 57 | #endif |
| 58 | #ifdef F_RGETLK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 59 | XLAT(F_RGETLK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 60 | #endif |
| 61 | #ifdef F_CNVT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 62 | XLAT(F_CNVT), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 63 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 64 | #ifdef F_SETSIG |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 65 | XLAT(F_SETSIG), |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 66 | #endif |
| 67 | #ifdef F_GETSIG |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 68 | XLAT(F_GETSIG), |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 69 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 70 | #ifdef F_CHKFL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 71 | XLAT(F_CHKFL), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 72 | #endif |
| 73 | #ifdef F_DUP2FD |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 74 | XLAT(F_DUP2FD), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 75 | #endif |
| 76 | #ifdef F_ALLOCSP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 77 | XLAT(F_ALLOCSP), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 78 | #endif |
| 79 | #ifdef F_ISSTREAM |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 80 | XLAT(F_ISSTREAM), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 81 | #endif |
| 82 | #ifdef F_PRIV |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 83 | XLAT(F_PRIV), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 84 | #endif |
| 85 | #ifdef F_NPRIV |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 86 | XLAT(F_NPRIV), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 87 | #endif |
| 88 | #ifdef F_QUOTACL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 89 | XLAT(F_QUOTACL), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 90 | #endif |
| 91 | #ifdef F_BLOCKS |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 92 | XLAT(F_BLOCKS), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 93 | #endif |
| 94 | #ifdef F_BLKSIZE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 95 | XLAT(F_BLKSIZE), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 96 | #endif |
| 97 | #ifdef F_GETOWN |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 98 | XLAT(F_GETOWN), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 99 | #endif |
| 100 | #ifdef F_SETOWN |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 101 | XLAT(F_SETOWN), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 102 | #endif |
| 103 | #ifdef F_REVOKE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 104 | XLAT(F_REVOKE), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 105 | #endif |
| 106 | #ifdef F_SETLK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 107 | XLAT(F_SETLK), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 108 | #endif |
| 109 | #ifdef F_SETLKW |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 110 | XLAT(F_SETLKW), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 111 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 112 | #ifdef F_GETLK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 113 | XLAT(F_GETLK), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 114 | #endif |
| 115 | #ifdef F_SETLK64 |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 116 | XLAT(F_SETLK64), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 117 | #endif |
| 118 | #ifdef F_SETLKW64 |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 119 | XLAT(F_SETLKW64), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 120 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 121 | #ifdef F_GETLK64 |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 122 | XLAT(F_GETLK64), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 123 | #endif |
| 124 | #ifdef F_SHARE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 125 | XLAT(F_SHARE), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 126 | #endif |
| 127 | #ifdef F_UNSHARE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 128 | XLAT(F_UNSHARE), |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 129 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 130 | #ifdef F_SETLEASE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 131 | XLAT(F_SETLEASE), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 132 | #endif |
| 133 | #ifdef F_GETLEASE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 134 | XLAT(F_GETLEASE), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 135 | #endif |
| 136 | #ifdef F_NOTIFY |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 137 | XLAT(F_NOTIFY), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 138 | #endif |
| 139 | #ifdef F_DUPFD_CLOEXEC |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 140 | XLAT(F_DUPFD_CLOEXEC), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 141 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 142 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 145 | static const struct xlat fdflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 146 | #ifdef FD_CLOEXEC |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 147 | XLAT(FD_CLOEXEC), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 148 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 149 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | #ifdef LOCK_SH |
| 153 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 154 | static const struct xlat flockcmds[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 155 | XLAT(LOCK_SH), |
| 156 | XLAT(LOCK_EX), |
| 157 | XLAT(LOCK_NB), |
| 158 | XLAT(LOCK_UN), |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 159 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | #endif /* LOCK_SH */ |
| 163 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 164 | static const struct xlat lockfcmds[] = { |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 165 | XLAT(F_RDLCK), |
| 166 | XLAT(F_WRLCK), |
| 167 | XLAT(F_UNLCK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 168 | #ifdef F_EXLCK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 169 | XLAT(F_EXLCK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 170 | #endif |
| 171 | #ifdef F_SHLCK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 172 | XLAT(F_SHLCK), |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 173 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 174 | XLAT_END |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 175 | }; |
| 176 | |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 177 | #ifdef F_NOTIFY |
| 178 | static const struct xlat notifyflags[] = { |
| 179 | #ifdef DN_ACCESS |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 180 | XLAT(DN_ACCESS), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 181 | #endif |
| 182 | #ifdef DN_MODIFY |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 183 | XLAT(DN_MODIFY), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 184 | #endif |
| 185 | #ifdef DN_CREATE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 186 | XLAT(DN_CREATE), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 187 | #endif |
| 188 | #ifdef DN_DELETE |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 189 | XLAT(DN_DELETE), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 190 | #endif |
| 191 | #ifdef DN_RENAME |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 192 | XLAT(DN_RENAME), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 193 | #endif |
| 194 | #ifdef DN_ATTRIB |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 195 | XLAT(DN_ATTRIB), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 196 | #endif |
| 197 | #ifdef DN_MULTISHOT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 198 | XLAT(DN_MULTISHOT), |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 199 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 200 | XLAT_END |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 201 | }; |
| 202 | #endif |
| 203 | |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 204 | static const struct xlat perf_event_open_flags[] = { |
| 205 | #ifdef PERF_FLAG_FD_NO_GROUP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 206 | XLAT(PERF_FLAG_FD_NO_GROUP), |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 207 | #endif |
| 208 | #ifdef PERF_FLAG_FD_OUTPUT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 209 | XLAT(PERF_FLAG_FD_OUTPUT), |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 210 | #endif |
| 211 | #ifdef PERF_FLAG_PID_CGROUP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 212 | XLAT(PERF_FLAG_PID_CGROUP), |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 213 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 214 | XLAT_END |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 215 | }; |
| 216 | |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 217 | /* |
| 218 | * Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined |
| 219 | * or not defined altogether. |
| 220 | */ |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 221 | #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 222 | # define USE_PRINTFLOCK64 1 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 223 | #else |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 224 | # define USE_PRINTFLOCK64 0 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 225 | #endif |
| 226 | |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 227 | #if USE_PRINTFLOCK64 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 228 | |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 229 | # ifndef HAVE_STRUCT_FLOCK64 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 230 | struct flock64 { |
| 231 | short int l_type, l_whence; |
| 232 | int64_t l_start, l_len; |
| 233 | int l_pid; |
| 234 | }; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 235 | # endif |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 236 | |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 237 | static void |
| 238 | printflock64(struct tcb *tcp, long addr, int getlk) |
| 239 | { |
| 240 | struct flock64 fl; |
| 241 | |
| 242 | if (umove(tcp, addr, &fl) < 0) { |
| 243 | tprints("{...}"); |
| 244 | return; |
| 245 | } |
| 246 | tprints("{type="); |
| 247 | printxval(lockfcmds, fl.l_type, "F_???"); |
| 248 | tprints(", whence="); |
| 249 | printxval(whence_codes, fl.l_whence, "SEEK_???"); |
| 250 | tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len); |
| 251 | if (getlk) |
| 252 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 253 | else |
| 254 | tprints("}"); |
| 255 | } |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 256 | #endif /* USE_PRINTFLOCK64 */ |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 257 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 258 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 259 | printflock(struct tcb *tcp, long addr, int getlk) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 260 | { |
| 261 | struct flock fl; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 262 | int r; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 263 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 264 | #if SUPPORTED_PERSONALITIES > 1 |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 265 | if ( |
| 266 | # if SIZEOF_OFF_T > SIZEOF_LONG |
| 267 | current_personality > 0 && |
| 268 | #endif |
| 269 | current_wordsize != sizeof(fl.l_start)) { |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 270 | if (current_wordsize == 4) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 271 | /* 32-bit x86 app on x86_64 and similar cases */ |
| 272 | struct { |
| 273 | short int l_type; |
| 274 | short int l_whence; |
| 275 | int32_t l_start; /* off_t */ |
| 276 | int32_t l_len; /* off_t */ |
| 277 | int32_t l_pid; /* pid_t */ |
| 278 | } fl32; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 279 | r = umove(tcp, addr, &fl32); |
| 280 | if (r >= 0) { |
| 281 | fl.l_type = fl32.l_type; |
| 282 | fl.l_whence = fl32.l_whence; |
| 283 | fl.l_start = fl32.l_start; |
| 284 | fl.l_len = fl32.l_len; |
| 285 | fl.l_pid = fl32.l_pid; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 286 | } |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 287 | } else { |
| 288 | /* let people know we have a problem here */ |
Denys Vlasenko | 751acb3 | 2013-02-08 15:34:46 +0100 | [diff] [blame] | 289 | tprintf("<decode error: unsupported wordsize %d>", |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 290 | current_wordsize); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | } else |
| 294 | #endif |
| 295 | { |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 296 | r = umove(tcp, addr, &fl); |
| 297 | } |
| 298 | if (r < 0) { |
| 299 | tprints("{...}"); |
| 300 | return; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 301 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 302 | tprints("{type="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 303 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 304 | tprints(", whence="); |
Denys Vlasenko | 86738a2 | 2013-02-17 14:31:55 +0100 | [diff] [blame] | 305 | printxval(whence_codes, fl.l_whence, "SEEK_???"); |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 306 | #if SIZEOF_OFF_T > SIZEOF_LONG |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 307 | tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len); |
| 308 | #else |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 309 | tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 310 | #endif |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 311 | if (getlk) |
| 312 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 313 | else |
| 314 | tprints("}"); |
| 315 | } |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 316 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 317 | int |
| 318 | sys_fcntl(struct tcb *tcp) |
| 319 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 320 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 321 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 322 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 324 | switch (tcp->u_arg[1]) { |
| 325 | case F_SETFD: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 326 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 327 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 328 | break; |
| 329 | case F_SETOWN: case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 330 | #ifdef F_DUPFD_CLOEXEC |
| 331 | case F_DUPFD_CLOEXEC: |
| 332 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | tprintf(", %ld", tcp->u_arg[2]); |
| 334 | break; |
| 335 | case F_SETFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 336 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 337 | tprint_open_modes(tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 338 | break; |
| 339 | case F_SETLK: case F_SETLKW: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 340 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 341 | printflock(tcp, tcp->u_arg[2], 0); |
| 342 | break; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 343 | #if USE_PRINTFLOCK64 |
| 344 | case F_SETLK64: case F_SETLKW64: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 345 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 346 | printflock64(tcp, tcp->u_arg[2], 0); |
| 347 | break; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 348 | #endif /* USE_PRINTFLOCK64 */ |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 349 | #ifdef F_NOTIFY |
| 350 | case F_NOTIFY: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 351 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 352 | printflags(notifyflags, tcp->u_arg[2], "DN_???"); |
| 353 | break; |
| 354 | #endif |
| 355 | #ifdef F_SETLEASE |
| 356 | case F_SETLEASE: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 357 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 358 | printxval(lockfcmds, tcp->u_arg[2], "F_???"); |
| 359 | break; |
| 360 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 361 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 362 | } |
| 363 | else { |
| 364 | switch (tcp->u_arg[1]) { |
| 365 | case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 366 | #ifdef F_DUPFD_CLOEXEC |
| 367 | case F_DUPFD_CLOEXEC: |
| 368 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 369 | case F_SETFD: case F_SETFL: |
| 370 | case F_SETLK: case F_SETLKW: |
| 371 | case F_SETOWN: case F_GETOWN: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 372 | #ifdef F_NOTIFY |
| 373 | case F_NOTIFY: |
| 374 | #endif |
| 375 | #ifdef F_SETLEASE |
| 376 | case F_SETLEASE: |
| 377 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 378 | break; |
| 379 | case F_GETFD: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 380 | if (syserror(tcp) || tcp->u_rval == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 381 | return 0; |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 382 | tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 383 | return RVAL_HEX|RVAL_STR; |
| 384 | case F_GETFL: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 385 | if (syserror(tcp)) |
| 386 | return 0; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 387 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 388 | return RVAL_HEX|RVAL_STR; |
| 389 | case F_GETLK: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 390 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 391 | printflock(tcp, tcp->u_arg[2], 1); |
| 392 | break; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame^] | 393 | #if USE_PRINTFLOCK64 |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 394 | case F_GETLK64: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 395 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 396 | printflock64(tcp, tcp->u_arg[2], 1); |
| 397 | break; |
| 398 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 399 | #ifdef F_GETLEASE |
| 400 | case F_GETLEASE: |
| 401 | if (syserror(tcp)) |
| 402 | return 0; |
| 403 | tcp->auxstr = xlookup(lockfcmds, tcp->u_rval); |
| 404 | return RVAL_HEX|RVAL_STR; |
| 405 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 406 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 407 | tprintf(", %#lx", tcp->u_arg[2]); |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | #ifdef LOCK_SH |
| 415 | |
| 416 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 417 | sys_flock(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 418 | { |
| 419 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 420 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 421 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 422 | printflags(flockcmds, tcp->u_arg[1], "LOCK_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 423 | } |
| 424 | return 0; |
| 425 | } |
| 426 | #endif /* LOCK_SH */ |
| 427 | |
| 428 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 429 | sys_close(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 430 | { |
| 431 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 432 | printfd(tcp, tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 433 | } |
| 434 | return 0; |
| 435 | } |
| 436 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 437 | static int |
| 438 | do_dup2(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 439 | { |
| 440 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 441 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 442 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 443 | printfd(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 444 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 445 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 446 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 447 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 448 | } |
| 449 | return 0; |
| 450 | } |
| 451 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 452 | int |
| 453 | sys_dup2(struct tcb *tcp) |
| 454 | { |
| 455 | return do_dup2(tcp, -1); |
| 456 | } |
| 457 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 458 | int |
| 459 | sys_dup3(struct tcb *tcp) |
| 460 | { |
| 461 | return do_dup2(tcp, 2); |
| 462 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 463 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 464 | #if defined(ALPHA) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 465 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 466 | sys_getdtablesize(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 467 | { |
| 468 | return 0; |
| 469 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 470 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 471 | |
Dmitry V. Levin | c2982b5 | 2013-11-05 23:00:22 +0000 | [diff] [blame] | 472 | static int |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 473 | decode_select(struct tcb *tcp, long *args, enum bitness_t bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 474 | { |
Denys Vlasenko | ad5155a | 2011-09-01 18:18:04 +0200 | [diff] [blame] | 475 | int i, j; |
Denys Vlasenko | 1f65c3c | 2013-11-05 16:20:16 +0100 | [diff] [blame] | 476 | int nfds, fdsize; |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 477 | fd_set *fds; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 478 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 479 | long arg; |
| 480 | |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 481 | /* Kernel truncates arg[0] to int, we do the same. */ |
| 482 | nfds = (int) args[0]; |
| 483 | |
| 484 | /* Kernel rejects negative nfds, so we don't parse it either. */ |
| 485 | if (nfds < 0) { |
| 486 | nfds = 0; |
| 487 | fds = NULL; |
| 488 | } |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 489 | /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */ |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 490 | if (nfds > 1024*1024) |
| 491 | nfds = 1024*1024; |
| 492 | |
| 493 | /* |
| 494 | * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below. |
Dr. David Alan Gilbert | 025f108 | 2013-11-05 11:54:51 +0100 | [diff] [blame] | 495 | * Instead of args[0], use nfds for fd count, fdsize for array lengths. |
| 496 | */ |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 497 | fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize; |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 498 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 499 | if (entering(tcp)) { |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 500 | tprintf("%d", (int) args[0]); |
| 501 | |
| 502 | if (fdsize > 0) { |
| 503 | fds = malloc(fdsize); |
| 504 | if (!fds) |
| 505 | die_out_of_memory(); |
| 506 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 507 | for (i = 0; i < 3; i++) { |
| 508 | arg = args[i+1]; |
| 509 | if (arg == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 510 | tprints(", NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 511 | continue; |
| 512 | } |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 513 | if (!verbose(tcp) || !fds) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 514 | tprintf(", %#lx", arg); |
| 515 | continue; |
| 516 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 517 | if (umoven(tcp, arg, fdsize, (char *) fds) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 518 | tprints(", [?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 519 | continue; |
| 520 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 521 | tprints(", ["); |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 522 | for (j = 0, sep = "";; j++) { |
| 523 | j = next_set_bit(fds, j, nfds); |
| 524 | if (j < 0) |
| 525 | break; |
| 526 | tprints(sep); |
| 527 | printfd(tcp, j); |
| 528 | sep = " "; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 529 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 530 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 531 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 532 | free(fds); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 533 | tprints(", "); |
Roland McGrath | 6afc565 | 2007-07-24 01:57:11 +0000 | [diff] [blame] | 534 | printtv_bitness(tcp, args[4], bitness, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 535 | } |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 536 | else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 537 | static char outstr[1024]; |
| 538 | char *outptr; |
| 539 | #define end_outstr (outstr + sizeof(outstr)) |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 540 | int ready_fds; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 541 | |
| 542 | if (syserror(tcp)) |
| 543 | return 0; |
| 544 | |
Dr. David Alan Gilbert | 025f108 | 2013-11-05 11:54:51 +0100 | [diff] [blame] | 545 | ready_fds = tcp->u_rval; |
| 546 | if (ready_fds == 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 547 | tcp->auxstr = "Timeout"; |
| 548 | return RVAL_STR; |
| 549 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 550 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 551 | fds = malloc(fdsize); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 552 | if (!fds) |
| 553 | die_out_of_memory(); |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 554 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 555 | outptr = outstr; |
| 556 | sep = ""; |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 557 | for (i = 0; i < 3 && ready_fds > 0; i++) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 558 | int first = 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 559 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 560 | arg = args[i+1]; |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 561 | if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 562 | continue; |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 563 | for (j = 0;; j++) { |
| 564 | j = next_set_bit(fds, j, nfds); |
| 565 | if (j < 0) |
| 566 | break; |
| 567 | /* +2 chars needed at the end: ']',NUL */ |
| 568 | if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) { |
| 569 | if (first) { |
| 570 | outptr += sprintf(outptr, "%s%s [%u", |
| 571 | sep, |
| 572 | i == 0 ? "in" : i == 1 ? "out" : "except", |
| 573 | j |
| 574 | ); |
| 575 | first = 0; |
| 576 | sep = ", "; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 577 | } |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 578 | else { |
| 579 | outptr += sprintf(outptr, " %u", j); |
| 580 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 581 | } |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 582 | if (--ready_fds == 0) |
| 583 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 584 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 585 | if (outptr != outstr) |
| 586 | *outptr++ = ']'; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 587 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 588 | free(fds); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 589 | /* This contains no useful information on SunOS. */ |
| 590 | if (args[4]) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 591 | if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 592 | outptr += sprintf(outptr, "%sleft ", sep); |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 593 | outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 594 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 595 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 596 | *outptr = '\0'; |
Denys Vlasenko | 1161725 | 2011-09-01 11:27:37 +0200 | [diff] [blame] | 597 | tcp->auxstr = outstr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 598 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 599 | #undef end_outstr |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 600 | } |
| 601 | return 0; |
| 602 | } |
| 603 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 604 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 605 | sys_oldselect(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 606 | { |
| 607 | long args[5]; |
| 608 | |
| 609 | if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 610 | tprints("[...]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 611 | return 0; |
| 612 | } |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 613 | return decode_select(tcp, args, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 616 | #ifdef ALPHA |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 617 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 618 | sys_osf_select(struct tcb *tcp) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 619 | { |
| 620 | long *args = tcp->u_arg; |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 621 | return decode_select(tcp, args, BITNESS_32); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 622 | } |
| 623 | #endif |
| 624 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 625 | static const struct xlat epollctls[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 626 | #ifdef EPOLL_CTL_ADD |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 627 | XLAT(EPOLL_CTL_ADD), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 628 | #endif |
| 629 | #ifdef EPOLL_CTL_MOD |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 630 | XLAT(EPOLL_CTL_MOD), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 631 | #endif |
| 632 | #ifdef EPOLL_CTL_DEL |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 633 | XLAT(EPOLL_CTL_DEL), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 634 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 635 | XLAT_END |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 636 | }; |
| 637 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 638 | static const struct xlat epollevents[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 639 | #ifdef EPOLLIN |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 640 | XLAT(EPOLLIN), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 641 | #endif |
| 642 | #ifdef EPOLLPRI |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 643 | XLAT(EPOLLPRI), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 644 | #endif |
| 645 | #ifdef EPOLLOUT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 646 | XLAT(EPOLLOUT), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 647 | #endif |
| 648 | #ifdef EPOLLRDNORM |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 649 | XLAT(EPOLLRDNORM), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 650 | #endif |
| 651 | #ifdef EPOLLRDBAND |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 652 | XLAT(EPOLLRDBAND), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 653 | #endif |
| 654 | #ifdef EPOLLWRNORM |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 655 | XLAT(EPOLLWRNORM), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 656 | #endif |
| 657 | #ifdef EPOLLWRBAND |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 658 | XLAT(EPOLLWRBAND), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 659 | #endif |
| 660 | #ifdef EPOLLMSG |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 661 | XLAT(EPOLLMSG), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 662 | #endif |
| 663 | #ifdef EPOLLERR |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 664 | XLAT(EPOLLERR), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 665 | #endif |
| 666 | #ifdef EPOLLHUP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 667 | XLAT(EPOLLHUP), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 668 | #endif |
Dmitry V. Levin | 5967c1a | 2011-10-11 15:55:40 +0000 | [diff] [blame] | 669 | #ifdef EPOLLRDHUP |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 670 | XLAT(EPOLLRDHUP), |
Dmitry V. Levin | 5967c1a | 2011-10-11 15:55:40 +0000 | [diff] [blame] | 671 | #endif |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 672 | #ifdef EPOLLONESHOT |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 673 | XLAT(EPOLLONESHOT), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 674 | #endif |
| 675 | #ifdef EPOLLET |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 676 | XLAT(EPOLLET), |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 677 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 678 | XLAT_END |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 679 | }; |
| 680 | |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 681 | /* Not aliased to printargs_ld: we want it to have a distinct address */ |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 682 | int |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 683 | sys_epoll_create(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 684 | { |
Denys Vlasenko | 72879c6 | 2012-02-27 14:18:02 +0100 | [diff] [blame] | 685 | return printargs_ld(tcp); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 688 | static const struct xlat epollflags[] = { |
| 689 | #ifdef EPOLL_CLOEXEC |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 690 | XLAT(EPOLL_CLOEXEC), |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 691 | #endif |
| 692 | #ifdef EPOLL_NONBLOCK |
Dmitry V. Levin | bce0cc6 | 2014-02-05 01:33:50 +0000 | [diff] [blame] | 693 | XLAT(EPOLL_NONBLOCK), |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 694 | #endif |
Dmitry V. Levin | 5945273 | 2014-02-05 02:20:51 +0000 | [diff] [blame] | 695 | XLAT_END |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 696 | }; |
| 697 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 698 | int |
| 699 | sys_epoll_create1(struct tcb *tcp) |
| 700 | { |
| 701 | if (entering(tcp)) |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 702 | printflags(epollflags, tcp->u_arg[0], "EPOLL_???"); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 706 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 707 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 708 | print_epoll_event(struct epoll_event *ev) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 709 | { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 710 | tprints("{"); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 711 | printflags(epollevents, ev->events, "EPOLL???"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 712 | /* We cannot know what format the program uses, so print u32 and u64 |
| 713 | which will cover every value. */ |
| 714 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 715 | ev->data.u32, ev->data.u64); |
| 716 | } |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 717 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 718 | |
| 719 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 720 | sys_epoll_ctl(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 721 | { |
| 722 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 723 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 724 | tprints(", "); |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 725 | printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 726 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 727 | printfd(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 728 | tprints(", "); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 729 | if (tcp->u_arg[3] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 730 | tprints("NULL"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 731 | else { |
| 732 | #ifdef HAVE_SYS_EPOLL_H |
| 733 | struct epoll_event ev; |
Roland McGrath | 6e52d23 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 734 | if (umove(tcp, tcp->u_arg[3], &ev) == 0) |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 735 | print_epoll_event(&ev); |
| 736 | else |
| 737 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 738 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 739 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 740 | } |
| 741 | return 0; |
| 742 | } |
| 743 | |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 744 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 745 | epoll_wait_common(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 746 | { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 747 | if (entering(tcp)) { |
| 748 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 749 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 750 | } else { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 751 | if (syserror(tcp)) |
| 752 | tprintf("%lx", tcp->u_arg[1]); |
| 753 | else if (tcp->u_rval == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 754 | tprints("{}"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 755 | else { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 756 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 757 | struct epoll_event ev, *start, *cur, *end; |
| 758 | int failed = 0; |
| 759 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 760 | tprints("{"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 761 | start = (struct epoll_event *) tcp->u_arg[1]; |
| 762 | end = start + tcp->u_rval; |
| 763 | for (cur = start; cur < end; ++cur) { |
| 764 | if (cur > start) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 765 | tprints(", "); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 766 | if (umove(tcp, (long) cur, &ev) == 0) |
| 767 | print_epoll_event(&ev); |
| 768 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 769 | tprints("?"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 770 | failed = 1; |
| 771 | break; |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 772 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 773 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 774 | tprints("}"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 775 | if (failed) |
| 776 | tprintf(" %#lx", (long) start); |
| 777 | #else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 778 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 779 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 780 | } |
Dmitry V. Levin | c327d71 | 2011-10-11 16:05:57 +0000 | [diff] [blame] | 781 | tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 782 | } |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 786 | sys_epoll_wait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 787 | { |
| 788 | epoll_wait_common(tcp); |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 793 | sys_epoll_pwait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 794 | { |
| 795 | epoll_wait_common(tcp); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 796 | if (exiting(tcp)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 797 | tprints(", "); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 798 | /* NB: kernel requires arg[5] == NSIG / 8 */ |
| 799 | print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]); |
| 800 | tprintf(", %lu", tcp->u_arg[5]); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 801 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 802 | return 0; |
| 803 | } |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 804 | |
| 805 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 806 | sys_select(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 807 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 808 | return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 809 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 810 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 811 | int |
| 812 | sys_pselect6(struct tcb *tcp) |
| 813 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 814 | int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 815 | if (entering(tcp)) { |
Denys Vlasenko | 8a1ebbb | 2013-07-18 18:10:13 +0200 | [diff] [blame] | 816 | long r; |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 817 | struct { |
Denys Vlasenko | 8a1ebbb | 2013-07-18 18:10:13 +0200 | [diff] [blame] | 818 | unsigned long ptr; |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 819 | unsigned long len; |
| 820 | } data; |
Denys Vlasenko | 8a1ebbb | 2013-07-18 18:10:13 +0200 | [diff] [blame] | 821 | #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4 |
| 822 | if (current_wordsize == 4) { |
| 823 | struct { |
| 824 | uint32_t ptr; |
| 825 | uint32_t len; |
| 826 | } data32; |
| 827 | r = umove(tcp, tcp->u_arg[5], &data32); |
| 828 | data.ptr = data32.ptr; |
| 829 | data.len = data32.len; |
| 830 | } else |
| 831 | #endif |
| 832 | r = umove(tcp, tcp->u_arg[5], &data); |
| 833 | if (r < 0) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 834 | tprintf(", %#lx", tcp->u_arg[5]); |
| 835 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 836 | tprints(", {"); |
Denys Vlasenko | 5e133aa | 2013-07-18 17:02:21 +0200 | [diff] [blame] | 837 | /* NB: kernel requires data.len == NSIG / 8 */ |
Denys Vlasenko | 8a1ebbb | 2013-07-18 18:10:13 +0200 | [diff] [blame] | 838 | print_sigset_addr_len(tcp, data.ptr, data.len); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 839 | tprintf(", %lu}", data.len); |
| 840 | } |
| 841 | } |
| 842 | return rc; |
| 843 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 844 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 845 | static int |
| 846 | do_eventfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 847 | { |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 848 | if (entering(tcp)) { |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 849 | tprintf("%lu", tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 850 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 851 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 852 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 853 | } |
| 854 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 855 | return 0; |
| 856 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 857 | |
| 858 | int |
| 859 | sys_eventfd(struct tcb *tcp) |
| 860 | { |
| 861 | return do_eventfd(tcp, -1); |
| 862 | } |
| 863 | |
| 864 | int |
| 865 | sys_eventfd2(struct tcb *tcp) |
| 866 | { |
| 867 | return do_eventfd(tcp, 1); |
| 868 | } |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 869 | |
| 870 | int |
| 871 | sys_perf_event_open(struct tcb *tcp) |
| 872 | { |
| 873 | if (entering(tcp)) { |
| 874 | tprintf("%#lx, %d, %d, %d, ", |
| 875 | tcp->u_arg[0], |
| 876 | (int) tcp->u_arg[1], |
| 877 | (int) tcp->u_arg[2], |
| 878 | (int) tcp->u_arg[3]); |
| 879 | printflags(perf_event_open_flags, tcp->u_arg[4], |
| 880 | "PERF_FLAG_???"); |
| 881 | } |
| 882 | return 0; |
| 883 | } |