10eea0d08Spefo /*- 20eea0d08Spefo * Copyright (c) 1991, 1993 30eea0d08Spefo * The Regents of the University of California. All rights reserved. 40eea0d08Spefo * 50eea0d08Spefo * This code is derived from software contributed to Berkeley by 60eea0d08Spefo * Ralph Campbell. 70eea0d08Spefo * 80eea0d08Spefo * Redistribution and use in source and binary forms, with or without 90eea0d08Spefo * modification, are permitted provided that the following conditions 100eea0d08Spefo * are met: 110eea0d08Spefo * 1. Redistributions of source code must retain the above copyright 120eea0d08Spefo * notice, this list of conditions and the following disclaimer. 130eea0d08Spefo * 2. Redistributions in binary form must reproduce the above copyright 140eea0d08Spefo * notice, this list of conditions and the following disclaimer in the 150eea0d08Spefo * documentation and/or other materials provided with the distribution. 160eea0d08Spefo * 3. Neither the name of the University nor the names of its contributors 170eea0d08Spefo * may be used to endorse or promote products derived from this software 180eea0d08Spefo * without specific prior written permission. 190eea0d08Spefo * 200eea0d08Spefo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 210eea0d08Spefo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 220eea0d08Spefo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230eea0d08Spefo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 240eea0d08Spefo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 250eea0d08Spefo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 260eea0d08Spefo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270eea0d08Spefo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 280eea0d08Spefo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 290eea0d08Spefo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 300eea0d08Spefo * SUCH DAMAGE. 310eea0d08Spefo * 32*5bcead81Skettenis * $OpenBSD: SYS.h,v 1.14 2023/12/11 22:24:16 kettenis Exp $ 330eea0d08Spefo */ 340eea0d08Spefo 350eea0d08Spefo #include <sys/syscall.h> 360eea0d08Spefo #include <machine/asm.h> 370eea0d08Spefo 389b9d2a55Sguenther /* 399b9d2a55Sguenther * We define a hidden alias with the prefix "_libc_" for each global symbol 409b9d2a55Sguenther * that may be used internally. By referencing _libc_x instead of x, other 419b9d2a55Sguenther * parts of libc prevent overriding by the application and avoid unnecessary 429b9d2a55Sguenther * relocations. 439b9d2a55Sguenther */ 449b9d2a55Sguenther #define _HIDDEN(x) _libc_##x 459b9d2a55Sguenther #define _HIDDEN_ALIAS(x,y) \ 469b9d2a55Sguenther STRONG_ALIAS(_HIDDEN(x),y); \ 479b9d2a55Sguenther .hidden _HIDDEN(x) 489b9d2a55Sguenther #define _HIDDEN_FALIAS(x,y) \ 499b9d2a55Sguenther _HIDDEN_ALIAS(x,y); \ 509b9d2a55Sguenther .type _HIDDEN(x),@function 519b9d2a55Sguenther 529b9d2a55Sguenther /* 539b9d2a55Sguenther * For functions implemented in ASM that aren't syscalls. 549b9d2a55Sguenther * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names 559b9d2a55Sguenther * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names 569b9d2a55Sguenther */ 579b9d2a55Sguenther #define END_STRONG(x) END(x); \ 589b9d2a55Sguenther _HIDDEN_FALIAS(x,x); \ 599b9d2a55Sguenther .size _HIDDEN(x), . - _HIDDEN(x) 609b9d2a55Sguenther #define END_WEAK(x) END_STRONG(x); .weak x 619b9d2a55Sguenther 62fe38b55cSguenther #define CERROR __cerror 63fe38b55cSguenther .hidden CERROR 649372e0f0Sguenther 650eea0d08Spefo # define __ENTRY(p,x) ENTRY(p ## x) 660eea0d08Spefo 670eea0d08Spefo # define __DO_SYSCALL(x) \ 680eea0d08Spefo li v0,SYS_ ## x; \ 6983762a71Sderaadt 97: syscall; \ 7083762a71Sderaadt PINSYSCALL(SYS_ ## x, 97b) \ 7183762a71Sderaadt 720eea0d08Spefo 735738bc62Spefo # define __LEAF2(p,x,sz) LEAF(p ## x, sz) \ 74eca0a8dbSguenther WEAK_ALIAS(x, p ## x); 755738bc62Spefo 76aa797096Sguenther # define __END2_HIDDEN(p,x) END(p ## x); \ 7721cb9346Smiod _HIDDEN_FALIAS(x, p ## x); \ 78aa797096Sguenther .size _HIDDEN(x), . - _HIDDEN(x) 79aa797096Sguenther # define __END2(p,x) __END2_HIDDEN(p,x); \ 80aa797096Sguenther .size x, . - x 815738bc62Spefo 820eea0d08Spefo #define __PSEUDO_NOERROR(p,x,y) \ 835738bc62Spefo __LEAF2(p,x, 0); \ 840eea0d08Spefo __DO_SYSCALL(y); \ 850eea0d08Spefo j ra; \ 860eea0d08Spefo __END2(p,x) 870eea0d08Spefo 880eea0d08Spefo #define __PSEUDO(p,x,y) \ 895738bc62Spefo __LEAF2(p,x,32); \ 905738bc62Spefo PTR_SUBU sp,32; \ 915aed4d28Sguenther SETUP_GP64(16,_HIDDEN(x)); \ 920eea0d08Spefo __DO_SYSCALL(y); \ 93aa797096Sguenther bne a3,zero,1f; \ 945738bc62Spefo RESTORE_GP64; \ 955738bc62Spefo PTR_ADDU sp,32; \ 960eea0d08Spefo j ra; \ 97aa797096Sguenther 1: LA t9,CERROR; \ 985738bc62Spefo RESTORE_GP64; \ 995738bc62Spefo PTR_ADDU sp,32; \ 1000eea0d08Spefo jr t9; \ 1010eea0d08Spefo __END2(p,x) 102514a545fSguenther #define __PSEUDO_HIDDEN(p,x,y) \ 103514a545fSguenther LEAF(p ## x,32); \ 104514a545fSguenther PTR_SUBU sp,32; \ 1055aed4d28Sguenther SETUP_GP64(16,_HIDDEN(x)); \ 106514a545fSguenther __DO_SYSCALL(y); \ 107aa797096Sguenther bne a3,zero,1f; \ 108514a545fSguenther RESTORE_GP64; \ 109514a545fSguenther PTR_ADDU sp,32; \ 110514a545fSguenther j ra; \ 111aa797096Sguenther 1: LA t9,CERROR; \ 112514a545fSguenther RESTORE_GP64; \ 113514a545fSguenther PTR_ADDU sp,32; \ 114514a545fSguenther jr t9; \ 115aa797096Sguenther __END2_HIDDEN(p,x) 1160eea0d08Spefo 1170eea0d08Spefo 1180eea0d08Spefo #define RSYSCALL(x) __PSEUDO(_thread_sys_,x,x) 119514a545fSguenther #define RSYSCALL_HIDDEN(x) __PSEUDO_HIDDEN(_thread_sys_,x,x) 1200eea0d08Spefo #define PSEUDO(x,y) __PSEUDO(_thread_sys_,x,y) 1210eea0d08Spefo #define PSEUDO_NOERROR(x,y) __PSEUDO_NOERROR(_thread_sys_,x,y) 1220eea0d08Spefo 1235738bc62Spefo #define SYSLEAF(x, sz) __LEAF2(_thread_sys_,x, sz) 1245aed4d28Sguenther #define SYSLEAF_HIDDEN(x, sz) LEAF(_thread_sys_ ## x, sz) 1255aed4d28Sguenther #define SYSCALL_END(x) __END2(_thread_sys_,x) 1265aed4d28Sguenther #define SYSCALL_END_HIDDEN(x) __END2_HIDDEN(_thread_sys_,x) 1270eea0d08Spefo 12883762a71Sderaadt #define PINSYSCALL(sysno, label) \ 12983762a71Sderaadt .pushsection .openbsd.syscalls,"",@progbits; \ 130*5bcead81Skettenis .p2align 2; \ 13183762a71Sderaadt .long label; \ 13283762a71Sderaadt .long sysno; \ 13383762a71Sderaadt .popsection; 134