1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright 2019 Alex Richardson <arichardson@FreeBSD.org> 5 * 6 * This software was developed by SRI International and the University of 7 * Cambridge Computer Laboratory (Department of Computer Science and 8 * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the 9 * DARPA SSITH research programme. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $FreeBSD$ 33 */ 34 #ifndef _RTLD_AVOID_LIBC_DEPS_H_ 35 #define _RTLD_AVOID_LIBC_DEPS_H_ 36 37 #include <sys/cdefs.h> 38 #include <sys/types.h> 39 #include <sys/fcntl.h> 40 #include <sys/stat.h> 41 42 /* Avoid dependencies on libthr (used by closedir/opendir/readdir) */ 43 #define __isthreaded 0 44 #define _pthread_mutex_lock(mtx) (void)0 45 #define _pthread_mutex_unlock(mtx) (void)0 46 #define _pthread_mutex_destroy(mtx) (void)0 47 #define __libc_interposing error, must not use this variable inside rtld 48 49 int __sys_close(int); 50 void __sys_exit(int) __dead2; 51 int __sys_fcntl(int, int, ...); 52 int __sys_fstat(int fd, struct stat *); 53 int __sys_fstatat(int, const char *, struct stat *, int); 54 int __sys___getcwd(char *, size_t); 55 int __sys_open(const char *, int, ...); 56 int __sys_openat(int, const char *, int, ...); 57 int __sys_sigprocmask(int, const sigset_t *, sigset_t *); 58 int __sys_thr_kill(long, int); 59 int __sys_thr_self(long *); 60 __ssize_t __sys_pread(int, void *, __size_t, __off_t); 61 __ssize_t __sys_read(int, void *, __size_t); 62 __ssize_t __sys_write(int, const void *, __size_t); 63 64 extern char* __progname; 65 const char *_getprogname(void); 66 int __getosreldate(void); 67 68 69 /* 70 * Don't pull in any of the libc wrappers. Instead we use the system call 71 * directly inside RTLD to avoid pulling in __libc_interposing (which pulls 72 * in lots more object files). 73 */ 74 #define close(fd) __sys_close(fd) 75 #define _close(fd) __sys_close(fd) 76 #define exit(status) __sys_exit(status) 77 #define _exit(status) __sys_exit(status) 78 #define fcntl(fd, cmd, arg) __sys_fcntl(fd, cmd, arg) 79 #define _fcntl(fd, cmd, arg) __sys_fcntl(fd, cmd, arg) 80 #define _fstat(fd, sb) __sys_fstat(fd, sb) 81 #define open(path, ...) __sys_open(path, __VA_ARGS__) 82 #define pread(fd, buf, nbytes, offset) __sys_pread(fd, buf, nbytes, offset) 83 #define read(fd, buf, nbytes) __sys_read(fd, buf, nbytes) 84 #define sigprocmask(how, set, oset) __sys_sigprocmask(how, set, oset) 85 #define strerror(errno) rtld_strerror(errno) 86 #define _write(fd, buf, nbytes) __sys_write(fd, buf, nbytes) 87 #define write(fd, buf, nbytes) __sys_write(fd, buf, nbytes) 88 89 #endif /* _RTLD_AVOID_LIBC_DEPS_H_ */ 90