1 /* $OpenBSD: namespace.h,v 1.14 2019/06/02 01:03:01 guenther Exp $ */ 2 3 #ifndef _LIBC_NAMESPACE_H_ 4 #define _LIBC_NAMESPACE_H_ 5 6 /* 7 * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> 8 * 9 * Permission to use, copy, modify, and distribute this software for any 10 * purpose with or without fee is hereby granted, provided that the above 11 * copyright notice and this permission notice appear in all copies. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 22 /* 23 * For explanations of how to use these, see README 24 * For explanations of why we use them and how they work, see DETAILS 25 */ 26 27 #include <sys/cdefs.h> /* for __dso_hidden and __{weak,strong}_alias */ 28 29 #define __dso_protected __attribute__((__visibility__("protected"))) 30 31 #define HIDDEN(x) _libc_##x 32 #define CANCEL(x) _libc_##x##_cancel 33 #define WRAP(x) _libc_##x##_wrap 34 #define HIDDEN_STRING(x) "_libc_" __STRING(x) 35 #define CANCEL_STRING(x) "_libc_" __STRING(x) "_cancel" 36 #define WRAP_STRING(x) "_libc_" __STRING(x) "_wrap" 37 38 #define PROTO_NORMAL(x) __dso_hidden typeof(x) x asm(HIDDEN_STRING(x)) 39 #define PROTO_STD_DEPRECATED(x) typeof(x) x __attribute__((deprecated)) 40 #define PROTO_DEPRECATED(x) typeof(x) x __attribute__((deprecated, weak)) 41 #define PROTO_CANCEL(x) __dso_hidden typeof(x) HIDDEN(x), \ 42 x asm(CANCEL_STRING(x)) 43 #define PROTO_WRAP(x) PROTO_NORMAL(x), WRAP(x) 44 #define PROTO_PROTECTED(x) __dso_protected typeof(x) x 45 46 #define DEF_STRONG(x) __strong_alias(x, HIDDEN(x)) 47 #define DEF_WEAK(x) __weak_alias(x, HIDDEN(x)) 48 #define DEF_CANCEL(x) __weak_alias(x, CANCEL(x)) 49 #define DEF_WRAP(x) __weak_alias(x, WRAP(x)) 50 #define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) 51 #ifdef __clang__ 52 #define DEF_BUILTIN(x) __asm("") 53 #define BUILTIN __dso_protected 54 #else 55 #define DEF_BUILTIN(x) DEF_STRONG(x) 56 #define BUILTIN 57 #endif 58 59 #define MAKE_CLONE(dst, src) __dso_hidden typeof(dst) HIDDEN(dst) \ 60 __attribute__((alias (HIDDEN_STRING(src)))) 61 62 #define __relro __attribute__((section(".data.rel.ro"))) 63 64 65 /* 66 * gcc and clang will generate calls to the functions below. 67 * Declare and redirect them here so we always go 68 * directly to our hidden aliases. 69 */ 70 #include <sys/_types.h> 71 BUILTIN void *memmove(void *, const void *, __size_t); 72 BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); 73 BUILTIN void *memset(void *, int, __size_t); 74 BUILTIN void __stack_smash_handler(const char [], int __unused); 75 #ifndef __clang__ 76 PROTO_NORMAL(memmove); 77 PROTO_NORMAL(memcpy); 78 PROTO_NORMAL(memset); 79 PROTO_NORMAL(__stack_smash_handler); 80 #endif 81 #undef BUILTIN 82 83 #endif /* _LIBC_NAMESPACE_H_ */ 84 85