process_vm.c \
ptp.c \
ptrace.h \
+ qualify.c \
quota.c \
readahead.c \
readlink.c \
#define QUAL_VERBOSE 0x004 /* decode the structures of this syscall */
#define QUAL_RAW 0x008 /* print all args in hex for this syscall */
#define QUAL_SIGNAL 0x010 /* report events with this signal */
-#define QUAL_READ 0x020 /* dump data read on this file descriptor */
-#define QUAL_WRITE 0x040 /* dump data written to this file descriptor */
+#define QUAL_READ 0x200 /* dump data read from this file descriptor */
+#define QUAL_WRITE 0x400 /* dump data written to this file descriptor */
#define QUAL_FAULT 0x080 /* fail this system call on purpose */
typedef uint8_t qualbits_t;
extern void print_ifindex(unsigned int);
+struct number_set;
+extern struct number_set read_set;
+extern struct number_set write_set;
+
+extern bool is_number_in_set(unsigned int number, const struct number_set *);
+extern void qualify_read(const char *);
+extern void qualify_write(const char *);
+
extern int dm_ioctl(struct tcb *, const unsigned int, long);
extern int file_ioctl(struct tcb *, const unsigned int, long);
extern int fs_x_ioctl(struct tcb *, const unsigned int, long);
--- /dev/null
+/*
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+
+typedef unsigned int number_slot_t;
+#define BITS_PER_SLOT (sizeof(number_slot_t) * 8)
+
+struct number_set {
+ number_slot_t *vec;
+ unsigned int nslots;
+ bool not;
+};
+
+struct number_set read_set;
+struct number_set write_set;
+
+static void
+number_setbit(const unsigned int i, number_slot_t *const vec)
+{
+ vec[i / BITS_PER_SLOT] |= (number_slot_t) 1 << (i % BITS_PER_SLOT);
+}
+
+static bool
+number_isset(const unsigned int i, const number_slot_t *const vec)
+{
+ return vec[i / BITS_PER_SLOT] & ((number_slot_t) 1 << (i % BITS_PER_SLOT));
+}
+
+static void
+reallocate_number_set(struct number_set *const set, const unsigned int new_nslots)
+{
+ if (new_nslots <= set->nslots)
+ return;
+ set->vec = xreallocarray(set->vec, new_nslots, sizeof(*set->vec));
+ memset(set->vec + set->nslots, 0,
+ sizeof(*set->vec) * (new_nslots - set->nslots));
+ set->nslots = new_nslots;
+}
+
+static void
+add_number_to_set(const unsigned int number, struct number_set *const set)
+{
+ reallocate_number_set(set, number / BITS_PER_SLOT + 1);
+ number_setbit(number, set->vec);
+}
+
+bool
+is_number_in_set(const unsigned int number, const struct number_set *const set)
+{
+ return ((number / BITS_PER_SLOT < set->nslots)
+ && number_isset(number, set->vec)) ^ set->not;
+}
+
+typedef int (*string_to_uint_func)(const char *);
+
+/*
+ * Add numbers to SET according to STR specification.
+ */
+static void
+qualify_tokens(const char *const str, struct number_set *const set,
+ string_to_uint_func func, const char *const name)
+{
+ /* Clear the set. */
+ if (set->nslots)
+ memset(set->vec, 0, sizeof(*set->vec) * set->nslots);
+ set->not = false;
+
+ /*
+ * Each leading ! character means inversion
+ * of the remaining specification.
+ */
+ const char *s = str;
+handle_inversion:
+ while (*s == '!') {
+ set->not = !set->not;
+ ++s;
+ }
+
+ if (strcmp(s, "none") == 0) {
+ /*
+ * No numbers are added to the set.
+ * Subsequent is_number_in_set invocations will return set->not.
+ */
+ return;
+ } else if (strcmp(s, "all") == 0) {
+ s = "!none";
+ goto handle_inversion;
+ }
+
+ /*
+ * Split the string into comma separated tokens.
+ * For each token, find out the corresponding number
+ * by calling FUNC, and add that number to the set.
+ * The absence of tokens or a negative answer
+ * from FUNC is a fatal error.
+ */
+ char *copy = xstrdup(s);
+ char *saveptr = NULL;
+ const char *token;
+ int number = -1;
+
+ for (token = strtok_r(copy, ",", &saveptr); token;
+ token = strtok_r(NULL, ",", &saveptr)) {
+ number = func(token);
+ if (number < 0) {
+ error_msg_and_die("invalid %s '%s'", name, token);
+ }
+
+ add_number_to_set(number, set);
+ }
+
+ free(copy);
+
+ if (number < 0) {
+ error_msg_and_die("invalid %s '%s'", name, str);
+ }
+}
+
+void
+qualify_read(const char *const str)
+{
+ qualify_tokens(str, &read_set, string_to_uint, "descriptor");
+}
+
+void
+qualify_write(const char *const str)
+{
+ qualify_tokens(str, &write_set, string_to_uint, "descriptor");
+}
}
#endif
-static int qual_desc(const char *, unsigned int, int);
static int qual_fault(const char *, unsigned int, int);
static int qual_signal(const char *, unsigned int, int);
static int qual_syscall(const char *, unsigned int, int);
{ QUAL_SIGNAL, "signal", qual_signal, "signal" },
{ QUAL_SIGNAL, "signals", qual_signal, "signal" },
{ QUAL_SIGNAL, "s", qual_signal, "signal" },
- { QUAL_READ, "read", qual_desc, "descriptor" },
- { QUAL_READ, "reads", qual_desc, "descriptor" },
- { QUAL_READ, "r", qual_desc, "descriptor" },
- { QUAL_WRITE, "write", qual_desc, "descriptor" },
- { QUAL_WRITE, "writes", qual_desc, "descriptor" },
- { QUAL_WRITE, "w", qual_desc, "descriptor" },
+ { QUAL_READ, "read", NULL, "descriptor" },
+ { QUAL_READ, "reads", NULL, "descriptor" },
+ { QUAL_READ, "r", NULL, "descriptor" },
+ { QUAL_WRITE, "write", NULL, "descriptor" },
+ { QUAL_WRITE, "writes", NULL, "descriptor" },
+ { QUAL_WRITE, "w", NULL, "descriptor" },
{ QUAL_FAULT, "fault", qual_fault, "fault argument"},
{ 0, NULL, NULL, NULL },
};
return -1;
}
-static int
-qual_desc(const char *s, const unsigned int bitflag, const int not)
-{
- int desc = string_to_uint_upto(s, 0x7fff);
- if (desc < 0)
- return -1;
- qualify_one(desc, bitflag, not, -1, NULL);
- return 0;
-}
-
void
qualify(const char *s)
{
break;
}
}
+
+ switch (opt->bitflag) {
+ case QUAL_READ:
+ qualify_read(s);
+ return;
+ case QUAL_WRITE:
+ qualify_write(s);
+ return;
+ }
+
not = 0;
if (*s == '!') {
not = 1;
return;
int fd = tcp->u_arg[0];
- if (fd < 0 || (unsigned int) fd >= num_quals)
+ if (fd < 0)
return;
- if (qual_flags[fd] & QUAL_READ) {
+ if (is_number_in_set(fd, &read_set)) {
switch (tcp->s_ent->sen) {
case SEN_read:
case SEN_pread:
return;
}
}
- if (qual_flags[fd] & QUAL_WRITE) {
+ if (is_number_in_set(fd, &write_set)) {
switch (tcp->s_ent->sen) {
case SEN_write:
case SEN_pwrite:
check_e "Syscall 'chdir' for -b isn't supported" -b chdir
check_e "Syscall 'chdir' for -b isn't supported" -b execve -b chdir
+check_e "invalid descriptor '-1'" -eread=-1
+check_e "invalid descriptor '-42'" -ewrite=-42
+check_e "invalid descriptor '2147483648'" -eread=2147483648
+check_e "invalid descriptor '4294967296'" -ewrite=4294967296
+check_e "invalid descriptor 'foo'" -eread=foo
+check_e "invalid descriptor ''" -ewrite=
+check_e "invalid descriptor ','" -eread=,
+check_e "invalid descriptor '!'" -ewrite='!'
+check_e "invalid descriptor '!'" -eread='0,!'
+check_e "invalid descriptor '!,'" -ewrite='!,'
+
check_h 'must have PROG [ARGS] or -p PID'
check_h 'PROG [ARGS] must be specified with -D' -D -p $$
check_h '-c and -C are mutually exclusive' -c -C true
#!/bin/sh
-
+#
# Check decoding and dumping of readv and writev syscalls.
+#
+# Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
. "${srcdir=.}/init.sh"
-maxfd="$(./print_maxfd)"
-run_strace_match_diff \
- -a16 -eread="$(($maxfd - 1))" -ewrite="$maxfd" -e trace=readv,writev
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread=all -ewrite='!none'
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread='!none' -ewrite=all
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread=none -ewrite='!all' -eread='!0,1,2' -ewrite='!0,1,2'
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread='!all' -ewrite=none -eread='!0,1,2' -ewrite='!0,1,2'
+
+wfd="$(./print_maxfd)"
+rfd="$(($wfd - 1))"
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread="$rfd" -ewrite="$wfd"
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread="!$rfd" -ewrite="!$wfd" -eread="$rfd" -ewrite="$wfd"
+
+rfds='!!!0'
+[ $rfd -lt 1023 ] || rfd=1023
+i=0
+while [ $i -lt $rfd ]; do
+ rfds="$rfds,$i"
+ i=$(($i + 1))
+done
+
+wfds='!!!0'
+[ $wfd -lt 1023 ] || wfd=1023
+i=0
+while [ $i -lt $wfd ]; do
+ wfds="$wfds,$i"
+ i=$(($i + 1))
+done
+
+run_strace_match_diff -a16 -e trace=readv,writev \
+ -eread="$rfds" -ewrite="$wfds"