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