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 #ifndef _RTLD_AVOID_LIBC_DEPS_H_ 33 #define _RTLD_AVOID_LIBC_DEPS_H_ 34 35 #include <sys/types.h> 36 #include <sys/fcntl.h> 37 #include <sys/stat.h> 38 39 /* Avoid dependencies on libthr (used by closedir/opendir/readdir) */ 40 #define __isthreaded 0 41 #define _pthread_mutex_lock(mtx) (void)0 42 #define _pthread_mutex_unlock(mtx) (void)0 43 #define _pthread_mutex_destroy(mtx) (void)0 44 #define __libc_interposing error, must not use this variable inside rtld 45 46 int __sys_close(int); 47 void __sys_exit(int) __dead2; 48 int __sys_fcntl(int, int, ...); 49 int __sys_fstat(int fd, struct stat *); 50 int __sys_fstatat(int, const char *, struct stat *, int); 51 int __sys___getcwd(char *, size_t); 52 int __sys_open(const char *, int, ...); 53 int __sys_openat(int, const char *, int, ...); 54 int __sys_sigprocmask(int, const sigset_t *, sigset_t *); 55 int __sys_thr_kill(long, int); 56 int __sys_thr_self(long *); 57 __ssize_t __sys_pread(int, void *, __size_t, __off_t); 58 __ssize_t __sys_read(int, void *, __size_t); 59 __ssize_t __sys_write(int, const void *, __size_t); 60 61 extern char* __progname; 62 const char *_getprogname(void); 63 int __getosreldate(void); 64 65 66 /* 67 * Don't pull in any of the libc wrappers. Instead we use the system call 68 * directly inside RTLD to avoid pulling in __libc_interposing (which pulls 69 * in lots more object files). 70 */ 71 #define close(fd) __sys_close(fd) 72 #define _close(fd) __sys_close(fd) 73 #define exit(status) __sys_exit(status) 74 #define _exit(status) __sys_exit(status) 75 #define fcntl(fd, cmd, arg) __sys_fcntl(fd, cmd, arg) 76 #define _fcntl(fd, cmd, arg) __sys_fcntl(fd, cmd, arg) 77 #define _fstat(fd, sb) __sys_fstat(fd, sb) 78 #define open(path, ...) __sys_open(path, __VA_ARGS__) 79 #define pread(fd, buf, nbytes, offset) __sys_pread(fd, buf, nbytes, offset) 80 #define read(fd, buf, nbytes) __sys_read(fd, buf, nbytes) 81 #define sigprocmask(how, set, oset) __sys_sigprocmask(how, set, oset) 82 #define strerror(errno) rtld_strerror(errno) 83 #define _write(fd, buf, nbytes) __sys_write(fd, buf, nbytes) 84 #define write(fd, buf, nbytes) __sys_write(fd, buf, nbytes) 85 86 #endif /* _RTLD_AVOID_LIBC_DEPS_H_ */ 87