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> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 30 | #include "defs.h" |
| 31 | #include <fcntl.h> |
Dmitry V. Levin | 6d44012 | 2016-05-09 21:46:17 +0000 | [diff] [blame] | 32 | #include <sys/epoll.h> |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 33 | |
Dmitry V. Levin | baaa41c | 2015-08-01 23:11:43 +0000 | [diff] [blame] | 34 | SYS_FUNC(epoll_create) |
| 35 | { |
| 36 | tprintf("%d", (int) tcp->u_arg[0]); |
| 37 | |
| 38 | return RVAL_DECODED | RVAL_FD; |
| 39 | } |
| 40 | |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 41 | #include "xlat/epollflags.h" |
| 42 | |
| 43 | SYS_FUNC(epoll_create1) |
| 44 | { |
| 45 | printflags(epollflags, tcp->u_arg[0], "EPOLL_???"); |
| 46 | |
Dmitry V. Levin | 7b378e6 | 2015-08-01 23:08:39 +0000 | [diff] [blame] | 47 | return RVAL_DECODED | RVAL_FD; |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Dmitry V. Levin | 6d44012 | 2016-05-09 21:46:17 +0000 | [diff] [blame] | 50 | #include "xlat/epollevents.h" |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 51 | |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 52 | static bool |
| 53 | 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] | 54 | { |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 55 | const struct epoll_event *ev = elem_buf; |
| 56 | |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 57 | tprints("{"); |
| 58 | printflags(epollevents, ev->events, "EPOLL???"); |
| 59 | /* We cannot know what format the program uses, so print u32 and u64 |
| 60 | which will cover every value. */ |
| 61 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 62 | ev->data.u32, ev->data.u64); |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 63 | |
| 64 | return true; |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 65 | } |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 66 | |
| 67 | #include "xlat/epollctls.h" |
| 68 | |
| 69 | SYS_FUNC(epoll_ctl) |
| 70 | { |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 71 | printfd(tcp, tcp->u_arg[0]); |
| 72 | tprints(", "); |
Dmitry V. Levin | 55044d9 | 2016-05-16 21:43:35 +0000 | [diff] [blame] | 73 | const unsigned int op = tcp->u_arg[1]; |
| 74 | printxval(epollctls, op, "EPOLL_CTL_???"); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 75 | tprints(", "); |
| 76 | printfd(tcp, tcp->u_arg[2]); |
| 77 | tprints(", "); |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 78 | struct epoll_event ev; |
Dmitry V. Levin | 55044d9 | 2016-05-16 21:43:35 +0000 | [diff] [blame] | 79 | if (EPOLL_CTL_DEL == op) |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 80 | printaddr(tcp->u_arg[3]); |
| 81 | else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev)) |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 82 | print_epoll_event(tcp, &ev, sizeof(ev), 0); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 83 | |
| 84 | return RVAL_DECODED; |
| 85 | } |
| 86 | |
| 87 | static void |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 88 | epoll_wait_common(struct tcb *tcp) |
| 89 | { |
| 90 | if (entering(tcp)) { |
| 91 | printfd(tcp, tcp->u_arg[0]); |
| 92 | tprints(", "); |
| 93 | } else { |
Dmitry V. Levin | 0238725 | 2016-05-07 22:49:39 +0000 | [diff] [blame] | 94 | struct epoll_event ev; |
| 95 | print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev), |
| 96 | umoven_or_printaddr, print_epoll_event, 0); |
Dmitry V. Levin | aba868c | 2015-08-01 22:58:17 +0000 | [diff] [blame] | 97 | tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | SYS_FUNC(epoll_wait) |
| 102 | { |
| 103 | epoll_wait_common(tcp); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | SYS_FUNC(epoll_pwait) |
| 108 | { |
| 109 | epoll_wait_common(tcp); |
| 110 | if (exiting(tcp)) { |
| 111 | tprints(", "); |
| 112 | /* NB: kernel requires arg[5] == NSIG / 8 */ |
| 113 | print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]); |
| 114 | tprintf(", %lu", tcp->u_arg[5]); |
| 115 | } |
| 116 | return 0; |
| 117 | } |