Mike Frysinger | 7c83058 | 2013-02-02 19:49:00 -0500 | [diff] [blame] | 1 | /* Copyright 2018, Google Inc. All rights reserved. |
| 2 | * |
| 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. |
| 13 | * * Neither the name of Google Inc. nor the names of its |
| 14 | * 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 Palmer | 29f7c7e | 2020-08-12 17:10:59 -0700 | [diff] [blame] | 47 | #include <stdbool.h> |
Mike Frysinger | 7c83058 | 2013-02-02 19:49:00 -0500 | [diff] [blame] | 48 | #include <stdint.h> |
| 49 | #include <stdio.h> |
| 50 | #include <stdlib.h> |
Chris Palmer | 29f7c7e | 2020-08-12 17:10:59 -0700 | [diff] [blame] | 51 | #include <string.h> |
Mike Frysinger | 7c83058 | 2013-02-02 19:49:00 -0500 | [diff] [blame] | 52 | #include <sys/mman.h> |
| 53 | #include <sys/prctl.h> |
| 54 | #include <sys/stat.h> |
| 55 | #include <sys/vfs.h> |
| 56 | #include <sys/wait.h> |
| 57 | |
| 58 | #include <linux/capability.h> |
| 59 | |
| 60 | #include "linux_syscall_support.h" |
| 61 | |
Matthew Denton | 92a65a8 | 2021-04-01 13:00:07 -0700 | [diff] [blame^] | 62 | #define SKIP_TEST_EXIT_STATUS 77 |
| 63 | |
Mike Frysinger | 7c83058 | 2013-02-02 19:49:00 -0500 | [diff] [blame] | 64 | void assert_buffers_eq_len(const void *buf1, const void *buf2, size_t len) { |
| 65 | const uint8_t *u8_1 = (const uint8_t *)buf1; |
| 66 | const uint8_t *u8_2 = (const uint8_t *)buf2; |
| 67 | size_t i; |
| 68 | |
| 69 | for (i = 0; i < len; ++i) { |
| 70 | if (u8_1[i] != u8_2[i]) |
| 71 | printf("offset %zu: %02x != %02x\n", i, u8_1[i], u8_2[i]); |
| 72 | } |
| 73 | } |
| 74 | #define assert_buffers_eq(obj1, obj2) assert_buffers_eq_len(obj1, obj2, sizeof(*obj1)) |