diff --git a/Zend/asm/jump_x86_64_sysv_elf_gas.S b/Zend/asm/jump_x86_64_sysv_elf_gas.S index 0c4a1a39eb8b0..c675c8c774c23 100644 --- a/Zend/asm/jump_x86_64_sysv_elf_gas.S +++ b/Zend/asm/jump_x86_64_sysv_elf_gas.S @@ -24,12 +24,18 @@ * * ****************************************************************************************/ +# if defined __CET__ +# include +# else +# define _CET_ENDBR +# endif .file "jump_x86_64_sysv_elf_gas.S" .text .globl jump_fcontext .type jump_fcontext,@function .align 16 jump_fcontext: + _CET_ENDBR leaq -0x38(%rsp), %rsp /* prepare stack */ #if !defined(BOOST_USE_TSX) diff --git a/Zend/asm/make_x86_64_sysv_elf_gas.S b/Zend/asm/make_x86_64_sysv_elf_gas.S index 0ef37569a0299..d422c6972df9c 100644 --- a/Zend/asm/make_x86_64_sysv_elf_gas.S +++ b/Zend/asm/make_x86_64_sysv_elf_gas.S @@ -24,12 +24,18 @@ * * ****************************************************************************************/ +# if defined __CET__ +# include +# else +# define _CET_ENDBR +# endif .file "make_x86_64_sysv_elf_gas.S" .text .globl make_fcontext .type make_fcontext,@function .align 16 make_fcontext: + _CET_ENDBR /* first arg of make_fcontext() == top of context-stack */ movq %rdi, %rax @@ -66,11 +72,13 @@ make_fcontext: trampoline: /* store return address on stack */ /* fix stack alignment */ + _CET_ENDBR push %rbp /* jump to context-function */ jmp *%rbx finish: + _CET_ENDBR /* exit code is zero */ xorq %rdi, %rdi /* exit application */ diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c index dd06f86ae8da6..1fec85528fbb3 100644 --- a/Zend/zend_fibers.c +++ b/Zend/zend_fibers.c @@ -141,7 +141,7 @@ typedef struct { /* These functions are defined in assembler files provided by boost.context (located in "Zend/asm"). */ extern void *make_fcontext(void *sp, size_t size, void (*fn)(boost_context_data)); -extern boost_context_data jump_fcontext(void *to, zend_fiber_transfer *transfer); +extern ZEND_INDIRECT_RETURN boost_context_data jump_fcontext(void *to, zend_fiber_transfer *transfer); #endif ZEND_API zend_class_entry *zend_ce_fiber; diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h index 6ad9f1b1db2f9..74f8be3c1a26c 100644 --- a/Zend/zend_portability.h +++ b/Zend/zend_portability.h @@ -679,4 +679,10 @@ extern "C++" { # define ZEND_VOIDP(ptr) (ptr) #endif +#if defined(__GNUC__) && ZEND_GCC_VERSION >= 9000 +# define ZEND_INDIRECT_RETURN __attribute__((__indirect_return__)) +#else +# define ZEND_INDIRECT_RETURN +#endif + #endif /* ZEND_PORTABILITY_H */