1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* Check decoding of rt_sigprocmask syscall.
*
* Copyright (c) 2016 Dmitry V. Levin <ldv@strace.io>
* Copyright (c) 2016-2023 The strace developers.
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include "scno.h"
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static long
k_sigprocmask(const unsigned long how, void *const new_set,
void *const old_set, const unsigned long size)
{
return syscall(__NR_rt_sigprocmask, how, new_set, old_set, size);
}
static void
iterate(const char *const text, void *set, void *old, unsigned int size)
{
for (;;) {
if (k_sigprocmask(SIG_UNBLOCK, set, old, size)) {
if (size < sizeof(long))
tprintf("rt_sigprocmask(SIG_UNBLOCK"
", %p, %p, %u)" RVAL_EINVAL,
set, old, size);
else
tprintf("rt_sigprocmask(SIG_UNBLOCK"
", %s, %p, %u)" RVAL_EINVAL,
text, old, size);
} else {
tprintf("rt_sigprocmask(SIG_UNBLOCK, %s, [], %u)"
" = 0\n", text, size);
}
if (!size)
break;
size >>= 1;
set += size;
old += size;
}
}
int
main(void)
{
tprintf("%s", "");
const unsigned int big_size = 1024 / 8;
unsigned int set_size;
for (set_size = big_size; set_size; set_size >>= 1) {
if (!k_sigprocmask(SIG_SETMASK, NULL, NULL, set_size))
break;
tprintf("rt_sigprocmask(SIG_SETMASK, NULL, NULL, %u)"
RVAL_EINVAL, set_size);
}
if (!set_size)
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_SETMASK, NULL, NULL, %u) = 0\n",
set_size);
void *const k_set = tail_alloc(set_size);
void *const old_set = tail_alloc(set_size);
TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
memset(k_set, 0, set_size);
if (k_sigprocmask(SIG_SETMASK, k_set, NULL, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_SETMASK, [], NULL, %u) = 0\n", set_size);
if (k_sigprocmask(SIG_UNBLOCK, k_set - set_size, old_set, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_UNBLOCK, ~[], [], %u) = 0\n", set_size);
assert(k_sigprocmask(SIG_SETMASK, k_set - set_size,
old_set, set_size << 1) == -1);
tprintf("rt_sigprocmask(SIG_SETMASK, %p, %p, %u)" RVAL_EINVAL,
k_set - set_size, old_set, set_size << 1);
iterate("~[]", k_set - set_size, old_set, set_size >> 1);
sigemptyset(libc_set);
sigaddset(libc_set, SIGHUP);
memcpy(k_set, libc_set, set_size);
if (k_sigprocmask(SIG_BLOCK, k_set, old_set, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_BLOCK, [HUP], [], %u) = 0\n", set_size);
memset(libc_set, -1, sizeof(sigset_t));
sigdelset(libc_set, SIGHUP);
memcpy(k_set, libc_set, set_size);
if (k_sigprocmask(SIG_UNBLOCK, k_set, old_set, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_UNBLOCK, ~[HUP], [HUP], %u) = 0\n",
set_size);
sigdelset(libc_set, SIGKILL);
memcpy(k_set, libc_set, set_size);
if (k_sigprocmask(SIG_UNBLOCK, k_set, old_set, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_UNBLOCK, ~[HUP KILL], [HUP], %u) = 0\n",
set_size);
sigemptyset(libc_set);
sigaddset(libc_set, SIGHUP);
sigaddset(libc_set, SIGINT);
sigaddset(libc_set, SIGQUIT);
sigaddset(libc_set, SIGALRM);
sigaddset(libc_set, SIGTERM);
memcpy(k_set, libc_set, set_size);
if (k_sigprocmask(SIG_BLOCK, k_set, old_set, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_BLOCK, %s, [HUP], %u) = 0\n",
"[HUP INT QUIT ALRM TERM]", set_size);
if (k_sigprocmask(SIG_SETMASK, NULL, old_set, set_size))
perror_msg_and_fail("rt_sigprocmask");
tprintf("rt_sigprocmask(SIG_SETMASK, NULL, %s, %u) = 0\n",
"[HUP INT QUIT ALRM TERM]", set_size);
assert(k_sigprocmask(SIG_SETMASK, k_set + (set_size >> 1), NULL,
set_size) == -1);
tprintf("rt_sigprocmask(SIG_SETMASK, %p, NULL, %u)" RVAL_EFAULT,
k_set + (set_size >> 1), set_size);
assert(k_sigprocmask(SIG_SETMASK, k_set, old_set + (set_size >> 1),
set_size) == -1);
tprintf("rt_sigprocmask(SIG_SETMASK, %s, %p, %u)" RVAL_EFAULT,
"[HUP INT QUIT ALRM TERM]",
old_set + (set_size >> 1), set_size);
tprintf("+++ exited with 0 +++\n");
return 0;
}
|