Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004-2007 Ulrich Drepper <drepper@redhat.com> |
| 3 | * Copyright (c) 2004 Roland McGrath <roland@redhat.com> |
| 4 | * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org> |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 5 | * Copyright (c) 2015-2018 The strace developers. |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +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. |
| 29 | */ |
| 30 | |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 31 | #include "defs.h" |
| 32 | #include <fcntl.h> |
Dmitry V. Levin | 6d44012 | 2016-05-09 21:46:17 +0000 | [diff] [blame] | 33 | #include <sys/epoll.h> |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 34 | |
Dmitry V. Levin | baaa41c | 2015-08-01 23:11:43 +0000 | [diff] [blame] | 35 | SYS_FUNC(epoll_create) |
| 36 | { |
| 37 | tprintf("%d", (int) tcp->u_arg[0]); |
| 38 | |
| 39 | return RVAL_DECODED | RVAL_FD; |
| 40 | } |
| 41 | |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 42 | #include "xlat/epollflags.h" |
| 43 | |
| 44 | SYS_FUNC(epoll_create1) |
| 45 | { |
| 46 | printflags(epollflags, tcp->u_arg[0], "EPOLL_???"); |
| 47 | |
Dmitry V. Levin | 7b378e6 | 2015-08-01 23:08:39 +0000 | [diff] [blame] | 48 | return RVAL_DECODED | RVAL_FD; |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Dmitry V. Levin | 6d44012 | 2016-05-09 21:46:17 +0000 | [diff] [blame] | 51 | #include "xlat/epollevents.h" |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 52 | |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 53 | static bool |
| 54 | print_epoll_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 55 | { |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 56 | const struct epoll_event *ev = elem_buf; |
| 57 | |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 58 | tprints("{"); |
| 59 | printflags(epollevents, ev->events, "EPOLL???"); |
| 60 | /* We cannot know what format the program uses, so print u32 and u64 |
| 61 | which will cover every value. */ |
| 62 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 63 | ev->data.u32, ev->data.u64); |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 64 | |
| 65 | return true; |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 66 | } |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 67 | |
| 68 | #include "xlat/epollctls.h" |
| 69 | |
| 70 | SYS_FUNC(epoll_ctl) |
| 71 | { |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 72 | printfd(tcp, tcp->u_arg[0]); |
| 73 | tprints(", "); |
Dmitry V. Levin | 55044d9 | 2016-05-16 21:43:35 +0000 | [diff] [blame] | 74 | const unsigned int op = tcp->u_arg[1]; |
| 75 | printxval(epollctls, op, "EPOLL_CTL_???"); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 76 | tprints(", "); |
| 77 | printfd(tcp, tcp->u_arg[2]); |
| 78 | tprints(", "); |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 79 | struct epoll_event ev; |
Dmitry V. Levin | 55044d9 | 2016-05-16 21:43:35 +0000 | [diff] [blame] | 80 | if (EPOLL_CTL_DEL == op) |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 81 | printaddr(tcp->u_arg[3]); |
| 82 | else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev)) |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 83 | print_epoll_event(tcp, &ev, sizeof(ev), 0); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 84 | |
| 85 | return RVAL_DECODED; |
| 86 | } |
| 87 | |
| 88 | static void |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 89 | epoll_wait_common(struct tcb *tcp) |
| 90 | { |
| 91 | if (entering(tcp)) { |
| 92 | printfd(tcp, tcp->u_arg[0]); |
| 93 | tprints(", "); |
| 94 | } else { |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 95 | struct epoll_event ev; |
| 96 | print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev), |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 97 | tfetch_mem, print_epoll_event, 0); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 98 | tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | SYS_FUNC(epoll_wait) |
| 103 | { |
| 104 | epoll_wait_common(tcp); |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | SYS_FUNC(epoll_pwait) |
| 109 | { |
| 110 | epoll_wait_common(tcp); |
| 111 | if (exiting(tcp)) { |
| 112 | tprints(", "); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 113 | /* NB: kernel requires arg[5] == NSIG_BYTES */ |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 114 | print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 115 | tprintf(", %" PRI_klu, tcp->u_arg[5]); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 116 | } |
| 117 | return 0; |
| 118 | } |