1*83762a71Sderaadt /* $OpenBSD: SYS.h,v 1.5 2023/12/10 16:45:52 deraadt Exp $ */ 27ecb72feSdrahn /*- 37ecb72feSdrahn * Copyright (c) 2020 Brian Bamsch <bbamsch@google.com> 47ecb72feSdrahn * Copyright (c) 1990 The Regents of the University of California. 57ecb72feSdrahn * All rights reserved. 67ecb72feSdrahn * 77ecb72feSdrahn * This code is derived from software contributed to Berkeley by 87ecb72feSdrahn * William Jolitz. 97ecb72feSdrahn * 107ecb72feSdrahn * Redistribution and use in source and binary forms, with or without 117ecb72feSdrahn * modification, are permitted provided that the following conditions 127ecb72feSdrahn * are met: 137ecb72feSdrahn * 1. Redistributions of source code must retain the above copyright 147ecb72feSdrahn * notice, this list of conditions and the following disclaimer. 157ecb72feSdrahn * 2. Redistributions in binary form must reproduce the above copyright 167ecb72feSdrahn * notice, this list of conditions and the following disclaimer in the 177ecb72feSdrahn * documentation and/or other materials provided with the distribution. 187ecb72feSdrahn * 3. Neither the name of the University nor the names of its contributors 197ecb72feSdrahn * may be used to endorse or promote products derived from this software 207ecb72feSdrahn * without specific prior written permission. 217ecb72feSdrahn * 227ecb72feSdrahn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 237ecb72feSdrahn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 247ecb72feSdrahn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 257ecb72feSdrahn * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 267ecb72feSdrahn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 277ecb72feSdrahn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 287ecb72feSdrahn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 297ecb72feSdrahn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 307ecb72feSdrahn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 317ecb72feSdrahn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 327ecb72feSdrahn * SUCH DAMAGE. 337ecb72feSdrahn * 347ecb72feSdrahn * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 357ecb72feSdrahn */ 367ecb72feSdrahn 377ecb72feSdrahn #include "DEFS.h" 387ecb72feSdrahn #include <sys/syscall.h> 397ecb72feSdrahn 400f2255fcSdrahn /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */ 410f2255fcSdrahn #define TCB_OFFSET_ERRNO (-12) 420f2255fcSdrahn 430f2255fcSdrahn /* offset of errno from tp */ 440f2255fcSdrahn #define TP_OFFSET_ERRNO TCB_OFFSET_ERRNO 450f2255fcSdrahn 467ecb72feSdrahn #define SYSENTRY(x) \ 4796b95d32Sjca .weak x; \ 4896b95d32Sjca x = _thread_sys_ ## x; \ 497ecb72feSdrahn ENTRY(_thread_sys_ ## x) 507ecb72feSdrahn #define SYSENTRY_HIDDEN(x) \ 517ecb72feSdrahn ENTRY(_thread_sys_ ## x) 527ecb72feSdrahn #define __END_HIDDEN(x) \ 537ecb72feSdrahn END(_thread_sys_ ## x); \ 547ecb72feSdrahn _HIDDEN_FALIAS(x, _thread_sys_ ## x); \ 557ecb72feSdrahn END(_HIDDEN(x)) 567ecb72feSdrahn #define __END(x) \ 577ecb72feSdrahn __END_HIDDEN(x); END(x) 587ecb72feSdrahn 597ecb72feSdrahn #define SYSTRAP(x) \ 607ecb72feSdrahn li t0, SYS_ ## x; \ 61*83762a71Sderaadt 97: ecall; \ 62*83762a71Sderaadt PINSYSCALL(SYS_ ## x, 97b) 637ecb72feSdrahn 647ecb72feSdrahn #define HANDLE_ERROR() \ 650f2255fcSdrahn beqz t0, 200f; \ 660f2255fcSdrahn sw a0, TP_OFFSET_ERRNO(tp); \ 670f2255fcSdrahn li a0, -1; \ 680f2255fcSdrahn 200: 690f2255fcSdrahn 700f2255fcSdrahn #define HANDLE_ERROR_TARGET(target) \ 710f2255fcSdrahn beqz t0, 200f; \ 720f2255fcSdrahn sw a0, TP_OFFSET_ERRNO(tp); \ 730f2255fcSdrahn li a0, -1; \ 740f2255fcSdrahn j target; \ 750f2255fcSdrahn 200: 767ecb72feSdrahn #define _SYSCALL_NOERROR(x,y) \ 777ecb72feSdrahn SYSENTRY(x); \ 787ecb72feSdrahn SYSTRAP(y) 797ecb72feSdrahn #define _SYSCALL_HIDDEN_NOERROR(x,y) \ 807ecb72feSdrahn SYSENTRY_HIDDEN(x); \ 817ecb72feSdrahn SYSTRAP(y) 827ecb72feSdrahn 837ecb72feSdrahn #define _SYSCALL(x, y) \ 847ecb72feSdrahn _SYSCALL_NOERROR(x,y); \ 850f2255fcSdrahn HANDLE_ERROR() \ 867ecb72feSdrahn #define _SYSCALL_HIDDEN(x, y) \ 877ecb72feSdrahn _SYSCALL_HIDDEN_NOERROR(x,y); \ 880f2255fcSdrahn HANDLE_ERROR() \ 897ecb72feSdrahn 907ecb72feSdrahn #define SYSCALL_NOERROR(x) \ 917ecb72feSdrahn _SYSCALL_NOERROR(x,x) 927ecb72feSdrahn 937ecb72feSdrahn #define SYSCALL(x) \ 947ecb72feSdrahn _SYSCALL(x,x) 957ecb72feSdrahn 967ecb72feSdrahn 977ecb72feSdrahn #define PSEUDO_NOERROR(x,y) \ 987ecb72feSdrahn SYSENTRY(x); \ 997ecb72feSdrahn RETGUARD_SETUP(x, t6); \ 1007ecb72feSdrahn SYSTRAP(y); \ 1017ecb72feSdrahn RETGUARD_CHECK(x, t6); \ 1027ecb72feSdrahn ret; \ 1037ecb72feSdrahn __END(x) 1047ecb72feSdrahn 1057ecb72feSdrahn #define PSEUDO(x,y) \ 1067ecb72feSdrahn SYSENTRY(x); \ 1077ecb72feSdrahn RETGUARD_SETUP(x, t6); \ 1087ecb72feSdrahn SYSTRAP(y); \ 1097ecb72feSdrahn HANDLE_ERROR(); \ 1107ecb72feSdrahn RETGUARD_CHECK(x, t6); \ 1117ecb72feSdrahn ret; \ 1127ecb72feSdrahn __END(x) 1137ecb72feSdrahn #define PSEUDO_HIDDEN(x,y) \ 1147ecb72feSdrahn SYSENTRY_HIDDEN(x); \ 1157ecb72feSdrahn RETGUARD_SETUP(x, t6); \ 1167ecb72feSdrahn SYSTRAP(y); \ 1177ecb72feSdrahn HANDLE_ERROR(); \ 1187ecb72feSdrahn RETGUARD_CHECK(x, t6); \ 1197ecb72feSdrahn ret; \ 1207ecb72feSdrahn __END_HIDDEN(x) 1217ecb72feSdrahn 1227ecb72feSdrahn #define RSYSCALL_NOERROR(x) \ 1237ecb72feSdrahn PSEUDO_NOERROR(x,x) 1247ecb72feSdrahn 1257ecb72feSdrahn #define RSYSCALL(x) \ 1267ecb72feSdrahn PSEUDO(x,x) 1277ecb72feSdrahn #define RSYSCALL_HIDDEN(x) \ 1287ecb72feSdrahn PSEUDO_HIDDEN(x,x) 1297ecb72feSdrahn #define SYSCALL_END(x) \ 1307ecb72feSdrahn __END(x) 1317ecb72feSdrahn #define SYSCALL_END_HIDDEN(x) \ 1327ecb72feSdrahn __END_HIDDEN(x) 133