Path: blob/main/libexec/rtld-elf/rtld-libc/rtld_libc.h
34923 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright 2019 Alex Richardson <[email protected]>4*5* This software was developed by SRI International and the University of6* Cambridge Computer Laboratory (Department of Computer Science and7* Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the8* DARPA SSITH research programme.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/31#ifndef _RTLD_AVOID_LIBC_DEPS_H_32#define _RTLD_AVOID_LIBC_DEPS_H_3334#include <sys/types.h>35#include <sys/fcntl.h>36#include <sys/stat.h>3738/* Avoid dependencies on libthr (used by closedir/opendir/readdir) */39#define __isthreaded 040#define _pthread_mutex_lock(mtx) (void)041#define _pthread_mutex_unlock(mtx) (void)042#define _pthread_mutex_destroy(mtx) (void)043#define __libc_interposing error, must not use this variable inside rtld4445int __sys_close(int);46void __sys__exit(int) __dead2;47int __sys_fcntl(int, int, ...);48int __sys_fstat(int fd, struct stat *);49int __sys_fstatat(int, const char *, struct stat *, int);50int __sys___getcwd(char *, size_t);51int __sys_open(const char *, int, ...);52int __sys_openat(int, const char *, int, ...);53int __sys_sigprocmask(int, const sigset_t *, sigset_t *);54int __sys_thr_kill(long, int);55int __sys_thr_self(long *);56__ssize_t __sys_pread(int, void *, __size_t, __off_t);57__ssize_t __sys_read(int, void *, __size_t);58__ssize_t __sys_write(int, const void *, __size_t);5960extern char* __progname;61const char *_getprogname(void);62int __getosreldate(void);636465/*66* Don't pull in any of the libc wrappers. Instead we use the system call67* directly inside RTLD to avoid pulling in __libc_interposing (which pulls68* in lots more object files).69*/70#define close(fd) __sys_close(fd)71#define _close(fd) __sys_close(fd)72#define exit(status) __sys__exit(status)73#define _exit(status) __sys__exit(status)74#define fcntl(fd, cmd, arg) __sys_fcntl(fd, cmd, arg)75#define _fcntl(fd, cmd, arg) __sys_fcntl(fd, cmd, arg)76#define _fstat(fd, sb) __sys_fstat(fd, sb)77#define open(path, ...) __sys_open(path, __VA_ARGS__)78#define pread(fd, buf, nbytes, offset) __sys_pread(fd, buf, nbytes, offset)79#define read(fd, buf, nbytes) __sys_read(fd, buf, nbytes)80#define sigprocmask(how, set, oset) __sys_sigprocmask(how, set, oset)81#define strerror(errno) rtld_strerror(errno)82#define _write(fd, buf, nbytes) __sys_write(fd, buf, nbytes)83#define write(fd, buf, nbytes) __sys_write(fd, buf, nbytes)8485#endif /* _RTLD_AVOID_LIBC_DEPS_H_ */868788