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