xref: /openbsd/libexec/ld.so/i386/SYS.h (revision 04459484)
1*04459484Sderaadt /*	$OpenBSD: SYS.h,v 1.3 2023/12/11 22:29:24 deraadt Exp $ */
2d6979ba5Sderaadt 
3d6979ba5Sderaadt /*
4d6979ba5Sderaadt  * Copyright (c) 2002 Dale Rahn
5d6979ba5Sderaadt  * All rights reserved.
6d6979ba5Sderaadt  *
7d6979ba5Sderaadt  * Redistribution and use in source and binary forms, with or without
8d6979ba5Sderaadt  * modification, are permitted provided that the following conditions
9d6979ba5Sderaadt  * are met:
10d6979ba5Sderaadt  * 1. Redistributions of source code must retain the above copyright
11d6979ba5Sderaadt  *    notice, this list of conditions and the following disclaimer.
12d6979ba5Sderaadt  * 2. Redistributions in binary form must reproduce the above copyright
13d6979ba5Sderaadt  *    notice, this list of conditions and the following disclaimer in the
14d6979ba5Sderaadt  *    documentation and/or other materials provided with the distribution.
15d6979ba5Sderaadt  *
16d6979ba5Sderaadt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17d6979ba5Sderaadt  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18d6979ba5Sderaadt  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d6979ba5Sderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20d6979ba5Sderaadt  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21d6979ba5Sderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22d6979ba5Sderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23d6979ba5Sderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24d6979ba5Sderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25d6979ba5Sderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26d6979ba5Sderaadt  * SUCH DAMAGE.
27d6979ba5Sderaadt  *
28d6979ba5Sderaadt  */
29d6979ba5Sderaadt 
30d6979ba5Sderaadt #include <sys/syscall.h>
31d6979ba5Sderaadt #include <machine/asm.h>
32d6979ba5Sderaadt 
3383762a71Sderaadt #define PINSYSCALL(sysno, label)				\
3483762a71Sderaadt 	.pushsection .openbsd.syscalls,"",@progbits		;\
35*04459484Sderaadt 	.p2align 2						;\
3683762a71Sderaadt 	.long label						;\
3783762a71Sderaadt 	.long sysno						;\
3883762a71Sderaadt 	.popsection
3983762a71Sderaadt 
40d6979ba5Sderaadt #define DL_SYSCALL(n)						\
41d6979ba5Sderaadt 	.section	".text"					;\
42d6979ba5Sderaadt 	.align		16,0xcc					;\
43d6979ba5Sderaadt 	.global		__CONCAT(_dl_,n)			;\
44d6979ba5Sderaadt 	.type		__CONCAT(_dl_,n),@function		;\
45d6979ba5Sderaadt __CONCAT(_dl_,n):						;\
46d6979ba5Sderaadt 	movl $__CONCAT(SYS_, n),%eax;				;\
4783762a71Sderaadt 99:	int $0x80						;\
4883762a71Sderaadt 	PINSYSCALL(__CONCAT(SYS_, n), 99b)			;\
49d6979ba5Sderaadt 	jb	.L_cerr						;\
50d6979ba5Sderaadt 	ret
51d6979ba5Sderaadt 
52d6979ba5Sderaadt .L_cerr:
53d6979ba5Sderaadt 	/* error: result = -errno; - handled here. */
54d6979ba5Sderaadt 	neg	%eax
55d6979ba5Sderaadt 	ret
56