1/* $NetBSD: h_linux.h,v 1.2 2023/08/23 20:05:05 rillig Exp $ */ 2 3/*- 4 * Copyright (c) 2023 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Theodore Preduta. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31#ifndef SRC_TESTS_COMPAT_LINUX_H_LINUX_H_ 32#define SRC_TESTS_COMPAT_LINUX_H_LINUX_H_ 33 34#include <sys/types.h> /* For register_t. */ 35 36#define FAIL (-1) 37 38#define syscall(number, ...) syscall6(number, ## __VA_ARGS__, \ 39 0, 0, 0, 0, 0, 0) 40 41#define RS(x) do { if ((x) == -1) exit(errno); } while (0) 42#define REQUIRE(x) do { if (!(x)) exit(FAIL); } while (0) 43 44/* Convenience wrappers for common syscalls. */ 45#define close(fd) (int)syscall(LINUX_SYS_close, fd) 46#define exit(status) (void)syscall(LINUX_SYS_exit_group, status) 47#define fcntl(fd, cmd, ...) (int)syscall(LINUX_SYS_fcntl, fd, cmd, \ 48 ## __VA_ARGS__) 49#define lseek(fd, off, whence) (off_t)syscall(LINUX_SYS_lseek, fd, \ 50 (register_t)off, whence) 51#define mkdir(path, mode) (int)syscall(LINUX_SYS_mkdir, \ 52 (register_t)path, mode) 53#define open(path, flags, ...) (int)syscall(LINUX_SYS_open, \ 54 (register_t)path, flags, \ 55 ## __VA_ARGS__) 56#define read(fd, buf, count) (ssize_t)syscall(LINUX_SYS_read, fd, \ 57 (register_t)buf, count) 58#define rename(from, to) (int)syscall(LINUX_SYS___posix_rename, \ 59 (register_t)from, (register_t)to) 60#define rmdir(path) (int)syscall(LINUX_SYS_rmdir, \ 61 (register_t)path) 62#define unlink(path) (int)syscall(LINUX_SYS_unlink, \ 63 (register_t)path) 64#define write(fd, buf, count) (ssize_t)syscall(LINUX_SYS_write, fd, \ 65 (register_t)buf, count) 66 67/* GCC builtins. */ 68#define strcmp(s1, s2) __builtin_strcmp(s1, s2) 69#define strlen(s) __builtin_strlen(s) 70 71long syscall6(long number, register_t, register_t, register_t, register_t, 72 register_t, register_t, ...); 73 74extern int errno; 75 76#endif /* !SRC_TESTS_COMPAT_LINUX_H_LINUX_H_ */ 77