-/* $OpenBSD: copy.S,v 1.18 2023/01/31 15:18:54 deraadt Exp $ */
+/* $OpenBSD: copy.S,v 1.19 2023/07/28 06:18:35 guenther Exp $ */
/* $NetBSD: copy.S,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
/*
ret
lfence
- .section .rodata
- .globl _stac
-_stac:
- stac
-
- .globl _clac
-_clac:
- clac
+CODEPATCH_CODE(_stac, stac)
+CODEPATCH_CODE(_clac, clac)
-/* $OpenBSD: locore.S,v 1.138 2023/07/27 00:28:24 guenther Exp $ */
+/* $OpenBSD: locore.S,v 1.139 2023/07/28 06:18:35 guenther Exp $ */
/* $NetBSD: locore.S,v 1.13 2004/03/25 18:33:17 drochner Exp $ */
/*
lfence
END(xsetbv_user)
- .section .rodata
- .globl _xrstor
-_xrstor:
- xrstor64 (%rdi)
-
- .globl _xrstors
-_xrstors:
- xrstors64 (%rdi)
-
- .globl _xsave
-_xsave:
- xsave64 (%rdi)
-
- .globl _xsaves
-_xsaves:
- xsaves64 (%rdi)
-
- .globl _xsaveopt
-_xsaveopt:
- xsaveopt64 (%rdi)
-
- .globl _pcid_set_reuse
-_pcid_set_reuse:
- orl $(CR3_REUSE_PCID >> 32),CPUVAR(USER_CR3 + 4)
+CODEPATCH_CODE(_xrstor, xrstor64 (%rdi))
+CODEPATCH_CODE(_xrstors, xrstors64 (%rdi))
+CODEPATCH_CODE(_xsave, xsave64 (%rdi))
+CODEPATCH_CODE(_xsaves, xsaves64 (%rdi))
+CODEPATCH_CODE(_xsaveopt, xsaveopt64 (%rdi))
+CODEPATCH_CODE(_pcid_set_reuse,
+ orl $(CR3_REUSE_PCID >> 32),CPUVAR(USER_CR3 + 4))
+CODEPATCH_CODE_LEN(_jmprax, jmp *%rax; int3)
+CODEPATCH_CODE_LEN(_jmpr11, jmp *%r11; int3)
+CODEPATCH_CODE_LEN(_jmpr13, jmp *%r13; int3)
ENTRY(pagezero)
RETGUARD_SETUP(pagezero, r11)
-/* $OpenBSD: codepatch.h,v 1.15 2023/07/10 03:32:10 guenther Exp $ */
+/* $OpenBSD: codepatch.h,v 1.16 2023/07/28 06:18:35 guenther Exp $ */
/*
* Copyright (c) 2014-2015 Stefan Fritsch <sf@sfritsch.de>
*
.byte 0x0f, 0x1f, 0x40, 0x00 ;\
CODEPATCH_END2(997, CPTAG_PCID_SET_REUSE)
+/* Would be neat if these could be in something like .cptext */
+#define CODEPATCH_CODE(symbol, instructions...) \
+ .section .rodata; \
+ .globl symbol; \
+symbol: instructions; \
+ .size symbol, . - symbol
+
+/* provide a (short) variable with the length of the patch */
+#define CODEPATCH_CODE_LEN(symbol, instructions...) \
+ CODEPATCH_CODE(symbol, instructions); \
+996: .globl symbol##_len; \
+ .align 2; \
+symbol##_len: \
+ .short 996b - symbol; \
+ .size symbol##_len, 2
+
#endif /* _MACHINE_CODEPATCH_H_ */