int main(void) { const int data[] = { 2, 4, 0, 8, 16, 0 }; const int v3 = 0x20080522; int * const head = tail_alloc(sizeof(int) * 2); head[0] = v3; head[1] = 0; int * const tail_data = tail_alloc(sizeof(data)); capget(NULL, NULL); capget(head + 2, tail_data); capget(head, tail_data + ARRAY_SIZE(data)); if (capget(head, tail_data)) perror_msg_and_skip("capget"); if (head[0] != v3) error_msg_and_skip("capget: v3 expected"); memcpy(tail_data, data, sizeof(data)); if (capset(head, data) == 0 || errno != EPERM) perror_msg_and_skip("capset"); return 0; }
int main(void) { struct { struct timespec ts; uint32_t pad[2]; } t = { .pad = { 0xdeadbeef, 0xbadc0ded } }; if (syscall(__NR_clock_getres, CLOCK_REALTIME, &t.ts)) perror_msg_and_skip("clock_getres CLOCK_REALTIME"); printf("clock_getres(CLOCK_REALTIME, {%jd, %jd}) = 0\n", (intmax_t) t.ts.tv_sec, (intmax_t) t.ts.tv_nsec); if (syscall(__NR_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &t.ts)) perror_msg_and_skip("clock_gettime CLOCK_PROCESS_CPUTIME_ID"); printf("clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {%jd, %jd}) = 0\n", (intmax_t) t.ts.tv_sec, (intmax_t) t.ts.tv_nsec); t.ts.tv_sec = 0xdeface1; t.ts.tv_nsec = 0xdeface2; if (!syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts)) error_msg_and_skip("clock_settime CLOCK_THREAD_CPUTIME_ID:" " EINVAL expected"); printf("clock_settime(CLOCK_THREAD_CPUTIME_ID, {%jd, %jd})" " = -1 EINVAL (%m)\n", (intmax_t) t.ts.tv_sec, (intmax_t) t.ts.tv_nsec); puts("+++ exited with 0 +++"); return 0; }
int main(void) { struct mq_attr attr; (void) close(0); char *name; if (asprintf(&name, "/strace-mq-%u.sample", getpid()) < 0) perror_msg_and_fail("asprintf"); if (mq_open(name, O_CREAT, 0700, NULL)) perror_msg_and_skip("mq_open"); printf("mq_open(\"%s\", O_RDONLY|O_CREAT, 0700, NULL) = 0\n", name + 1); if (mq_getattr(0, &attr)) perror_msg_and_skip("mq_getattr"); printf("mq_getsetattr(0, NULL, {mq_flags=0, mq_maxmsg=%lld" ", mq_msgsize=%lld, mq_curmsgs=0}) = 0\n", (long long) attr.mq_maxmsg, (long long) attr.mq_msgsize); if (mq_setattr(0, &attr, NULL)) perror_msg_and_skip("mq_setattr"); printf("mq_getsetattr(0, {mq_flags=0, mq_maxmsg=%lld" ", mq_msgsize=%lld, mq_curmsgs=0}, NULL) = 0\n", (long long) attr.mq_maxmsg, (long long) attr.mq_msgsize); if (mq_unlink(name)) perror_msg_and_skip("mq_unlink"); printf("mq_unlink(\"%s\") = 0\n", name + 1); puts("+++ exited with 0 +++"); return 0; }
int main(void) { int lfd = socket(AF_UNIX, SOCK_STREAM, 0); int cfd = socket(AF_UNIX, SOCK_STREAM, 0); if (lfd < 0 || cfd < 0) perror_msg_and_skip("socket"); (void) unlink(TEST_SOCKET); const struct sockaddr_un un = { .sun_family = AF_UNIX, .sun_path = TEST_SOCKET }; if (bind(lfd, (const void *) &un, sizeof(un))) perror_msg_and_skip("bind"); if (listen(lfd, 1)) perror_msg_and_skip("listen"); if (connect(cfd, (const void *) &un, sizeof(un))) perror_msg_and_skip("connect"); if (accept(lfd, 0, 0) < 0) perror_msg_and_skip("accept"); test_sockname_syscall(cfd); (void) unlink(TEST_SOCKET); puts("+++ exited with 0 +++"); return 0; }
int main(void) { id = semget(IPC_PRIVATE, 1, 0600); if (id < 0) perror_msg_and_skip("semget"); atexit(cleanup); union semun sem_union = { .val = 0 }; if (semctl(id, 0, SETVAL, sem_union) == -1) perror_msg_and_skip("semctl"); struct sembuf *const sem_b = tail_alloc(sizeof(*sem_b)); sem_b->sem_num = 0; sem_b->sem_op = 1; sem_b->sem_flg = SEM_UNDO; if (semop(id, sem_b, 1)) perror_msg_and_skip("semop, 1"); printf("semop(%d, [{0, 1, SEM_UNDO}], 1) = 0\n", id); sem_b->sem_op = -1; if (semop(id, sem_b, 1)) perror_msg_and_skip("semop, -1"); printf("semop(%d, [{0, -1, SEM_UNDO}], 1) = 0\n", id); puts("+++ exited with 0 +++"); return 0; }
int main(void) { const pid_t pid = getpid(); const long long_pid = (unsigned long) (0xdeadbeef00000000LL | pid); void **p_head = tail_alloc(sizeof(void *)); size_t *p_len = tail_alloc(sizeof(size_t)); if (syscall(__NR_get_robust_list, long_pid, p_head, p_len)) perror_msg_and_skip("get_robust_list"); printf("get_robust_list(%d, [%#lx], [%lu]) = 0\n", (int) pid, (unsigned long) *p_head, (unsigned long) *p_len); void *head = tail_alloc(*p_len); if (syscall(__NR_set_robust_list, head, *p_len)) perror_msg_and_skip("set_robust_list"); printf("set_robust_list(%p, %lu) = 0\n", head, (unsigned long) *p_len); if (syscall(__NR_get_robust_list, long_pid, p_head, p_len)) perror_msg_and_skip("get_robust_list"); printf("get_robust_list(%d, [%#lx], [%lu]) = 0\n", (int) pid, (unsigned long) *p_head, (unsigned long) *p_len); puts("+++ exited with 0 +++"); return 0; }
int main(void) { struct ip_mreq m4; struct ipv6_mreq m6; inet_pton(AF_INET, "224.0.0.3", &m4.imr_multiaddr); inet_pton(AF_INET, "127.0.0.1", &m4.imr_interface); inet_pton(AF_INET6, "ff01::c", &m6.ipv6mr_multiaddr); m6.ipv6mr_interface = 1; (void) close(0); if (socket(AF_INET, SOCK_DGRAM, 0)) perror_msg_and_skip("socket"); assert(setsockopt(0, SOL_IP, IP_ADD_MEMBERSHIP, &m4, 1) == -1); assert(setsockopt(0, SOL_IP, IP_DROP_MEMBERSHIP, &m4, 1) == -1); if (setsockopt(0, SOL_IP, IP_ADD_MEMBERSHIP, &m4, sizeof(m4)) || setsockopt(0, SOL_IP, IP_DROP_MEMBERSHIP, &m4, sizeof(m4))) perror_msg_and_skip("setsockopt"); assert(setsockopt(0, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &m6, 1) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_DROP_MEMBERSHIP, &m6, 1) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &m6, sizeof(m6)) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_DROP_MEMBERSHIP, &m6, sizeof(m6)) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_JOIN_ANYCAST, &m6, 1) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_LEAVE_ANYCAST, &m6, 1) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_JOIN_ANYCAST, &m6, sizeof(m6)) == -1); assert(setsockopt(0, SOL_IPV6, IPV6_LEAVE_ANYCAST, &m6, sizeof(m6)) == -1); return 0; }
int main(void) { struct file_handle *handle = alloca(sizeof(struct file_handle) + MAX_HANDLE_SZ); const int dirfd = AT_FDCWD; const int flags = AT_SYMLINK_FOLLOW; int mount_id; unsigned int i; handle->handle_bytes = 0; assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags | 1) == -1); if (EINVAL != errno) perror_msg_and_skip("name_to_handle_at"); printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=0}, %p" ", AT_SYMLINK_FOLLOW|0x1) = -1 EINVAL (%m)\n", &mount_id); assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags) == -1); if (EOVERFLOW != errno) perror_msg_and_skip("name_to_handle_at"); printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=0 => %u}" ", %p, AT_SYMLINK_FOLLOW) = -1 EOVERFLOW (%m)\n", handle->handle_bytes, &mount_id); assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags) == 0); printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=%u" ", handle_type=%d, f_handle=0x", handle->handle_bytes, handle->handle_type); for (i = 0; i < handle->handle_bytes; ++i) printf("%02x", handle->f_handle[i]); printf("}, [%d], AT_SYMLINK_FOLLOW) = 0\n", mount_id); printf("open_by_handle_at(-1, {handle_bytes=%u, handle_type=%d" ", f_handle=0x", handle->handle_bytes, handle->handle_type); for (i = 0; i < handle->handle_bytes; ++i) printf("%02x", handle->f_handle[i]); printf("}, O_RDONLY|O_DIRECTORY) = -1 "); assert(open_by_handle_at(-1, handle, O_RDONLY | O_DIRECTORY) == -1); const char *errno_text; switch (errno) { case EPERM: errno_text = "EPERM"; break; case EINVAL: errno_text = "EINVAL"; break; default: errno_text = "EBADF"; } printf("%s (%m)\n", errno_text); puts("+++ exited with 0 +++"); return 0; }
int main(void) { TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv); TAIL_ALLOC_OBJECT_CONST_PTR(struct timezone, tz); if (syscall(__NR_gettimeofday, tv, NULL)) perror_msg_and_skip("gettimeofday"); printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}, NULL) = 0\n", (long long) tv->tv_sec, zero_extend_signed_to_ull(tv->tv_usec)); if (syscall(__NR_gettimeofday, tv, tz)) perror_msg_and_skip("gettimeofday"); printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}" ", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n", (long long) tv->tv_sec, zero_extend_signed_to_ull(tv->tv_usec), tz->tz_minuteswest, tz->tz_dsttime); tv->tv_sec = -1; tv->tv_usec = 1000000; assert(syscall(__NR_settimeofday, tv, tz) == -1); printf("settimeofday({tv_sec=%lld, tv_usec=%llu}" ", {tz_minuteswest=%d, tz_dsttime=%d}) = -1 EINVAL (%m)\n", (long long) tv->tv_sec, zero_extend_signed_to_ull(tv->tv_usec), tz->tz_minuteswest, tz->tz_dsttime); tv->tv_sec = 0xdeadbeefU; tv->tv_usec = 0xfacefeedU; assert(syscall(__NR_settimeofday, tv, tz) == -1); printf("settimeofday({tv_sec=%lld, tv_usec=%llu}" ", {tz_minuteswest=%d, tz_dsttime=%d}) = -1 EINVAL (%m)\n", (long long) tv->tv_sec, zero_extend_signed_to_ull(tv->tv_usec), tz->tz_minuteswest, tz->tz_dsttime); tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL; tv->tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL; assert(syscall(__NR_settimeofday, tv, tz) == -1); printf("settimeofday({tv_sec=%lld, tv_usec=%llu}" ", {tz_minuteswest=%d, tz_dsttime=%d}) = -1 EINVAL (%m)\n", (long long) tv->tv_sec, zero_extend_signed_to_ull(tv->tv_usec), tz->tz_minuteswest, tz->tz_dsttime); puts("+++ exited with 0 +++"); return 0; }
static void do_send(int fd, char *msg, unsigned int msg_size, struct timespec *tmout, bool cropped) { long rc; long saved_errno; do { rc = syscall(__NR_mq_timedsend, fd, msg, msg_size, 42, tmout); saved_errno = errno; printf("mq_timedsend(%d, ", fd); printstr(MSG_START, msg_size > MSG_MAX_UNCUT ? MSG_MAX_UNCUT : msg_size); if (cropped) printf("..."); errno = saved_errno; printf(", %u, 42, {tv_sec=%lld, tv_nsec=%llu}) = %s\n", msg_size, (long long) tmout->tv_sec, zero_extend_signed_to_ull(tmout->tv_nsec), sprintrc(rc)); errno = saved_errno; if (rc == -1) { if (errno == EINTR) continue; perror_msg_and_skip("mq_timedsend"); } # if DUMPIO_WRITE dumpstr(MSG_START, msg_size); # endif } while (rc); }
int main(void) { tprintf("%s", ""); int fds[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) perror_msg_and_skip("socketpair"); assert(0 == fds[0]); assert(1 == fds[1]); static const char w0_c[] = "012"; const char *w0_d = hexdump_strdup(w0_c); void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c)); static const char w1_c[] = "34567"; const char *w1_d = hexdump_strdup(w1_c); void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c)); static const char w2_c[] = "89abcde"; const char *w2_d = hexdump_strdup(w2_c); void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); static const char r0_c[] = "01234567"; const char *r0_d = hexdump_strdup(r0_c); static const char r1_c[] = "89abcde"; const char *r1_d = hexdump_strdup(r1_c); const struct iovec w_iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1,
int main(int ac, char **av) { # ifdef PATH_TRACING_FD skip_if_unavailable("/proc/self/fd/"); # endif tprintf("%s", ""); assert(syscall(__NR_poll, NULL, 42, 0) == -1); if (ENOSYS == errno) perror_msg_and_skip("poll"); # ifndef PATH_TRACING_FD tprintf("poll(NULL, 42, 0) = -1 EFAULT (%m)\n"); # endif int fds[2]; if (pipe(fds) || pipe(fds)) perror_msg_and_fail("pipe"); const unsigned int abbrev = (ac > 1) ? atoi(av[1]) : -1; const struct pollfd pfds0[] = { { .fd = 0, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND }, { .fd = 1, .events = POLLOUT | POLLWRNORM | POLLWRBAND },
int main(void) { int rc; struct msqid_ds ds; id = msgget(IPC_PRIVATE, 0600); if (id < 0) perror_msg_and_skip("msgget"); printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id); atexit(cleanup); if (msgctl(id, IPC_STAT, &ds)) perror_msg_and_skip("msgctl IPC_STAT"); printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{msg_perm=\\{uid=%u, gid=%u, " "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, msg_stime=%u, msg_rtime=%u, " "msg_ctime=%u, msg_qnum=%u, msg_qbytes=%u, msg_lspid=%u, " "msg_lrpid=%u\\}\\) += 0\n", id, (unsigned) ds.msg_perm.uid, (unsigned) ds.msg_perm.gid, (unsigned) ds.msg_perm.mode, (unsigned) ds.msg_perm.__key, (unsigned) ds.msg_perm.cuid, (unsigned) ds.msg_perm.cgid, (unsigned) ds.msg_stime, (unsigned) ds.msg_rtime, (unsigned) ds.msg_ctime, (unsigned) ds.msg_qnum, (unsigned) ds.msg_qbytes, (unsigned) ds.msg_lspid, (unsigned) ds.msg_lrpid); int max = msgctl(0, MSG_INFO, &ds); if (max < 0) perror_msg_and_skip("msgctl MSG_INFO"); printf("msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\n", &ds, max); rc = msgctl(id, MSG_STAT, &ds); if (rc != id) { /* * In linux < v2.6.24-rc1 the first argument must be * an index in the kernel's internal array. */ if (-1 != rc || EINVAL != errno) perror_msg_and_skip("msgctl MSG_STAT"); printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(%m\\)\n", id, &ds); } else { printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id); } return 0; }
int main(void) { static union { struct { uint32_t size; uint32_t sched_policy; uint64_t sched_flags; uint32_t sched_nice; uint32_t sched_priority; uint64_t sched_runtime; uint64_t sched_deadline; uint64_t sched_period; } attr; char buf[256]; } sched; if (syscall(__NR_sched_getattr, 0, &sched, sizeof(sched), 0)) perror_msg_and_skip("sched_getattr"); printf("sched_getattr\\(0, \\{size=%u, sched_policy=SCHED_[A-Z]+, sched_flags=%s, sched_nice=%u, sched_priority=%u, sched_runtime=%" PRIu64 ", sched_deadline=%" PRIu64 ", sched_period=%" PRIu64 "\\}, 256, 0\\) += 0\n", sched.attr.size, sched.attr.sched_flags ? "SCHED_FLAG_RESET_ON_FORK" : "0", sched.attr.sched_nice, sched.attr.sched_priority, sched.attr.sched_runtime, sched.attr.sched_deadline, sched.attr.sched_period); sched.attr.sched_flags |= 1; if (syscall(__NR_sched_setattr, 0, &sched, 0)) perror_msg_and_skip("sched_setattr"); printf("sched_setattr\\(0, \\{size=%u, sched_policy=SCHED_[A-Z]+, sched_flags=%s, sched_nice=%u, sched_priority=%u, sched_runtime=%" PRIu64 ", sched_deadline=%" PRIu64 ", sched_period=%" PRIu64 "\\}, 0\\) += 0\n", sched.attr.size, "SCHED_FLAG_RESET_ON_FORK", sched.attr.sched_nice, sched.attr.sched_priority, sched.attr.sched_runtime, sched.attr.sched_deadline, sched.attr.sched_period); return 0; }
int main(void) { if (!test_process_vm_readv()) perror_msg_and_skip("process_vm_readv"); test_printstrn(4096); puts("+++ exited with 0 +++"); return 0; }
int main(void) { if (!test_process_vm_readv()) perror_msg_and_skip("process_vm_readv"); test_printpath(PATH_MAX); puts("+++ exited with 0 +++"); return 0; }
int create_nl_socket_ext(const int proto, const char *const name) { const int fd = socket(AF_NETLINK, SOCK_RAW, proto); if (fd < 0) perror_msg_and_skip("socket AF_NETLINK %s", name); const struct sockaddr_nl addr = { .nl_family = AF_NETLINK }; socklen_t len = sizeof(addr); if (bind(fd, (const struct sockaddr *) &addr, len)) perror_msg_and_skip("bind AF_NETLINK %s", name); /* one more operation on this socket to win the race */ int listening; len = sizeof(listening); if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &listening, &len)) perror_msg_and_fail("getsockopt"); return fd; }
int main(void) { int fds[2]; puts("prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) = 0"); printf("prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, {len=%u, filter=[", prog.len); printf("BPF_STMT(BPF_LD|BPF_W|BPF_ABS, %#x), ", (unsigned) offsetof(struct seccomp_data, nr)); PRINT_ALLOW_SYSCALL(close); PRINT_ALLOW_SYSCALL(exit); PRINT_ALLOW_SYSCALL(exit_group); PRINT_DENY_SYSCALL(sync, EBUSY), PRINT_DENY_SYSCALL(setsid, EPERM), printf("BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL)"); puts("]}) = 0"); puts("+++ exited with 0 +++"); fflush(stdout); close(0); close(1); if (pipe(fds)) perror_msg_and_fail("pipe"); if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) perror_msg_and_skip("PR_SET_NO_NEW_PRIVS"); if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) perror_msg_and_skip("PR_SET_SECCOMP"); if (close(0) || close(1)) _exit(77); _exit(0); }
int main(void) { time_t *p = tail_alloc(sizeof(time_t)); time_t t = syscall(__NR_time, p); if ((time_t) -1 == t) perror_msg_and_skip("time"); printf("time([%jd]) = %jd\n", (intmax_t) *p, (intmax_t) t); puts("+++ exited with 0 +++"); return 0; }
static void test_in6_addr(const int fd) { const char address6[] = "12:34:56:78:90:ab:cd:ef"; static const struct inet_diag_bc_op op = { .code = INET_DIAG_BC_S_COND, }; static const struct inet_diag_hostcond cond = { .family = AF_INET6, }; struct in6_addr addr; if (!inet_pton(AF_INET6, address6, &addr)) perror_msg_and_skip("inet_pton"); char buf[sizeof(op) + sizeof(cond) + sizeof(addr)]; memcpy(buf, &op, sizeof(op)); memcpy(buf + sizeof(op), &cond, sizeof(cond)); const unsigned int plen = sizeof(addr) - 1 > DEFAULT_STRLEN ? sizeof(cond) + sizeof(cond) + DEFAULT_STRLEN : sizeof(buf) - 1; memcpy(buf + sizeof(op) + sizeof(cond), &pattern, sizeof(addr)); TEST_NLATTR(fd, nlh0, hdrlen, init_inet_diag_req_v2, print_inet_diag_req_v2, INET_DIAG_REQ_BYTECODE, plen, buf, plen, print_inet_diag_bc_op("INET_DIAG_BC_S_COND"); print_inet_diag_hostcond("AF_INET6"); printf("addr="); print_quoted_hex(pattern, plen - sizeof(op) - sizeof(cond)); printf("}}")); TEST_NLATTR(fd, nlh0, hdrlen, init_inet_diag_req_v2, print_inet_diag_req_v2, INET_DIAG_REQ_BYTECODE, sizeof(buf), buf, sizeof(buf) - 1, print_inet_diag_bc_op("INET_DIAG_BC_S_COND"); print_inet_diag_hostcond("AF_INET6"); printf("addr=%p}}", RTA_DATA(TEST_NLATTR_nla) + sizeof(op) + sizeof(cond))); memcpy(buf + sizeof(op) + sizeof(cond), &addr, sizeof(addr)); TEST_NLATTR(fd, nlh0, hdrlen, init_inet_diag_req_v2, print_inet_diag_req_v2, INET_DIAG_REQ_BYTECODE, sizeof(buf), buf, sizeof(buf), print_inet_diag_bc_op("INET_DIAG_BC_S_COND"); print_inet_diag_hostcond("AF_INET6"); printf("inet_pton(AF_INET6, \"%s\", &addr)}}", address6)); }
int main(int ac, char **av) { if (ac < 2 && test_process_vm_readv()) error_msg_and_skip("process_vm_readv is available"); if (!test_ptrace_peekdata()) perror_msg_and_skip("PTRACE_PEEKDATA"); test_printpath(sizeof(long) * 4); puts("+++ exited with 0 +++"); return 0; }
int main(void) { if (!test_process_vm_readv()) perror_msg_and_skip("process_vm_readv"); /* * Clearing dumpable flag disallows process_vm_readv. * If the kernel does not contain commit * 84d77d3f06e7e8dea057d10e8ec77ad71f721be3, then * PTRACE_PEEKDATA remains allowed. */ if (prctl(PR_SET_DUMPABLE, 0)) perror_msg_and_skip("PR_SET_DUMPABLE 0"); if (!test_ptrace_peekdata()) perror_msg_and_skip("PTRACE_PEEKDATA"); test_printpath(sizeof(long) * 4); puts("+++ exited with 0 +++"); return 0; }
int main(void) { unsigned char buf[4]; if (syscall(__NR_getrandom, buf, sizeof(buf) - 1, 0) != sizeof(buf) - 1) perror_msg_and_skip("getrandom"); printf("getrandom(\"\\x%02x\\x%02x\\x%02x\", 3, 0) = 3\n", (int) buf[0], (int) buf[1], (int) buf[2]); if (syscall(__NR_getrandom, buf, sizeof(buf), 1) != sizeof(buf)) perror_msg_and_skip("getrandom"); printf("getrandom(\"\\x%02x\\x%02x\\x%02x\"..., 4, GRND_NONBLOCK) = 4\n", (int) buf[0], (int) buf[1], (int) buf[2]); if (syscall(__NR_getrandom, buf, sizeof(buf), 0x3003) != -1) perror_msg_and_skip("getrandom"); printf("getrandom(%p, 4, GRND_NONBLOCK|GRND_RANDOM|0x3000) = " "-1 EINVAL (%m)\n", buf); puts("+++ exited with 0 +++"); return 0; }
int main(void) { (void) close(0); (void) close(1); int fds[2]; if (pipe(fds)) perror_msg_and_fail("pipe"); (void) close(0); (void) close(1); if (pipe2(fds, O_NONBLOCK)) perror_msg_and_skip("pipe2"); return 0; }
int main(void) { static const char fname[] = "truncate64\nfilename"; static const char qname[] = "truncate64\\nfilename"; const off_t len = 0xdefaceddeadbeef; assert(truncate(fname, len) == -1); if (ENOENT != errno) perror_msg_and_skip("truncate"); printf("truncate64(\"%s\", %llu) = -1 ENOENT (%m)\n", qname, (unsigned long long) len); puts("+++ exited with 0 +++"); return 0; }
int main(void) { static const char fname[] = "utimensat\nfilename"; assert(utimensat(AT_FDCWD, fname, NULL, 0) == -1); if (ENOENT != errno) error_msg_and_skip("utimensat"); #define PREFIX "utimensat(AT_FDCWD, \"utimensat\\nfilename\", " printf(PREFIX "NULL, 0) = -1 ENOENT (%m)\n"); struct timeval tv; struct timespec ts[2]; if (gettimeofday(&tv, NULL)) perror_msg_and_skip("gettimeofday"); ts[0].tv_sec = tv.tv_sec; ts[0].tv_nsec = tv.tv_usec; ts[1].tv_sec = tv.tv_sec - 1; ts[1].tv_nsec = tv.tv_usec + 1; printf(PREFIX "["); print_ts(&ts[0]); printf(", "); print_ts(&ts[1]); printf("], AT_SYMLINK_NOFOLLOW) = -1 ENOENT "); assert(utimensat(AT_FDCWD, fname, ts, AT_SYMLINK_NOFOLLOW) == -1); if (ENOENT != errno) error_msg_and_skip("utimensat"); printf("(%m)\n"); ts[0].tv_nsec = UTIME_NOW; ts[1].tv_nsec = UTIME_OMIT; assert(utimensat(AT_FDCWD, fname, ts, AT_SYMLINK_NOFOLLOW) == -1); if (ENOENT != errno) error_msg_and_skip("utimensat"); printf(PREFIX "[UTIME_NOW, UTIME_OMIT], AT_SYMLINK_NOFOLLOW)" " = -1 ENOENT (%m)\n"); puts("+++ exited with 0 +++"); return 0; }
int main(int ac, const char **av) { char *dname; assert(ac == 1); assert(asprintf(&dname, "%s.test.tmp.dir", av[0]) > 0); assert(!mkdir(dname, 0700)); assert(!chdir(dname)); (void) close(0); assert(!creat(fname, 0600)); assert(!close(0)); assert(!open(".", O_RDONLY | O_DIRECTORY)); unsigned long count = (unsigned long) 0xfacefeeddeadbeefULL; long rc = syscall(__NR_getdents64, (long) 0xdefacedffffffffULL, NULL, count); printf("getdents64(-1, NULL, %u) = %ld %s (%m)\n", (unsigned) count, rc, errno2name()); count = (unsigned long) 0xfacefeed00000000ULL | sizeof(buf); while ((rc = syscall(__NR_getdents64, 0, buf, count))) { kernel_dirent64 *d; long i; if (rc < 0) perror_msg_and_skip("getdents64"); printf("getdents64(0, ["); for (i = 0; i < rc; i += d->d_reclen) { d = (kernel_dirent64 *) &buf[i]; if (i) printf(", "); print_dirent(d); } printf("], %u) = %ld\n", (unsigned) count, rc); } printf("getdents64(0, [], %u) = 0\n", (unsigned) count); puts("+++ exited with 0 +++"); assert(!unlink(fname)); assert(!chdir("..")); assert(!rmdir(dname)); return 0; }
int main(void) { sysinfo(NULL); printf("sysinfo(NULL) = -1 EFAULT (%m)\n"); TAIL_ALLOC_OBJECT_CONST_PTR(struct sysinfo, si); if (sysinfo(si)) perror_msg_and_skip("sysinfo"); printf("sysinfo({uptime=%llu" ", loads=[%llu, %llu, %llu]" ", totalram=%llu" ", freeram=%llu" ", sharedram=%llu" ", bufferram=%llu" ", totalswap=%llu" ", freeswap=%llu" ", procs=%u" ", totalhigh=%llu" ", freehigh=%llu" ", mem_unit=%u" "}) = 0\n" , (unsigned long long) si->uptime , (unsigned long long) si->loads[0] , (unsigned long long) si->loads[1] , (unsigned long long) si->loads[2] , (unsigned long long) si->totalram , (unsigned long long) si->freeram , (unsigned long long) si->sharedram , (unsigned long long) si->bufferram , (unsigned long long) si->totalswap , (unsigned long long) si->freeswap , (unsigned) si->procs , (unsigned long long) si->totalhigh , (unsigned long long) si->freehigh , si->mem_unit ); puts("+++ exited with 0 +++"); return 0; }
static void test_mincore(const unsigned int pages) { const size_t size = pages * get_page_size(); char *addr = tail_alloc(size); unsigned char *vec = tail_alloc(pages); unsigned int i; if (mincore(addr, size, vec)) perror_msg_and_skip("mincore"); printf("mincore(%p, %zu, [", addr, size); for (i = 0; i < pages; ++i) { if (i >= DEFAULT_STRLEN) { printf("..."); break; } printf("%u", vec[i] & 1); } puts("]) = 0"); }
static void do_recv(int fd, char *msg, unsigned int msg_size, struct timespec *tmout, bool cropped) { long rc; long saved_errno; unsigned prio; do { rc = syscall(__NR_mq_timedreceive, fd, msg, MSG_SIZE, &prio, tmout); saved_errno = errno; printf("mq_timedreceive(%d, ", fd); if (rc >= 0) { printstr(MSG_START, rc > MSG_MAX_UNCUT ? MSG_MAX_UNCUT : rc); if (cropped) printf("..."); } else { printf("%p", msg); } errno = saved_errno; printf(", %u, [42], {tv_sec=%lld, tv_nsec=%llu}) = %s\n", MSG_SIZE, (long long) tmout->tv_sec, zero_extend_signed_to_ull(tmout->tv_nsec), sprintrc(rc)); errno = saved_errno; if (rc == -1) { if (errno == EINTR) continue; perror_msg_and_skip("mq_timedreceive"); } if ((rc >= 0) && ((unsigned long) rc != msg_size)) error_msg_and_skip("mq_timedreceive size mismatch" ": expected %u, got %ld", msg_size, rc); # if DUMPIO_READ dumpstr(MSG_START, rc); # endif } while (rc < 0); }