1 /* $OpenBSD: SYS.h,v 1.25 2023/12/11 02:30:36 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1998-2002 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND 22 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include <sys/syscall.h> 29 #include <machine/asm.h> 30 #undef _LOCORE 31 #define _LOCORE 32 #include <machine/frame.h> 33 #include <machine/vmparam.h> 34 #undef _LOCORE 35 36 /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ 37 #define TCB_OFFSET_ERRNO -8 38 39 /* 40 * We define a hidden alias with the prefix "_libc_" for each global symbol 41 * that may be used internally. By referencing _libc_x instead of x, other 42 * parts of libc prevent overriding by the application and avoid unnecessary 43 * relocations. 44 */ 45 #define _HIDDEN(x) _libc_##x 46 #define _HIDDEN_ALIAS(x,y) \ 47 STRONG_ALIAS(_HIDDEN(x),y) !\ 48 .hidden _HIDDEN(x) 49 #define _HIDDEN_FALIAS(x,y) \ 50 _HIDDEN_ALIAS(x,y) !\ 51 .type _HIDDEN(x),@function 52 53 /* 54 * For functions implemented in ASM that aren't syscalls. 55 * EXIT_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 56 * EXIT_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 57 * ALTEXIT_STRONG(x) and ALTEXIT_WEAK() 58 * Matching macros for ALTENTRY functions 59 */ 60 #define ALTEXIT_STRONG(x) \ 61 _HIDDEN_FALIAS(x,x) !\ 62 .size _HIDDEN(x), . - _HIDDEN(x) 63 #define ALTEXIT_WEAK(x) ALTEXIT_STRONG(x) !\ 64 .weak x 65 #define EXIT_STRONG(x) EXIT(x) !\ 66 ALTEXIT_STRONG(x) 67 #define EXIT_WEAK(x) EXIT_STRONG(x) !\ 68 .weak x 69 70 #define PINSYSCALL(sysno, label) \ 71 .pushsection .openbsd.syscalls,"",@progbits !\ 72 .long label !\ 73 .long sysno !\ 74 .popsection 75 76 #define SYSENTRY(x) !\ 77 LEAF_ENTRY(__CONCAT(_thread_sys_,x)) !\ 78 WEAK_ALIAS(x,__CONCAT(_thread_sys_,x)) 79 #define SYSENTRY_HIDDEN(x) !\ 80 LEAF_ENTRY(__CONCAT(_thread_sys_,x)) 81 #define SYSEXIT(x) !\ 82 SYSEXIT_HIDDEN(x) !\ 83 .size x, . - x 84 #define SYSEXIT_HIDDEN(x) !\ 85 EXIT(__CONCAT(_thread_sys_,x)) !\ 86 _HIDDEN_FALIAS(x,_thread_sys_##x) !\ 87 .size _HIDDEN(x), . - _HIDDEN(x) 88 89 #define SYSCALL(x) !\ 90 stw rp, HPPA_FRAME_ERP(sr0,sp) !\ 91 ldil L%SYSCALLGATE, r1 !\ 92 97: ble 4(sr7, r1) !\ 93 PINSYSCALL(__CONCAT(SYS_,x), 97b) !\ 94 ldi __CONCAT(SYS_,x), t1 !\ 95 comb,= 0, t1, 1f !\ 96 ldw HPPA_FRAME_ERP(sr0,sp), rp !\ 97 /* set errno */ \ 98 mfctl cr27, r1 !\ 99 stw t1, TCB_OFFSET_ERRNO(r1) !\ 100 ldi -1, ret0 !\ 101 bv r0(rp) !\ 102 ldi -1, ret1 /* for lseek */ !\ 103 1: 104 105 #define PSEUDO(x,y) !\ 106 SYSENTRY(x) !\ 107 SYSCALL(y) !\ 108 bv r0(rp) !\ 109 nop !\ 110 SYSEXIT(x) 111 #define PSEUDO_HIDDEN(x,y) !\ 112 SYSENTRY_HIDDEN(x) !\ 113 SYSCALL(y) !\ 114 bv r0(rp) !\ 115 nop !\ 116 SYSEXIT_HIDDEN(x) 117 118 #define PSEUDO_NOERROR(x,y) !\ 119 SYSENTRY(x) !\ 120 stw rp, HPPA_FRAME_ERP(sr0,sp) !\ 121 ldil L%SYSCALLGATE, r1 !\ 122 97: ble 4(sr7, r1) !\ 123 PINSYSCALL(__CONCAT(SYS_,y), 97b) !\ 124 ldi __CONCAT(SYS_,y), t1 !\ 125 ldw HPPA_FRAME_ERP(sr0,sp), rp !\ 126 bv r0(rp) !\ 127 nop !\ 128 SYSEXIT(x) 129 130 #define RSYSCALL(x) PSEUDO(x,x) 131 #define RSYSCALL_HIDDEN(x) PSEUDO_HIDDEN(x,x) 132 133