xref: /openbsd-src/libexec/ld.so/amd64/SYS.h (revision 04459484ef65b24eeb35e1d5ee05aa2e814916db)
1*04459484Sderaadt /*	$OpenBSD: SYS.h,v 1.5 2023/12/11 22:29:24 deraadt Exp $	*/
2d6979ba5Sderaadt 
3d6979ba5Sderaadt /*
4d6979ba5Sderaadt  * Copyright (c) 2002,2004 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 	.global	__CONCAT(_dl_,n)				;\
42d6979ba5Sderaadt 	.type	__CONCAT(_dl_,n), @function			;\
43d6979ba5Sderaadt 	.align	16,0xcc						;\
44d6979ba5Sderaadt __CONCAT(_dl_,n):						;\
4512e285c6Sderaadt 	endbr64							;\
4639b8558cSmortimer 	RETGUARD_SETUP(_dl_##n, r11)				;\
4739b8558cSmortimer 	RETGUARD_PUSH(r11)					;\
48d6979ba5Sderaadt 	movl	$(__CONCAT(SYS_,n)), %eax			;\
49d6979ba5Sderaadt 	movq	%rcx, %r10					;\
5083762a71Sderaadt 99:	syscall							;\
5183762a71Sderaadt 	PINSYSCALL(__CONCAT(SYS_,n), 99b)			;\
5239b8558cSmortimer 	jnc	1f						;\
5339b8558cSmortimer 	neg	%rax						;\
5439b8558cSmortimer 1:	RETGUARD_POP(r11)					;\
5539b8558cSmortimer 	RETGUARD_CHECK(_dl_##n, r11)				;\
56d6979ba5Sderaadt 	ret
57