[go: nahoru, domu]

blob: 89077c95dfba1e4f22e9aa6664de9f33425a8bae [file] [log] [blame]
Mike Frysinger3159ddc2022-09-07 12:24:211/* Copyright 2018 Google LLC
Mike Frysinger7c830582013-02-03 00:49:002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following disclaimer
11 * in the documentation and/or other materials provided with the
12 * distribution.
Mike Frysinger3159ddc2022-09-07 12:24:2113 * * Neither the name of Google LLC nor the names of its
Mike Frysinger7c830582013-02-03 00:49:0014 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * 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
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * Make sure it's defined before including anything else. A number of syscalls
32 * are GNU extensions and rely on being exported by glibc.
33 */
34#ifndef _GNU_SOURCE
35#define _GNU_SOURCE
36#endif
37
38/*
39 * Make sure the assert checks aren't removed as all the unittests are based
40 * on them.
41 */
42#undef NDEBUG
43
44#include <assert.h>
45#include <fcntl.h>
46#include <sched.h>
Chris Palmer29f7c7e2020-08-13 00:10:5947#include <stdbool.h>
Mike Frysinger7c830582013-02-03 00:49:0048#include <stdint.h>
49#include <stdio.h>
50#include <stdlib.h>
Chris Palmer29f7c7e2020-08-13 00:10:5951#include <string.h>
Mike Frysinger7c830582013-02-03 00:49:0052#include <sys/mman.h>
53#include <sys/prctl.h>
54#include <sys/stat.h>
55#include <sys/vfs.h>
56#include <sys/wait.h>
Doug Kwan32a80cd2022-07-01 17:52:3957#include <unistd.h>
Mike Frysinger7c830582013-02-03 00:49:0058
59#include <linux/capability.h>
60
61#include "linux_syscall_support.h"
62
Matthew Denton92a65a82021-04-01 20:00:0763#define SKIP_TEST_EXIT_STATUS 77
64
Mike Frysinger7c830582013-02-03 00:49:0065void assert_buffers_eq_len(const void *buf1, const void *buf2, size_t len) {
66 const uint8_t *u8_1 = (const uint8_t *)buf1;
67 const uint8_t *u8_2 = (const uint8_t *)buf2;
68 size_t i;
69
70 for (i = 0; i < len; ++i) {
71 if (u8_1[i] != u8_2[i])
72 printf("offset %zu: %02x != %02x\n", i, u8_1[i], u8_2[i]);
73 }
74}
75#define assert_buffers_eq(obj1, obj2) assert_buffers_eq_len(obj1, obj2, sizeof(*obj1))
Doug Kwan32a80cd2022-07-01 17:52:3976
77// Returns true iff pointed timevals are equal.
78static inline bool kernel_timeval_eq(const struct kernel_timeval* lhs,
79 const struct kernel_timeval* rhs) {
80 return (lhs->tv_sec == rhs->tv_sec) && (lhs->tv_usec == rhs->tv_usec);
81}
82
83// Returns true iff pointed itimervals are equal.
84static inline bool kernel_itimerval_eq(const struct kernel_itimerval* lhs,
85 const struct kernel_itimerval* rhs) {
86 return kernel_timeval_eq(&lhs->it_interval, &rhs->it_interval) &&
87 kernel_timeval_eq(&lhs->it_value, &rhs->it_value);
88}
89