Use ENDBR instruction in amd64 coroutine on OpenBSD

When running on newer Intel processors supporting the feature,
OpenBSD enforces indirect branch tracking.  Without this endbr64
instruction, jumps to the coroutine_transfer function result
in SIGILL on OpenBSD/amd64 when using such processors.

The OpenBSD Ruby ports have been using a patch similar to this
for the past two months.

From some research, cet.h has been supported by GCC for about
6 years and LLVM for about 4 years.
This commit is contained in:
Jeremy Evans 2024-06-12 16:32:06 -07:00
Родитель c2f8e91815
Коммит a60831f9b6
1 изменённых файлов: 8 добавлений и 0 удалений

Просмотреть файл

@ -5,6 +5,10 @@
## Copyright, 2018, by Samuel Williams.
##
#if defined(__OpenBSD__)
#include <cet.h>
#endif
#define TOKEN_PASTE(x,y) x##y
#define PREFIXED_SYMBOL(prefix,name) TOKEN_PASTE(prefix,name)
@ -13,6 +17,10 @@
.globl PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer)
PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer):
#if defined(__OpenBSD__)
_CET_ENDBR
#endif
# Make space on the stack for 6 registers:
subq $48, %rsp