1*b247cc18Smiod /* $OpenBSD: DEFS.h,v 1.2 2023/12/13 09:01:25 miod Exp $ */ 2*b247cc18Smiod 3*b247cc18Smiod /* 4*b247cc18Smiod * Copyright (c) 1998-2002 Michael Shalayeff 5*b247cc18Smiod * All rights reserved. 6*b247cc18Smiod * 7*b247cc18Smiod * Redistribution and use in source and binary forms, with or without 8*b247cc18Smiod * modification, are permitted provided that the following conditions 9*b247cc18Smiod * are met: 10*b247cc18Smiod * 1. Redistributions of source code must retain the above copyright 11*b247cc18Smiod * notice, this list of conditions and the following disclaimer. 12*b247cc18Smiod * 2. Redistributions in binary form must reproduce the above copyright 13*b247cc18Smiod * notice, this list of conditions and the following disclaimer in the 14*b247cc18Smiod * documentation and/or other materials provided with the distribution. 15*b247cc18Smiod * 16*b247cc18Smiod * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17*b247cc18Smiod * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18*b247cc18Smiod * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19*b247cc18Smiod * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20*b247cc18Smiod * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21*b247cc18Smiod * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND 22*b247cc18Smiod * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23*b247cc18Smiod * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24*b247cc18Smiod * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25*b247cc18Smiod * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26*b247cc18Smiod */ 27b66d684dSmickey 28b66d684dSmickey #include <machine/asm.h> 29*b247cc18Smiod 30*b247cc18Smiod #define END(x) EXIT(x) 31*b247cc18Smiod 32*b247cc18Smiod /* 33*b247cc18Smiod * We define a hidden alias with the prefix "_libc_" for each global symbol 34*b247cc18Smiod * that may be used internally. By referencing _libc_x instead of x, other 35*b247cc18Smiod * parts of libc prevent overriding by the application and avoid unnecessary 36*b247cc18Smiod * relocations. 37*b247cc18Smiod */ 38*b247cc18Smiod #define _HIDDEN(x) _libc_##x 39*b247cc18Smiod #define _HIDDEN_ALIAS(x,y) \ 40*b247cc18Smiod STRONG_ALIAS(_HIDDEN(x),y) !\ 41*b247cc18Smiod .hidden _HIDDEN(x) 42*b247cc18Smiod #define _HIDDEN_FALIAS(x,y) \ 43*b247cc18Smiod _HIDDEN_ALIAS(x,y) !\ 44*b247cc18Smiod .type _HIDDEN(x),@function 45*b247cc18Smiod 46*b247cc18Smiod /* 47*b247cc18Smiod * For functions implemented in ASM that aren't syscalls. 48*b247cc18Smiod * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 49*b247cc18Smiod * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 50*b247cc18Smiod * ALTEND_STRONG(x) and ALTEND_WEAK() 51*b247cc18Smiod * Matching macros for ALTENTRY functions 52*b247cc18Smiod * END_BUILTIN(x) If compiling with clang, then just END() and 53*b247cc18Smiod * mark it .protected, else be like END_STRONG(); 54*b247cc18Smiod * for clang builtins like memcpy 55*b247cc18Smiod * 56*b247cc18Smiod * If a 'BUILTIN' function needs be referenced by other ASM code, then use 57*b247cc18Smiod * _BUILTIN(x) If compiled with clang, then just x, otherwise 58*b247cc18Smiod * _HIDDEN(x) 59*b247cc18Smiod * 60*b247cc18Smiod * _END(x) Set a size on a symbol, like END(), but even for 61*b247cc18Smiod * symbols with no matching ENTRY(). (On alpha and 62*b247cc18Smiod * mips64, END() generates .end which requires a 63*b247cc18Smiod * matching .ent from ENTRY()) 64*b247cc18Smiod */ 65*b247cc18Smiod #define END_STRONG(x) END(x) ! _HIDDEN_FALIAS(x,x) ! _END(_HIDDEN(x)) 66*b247cc18Smiod #define END_WEAK(x) END_STRONG(x) ! .weak x 67*b247cc18Smiod #define ALTEND_STRONG(x) _HIDDEN_FALIAS(x,x) ! _END(_HIDDEN(x)) 68*b247cc18Smiod #define ALTEND_WEAK(x) ALTEND_STRONG(x) ! .weak x 69*b247cc18Smiod 70*b247cc18Smiod #ifdef __clang__ 71*b247cc18Smiod #define END_BUILTIN(x) END(x) ! .protected x 72*b247cc18Smiod #define _BUILTIN(x) x 73*b247cc18Smiod #else 74*b247cc18Smiod #define END_BUILTIN(x) END_STRONG(x) 75*b247cc18Smiod #define _BUILTIN(x) _HIDDEN(x) 76*b247cc18Smiod #endif 77*b247cc18Smiod 78*b247cc18Smiod #define _END(x) .size x, . - x 79*b247cc18Smiod 80*b247cc18Smiod #define PINSYSCALL(sysno, label) \ 81*b247cc18Smiod .pushsection .openbsd.syscalls,"",@progbits !\ 82*b247cc18Smiod .p2align 2 !\ 83*b247cc18Smiod .long label !\ 84*b247cc18Smiod .long sysno !\ 85*b247cc18Smiod .popsection 86