1*5bcead81Skettenis /* $OpenBSD: DEFS.h,v 1.4 2023/12/11 22:24:15 kettenis Exp $ */ 2ec0f1ad6Sguenther /* 3ec0f1ad6Sguenther * Copyright (c) 2015,2018,2021 Philip Guenther <guenther@openbsd.org> 4ec0f1ad6Sguenther * 5ec0f1ad6Sguenther * Permission to use, copy, modify, and distribute this software for any 6ec0f1ad6Sguenther * purpose with or without fee is hereby granted, provided that the above 7ec0f1ad6Sguenther * copyright notice and this permission notice appear in all copies. 8ec0f1ad6Sguenther * 9ec0f1ad6Sguenther * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10ec0f1ad6Sguenther * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11ec0f1ad6Sguenther * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12ec0f1ad6Sguenther * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13ec0f1ad6Sguenther * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14ec0f1ad6Sguenther * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15ec0f1ad6Sguenther * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16ec0f1ad6Sguenther */ 17ec0f1ad6Sguenther 18ec0f1ad6Sguenther #include <machine/asm.h> 19ec0f1ad6Sguenther 20ec0f1ad6Sguenther /* ARM just had to be different... */ 21ec0f1ad6Sguenther #ifndef __arm__ 22ec0f1ad6Sguenther # define _FUNC_TYPE @function 23a0ef76c2Sderaadt # define _PROGBITS @progbits 24ec0f1ad6Sguenther #else 25ec0f1ad6Sguenther # define _FUNC_TYPE #function 26a0ef76c2Sderaadt # define _PROGBITS %progbits 27ec0f1ad6Sguenther #endif 28ec0f1ad6Sguenther 29ec0f1ad6Sguenther /* 30ec0f1ad6Sguenther * We define a hidden alias with the prefix "_libc_" for each global symbol 31ec0f1ad6Sguenther * that may be used internally. By referencing _libc_x instead of x, other 32ec0f1ad6Sguenther * parts of libc prevent overriding by the application and avoid unnecessary 33ec0f1ad6Sguenther * relocations. 34ec0f1ad6Sguenther */ 35ec0f1ad6Sguenther #define _HIDDEN(x) _libc_##x 36ec0f1ad6Sguenther #define _HIDDEN_ALIAS(x,y) \ 37ec0f1ad6Sguenther STRONG_ALIAS(_HIDDEN(x),y); \ 38ec0f1ad6Sguenther .hidden _HIDDEN(x) 39ec0f1ad6Sguenther #define _HIDDEN_FALIAS(x,y) \ 40ec0f1ad6Sguenther _HIDDEN_ALIAS(x,y); \ 41ec0f1ad6Sguenther .type _HIDDEN(x),_FUNC_TYPE 42ec0f1ad6Sguenther 43ec0f1ad6Sguenther /* 44ec0f1ad6Sguenther * For functions implemented in ASM that aren't syscalls. 45ec0f1ad6Sguenther * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 46ec0f1ad6Sguenther * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 47ec0f1ad6Sguenther * END_BUILTIN(x) If compiling with clang, then just END() and 48ec0f1ad6Sguenther * mark it .protected, else be like END_STRONG(); 49ec0f1ad6Sguenther * for clang builtins like memcpy 50ec0f1ad6Sguenther * 51ec0f1ad6Sguenther * If a 'BUILTIN' function needs be referenced by other ASM code, then use 52ec0f1ad6Sguenther * _BUILTIN(x) If compiled with clang, then just x, otherwise 53ec0f1ad6Sguenther * _HIDDEN(x) 54ec0f1ad6Sguenther * 55ec0f1ad6Sguenther * _END(x) Set a size on a symbol, like END(), but even for 56ec0f1ad6Sguenther * symbols with no matching ENTRY(). (On alpha and 57ec0f1ad6Sguenther * mips64, END() generates .end which requires a 58ec0f1ad6Sguenther * matching .ent from ENTRY()) 59ec0f1ad6Sguenther */ 60ec0f1ad6Sguenther #define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); _END(_HIDDEN(x)) 61ec0f1ad6Sguenther #define END_WEAK(x) END_STRONG(x); .weak x 62ec0f1ad6Sguenther 63ec0f1ad6Sguenther #ifdef __clang__ 64ec0f1ad6Sguenther #define END_BUILTIN(x) END(x); .protected x 65ec0f1ad6Sguenther #define _BUILTIN(x) x 66ec0f1ad6Sguenther #else 67ec0f1ad6Sguenther #define END_BUILTIN(x) END_STRONG(x) 68ec0f1ad6Sguenther #define _BUILTIN(x) _HIDDEN(x) 69ec0f1ad6Sguenther #endif 70ec0f1ad6Sguenther 71ec0f1ad6Sguenther #define _END(x) .size x, . - x 7283762a71Sderaadt 7383762a71Sderaadt #define PINSYSCALL(sysno, label) \ 74a0ef76c2Sderaadt .pushsection .openbsd.syscalls,"",_PROGBITS; \ 75*5bcead81Skettenis .p2align 2; \ 7683762a71Sderaadt .long label; \ 7783762a71Sderaadt .long sysno; \ 7883762a71Sderaadt .popsection; 79