1*83762a71Sderaadt /* $OpenBSD: SYS.h,v 1.22 2023/12/10 16:45:50 deraadt Exp $ */ 2118f6189Smickey 3118f6189Smickey /*- 4118f6189Smickey * Copyright (c) 1990 The Regents of the University of California. 5118f6189Smickey * All rights reserved. 6118f6189Smickey * 7118f6189Smickey * This code is derived from software contributed to Berkeley by 8118f6189Smickey * William Jolitz. 9118f6189Smickey * 10118f6189Smickey * Redistribution and use in source and binary forms, with or without 11118f6189Smickey * modification, are permitted provided that the following conditions 12118f6189Smickey * are met: 13118f6189Smickey * 1. Redistributions of source code must retain the above copyright 14118f6189Smickey * notice, this list of conditions and the following disclaimer. 15118f6189Smickey * 2. Redistributions in binary form must reproduce the above copyright 16118f6189Smickey * notice, this list of conditions and the following disclaimer in the 17118f6189Smickey * documentation and/or other materials provided with the distribution. 1824fdaee6Sjsg * 3. Neither the name of the University nor the names of its contributors 19118f6189Smickey * may be used to endorse or promote products derived from this software 20118f6189Smickey * without specific prior written permission. 21118f6189Smickey * 22118f6189Smickey * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23118f6189Smickey * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24118f6189Smickey * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25118f6189Smickey * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26118f6189Smickey * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27118f6189Smickey * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28118f6189Smickey * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29118f6189Smickey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30118f6189Smickey * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31118f6189Smickey * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32118f6189Smickey * SUCH DAMAGE. 33118f6189Smickey * 34118f6189Smickey * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 35118f6189Smickey * $NetBSD: SYS.h,v 1.5 2002/06/03 18:30:32 fvdl Exp $ 36118f6189Smickey */ 37118f6189Smickey 38b4551fdeSguenther #include "DEFS.h" 39118f6189Smickey #include <sys/syscall.h> 40118f6189Smickey 41fe38b55cSguenther /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ 42fe38b55cSguenther #define TCB_OFFSET_ERRNO 32 43981a1c29Sderaadt 44*83762a71Sderaadt #define SYSTRAP(x) \ 45*83762a71Sderaadt movl $(SYS_ ## x),%eax; \ 46*83762a71Sderaadt movq %rcx, %r10; \ 47*83762a71Sderaadt 97: syscall; \ 48*83762a71Sderaadt PINSYSCALL(SYS_ ## x, 97b) 49514a545fSguenther 50118f6189Smickey #define SYSENTRY(x) \ 5161dbf52cSuebayasi SYSENTRY_HIDDEN(x); \ 529b9d2a55Sguenther WEAK_ALIAS(x, _thread_sys_##x) 53514a545fSguenther #define SYSENTRY_HIDDEN(x) \ 54aa797096Sguenther ENTRY(_thread_sys_ ## x) 55981a1c29Sderaadt 5600669040Sguenther #define SYSCALL_END_HIDDEN(x) \ 57aa797096Sguenther END(_thread_sys_ ## x); \ 58aa797096Sguenther _HIDDEN_FALIAS(x,_thread_sys_##x); \ 59aa797096Sguenther END(_HIDDEN(x)) 6000669040Sguenther #define SYSCALL_END(x) SYSCALL_END_HIDDEN(x); END(x) 61c9935a76Suebayasi 62fe38b55cSguenther 63fe38b55cSguenther #define SET_ERRNO \ 64fe38b55cSguenther movl %eax,%fs:(TCB_OFFSET_ERRNO); \ 65fe38b55cSguenther movq $-1, %rax 66fe38b55cSguenther #define HANDLE_ERRNO \ 67c9c28596Skettenis jnc 99f; \ 68fe38b55cSguenther SET_ERRNO; \ 69fe38b55cSguenther 99: 70118f6189Smickey 71118f6189Smickey #define _SYSCALL_NOERROR(x,y) \ 72118f6189Smickey SYSENTRY(x); \ 73118f6189Smickey SYSTRAP(y) 74514a545fSguenther #define _SYSCALL_HIDDEN_NOERROR(x,y) \ 75514a545fSguenther SYSENTRY_HIDDEN(x); \ 76514a545fSguenther SYSTRAP(y) 77118f6189Smickey 78118f6189Smickey #define SYSCALL_NOERROR(x) \ 79118f6189Smickey _SYSCALL_NOERROR(x,x) 80118f6189Smickey 815aed4d28Sguenther #define SYSCALL_HIDDEN(x) \ 82fe38b55cSguenther _SYSCALL_HIDDEN_NOERROR(x,x); \ 83fe38b55cSguenther HANDLE_ERRNO 84118f6189Smickey #define SYSCALL(x) \ 85fe38b55cSguenther _SYSCALL_NOERROR(x,x); \ 86fe38b55cSguenther HANDLE_ERRNO 87fe38b55cSguenther 88fe38b55cSguenther 89118f6189Smickey #define PSEUDO_NOERROR(x,y) \ 9039b8558cSmortimer SYSENTRY(x); \ 9139b8558cSmortimer RETGUARD_SETUP(_thread_sys_##x, r11); \ 9239b8558cSmortimer RETGUARD_PUSH(r11); \ 9339b8558cSmortimer SYSTRAP(y); \ 9439b8558cSmortimer RETGUARD_POP(r11); \ 9539b8558cSmortimer RETGUARD_CHECK(_thread_sys_##x, r11); \ 96c9935a76Suebayasi ret; \ 9700669040Sguenther SYSCALL_END(x) 98118f6189Smickey 99118f6189Smickey #define PSEUDO(x,y) \ 10039b8558cSmortimer SYSENTRY(x); \ 10139b8558cSmortimer RETGUARD_SETUP(_thread_sys_##x, r11); \ 10239b8558cSmortimer RETGUARD_PUSH(r11); \ 10339b8558cSmortimer SYSTRAP(y); \ 10439b8558cSmortimer HANDLE_ERRNO; \ 10539b8558cSmortimer RETGUARD_POP(r11); \ 10639b8558cSmortimer RETGUARD_CHECK(_thread_sys_##x, r11); \ 10739b8558cSmortimer ret; \ 10800669040Sguenther SYSCALL_END(x) 10939b8558cSmortimer 110514a545fSguenther #define PSEUDO_HIDDEN(x,y) \ 11139b8558cSmortimer SYSENTRY_HIDDEN(x); \ 11239b8558cSmortimer RETGUARD_SETUP(_thread_sys_##x, r11); \ 11339b8558cSmortimer RETGUARD_PUSH(r11); \ 11439b8558cSmortimer SYSTRAP(y); \ 11539b8558cSmortimer HANDLE_ERRNO; \ 11639b8558cSmortimer RETGUARD_POP(r11); \ 11739b8558cSmortimer RETGUARD_CHECK(_thread_sys_##x , r11); \ 11839b8558cSmortimer ret; \ 11900669040Sguenther SYSCALL_END_HIDDEN(x) 120118f6189Smickey 121118f6189Smickey #define RSYSCALL_NOERROR(x) \ 122118f6189Smickey PSEUDO_NOERROR(x,x) 123118f6189Smickey 124118f6189Smickey #define RSYSCALL(x) \ 125118f6189Smickey PSEUDO(x,x) 126514a545fSguenther #define RSYSCALL_HIDDEN(x) \ 127514a545fSguenther PSEUDO_HIDDEN(x,x) 128