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