Index: sys/sys/_atomic_subword.h =================================================================== --- sys/sys/_atomic_subword.h +++ sys/sys/_atomic_subword.h @@ -41,7 +41,8 @@ #endif #include -#ifndef _KERNEL +#include +#if __EXPOSE_USERLAND_SYMS() #include #endif Index: sys/sys/_cpuset.h =================================================================== --- sys/sys/_cpuset.h +++ sys/sys/_cpuset.h @@ -49,7 +49,7 @@ __BITSET_DEFINE(_cpuset, CPU_SETSIZE); typedef struct _cpuset cpuset_t; -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS cpuset_t *__cpuset_alloc(size_t set_size); void __cpuset_free(cpuset_t *ptr); Index: sys/sys/_semaphore.h =================================================================== --- sys/sys/_semaphore.h +++ sys/sys/_semaphore.h @@ -35,7 +35,7 @@ #define SEM_VALUE_MAX __INT_MAX -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS Index: sys/sys/capsicum.h =================================================================== --- sys/sys/capsicum.h +++ sys/sys/capsicum.h @@ -48,7 +48,7 @@ #include #include -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #include #endif @@ -453,7 +453,9 @@ extern bool trap_enotcap; -#else /* !_KERNEL */ +#endif /* _KERNEL */ + +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS /* @@ -506,6 +508,6 @@ __END_DECLS -#endif /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ #endif /* !_SYS_CAPSICUM_H_ */ Index: sys/sys/cdefs.h =================================================================== --- sys/sys/cdefs.h +++ sys/sys/cdefs.h @@ -911,4 +911,7 @@ #define __align_down(x, y) __builtin_align_down(x, y) #define __is_aligned(x, y) __builtin_is_aligned(x, y) +#define __EXPOSE_USERLAND_SYMS() \ + (!defined(_KERNEL) || (defined(_KERNEL_UT) && !defined(_KERNEL_UT_KSRC))) + #endif /* !_SYS_CDEFS_H_ */ Index: sys/sys/disklabel.h =================================================================== --- sys/sys/disklabel.h +++ sys/sys/disklabel.h @@ -35,7 +35,8 @@ #ifndef _SYS_DISKLABEL_H_ #define _SYS_DISKLABEL_H_ -#ifndef _KERNEL +#include +#if __EXPOSE_USERLAND_SYMS() #include #endif #include @@ -162,7 +163,7 @@ void bsd_partition_le_enc(u_char *ptr, struct partition *d); void bsd_disklabel_le_enc(u_char *ptr, struct disklabel *d); -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS struct disklabel *getdiskbyname(const char *); __END_DECLS Index: sys/sys/errno.h =================================================================== --- sys/sys/errno.h +++ sys/sys/errno.h @@ -40,8 +40,8 @@ #ifndef _SYS_ERRNO_H_ #define _SYS_ERRNO_H_ -#if !defined(_KERNEL) && !defined(_STANDALONE) #include +#if __EXPOSE_USERLAND_SYMS() && !defined(_STANDALONE) __BEGIN_DECLS int * __error(void); __END_DECLS @@ -196,7 +196,7 @@ #define ERELOOKUP (-5) /* retry the directory lookup */ #endif -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #if __EXT1_VISIBLE /* ISO/IEC 9899:2011 K.3.2.2 */ #ifndef _ERRNO_T_DEFINED Index: sys/sys/eui64.h =================================================================== --- sys/sys/eui64.h +++ sys/sys/eui64.h @@ -32,6 +32,8 @@ #ifndef _SYS_EUI64_H #define _SYS_EUI64_H +#include + /* * Size of the ASCII representation of an EUI-64. */ @@ -49,11 +51,13 @@ u_char octet[EUI64_LEN]; }; -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() +__BEGIN_DECLS int eui64_aton(const char *, struct eui64 *); int eui64_ntoa(const struct eui64 *, char *, size_t); int eui64_ntohost(char *, size_t, const struct eui64 *); int eui64_hostton(const char *, struct eui64 *); -#endif /* !_KERNEL */ +__END_DECLS +#endif /* __EXPOSE_USERLAND_SYMS() */ #endif /* !_SYS_EUI64_H */ Index: sys/sys/event.h =================================================================== --- sys/sys/event.h +++ sys/sys/event.h @@ -32,6 +32,7 @@ #define _SYS_EVENT_H_ #include +#include #include #define EVFILT_READ (-1) @@ -352,9 +353,9 @@ int kqueue_del_filteropts(int filt); void kqueue_drain_schedtask(void); -#else /* !_KERNEL */ +#endif /* _KERNEL */ -#include +#if __EXPOSE_USERLAND_SYMS() struct timespec; __BEGIN_DECLS Index: sys/sys/fcntl.h =================================================================== --- sys/sys/fcntl.h +++ sys/sys/fcntl.h @@ -373,7 +373,7 @@ #define SPACECTL_F_SUPPORTED 0 #endif -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS int open(const char *, int, ...); int creat(const char *, mode_t); Index: sys/sys/iconv.h =================================================================== --- sys/sys/iconv.h +++ sys/sys/iconv.h @@ -84,7 +84,7 @@ int ia_csid; }; -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS @@ -100,7 +100,9 @@ __END_DECLS -#else /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ + +#ifdef _KERNEL #include #include /* can't avoid that */ @@ -247,6 +249,6 @@ #define ICDEBUG(format, ...) #endif -#endif /* !_KERNEL */ +#endif /* _KERNEL */ #endif /* !_SYS_ICONV_H_ */ Index: sys/sys/jail.h =================================================================== --- sys/sys/jail.h +++ sys/sys/jail.h @@ -57,7 +57,7 @@ * For all xprison structs, always keep the pr_version an int and * the first variable so userspace can easily distinguish them. */ -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() struct xprison_v1 { int pr_version; int pr_id; @@ -108,7 +108,7 @@ #define JAIL_SYS_NEW 1 #define JAIL_SYS_INHERIT 2 -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() struct iovec; @@ -120,7 +120,9 @@ int jail_remove(int); __END_DECLS -#else /* _KERNEL */ +#endif + +#ifdef _KERNEL #include #include Index: sys/sys/libkern.h =================================================================== --- sys/sys/libkern.h +++ sys/sys/libkern.h @@ -112,8 +112,10 @@ } static __inline off_t omax(off_t a, off_t b) { return (a > b ? a : b); } static __inline off_t omin(off_t a, off_t b) { return (a < b ? a : b); } +#if !__EXPOSE_USERLAND_SYMS() static __inline int abs(int a) { return (a < 0 ? -a : a); } static __inline long labs(long a) { return (a < 0 ? -a : a); } +#endif static __inline quad_t qabs(quad_t a) { return (a < 0 ? -a : a); } #ifndef RANDOM_FENESTRASX @@ -165,7 +167,9 @@ int (*compar)(const void *, const void *)); void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *)); +#if !__EXPOSE_USERLAND_SYMS() u_long random(void); +#endif int scanc(u_int, const u_char *, const u_char *, int); int strcasecmp(const char *, const char *); char *strcasestr(const char *, const char *); @@ -176,9 +180,13 @@ char *strcpy(char * __restrict, const char * __restrict); char *strdup_flags(const char *__restrict, struct malloc_type *, int); size_t strcspn(const char *, const char *) __pure; +#if !__EXPOSE_USERLAND_SYMS() char *strdup(const char *__restrict, struct malloc_type *); +#endif char *strncat(char *, const char *, size_t); +#if !__EXPOSE_USERLAND_SYMS() char *strndup(const char *__restrict, size_t, struct malloc_type *); +#endif size_t strlcat(char *, const char *, size_t); size_t strlcpy(char *, const char *, size_t); size_t strlen(const char *); @@ -207,11 +215,14 @@ #define strlen(s) SAN_INTERCEPTOR(strlen)(s) #endif /* !SAN_RUNTIME */ #else /* !SAN_NEEDS_INTERCEPTORS */ +#if !__EXPOSE_USERLAND_SYMS() #define strcpy(d, s) __builtin_strcpy((d), (s)) #define strcmp(s1, s2) __builtin_strcmp((s1), (s2)) #define strlen(s) __builtin_strlen((s)) +#endif #endif /* SAN_NEEDS_INTERCEPTORS */ +#if !__EXPOSE_USERLAND_SYMS() static __inline char * index(const char *p, int ch) { @@ -225,6 +236,7 @@ return (strrchr(p, ch)); } +#endif static __inline int64_t signed_extend64(uint64_t bitmap, int lsb, int width) Index: sys/sys/linker.h =================================================================== --- sys/sys/linker.h +++ sys/sys/linker.h @@ -368,10 +368,10 @@ #define LINKER_UNLOAD_NORMAL 0 #define LINKER_UNLOAD_FORCE 1 -#ifndef _KERNEL - #include +#if __EXPOSE_USERLAND_SYMS() + __BEGIN_DECLS int kldload(const char* _file); int kldunload(int _fileid); Index: sys/sys/mac.h =================================================================== --- sys/sys/mac.h +++ sys/sys/mac.h @@ -72,7 +72,7 @@ typedef struct mac *mac_t; -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() /* * Location of the userland MAC framework configuration file. mac.conf @@ -108,6 +108,6 @@ int mac_to_text(mac_t mac, char **_text); __END_DECLS -#endif /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ #endif /* !_SYS_MAC_H_ */ Index: sys/sys/malloc.h =================================================================== --- sys/sys/malloc.h +++ sys/sys/malloc.h @@ -186,10 +186,15 @@ struct domainset *ds, int flags, vm_paddr_t low, vm_paddr_t high, unsigned long alignment, vm_paddr_t boundary) __malloc_like __result_use_check __alloc_size(1) __alloc_align(7); +#if !__EXPOSE_USERLAND_SYMS() void free(void *addr, struct malloc_type *type); +#endif void zfree(void *addr, struct malloc_type *type); + +#if !__EXPOSE_USERLAND_SYMS() void *malloc(size_t size, struct malloc_type *type, int flags) __malloc_like __result_use_check __alloc_size(1); +#endif /* * Try to optimize malloc(..., ..., M_ZERO) allocations by doing zeroing in * place if the size is known at compilation time. @@ -225,6 +230,7 @@ * an inline function variant ended up being compiled to a mere malloc call * regardless of argument. gcc generates expected code (like the above). */ +#ifndef _KERNEL_UT #define malloc(size, type, flags) ({ \ void *_malloc_item; \ size_t _size = (size); \ @@ -239,6 +245,7 @@ } \ _malloc_item; \ }) +#endif void *malloc_domainset(size_t size, struct malloc_type *type, struct domainset *ds, int flags) __malloc_like __result_use_check @@ -261,10 +268,12 @@ void malloc_uninit(void *); size_t malloc_size(size_t); size_t malloc_usable_size(const void *); +#if !__EXPOSE_USERLAND_SYMS() void *realloc(void *addr, size_t size, struct malloc_type *type, int flags) __result_use_check __alloc_size(2); void *reallocf(void *addr, size_t size, struct malloc_type *type, int flags) __result_use_check __alloc_size(2); +#endif void *malloc_aligned(size_t size, size_t align, struct malloc_type *type, int flags) __malloc_like __result_use_check __alloc_size(1); void *malloc_domainset_aligned(size_t size, size_t align, Index: sys/sys/md4.h =================================================================== --- sys/sys/md4.h +++ sys/sys/md4.h @@ -42,7 +42,7 @@ void MD4Update(MD4_CTX *, const unsigned char *, unsigned int); void MD4Pad(MD4_CTX *); void MD4Final(unsigned char [__min_size(16)], MD4_CTX *); -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() char * MD4End(MD4_CTX *, char *); char * MD4File(const char *, char *); char * MD4Data(const unsigned char *, unsigned int, char *); Index: sys/sys/mman.h =================================================================== --- sys/sys/mman.h +++ sys/sys/mman.h @@ -93,9 +93,9 @@ */ #define MAP_FILE 0x0000 /* map from file (default) */ #define MAP_ANON 0x1000 /* allocated from memory, swap space */ -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #define MAP_ANONYMOUS MAP_ANON /* For compatibility. */ -#endif /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ /* * Extended flags @@ -314,8 +314,9 @@ #define MAP_32BIT_MAX_ADDR ((vm_offset_t)1 << 31) -#else /* !_KERNEL */ +#endif /* _KERNEL */ +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS /* * XXX not yet implemented: posix_mem_offset(), posix_typed_mem_get_info(), @@ -352,6 +353,6 @@ #endif __END_DECLS -#endif /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ #endif /* !_SYS_MMAN_H_ */ Index: sys/sys/module.h =================================================================== --- sys/sys/module.h +++ sys/sys/module.h @@ -265,10 +265,10 @@ modspecific_t data; }; -#ifndef _KERNEL - #include +#if __EXPOSE_USERLAND_SYMS() + __BEGIN_DECLS int modnext(int _modid); int modfnext(int _modid); Index: sys/sys/poll.h =================================================================== --- sys/sys/poll.h +++ sys/sys/poll.h @@ -96,7 +96,7 @@ #endif -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #if __BSD_VISIBLE #include Index: sys/sys/procctl.h =================================================================== --- sys/sys/procctl.h +++ sys/sys/procctl.h @@ -36,7 +36,9 @@ #ifndef _SYS_PROCCTL_H_ #define _SYS_PROCCTL_H_ -#ifndef _KERNEL +#include + +#if __EXPOSE_USERLAND_SYMS() #include #include #endif @@ -152,7 +154,7 @@ #define PROC_WX_MAPPINGS_DISALLOW_EXEC 0x0002 #define PROC_WXORX_ENFORCE 0x80000000 -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS int procctl(idtype_t, id_t, int, void *); __END_DECLS Index: sys/sys/rtprio.h =================================================================== --- sys/sys/rtprio.h +++ sys/sys/rtprio.h @@ -84,9 +84,9 @@ #endif #endif -#ifndef _KERNEL #include +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS int rtprio(int, pid_t, struct rtprio *); int rtprio_thread(int, lwpid_t, struct rtprio *); Index: sys/sys/sched.h =================================================================== --- sys/sys/sched.h +++ sys/sys/sched.h @@ -64,6 +64,8 @@ #ifndef _SCHED_H_ #define _SCHED_H_ +#include + #ifdef _KERNEL /* * General scheduling info. @@ -250,8 +252,7 @@ /* * POSIX scheduling declarations for userland. */ -#ifndef _KERNEL -#include +#if __EXPOSE_USERLAND_SYMS() #include #include Index: sys/sys/select.h =================================================================== --- sys/sys/select.h +++ sys/sys/select.h @@ -94,7 +94,7 @@ _p->__fds_bits[--_n] = 0; \ } while (0) -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS int pselect(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, Index: sys/sys/stat.h =================================================================== --- sys/sys/stat.h +++ sys/sys/stat.h @@ -218,7 +218,7 @@ }; #endif -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #define st_atime st_atim.tv_sec #define st_mtime st_mtim.tv_sec #define st_ctime st_ctim.tv_sec @@ -237,7 +237,7 @@ #define st_ctimespec st_ctim #define st_birthtimespec st_birthtim #endif -#endif /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ @@ -359,7 +359,7 @@ #define UTIME_OMIT -2 #endif -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS #if __BSD_VISIBLE int chflags(const char *, unsigned long); @@ -403,6 +403,6 @@ int mknodat(int, const char *, mode_t, dev_t); #endif __END_DECLS -#endif /* !_KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ #endif /* !_SYS_STAT_H_ */ Index: sys/sys/systm.h =================================================================== --- sys/sys/systm.h +++ sys/sys/systm.h @@ -205,18 +205,24 @@ #endif int kvprintf(char const *, void (*)(int, void*), void *, int, __va_list) __printflike(1, 0); +#if !__EXPOSE_USERLAND_SYMS() void log(int, const char *, ...) __printflike(2, 3); +#endif void log_console(struct uio *); void vlog(int, const char *, __va_list) __printflike(2, 0); +#if !__EXPOSE_USERLAND_SYMS() int asprintf(char **ret, struct malloc_type *mtp, const char *format, ...) __printflike(3, 4); +#endif int printf(const char *, ...) __printflike(1, 2); int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); int sprintf(char *buf, const char *, ...) __printflike(2, 3); int uprintf(const char *, ...) __printflike(1, 2); int vprintf(const char *, __va_list) __printflike(1, 0); +#if !__EXPOSE_USERLAND_SYMS() int vasprintf(char **ret, struct malloc_type *mtp, const char *format, __va_list ap) __printflike(3, 0); +#endif int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0); int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0); @@ -260,6 +266,7 @@ #define memcmp(b1, b2, len) SAN_INTERCEPTOR(memcmp)((b1), (b2), (len)) #endif /* !SAN_RUNTIME */ #else /* !SAN_NEEDS_INTERCEPTORS */ +#if !__EXPOSE_USERLAND_SYMS() #define bcopy(from, to, len) __builtin_memmove((to), (from), (len)) #define bzero(buf, len) __builtin_memset((buf), 0, (len)) #define bcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len)) @@ -267,6 +274,7 @@ #define memcpy(to, from, len) __builtin_memcpy((to), (from), (len)) #define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) #define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len)) +#endif #endif /* SAN_NEEDS_INTERCEPTORS */ void *memset_early(void * _Nonnull buf, int c, size_t len); @@ -451,8 +459,10 @@ 0, C_HARDCLOCK) int pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags); +#if !__EXPOSE_USERLAND_SYMS() #define pause(wmesg, timo) \ pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK) +#endif #define pause_sig(wmesg, timo) \ pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK | C_CATCH) #define tsleep(chan, pri, wmesg, timo) \ Index: sys/sys/thr.h =================================================================== --- sys/sys/thr.h +++ sys/sys/thr.h @@ -63,7 +63,7 @@ /* * See pthread_* */ -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #include #ifndef _PID_T_DECLARED Index: sys/sys/times.h =================================================================== --- sys/sys/times.h +++ sys/sys/times.h @@ -54,9 +54,9 @@ clock_t tms_cstime; /* System CPU time of terminated child procs */ }; -#ifndef _KERNEL #include +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS clock_t times(struct tms *); __END_DECLS Index: sys/sys/types.h =================================================================== --- sys/sys/types.h +++ sys/sys/types.h @@ -411,7 +411,7 @@ * to give broken programs a better chance of working with * 64-bit off_t's. */ -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS #ifndef _FTRUNCATE_DECLARED #define _FTRUNCATE_DECLARED Index: sys/sys/ucontext.h =================================================================== --- sys/sys/ucontext.h +++ sys/sys/ucontext.h @@ -39,7 +39,7 @@ #define UCF_SWAPPED 0x00000001 /* Used by swapcontext(3). */ -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS @@ -58,7 +58,9 @@ __END_DECLS -#else /* _KERNEL */ +#endif + +#ifdef _KERNEL struct thread; @@ -73,6 +75,6 @@ int get_mcontext(struct thread *, mcontext_t *, int); int set_mcontext(struct thread *, mcontext_t *); -#endif /* !_KERNEL */ +#endif /* _KERNEL */ #endif /* !_SYS_UCONTEXT_H_ */ Index: sys/sys/utsname.h =================================================================== --- sys/sys/utsname.h +++ sys/sys/utsname.h @@ -56,7 +56,7 @@ #include -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() __BEGIN_DECLS int __xuname(int, void *); /* Variable record size. */ __END_DECLS @@ -66,6 +66,6 @@ { return __xuname(SYS_NMLN, (void *)name); } -#endif /* _KERNEL */ +#endif /* __EXPOSE_USERLAND_SYMS() */ #endif /* !_SYS_UTSNAME_H */ Index: sys/sys/wait.h =================================================================== --- sys/sys/wait.h +++ sys/sys/wait.h @@ -151,7 +151,7 @@ #endif /* _KERNEL || _WANT_KW_EXITCODE */ -#ifndef _KERNEL +#if __EXPOSE_USERLAND_SYMS() #include