1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * William Jolitz. 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.27 2017/11/29 05:13:57 guenther Exp $ 33 */ 34 35 #include "DEFS.h" 36 #include <sys/syscall.h> 37 38 #define TCB_OFFSET_ERRNO 16 39 40 /* 41 * Design note: 42 * 43 * System calls entry points are really named _thread_sys_{syscall}, 44 * and weakly aliased to the name {syscall}. This allows the thread 45 * library to replace system calls at link time. 46 */ 47 48 /* Use both _thread_sys_{syscall} and [weak] {syscall}. */ 49 50 #define SYSENTRY(x) \ 51 ENTRY(_thread_sys_##x); \ 52 WEAK_ALIAS(x, _thread_sys_##x) 53 #define SYSENTRY_HIDDEN(x) \ 54 ENTRY(_thread_sys_ ## x) 55 #define __END_HIDDEN(x) END(_thread_sys_ ## x); \ 56 _HIDDEN_FALIAS(x,_thread_sys_ ## x); \ 57 END(_HIDDEN(x)) 58 #define __END(x) __END_HIDDEN(x); END(x) 59 60 #define __DO_SYSCALL(x) \ 61 movl $(SYS_ ## x),%eax; \ 62 int $0x80 63 64 #define SET_ERRNO() \ 65 movl %eax,%gs:(TCB_OFFSET_ERRNO); \ 66 movl $-1, %eax; \ 67 movl $-1, %edx /* for lseek */ 68 #define HANDLE_ERRNO() \ 69 jnc 99f; \ 70 SET_ERRNO(); \ 71 99: 72 73 /* perform a syscall */ 74 #define _SYSCALL_NOERROR(x,y) \ 75 SYSENTRY(x); \ 76 __DO_SYSCALL(y); 77 #define _SYSCALL_HIDDEN_NOERROR(x,y) \ 78 SYSENTRY_HIDDEN(x); \ 79 __DO_SYSCALL(y); 80 81 #define SYSCALL_NOERROR(x) \ 82 _SYSCALL_NOERROR(x,x) 83 84 /* perform a syscall, set errno */ 85 #define _SYSCALL(x,y) \ 86 .text; \ 87 .align 2; \ 88 _SYSCALL_NOERROR(x,y) \ 89 HANDLE_ERRNO() 90 #define _SYSCALL_HIDDEN(x,y) \ 91 .text; \ 92 .align 2; \ 93 _SYSCALL_HIDDEN_NOERROR(x,y) \ 94 HANDLE_ERRNO() 95 96 #define SYSCALL(x) \ 97 _SYSCALL(x,x) 98 #define SYSCALL_HIDDEN(x) \ 99 _SYSCALL_HIDDEN(x,y) 100 101 /* perform a syscall, return */ 102 #define PSEUDO_NOERROR(x,y) \ 103 _SYSCALL_NOERROR(x,y); \ 104 ret; \ 105 __END(x) 106 107 /* perform a syscall, set errno, return */ 108 #define PSEUDO(x,y) \ 109 _SYSCALL(x,y); \ 110 ret; \ 111 __END(x) 112 #define PSEUDO_HIDDEN(x,y) \ 113 _SYSCALL_HIDDEN(x,y); \ 114 ret; \ 115 __END_HIDDEN(x) 116 117 /* perform a syscall with the same name, set errno, return */ 118 #define RSYSCALL(x) \ 119 PSEUDO(x,x); 120 #define RSYSCALL_HIDDEN(x) \ 121 PSEUDO_HIDDEN(x,x) 122 #define SYSCALL_END(x) __END(x) 123 #define SYSCALL_END_HIDDEN(x) \ 124 __END_HIDDEN(x) 125