1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ralph Campbell. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $OpenBSD: SYS.h,v 1.14 2023/12/11 22:24:16 kettenis Exp $ 33 */ 34 35#include <sys/syscall.h> 36#include <machine/asm.h> 37 38/* 39 * We define a hidden alias with the prefix "_libc_" for each global symbol 40 * that may be used internally. By referencing _libc_x instead of x, other 41 * parts of libc prevent overriding by the application and avoid unnecessary 42 * relocations. 43 */ 44#define _HIDDEN(x) _libc_##x 45#define _HIDDEN_ALIAS(x,y) \ 46 STRONG_ALIAS(_HIDDEN(x),y); \ 47 .hidden _HIDDEN(x) 48#define _HIDDEN_FALIAS(x,y) \ 49 _HIDDEN_ALIAS(x,y); \ 50 .type _HIDDEN(x),@function 51 52/* 53 * For functions implemented in ASM that aren't syscalls. 54 * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 55 * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 56 */ 57#define END_STRONG(x) END(x); \ 58 _HIDDEN_FALIAS(x,x); \ 59 .size _HIDDEN(x), . - _HIDDEN(x) 60#define END_WEAK(x) END_STRONG(x); .weak x 61 62#define CERROR __cerror 63 .hidden CERROR 64 65# define __ENTRY(p,x) ENTRY(p ## x) 66 67# define __DO_SYSCALL(x) \ 68 li v0,SYS_ ## x; \ 69 97: syscall; \ 70 PINSYSCALL(SYS_ ## x, 97b) \ 71 72 73# define __LEAF2(p,x,sz) LEAF(p ## x, sz) \ 74 WEAK_ALIAS(x, p ## x); 75 76# define __END2_HIDDEN(p,x) END(p ## x); \ 77 _HIDDEN_FALIAS(x, p ## x); \ 78 .size _HIDDEN(x), . - _HIDDEN(x) 79# define __END2(p,x) __END2_HIDDEN(p,x); \ 80 .size x, . - x 81 82#define __PSEUDO_NOERROR(p,x,y) \ 83 __LEAF2(p,x, 0); \ 84 __DO_SYSCALL(y); \ 85 j ra; \ 86 __END2(p,x) 87 88#define __PSEUDO(p,x,y) \ 89 __LEAF2(p,x,32); \ 90 PTR_SUBU sp,32; \ 91 SETUP_GP64(16,_HIDDEN(x)); \ 92 __DO_SYSCALL(y); \ 93 bne a3,zero,1f; \ 94 RESTORE_GP64; \ 95 PTR_ADDU sp,32; \ 96 j ra; \ 97 1: LA t9,CERROR; \ 98 RESTORE_GP64; \ 99 PTR_ADDU sp,32; \ 100 jr t9; \ 101 __END2(p,x) 102#define __PSEUDO_HIDDEN(p,x,y) \ 103 LEAF(p ## x,32); \ 104 PTR_SUBU sp,32; \ 105 SETUP_GP64(16,_HIDDEN(x)); \ 106 __DO_SYSCALL(y); \ 107 bne a3,zero,1f; \ 108 RESTORE_GP64; \ 109 PTR_ADDU sp,32; \ 110 j ra; \ 111 1: LA t9,CERROR; \ 112 RESTORE_GP64; \ 113 PTR_ADDU sp,32; \ 114 jr t9; \ 115 __END2_HIDDEN(p,x) 116 117 118#define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) 119#define RSYSCALL_HIDDEN(x) __PSEUDO_HIDDEN(_thread_sys_,x,x) 120#define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 121#define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 122 123#define SYSLEAF(x, sz) __LEAF2(_thread_sys_,x, sz) 124#define SYSLEAF_HIDDEN(x, sz) LEAF(_thread_sys_ ## x, sz) 125#define SYSCALL_END(x) __END2(_thread_sys_,x) 126#define SYSCALL_END_HIDDEN(x) __END2_HIDDEN(_thread_sys_,x) 127 128#define PINSYSCALL(sysno, label) \ 129 .pushsection .openbsd.syscalls,"",@progbits; \ 130 .p2align 2; \ 131 .long label; \ 132 .long sysno; \ 133 .popsection; 134