From 4839338cef004d9be27b48279c975af78ff1fdcb Mon Sep 17 00:00:00 2001 From: kn1g78 Date: Sat, 4 Jul 2026 08:54:57 +0800 Subject: [PATCH 1/3] Sync Boost.Context assembly with 1.91.0 --- .../scripts/download-bundled/boost-context.sh | 2 +- Zend/asm/jump_arm64_aapcs_elf_gas.S | 19 +++ Zend/asm/jump_arm64_aapcs_macho_gas.S | 1 + Zend/asm/jump_arm64_aapcs_pe_armasm.asm | 4 +- Zend/asm/jump_arm64_aapcs_pe_armclang.S | 141 ++++++++++++++++++ Zend/asm/jump_arm_aapcs_elf_gas.S | 58 +++++++ Zend/asm/jump_arm_aapcs_macho_gas.S | 1 + Zend/asm/jump_i386_ms_pe_masm.asm | 18 +-- Zend/asm/jump_i386_sysv_elf_gas.S | 1 + Zend/asm/jump_i386_sysv_macho_gas.S | 5 +- Zend/asm/jump_loongarch64_sysv_elf_gas.S | 1 + Zend/asm/jump_mips32_o32_elf_gas.S | 5 +- Zend/asm/jump_mips64_n64_elf_gas.S | 1 + Zend/asm/jump_ppc32_sysv_elf_gas.S | 1 + Zend/asm/jump_ppc32_sysv_macho_gas.S | 5 +- Zend/asm/jump_ppc64_sysv_elf_gas.S | 14 +- Zend/asm/jump_ppc64_sysv_macho_gas.S | 1 + Zend/asm/jump_riscv64_sysv_elf_gas.S | 1 + Zend/asm/jump_s390x_sysv_elf_gas.S | 1 + Zend/asm/jump_x86_64_sysv_elf_gas.S | 9 +- Zend/asm/jump_x86_64_sysv_macho_gas.S | 1 + Zend/asm/make_arm64_aapcs_elf_gas.S | 19 +++ Zend/asm/make_arm64_aapcs_macho_gas.S | 1 + Zend/asm/make_arm64_aapcs_pe_armasm.asm | 2 +- Zend/asm/make_arm64_aapcs_pe_armclang.S | 118 +++++++++++++++ Zend/asm/make_arm_aapcs_elf_gas.S | 27 ++++ Zend/asm/make_arm_aapcs_macho_gas.S | 1 + Zend/asm/make_i386_ms_pe_masm.asm | 2 +- Zend/asm/make_i386_sysv_elf_gas.S | 1 + Zend/asm/make_i386_sysv_macho_gas.S | 3 +- Zend/asm/make_loongarch64_sysv_elf_gas.S | 1 + Zend/asm/make_mips32_o32_elf_gas.S | 1 + Zend/asm/make_mips64_n64_elf_gas.S | 3 +- Zend/asm/make_ppc32_sysv_elf_gas.S | 1 + Zend/asm/make_ppc32_sysv_macho_gas.S | 7 +- Zend/asm/make_ppc64_sysv_elf_gas.S | 1 + Zend/asm/make_ppc64_sysv_macho_gas.S | 1 + Zend/asm/make_riscv64_sysv_elf_gas.S | 1 + Zend/asm/make_s390x_sysv_elf_gas.S | 1 + Zend/asm/make_sparc64_sysv_elf_gas.S | 2 +- Zend/asm/make_x86_64_ms_pe_gas.S | 4 +- Zend/asm/make_x86_64_ms_pe_masm.asm | 4 +- Zend/asm/make_x86_64_sysv_elf_gas.S | 35 +---- Zend/asm/make_x86_64_sysv_macho_gas.S | 1 + 44 files changed, 457 insertions(+), 70 deletions(-) create mode 100644 Zend/asm/jump_arm64_aapcs_pe_armclang.S create mode 100644 Zend/asm/make_arm64_aapcs_pe_armclang.S diff --git a/.github/scripts/download-bundled/boost-context.sh b/.github/scripts/download-bundled/boost-context.sh index b1fd8708b85b..70c68b3ceb94 100755 --- a/.github/scripts/download-bundled/boost-context.sh +++ b/.github/scripts/download-bundled/boost-context.sh @@ -5,7 +5,7 @@ cd "$(dirname "$0")/../../.." tmp_dir=/tmp/php-src-download-bundled/boost-context rm -rf "$tmp_dir" -revision=refs/tags/boost-1.86.0 +revision=refs/tags/boost-1.91.0 git clone --depth 1 --revision="$revision" https://github.com/boostorg/context.git "$tmp_dir" diff --git a/Zend/asm/jump_arm64_aapcs_elf_gas.S b/Zend/asm/jump_arm64_aapcs_elf_gas.S index cefd1830d718..b8abb2ef6bc4 100644 --- a/Zend/asm/jump_arm64_aapcs_elf_gas.S +++ b/Zend/asm/jump_arm64_aapcs_elf_gas.S @@ -53,10 +53,29 @@ .file "jump_arm64_aapcs_elf_gas.S" .text +#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) +/* Mark this object as requiring BTI, enabling the linker to set BTI on the output */ + .pushsection .note.gnu.property, "a", %note + .p2align 3 + .long 4 /* namesz */ + .long 16 /* descsz (16 bytes) */ + .long 5 /* type = NT_GNU_PROPERTY_TYPE_0 */ + .asciz "GNU" + .p2align 3 + .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ + .long 4 /* datasz = 4 */ + .long 1 /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ + .long 0 /* pad to 8-byte alignment */ + .popsection +#endif .align 2 .global jump_fcontext +.hidden jump_fcontext .type jump_fcontext, %function jump_fcontext: +#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) + hint #34 /* bti c: valid indirect-entry target */ +#endif # prepare stack for GP + FPU sub sp, sp, #0xb0 diff --git a/Zend/asm/jump_arm64_aapcs_macho_gas.S b/Zend/asm/jump_arm64_aapcs_macho_gas.S index 31738f745314..12cc02158685 100644 --- a/Zend/asm/jump_arm64_aapcs_macho_gas.S +++ b/Zend/asm/jump_arm64_aapcs_macho_gas.S @@ -52,6 +52,7 @@ *******************************************************/ .text +.private_extern _jump_fcontext .globl _jump_fcontext .balign 16 _jump_fcontext: diff --git a/Zend/asm/jump_arm64_aapcs_pe_armasm.asm b/Zend/asm/jump_arm64_aapcs_pe_armasm.asm index 3100243d68de..afb6d2b2e703 100644 --- a/Zend/asm/jump_arm64_aapcs_pe_armasm.asm +++ b/Zend/asm/jump_arm64_aapcs_pe_armasm.asm @@ -45,7 +45,7 @@ ;* ------------------------------------------------- * ;* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * ;* ------------------------------------------------- * -;* | fiber data| base | limit | dealloc | * +;* | base | limit | dealloc | fiber data| * ;* ------------------------------------------------- * ;* ------------------------------------------------- * ;* | 48 | 49 | 50 | 51 | | | * @@ -130,4 +130,4 @@ jump_fcontext proc ret x4 ENDP - END \ No newline at end of file + END diff --git a/Zend/asm/jump_arm64_aapcs_pe_armclang.S b/Zend/asm/jump_arm64_aapcs_pe_armclang.S new file mode 100644 index 000000000000..3a62562fa833 --- /dev/null +++ b/Zend/asm/jump_arm64_aapcs_pe_armclang.S @@ -0,0 +1,141 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** +* * +* ------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +* ------------------------------------------------- * +* | d8 | d9 | d10 | d11 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ------------------------------------------------- * +* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +* ------------------------------------------------- * +* | d12 | d13 | d14 | d15 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ------------------------------------------------- * +* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +* ------------------------------------------------- * +* | x19 | x20 | x21 | x22 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ------------------------------------------------- * +* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +* ------------------------------------------------- * +* | x23 | x24 | x25 | x26 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +* ------------------------------------------------- * +* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +* ------------------------------------------------- * +* | x27 | x28 | FP | LR | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +* ------------------------------------------------- * +* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +* ------------------------------------------------- * +* | base | limit | dealloc | fiber data| * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 48 | 49 | 50 | 51 | | | * +* ------------------------------------------------- * +* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +* ------------------------------------------------- * +* | PC | align | | | * +* ------------------------------------------------- * +* * +*******************************************************/ + +.file "jump_arm64_aapcs_pe_armclang.S" +.text +.balign 4 + +.def jump_fcontext; .scl 2; .type 32; .endef +.seh_proc jump_fcontext +jump_fcontext: +.seh_endprologue + // prepare stack for GP + FPU + sub sp, sp, #0xd0 + + // save d8 - d15 + stp d8, d9, [sp, #0x00] + stp d10, d11, [sp, #0x10] + stp d12, d13, [sp, #0x20] + stp d14, d15, [sp, #0x30] + + // save x19-x30 + stp x19, x20, [sp, #0x40] + stp x21, x22, [sp, #0x50] + stp x23, x24, [sp, #0x60] + stp x25, x26, [sp, #0x70] + stp x27, x28, [sp, #0x80] + stp x29, x30, [sp, #0x90] + + // save LR as PC + str x30, [sp, #0xc0] + + // save current stack base and limit + ldp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h + stp x5, x6, [sp, #0xa0] + // save current fiber data and deallocation stack + ldr x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h + ldr x6, [x18, #0x20] // TeFiberData at ksarm64.h + stp x5, x6, [sp, #0xb0] + + // store RSP (pointing to context-data) in X0 + mov x4, sp + + // restore RSP (pointing to context-data) from X1 + mov sp, x0 + + // restore stack base and limit + ldp x5, x6, [sp, #0xa0] + stp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h + // restore fiber data and deallocation stack + ldp x5, x6, [sp, #0xb0] + str x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h + str x6, [x18, #0x20] // TeFiberData at ksarm64.h + + // load d8 - d15 + ldp d8, d9, [sp, #0x00] + ldp d10, d11, [sp, #0x10] + ldp d12, d13, [sp, #0x20] + ldp d14, d15, [sp, #0x30] + + // load x19-x30 + ldp x19, x20, [sp, #0x40] + ldp x21, x22, [sp, #0x50] + ldp x23, x24, [sp, #0x60] + ldp x25, x26, [sp, #0x70] + ldp x27, x28, [sp, #0x80] + ldp x29, x30, [sp, #0x90] + + // return transfer_t from jump + // pass transfer_t as first arg in context function + // X0 == FCTX, X1 == DATA + mov x0, x4 + + // load pc + ldr x4, [sp, #0xc0] + + // restore stack from GP + FPU + add sp, sp, #0xd0 + + ret x4 +.seh_endproc + +.section .drectve +.ascii " -export:\"jump_fcontext\"" diff --git a/Zend/asm/jump_arm_aapcs_elf_gas.S b/Zend/asm/jump_arm_aapcs_elf_gas.S index 86efe9d82146..4415a541fd3e 100644 --- a/Zend/asm/jump_arm_aapcs_elf_gas.S +++ b/Zend/asm/jump_arm_aapcs_elf_gas.S @@ -41,6 +41,7 @@ .file "jump_arm_aapcs_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .align 2 .type jump_fcontext,%function .syntax unified @@ -48,8 +49,38 @@ jump_fcontext: @ save LR as PC push {lr} @ save hidden,V1-V8,LR + + #if __ARM_ARCH >= 7 + push {a1,v1-v8,lr} + #else + + sub sp, #40 + + str a1, [sp, #0] + str v1, [sp, #4] + str v2, [sp, #8] + str v3, [sp, #12] + str v4, [sp, #16] + + mov v4, v5 + str v4, [sp, #20] + + mov v4, v6 + str v4, [sp, #24] + + mov v4, v7 + str v4, [sp, #28] + + mov v4, v8 + str v4, [sp, #32] + + mov v4, lr + str v4, [sp, #36] + + #endif + @ prepare stack for FPU sub sp, sp, #64 #if (defined(__VFP_FP__) && !defined(__SOFTFP__)) @@ -71,7 +102,34 @@ jump_fcontext: add sp, sp, #64 @ restore hidden,V1-V8,LR + #if __ARM_ARCH >= 7 pop {a4,v1-v8,lr} + #else + + ldr v4, [sp, #20] + mov v5, v4 + + ldr v4, [sp, #24] + mov v6, v4 + + ldr v4, [sp, #28] + mov v7, v4 + + ldr v4, [sp, #32] + mov v8, v4 + + ldr v4, [sp, #36] + mov lr, v4 + + ldr a4, [sp, #0] + ldr v1, [sp, #4] + ldr v2, [sp, #8] + ldr v3, [sp, #12] + ldr v4, [sp, #16] + + add sp, #40 + + #endif @ return transfer_t from jump str a1, [a4, #0] diff --git a/Zend/asm/jump_arm_aapcs_macho_gas.S b/Zend/asm/jump_arm_aapcs_macho_gas.S index 077c36409e83..44e7f2a42274 100644 --- a/Zend/asm/jump_arm_aapcs_macho_gas.S +++ b/Zend/asm/jump_arm_aapcs_macho_gas.S @@ -39,6 +39,7 @@ *******************************************************/ .text +.private_extern _jump_fcontext .globl _jump_fcontext .align 2 _jump_fcontext: diff --git a/Zend/asm/jump_i386_ms_pe_masm.asm b/Zend/asm/jump_i386_ms_pe_masm.asm index 7a9e848f1c3f..a0450d0532f8 100644 --- a/Zend/asm/jump_i386_ms_pe_masm.asm +++ b/Zend/asm/jump_i386_ms_pe_masm.asm @@ -55,17 +55,17 @@ ENDIF mov eax, [edx] mov [esp+018h], eax - mov [esp+01ch], edi ; save EDI - mov [esp+020h], esi ; save ESI - mov [esp+024h], ebx ; save EBX - mov [esp+028h], ebp ; save EBP + mov [esp+01ch], edi ; save EDI + mov [esp+020h], esi ; save ESI + mov [esp+024h], ebx ; save EBX + mov [esp+028h], ebp ; save EBP ; store ESP (pointing to context-data) in EAX mov eax, esp ; firstarg of jump_fcontext() == fcontext to jump to mov ecx, [esp+030h] - + ; restore ESP (pointing to context-data) from ECX mov esp, ecx @@ -98,10 +98,10 @@ ENDIF mov ecx, [esp+02ch] ; restore EIP - mov edi, [esp+01ch] ; restore EDI - mov esi, [esp+020h] ; restore ESI - mov ebx, [esp+024h] ; restore EBX - mov ebp, [esp+028h] ; restore EBP + mov edi, [esp+01ch] ; restore EDI + mov esi, [esp+020h] ; restore ESI + mov ebx, [esp+024h] ; restore EBX + mov ebp, [esp+028h] ; restore EBP ; prepare stack lea esp, [esp+030h] diff --git a/Zend/asm/jump_i386_sysv_elf_gas.S b/Zend/asm/jump_i386_sysv_elf_gas.S index ed83717ce2b8..d00ac4fffd42 100644 --- a/Zend/asm/jump_i386_sysv_elf_gas.S +++ b/Zend/asm/jump_i386_sysv_elf_gas.S @@ -31,6 +31,7 @@ .file "jump_i386_sysv_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .align 2 .type jump_fcontext,@function jump_fcontext: diff --git a/Zend/asm/jump_i386_sysv_macho_gas.S b/Zend/asm/jump_i386_sysv_macho_gas.S index 8ab7c6f29c66..4cae3252d171 100644 --- a/Zend/asm/jump_i386_sysv_macho_gas.S +++ b/Zend/asm/jump_i386_sysv_macho_gas.S @@ -25,6 +25,7 @@ ****************************************************************************************/ .text +.private_extern _jump_fcontext .globl _jump_fcontext .align 2 _jump_fcontext: @@ -54,8 +55,8 @@ _jump_fcontext: /* return parent fcontext_t */ movl %ecx, %eax - /* returned data is stored in EDX */ - + /* returned data is stored in EDX */ + movl 0x18(%esp), %ecx /* restore EIP */ #if !defined(BOOST_USE_TSX) diff --git a/Zend/asm/jump_loongarch64_sysv_elf_gas.S b/Zend/asm/jump_loongarch64_sysv_elf_gas.S index 74c081e07faa..6f99e719ec00 100644 --- a/Zend/asm/jump_loongarch64_sysv_elf_gas.S +++ b/Zend/asm/jump_loongarch64_sysv_elf_gas.S @@ -41,6 +41,7 @@ .file "jump_loongarch64_sysv_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .align 2 .type jump_fcontext,@function jump_fcontext: diff --git a/Zend/asm/jump_mips32_o32_elf_gas.S b/Zend/asm/jump_mips32_o32_elf_gas.S index f2b8034d8c5b..38d22d26f6d7 100644 --- a/Zend/asm/jump_mips32_o32_elf_gas.S +++ b/Zend/asm/jump_mips32_o32_elf_gas.S @@ -41,6 +41,7 @@ .file "jump_mips32_o32_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .align 2 .type jump_fcontext,@function .ent jump_fcontext @@ -102,13 +103,13 @@ jump_fcontext: # adjust stack addiu $sp, $sp, 96 - + # return transfer_t from jump sw $a0, ($v0) # fctx of transfer_t sw $a2, 4($v0) # data of transfer_t # pass transfer_t as first arg in context function # A0 == fctx, A1 == data - move $a1, $a2 + move $a1, $a2 # jump to context jr $t9 diff --git a/Zend/asm/jump_mips64_n64_elf_gas.S b/Zend/asm/jump_mips64_n64_elf_gas.S index e338912bb6e8..60027fe61734 100644 --- a/Zend/asm/jump_mips64_n64_elf_gas.S +++ b/Zend/asm/jump_mips64_n64_elf_gas.S @@ -48,6 +48,7 @@ .file "jump_mips64_n64_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .align 3 .type jump_fcontext,@function .ent jump_fcontext diff --git a/Zend/asm/jump_ppc32_sysv_elf_gas.S b/Zend/asm/jump_ppc32_sysv_elf_gas.S index 48e09c935e09..e31336640065 100644 --- a/Zend/asm/jump_ppc32_sysv_elf_gas.S +++ b/Zend/asm/jump_ppc32_sysv_elf_gas.S @@ -53,6 +53,7 @@ .file "jump_ppc32_sysv_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .align 2 .type jump_fcontext,@function jump_fcontext: diff --git a/Zend/asm/jump_ppc32_sysv_macho_gas.S b/Zend/asm/jump_ppc32_sysv_macho_gas.S index fef90c295f8c..c2a2061e8774 100644 --- a/Zend/asm/jump_ppc32_sysv_macho_gas.S +++ b/Zend/asm/jump_ppc32_sysv_macho_gas.S @@ -68,12 +68,13 @@ * ------------------------------------------------- * * | 256 | | * * ------------------------------------------------- * - * | DATA| | * + * | DATA| | * * ------------------------------------------------- * * * *******************************************************/ .text +.private_extern _jump_fcontext .globl _jump_fcontext .align 2 _jump_fcontext: @@ -193,7 +194,7 @@ _jump_fcontext: ; adjust stack addi r1, r1, 244 - ; return transfer_t + ; return transfer_t stw r6, 0(r3) stw r5, 4(r3) diff --git a/Zend/asm/jump_ppc64_sysv_elf_gas.S b/Zend/asm/jump_ppc64_sysv_elf_gas.S index 28907db32b8c..debeb3466404 100644 --- a/Zend/asm/jump_ppc64_sysv_elf_gas.S +++ b/Zend/asm/jump_ppc64_sysv_elf_gas.S @@ -68,6 +68,7 @@ .file "jump_ppc64_sysv_elf_gas.S" .globl jump_fcontext +.hidden jump_fcontext #if _CALL_ELF == 2 .text .align 2 @@ -97,7 +98,7 @@ jump_fcontext: # endif #endif # reserve space on stack - subi %r1, %r1, 184 + subi %r1, %r1, 200 #if _CALL_ELF != 2 std %r2, 0(%r1) # save TOC @@ -133,6 +134,10 @@ jump_fcontext: # save LR as PC std %r0, 176(%r1) + # Save VS63 + li %r31, 184 + stvx %v31, %r1, %r31 + # store RSP (pointing to context-data) in R6 mr %r6, %r1 @@ -145,6 +150,11 @@ jump_fcontext: ld %r2, 0(%r1) # restore TOC #endif + + # Restore VS63 + li %r31, 184 + lvx %v31, %r1, %r31 + ld %r14, 8(%r1) # restore R14 ld %r15, 16(%r1) # restore R15 ld %r16, 24(%r1) # restore R16 @@ -180,7 +190,7 @@ jump_fcontext: mtctr %r12 # adjust stack - addi %r1, %r1, 184 + addi %r1, %r1, 200 #if _CALL_ELF == 2 # copy transfer_t into transfer_fn arg registers diff --git a/Zend/asm/jump_ppc64_sysv_macho_gas.S b/Zend/asm/jump_ppc64_sysv_macho_gas.S index dcc6c645db61..e4d8944b563d 100644 --- a/Zend/asm/jump_ppc64_sysv_macho_gas.S +++ b/Zend/asm/jump_ppc64_sysv_macho_gas.S @@ -68,6 +68,7 @@ .text .align 2 +.private_extern _jump_fcontext .globl _jump_fcontext _jump_fcontext: diff --git a/Zend/asm/jump_riscv64_sysv_elf_gas.S b/Zend/asm/jump_riscv64_sysv_elf_gas.S index 5417e5d5e349..879eb7efee62 100644 --- a/Zend/asm/jump_riscv64_sysv_elf_gas.S +++ b/Zend/asm/jump_riscv64_sysv_elf_gas.S @@ -61,6 +61,7 @@ .text .align 1 .global jump_fcontext +.hidden jump_fcontext .type jump_fcontext, %function jump_fcontext: # prepare stack for GP + FPU diff --git a/Zend/asm/jump_s390x_sysv_elf_gas.S b/Zend/asm/jump_s390x_sysv_elf_gas.S index fa71467756d2..59bc58bf370b 100644 --- a/Zend/asm/jump_s390x_sysv_elf_gas.S +++ b/Zend/asm/jump_s390x_sysv_elf_gas.S @@ -46,6 +46,7 @@ .text .align 8 .global jump_fcontext +.hidden jump_fcontext .type jump_fcontext, @function #define ARG_OFFSET 0 diff --git a/Zend/asm/jump_x86_64_sysv_elf_gas.S b/Zend/asm/jump_x86_64_sysv_elf_gas.S index be264bdc2e2b..2eff59a380cb 100644 --- a/Zend/asm/jump_x86_64_sysv_elf_gas.S +++ b/Zend/asm/jump_x86_64_sysv_elf_gas.S @@ -44,6 +44,7 @@ .file "jump_x86_64_sysv_elf_gas.S" .text .globl jump_fcontext +.hidden jump_fcontext .type jump_fcontext,@function .align 16 jump_fcontext: @@ -67,14 +68,6 @@ jump_fcontext: movq %rbx, 0x30(%rsp) /* save RBX */ movq %rbp, 0x38(%rsp) /* save RBP */ -#if BOOST_CONTEXT_SHADOW_STACK - /* grow the stack to reserve space for shadow stack pointer(SSP) */ - leaq -0x8(%rsp), %rsp - /* read the current SSP and store it */ - rdsspq %rcx - movq %rcx, (%rsp) -#endif - #if BOOST_CONTEXT_SHADOW_STACK /* grow the stack to reserve space for shadow stack pointer(SSP) */ leaq -0x8(%rsp), %rsp diff --git a/Zend/asm/jump_x86_64_sysv_macho_gas.S b/Zend/asm/jump_x86_64_sysv_macho_gas.S index afc3e5c126f9..673daa61dfaa 100644 --- a/Zend/asm/jump_x86_64_sysv_macho_gas.S +++ b/Zend/asm/jump_x86_64_sysv_macho_gas.S @@ -25,6 +25,7 @@ ****************************************************************************************/ .text +.private_extern _jump_fcontext .globl _jump_fcontext .align 8 _jump_fcontext: diff --git a/Zend/asm/make_arm64_aapcs_elf_gas.S b/Zend/asm/make_arm64_aapcs_elf_gas.S index 66cfb2da17ea..246525402f5c 100644 --- a/Zend/asm/make_arm64_aapcs_elf_gas.S +++ b/Zend/asm/make_arm64_aapcs_elf_gas.S @@ -53,10 +53,29 @@ .file "make_arm64_aapcs_elf_gas.S" .text +#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) +/* Mark this object as requiring BTI, enabling the linker to set BTI on the output */ + .pushsection .note.gnu.property, "a", %note + .p2align 3 + .long 4 /* namesz */ + .long 16 /* descsz (16 bytes) */ + .long 5 /* type = NT_GNU_PROPERTY_TYPE_0 */ + .asciz "GNU" + .p2align 3 + .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */ + .long 4 /* datasz = 4 */ + .long 1 /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ + .long 0 /* pad to 8-byte alignment */ + .popsection +#endif .align 2 .global make_fcontext +.hidden make_fcontext .type make_fcontext, %function make_fcontext: +#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1) + hint #34 /* bti c */ +#endif # shift address in x0 (allocated stack) to lower 16 byte boundary and x0, x0, ~0xF diff --git a/Zend/asm/make_arm64_aapcs_macho_gas.S b/Zend/asm/make_arm64_aapcs_macho_gas.S index b30b1e3e5bbb..a6a1314c0dcd 100644 --- a/Zend/asm/make_arm64_aapcs_macho_gas.S +++ b/Zend/asm/make_arm64_aapcs_macho_gas.S @@ -52,6 +52,7 @@ *******************************************************/ .text +.private_extern _make_fcontext .globl _make_fcontext .balign 16 diff --git a/Zend/asm/make_arm64_aapcs_pe_armasm.asm b/Zend/asm/make_arm64_aapcs_pe_armasm.asm index 50f9b69876be..c384af039fc4 100644 --- a/Zend/asm/make_arm64_aapcs_pe_armasm.asm +++ b/Zend/asm/make_arm64_aapcs_pe_armasm.asm @@ -73,7 +73,7 @@ make_fcontext proc ; save top address of context_stack as 'base' str x3, [x0, #0xa0] - ; save bottom address of context-stack as 'limit' and 'dealloction stack' + ; save bottom address of context-stack as 'limit' and 'deallocation stack' sub x3, x3, x1 stp x3, x3, [x0, #0xa8] ; save 0 as 'fiber data' diff --git a/Zend/asm/make_arm64_aapcs_pe_armclang.S b/Zend/asm/make_arm64_aapcs_pe_armclang.S new file mode 100644 index 000000000000..761092f2fa6b --- /dev/null +++ b/Zend/asm/make_arm64_aapcs_pe_armclang.S @@ -0,0 +1,118 @@ +/* + Copyright Edward Nevill + Oliver Kowalke 2015 + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +*/ + +/****************************************************** +* * +* ------------------------------------------------- * +* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +* ------------------------------------------------- * +* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * +* ------------------------------------------------- * +* | d8 | d9 | d10 | d11 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * +* ------------------------------------------------- * +* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * +* ------------------------------------------------- * +* | d12 | d13 | d14 | d15 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * +* ------------------------------------------------- * +* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * +* ------------------------------------------------- * +* | x19 | x20 | x21 | x22 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * +* ------------------------------------------------- * +* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * +* ------------------------------------------------- * +* | x23 | x24 | x25 | x26 | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * +* ------------------------------------------------- * +* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * +* ------------------------------------------------- * +* | x27 | x28 | FP | LR | * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * +* ------------------------------------------------- * +* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * +* ------------------------------------------------- * +* | base | limit | dealloc | fiber data| * +* ------------------------------------------------- * +* ------------------------------------------------- * +* | 48 | 49 | 50 | 51 | | | * +* ------------------------------------------------- * +* | 0xc0| 0xc4| 0xc8| 0xcc| | | * +* ------------------------------------------------- * +* | PC | align | | | * +* ------------------------------------------------- * +* * +*******************************************************/ + +.file "make_arm64_aapcs_pe_armclang.S" +.text +.balign 4 + +.globl make_fcontext +.def make_fcontext; .scl 2; .type 32; .endef +.seh_proc make_fcontext +make_fcontext: +.seh_endprologue + // save stack top address to x3 + mov x3, x0 + + // shift address in x0 (allocated stack) to lower 16 byte boundary + and x0, x0, ~0xF + + // reserve space for context-data on context-stack + sub x0, x0, #0xd0 + + // save top address of context_stack as 'base' + str x3, [x0, #0xa0] + // save bottom address of context-stack as 'limit' and 'deallocation stack' + sub x3, x3, x1 + stp x3, x3, [x0, #0xa8] + // save 0 as 'fiber data' + str xzr, [x0, #0xb8] + + // third arg of make_fcontext() == address of context-function + // store address as x19 for trampoline + str x2, [x0, #0x40] + // store trampoline address as pc + adr x2, trampoline + str x2, [x0, #0xc0] + + // save address of finish as return-address for context-function + // will be entered after context-function returns (LR register) + adr x1, finish + str x1, [x0, #0x98] + + ret x30 // return pointer to context-data (x0) + +trampoline: + stp fp, lr, [sp, #-0x10]! + mov fp, sp + blr x19 + +finish: + // exit code is zero + mov x0, #0 + // exit application + bl _exit + +.seh_endproc + +.def _exit; .scl 2; .type 32; .endef /* standard C library function */ + +.section .drectve +.ascii " -export:\"make_fcontext\"" diff --git a/Zend/asm/make_arm_aapcs_elf_gas.S b/Zend/asm/make_arm_aapcs_elf_gas.S index 98ae64b43f9d..2367c75a6a77 100644 --- a/Zend/asm/make_arm_aapcs_elf_gas.S +++ b/Zend/asm/make_arm_aapcs_elf_gas.S @@ -41,26 +41,47 @@ .file "make_arm_aapcs_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .align 2 .type make_fcontext,%function .syntax unified make_fcontext: @ shift address in A1 to lower 16 byte boundary + + #if __ARM_ARCH >= 7 bic a1, a1, #15 + #else + lsrs a1, a1, #4 + lsls a1, a1, #4 + #endif @ reserve space for context-data on context-stack + #if __ARM_ARCH >= 7 sub a1, a1, #124 + #else + subs a1, #124 + #endif @ third arg of make_fcontext() == address of context-function str a3, [a1, #104] @ compute address of returned transfer_t + #if __ARM_ARCH >= 7 add a2, a1, #108 + #else + mov a2, a1 + adds a2, #108 + #endif mov a3, a2 str a3, [a1, #64] + @ compute abs address of label finish + #if __ARM_ARCH >= 7 adr a2, finish + #else + ldr a2, =finish + #endif @ save address of finish as return-address for context-function @ will be entered after context-function returns str a2, [a1, #100] @@ -72,7 +93,13 @@ make_fcontext: finish: @ exit code is zero + #if __ARM_ARCH >=7 mov a1, #0 + #else + movs r3, #0 + movs r0, r3 + #endif + @ exit application bl _exit@PLT .size make_fcontext,.-make_fcontext diff --git a/Zend/asm/make_arm_aapcs_macho_gas.S b/Zend/asm/make_arm_aapcs_macho_gas.S index c909ae9d43a2..de934075d247 100644 --- a/Zend/asm/make_arm_aapcs_macho_gas.S +++ b/Zend/asm/make_arm_aapcs_macho_gas.S @@ -39,6 +39,7 @@ *******************************************************/ .text +.private_extern _make_fcontext .globl _make_fcontext .align 2 _make_fcontext: diff --git a/Zend/asm/make_i386_ms_pe_masm.asm b/Zend/asm/make_i386_ms_pe_masm.asm index 5246465cb975..3879396390f2 100644 --- a/Zend/asm/make_i386_ms_pe_masm.asm +++ b/Zend/asm/make_i386_ms_pe_masm.asm @@ -53,7 +53,7 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT mov [eax+014h], ecx ; second arg of make_fcontext() == size of context-stack mov edx, [esp+08h] - ; negate stack size for LEA instruction (== substraction) + ; negate stack size for LEA instruction (== subtraction) neg edx ; compute bottom address of context stack (limit) lea ecx, [ecx+edx] diff --git a/Zend/asm/make_i386_sysv_elf_gas.S b/Zend/asm/make_i386_sysv_elf_gas.S index c6e0b36558a6..992bae019af2 100644 --- a/Zend/asm/make_i386_sysv_elf_gas.S +++ b/Zend/asm/make_i386_sysv_elf_gas.S @@ -31,6 +31,7 @@ .file "make_i386_sysv_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .align 2 .type make_fcontext,@function make_fcontext: diff --git a/Zend/asm/make_i386_sysv_macho_gas.S b/Zend/asm/make_i386_sysv_macho_gas.S index 519e406248bb..01076129bcf5 100644 --- a/Zend/asm/make_i386_sysv_macho_gas.S +++ b/Zend/asm/make_i386_sysv_macho_gas.S @@ -25,6 +25,7 @@ ****************************************************************************************/ .text +.private_extern _make_fcontext .globl _make_fcontext .align 2 _make_fcontext: @@ -69,7 +70,7 @@ _make_fcontext: addl $finish-2b, %ecx /* save address of finish as return-address for context-function */ /* will be entered after context-function returns */ - movl %ecx, 0x14(%eax) + movl %ecx, 0x14(%eax) ret /* return pointer to context-data */ diff --git a/Zend/asm/make_loongarch64_sysv_elf_gas.S b/Zend/asm/make_loongarch64_sysv_elf_gas.S index 55062702f18d..a067baded56f 100644 --- a/Zend/asm/make_loongarch64_sysv_elf_gas.S +++ b/Zend/asm/make_loongarch64_sysv_elf_gas.S @@ -41,6 +41,7 @@ .file "make_loongarch64_sysv_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .align 2 .type make_fcontext,@function make_fcontext: diff --git a/Zend/asm/make_mips32_o32_elf_gas.S b/Zend/asm/make_mips32_o32_elf_gas.S index 4e11e3d05825..54742f3a8be2 100644 --- a/Zend/asm/make_mips32_o32_elf_gas.S +++ b/Zend/asm/make_mips32_o32_elf_gas.S @@ -41,6 +41,7 @@ .file "make_mips32_o32_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .align 2 .type make_fcontext,@function .ent make_fcontext diff --git a/Zend/asm/make_mips64_n64_elf_gas.S b/Zend/asm/make_mips64_n64_elf_gas.S index 7bb30b14dee7..c43f2ff368f9 100644 --- a/Zend/asm/make_mips64_n64_elf_gas.S +++ b/Zend/asm/make_mips64_n64_elf_gas.S @@ -48,6 +48,7 @@ .file "make_mips64_n64_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .align 3 .type make_fcontext,@function .ent make_fcontext @@ -69,7 +70,7 @@ make_fcontext: # save global pointer in context-data sd $gp, 136($v0) - # psudo instruction compute abs address of label finish based on GP + # pseudo instruction compute abs address of label finish based on GP dla $t9, finish # save address of finish as return-address for context-function diff --git a/Zend/asm/make_ppc32_sysv_elf_gas.S b/Zend/asm/make_ppc32_sysv_elf_gas.S index 9616c4ca9b46..0dd77719354b 100644 --- a/Zend/asm/make_ppc32_sysv_elf_gas.S +++ b/Zend/asm/make_ppc32_sysv_elf_gas.S @@ -53,6 +53,7 @@ .file "make_ppc32_sysv_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .align 2 .type make_fcontext,@function make_fcontext: diff --git a/Zend/asm/make_ppc32_sysv_macho_gas.S b/Zend/asm/make_ppc32_sysv_macho_gas.S index 1102ee90ef07..75d1c80e5263 100644 --- a/Zend/asm/make_ppc32_sysv_macho_gas.S +++ b/Zend/asm/make_ppc32_sysv_macho_gas.S @@ -68,12 +68,13 @@ * ------------------------------------------------- * * | 256 | | * * ------------------------------------------------- * - * | DATA| | * + * | DATA| | * * ------------------------------------------------- * * * *******************************************************/ .text +.private_extern _make_fcontext .globl _make_fcontext .align 2 _make_fcontext: @@ -101,8 +102,8 @@ _make_fcontext: ; compute address of returned transfer_t addi r0, r3, 252 - mr r4, r0 - stw r4, 228(r3) + mr r4, r0 + stw r4, 228(r3) ; load LR mflr r0 diff --git a/Zend/asm/make_ppc64_sysv_elf_gas.S b/Zend/asm/make_ppc64_sysv_elf_gas.S index c4d7ee59826a..f513d3639ea9 100644 --- a/Zend/asm/make_ppc64_sysv_elf_gas.S +++ b/Zend/asm/make_ppc64_sysv_elf_gas.S @@ -68,6 +68,7 @@ .file "make_ppc64_sysv_elf_gas.S" .globl make_fcontext +.hidden make_fcontext #if _CALL_ELF == 2 .text .align 2 diff --git a/Zend/asm/make_ppc64_sysv_macho_gas.S b/Zend/asm/make_ppc64_sysv_macho_gas.S index dd7bf2c5c0c0..d8cdd2d080db 100644 --- a/Zend/asm/make_ppc64_sysv_macho_gas.S +++ b/Zend/asm/make_ppc64_sysv_macho_gas.S @@ -67,6 +67,7 @@ *******************************************************/ .text +.private_extern _make_fcontext .globl _make_fcontext _make_fcontext: ; save return address into R6 diff --git a/Zend/asm/make_riscv64_sysv_elf_gas.S b/Zend/asm/make_riscv64_sysv_elf_gas.S index 5322e0fdbdec..6d97c59e877e 100644 --- a/Zend/asm/make_riscv64_sysv_elf_gas.S +++ b/Zend/asm/make_riscv64_sysv_elf_gas.S @@ -61,6 +61,7 @@ .text .align 1 .global make_fcontext +.hidden make_fcontext .type make_fcontext, %function make_fcontext: # shift address in a0 (allocated stack) to lower 16 byte boundary diff --git a/Zend/asm/make_s390x_sysv_elf_gas.S b/Zend/asm/make_s390x_sysv_elf_gas.S index 4dd423e2a44c..4d6aa62c0ae1 100644 --- a/Zend/asm/make_s390x_sysv_elf_gas.S +++ b/Zend/asm/make_s390x_sysv_elf_gas.S @@ -46,6 +46,7 @@ .text .align 8 .global make_fcontext +.hidden make_fcontext .type make_fcontext, @function #define ARG_OFFSET 0 diff --git a/Zend/asm/make_sparc64_sysv_elf_gas.S b/Zend/asm/make_sparc64_sysv_elf_gas.S index 3e7ee809c918..3d504471afd5 100644 --- a/Zend/asm/make_sparc64_sysv_elf_gas.S +++ b/Zend/asm/make_sparc64_sysv_elf_gas.S @@ -45,7 +45,7 @@ make_fcontext: add %l0, (trampoline - 1b - 8), %l0 stx %l0, [%i0 + I7] - # Save framepointer to first stack frame but first substract the BIAS + # Save framepointer to first stack frame but first subtract the BIAS add %i0, CC64FSZ - BIAS, %l0 stx %l0, [%i0 + SP] diff --git a/Zend/asm/make_x86_64_ms_pe_gas.S b/Zend/asm/make_x86_64_ms_pe_gas.S index 958a2a7b6d0e..7146637c0319 100644 --- a/Zend/asm/make_x86_64_ms_pe_gas.S +++ b/Zend/asm/make_x86_64_ms_pe_gas.S @@ -113,7 +113,7 @@ make_fcontext: /* save top address of context stack as 'base' */ movq %rcx, 0xc8(%rax) /* second arg of make_fcontext() == size of context-stack */ - /* negate stack size for LEA instruction (== substraction) */ + /* negate stack size for LEA instruction (== subtraction) */ negq %rdx /* compute bottom address of context stack (limit) */ leaq (%rcx,%rdx), %rcx @@ -151,7 +151,7 @@ make_fcontext: trampoline: /* store return address on stack */ - /* fix stack alignment */ + /* fix stack alignment */ pushq %rbp /* jump to context-function */ jmp *%rbx diff --git a/Zend/asm/make_x86_64_ms_pe_masm.asm b/Zend/asm/make_x86_64_ms_pe_masm.asm index 8f6c959a8376..a6c2b147e446 100644 --- a/Zend/asm/make_x86_64_ms_pe_masm.asm +++ b/Zend/asm/make_x86_64_ms_pe_masm.asm @@ -110,7 +110,7 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME ; save top address of context stack as 'base' mov [rax+0c8h], rcx ; second arg of make_fcontext() == size of context-stack - ; negate stack size for LEA instruction (== substraction) + ; negate stack size for LEA instruction (== subtraction) neg rdx ; compute bottom address of context stack (limit) lea rcx, [rcx+rdx] @@ -141,7 +141,7 @@ make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME ; compute abs address of label finish lea rcx, finish ; save address of finish as return-address for context-function in RBP - ; will be entered after context-function returns + ; will be entered after context-function returns mov [rax+0108h], rcx ret ; return pointer to context-data diff --git a/Zend/asm/make_x86_64_sysv_elf_gas.S b/Zend/asm/make_x86_64_sysv_elf_gas.S index b0d0c0341ef3..cabebff6e626 100644 --- a/Zend/asm/make_x86_64_sysv_elf_gas.S +++ b/Zend/asm/make_x86_64_sysv_elf_gas.S @@ -44,6 +44,7 @@ .file "make_x86_64_sysv_elf_gas.S" .text .globl make_fcontext +.hidden make_fcontext .type make_fcontext,@function .align 16 make_fcontext: @@ -76,7 +77,7 @@ make_fcontext: #if defined(BOOST_CONTEXT_TLS_STACK_PROTECTOR) /* save stack guard */ movq %fs:0x28, %rcx /* read stack guard from TLS record */ - movq %rcx, 0x8(%rsp) /* save stack guard */ + movq %rcx, 0x8(%rax) /* save stack guard */ #endif /* compute abs address of label trampoline */ @@ -91,35 +92,6 @@ make_fcontext: /* will be entered after context-function returns */ movq %rcx, 0x38(%rax) -#if BOOST_CONTEXT_SHADOW_STACK - /* Populate the shadow stack and normal stack */ - /* get original SSP */ - rdsspq %r8 - /* restore new shadow stack */ - rstorssp -0x8(%r9) - /* save the restore token on the original shadow stack */ - saveprevssp - /* push the address of "jmp trampoline" to the new shadow stack */ - /* as well as the stack */ - call 1f - jmp trampoline -1: - /* save address of "jmp trampoline" as return-address */ - /* for context-function */ - pop 0x38(%rax) - /* Get the new SSP. */ - rdsspq %r9 - /* restore original shadow stack */ - rstorssp -0x8(%r8) - /* save the restore token on the new shadow stack. */ - saveprevssp - - /* reserve space for the new SSP */ - leaq -0x8(%rax), %rax - /* save the new SSP to this fcontext */ - movq %r9, (%rax) -#endif - #if BOOST_CONTEXT_SHADOW_STACK /* Populate the shadow stack */ @@ -161,6 +133,8 @@ make_fcontext: ret /* return pointer to context-data */ trampoline: + .cfi_startproc + .cfi_undefined rip /* store return address on stack */ /* fix stack alignment */ _CET_ENDBR @@ -175,6 +149,7 @@ trampoline: #endif /* jump to context-function */ jmp *%rbx + .cfi_endproc finish: _CET_ENDBR diff --git a/Zend/asm/make_x86_64_sysv_macho_gas.S b/Zend/asm/make_x86_64_sysv_macho_gas.S index 5d6c5431c598..06357f678ac9 100644 --- a/Zend/asm/make_x86_64_sysv_macho_gas.S +++ b/Zend/asm/make_x86_64_sysv_macho_gas.S @@ -25,6 +25,7 @@ ****************************************************************************************/ .text +.private_extern _make_fcontext .globl _make_fcontext .align 8 _make_fcontext: From 0dd187bc0398f4d2101b3c73045bcf5ff9a38bde Mon Sep 17 00:00:00 2001 From: kn1g78 Date: Sat, 4 Jul 2026 21:38:11 +0800 Subject: [PATCH 2/3] Exclude unused arm64 armclang bundle files --- .../scripts/download-bundled/boost-context.sh | 2 + Zend/asm/jump_arm64_aapcs_pe_armclang.S | 141 ------------------ Zend/asm/make_arm64_aapcs_pe_armclang.S | 118 --------------- 3 files changed, 2 insertions(+), 259 deletions(-) delete mode 100644 Zend/asm/jump_arm64_aapcs_pe_armclang.S delete mode 100644 Zend/asm/make_arm64_aapcs_pe_armclang.S diff --git a/.github/scripts/download-bundled/boost-context.sh b/.github/scripts/download-bundled/boost-context.sh index 70c68b3ceb94..02febff73c3f 100755 --- a/.github/scripts/download-bundled/boost-context.sh +++ b/.github/scripts/download-bundled/boost-context.sh @@ -16,12 +16,14 @@ cd Zend/asm # remove unneeded files rm jump_arm_aapcs_pe_armasm.asm +rm jump_arm64_aapcs_pe_armclang.S rm jump_i386_ms_pe_clang_gas.S rm jump_i386_ms_pe_gas.asm rm jump_i386_x86_64_sysv_macho_gas.S rm jump_ppc32_ppc64_sysv_macho_gas.S rm jump_x86_64_ms_pe_clang_gas.S rm make_arm_aapcs_pe_armasm.asm +rm make_arm64_aapcs_pe_armclang.S rm make_i386_ms_pe_clang_gas.S rm make_i386_ms_pe_gas.asm rm make_i386_x86_64_sysv_macho_gas.S diff --git a/Zend/asm/jump_arm64_aapcs_pe_armclang.S b/Zend/asm/jump_arm64_aapcs_pe_armclang.S deleted file mode 100644 index 3a62562fa833..000000000000 --- a/Zend/asm/jump_arm64_aapcs_pe_armclang.S +++ /dev/null @@ -1,141 +0,0 @@ -/* - Copyright Edward Nevill + Oliver Kowalke 2015 - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE_1_0.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -/****************************************************** -* * -* ------------------------------------------------- * -* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * -* ------------------------------------------------- * -* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * -* ------------------------------------------------- * -* | d8 | d9 | d10 | d11 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * -* ------------------------------------------------- * -* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * -* ------------------------------------------------- * -* | d12 | d13 | d14 | d15 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * -* ------------------------------------------------- * -* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * -* ------------------------------------------------- * -* | x19 | x20 | x21 | x22 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * -* ------------------------------------------------- * -* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * -* ------------------------------------------------- * -* | x23 | x24 | x25 | x26 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * -* ------------------------------------------------- * -* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * -* ------------------------------------------------- * -* | x27 | x28 | FP | LR | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * -* ------------------------------------------------- * -* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * -* ------------------------------------------------- * -* | base | limit | dealloc | fiber data| * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 48 | 49 | 50 | 51 | | | * -* ------------------------------------------------- * -* | 0xc0| 0xc4| 0xc8| 0xcc| | | * -* ------------------------------------------------- * -* | PC | align | | | * -* ------------------------------------------------- * -* * -*******************************************************/ - -.file "jump_arm64_aapcs_pe_armclang.S" -.text -.balign 4 - -.def jump_fcontext; .scl 2; .type 32; .endef -.seh_proc jump_fcontext -jump_fcontext: -.seh_endprologue - // prepare stack for GP + FPU - sub sp, sp, #0xd0 - - // save d8 - d15 - stp d8, d9, [sp, #0x00] - stp d10, d11, [sp, #0x10] - stp d12, d13, [sp, #0x20] - stp d14, d15, [sp, #0x30] - - // save x19-x30 - stp x19, x20, [sp, #0x40] - stp x21, x22, [sp, #0x50] - stp x23, x24, [sp, #0x60] - stp x25, x26, [sp, #0x70] - stp x27, x28, [sp, #0x80] - stp x29, x30, [sp, #0x90] - - // save LR as PC - str x30, [sp, #0xc0] - - // save current stack base and limit - ldp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h - stp x5, x6, [sp, #0xa0] - // save current fiber data and deallocation stack - ldr x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h - ldr x6, [x18, #0x20] // TeFiberData at ksarm64.h - stp x5, x6, [sp, #0xb0] - - // store RSP (pointing to context-data) in X0 - mov x4, sp - - // restore RSP (pointing to context-data) from X1 - mov sp, x0 - - // restore stack base and limit - ldp x5, x6, [sp, #0xa0] - stp x5, x6, [x18, #0x08] // TeStackBase and TeStackLimit at ksarm64.h - // restore fiber data and deallocation stack - ldp x5, x6, [sp, #0xb0] - str x5, [x18, #0x1478] // TeDeallocationStack at ksarm64.h - str x6, [x18, #0x20] // TeFiberData at ksarm64.h - - // load d8 - d15 - ldp d8, d9, [sp, #0x00] - ldp d10, d11, [sp, #0x10] - ldp d12, d13, [sp, #0x20] - ldp d14, d15, [sp, #0x30] - - // load x19-x30 - ldp x19, x20, [sp, #0x40] - ldp x21, x22, [sp, #0x50] - ldp x23, x24, [sp, #0x60] - ldp x25, x26, [sp, #0x70] - ldp x27, x28, [sp, #0x80] - ldp x29, x30, [sp, #0x90] - - // return transfer_t from jump - // pass transfer_t as first arg in context function - // X0 == FCTX, X1 == DATA - mov x0, x4 - - // load pc - ldr x4, [sp, #0xc0] - - // restore stack from GP + FPU - add sp, sp, #0xd0 - - ret x4 -.seh_endproc - -.section .drectve -.ascii " -export:\"jump_fcontext\"" diff --git a/Zend/asm/make_arm64_aapcs_pe_armclang.S b/Zend/asm/make_arm64_aapcs_pe_armclang.S deleted file mode 100644 index 761092f2fa6b..000000000000 --- a/Zend/asm/make_arm64_aapcs_pe_armclang.S +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright Edward Nevill + Oliver Kowalke 2015 - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE_1_0.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ - -/****************************************************** -* * -* ------------------------------------------------- * -* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * -* ------------------------------------------------- * -* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * -* ------------------------------------------------- * -* | d8 | d9 | d10 | d11 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * -* ------------------------------------------------- * -* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * -* ------------------------------------------------- * -* | d12 | d13 | d14 | d15 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * -* ------------------------------------------------- * -* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * -* ------------------------------------------------- * -* | x19 | x20 | x21 | x22 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * -* ------------------------------------------------- * -* | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * -* ------------------------------------------------- * -* | x23 | x24 | x25 | x26 | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * -* ------------------------------------------------- * -* | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * -* ------------------------------------------------- * -* | x27 | x28 | FP | LR | * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * -* ------------------------------------------------- * -* | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| * -* ------------------------------------------------- * -* | base | limit | dealloc | fiber data| * -* ------------------------------------------------- * -* ------------------------------------------------- * -* | 48 | 49 | 50 | 51 | | | * -* ------------------------------------------------- * -* | 0xc0| 0xc4| 0xc8| 0xcc| | | * -* ------------------------------------------------- * -* | PC | align | | | * -* ------------------------------------------------- * -* * -*******************************************************/ - -.file "make_arm64_aapcs_pe_armclang.S" -.text -.balign 4 - -.globl make_fcontext -.def make_fcontext; .scl 2; .type 32; .endef -.seh_proc make_fcontext -make_fcontext: -.seh_endprologue - // save stack top address to x3 - mov x3, x0 - - // shift address in x0 (allocated stack) to lower 16 byte boundary - and x0, x0, ~0xF - - // reserve space for context-data on context-stack - sub x0, x0, #0xd0 - - // save top address of context_stack as 'base' - str x3, [x0, #0xa0] - // save bottom address of context-stack as 'limit' and 'deallocation stack' - sub x3, x3, x1 - stp x3, x3, [x0, #0xa8] - // save 0 as 'fiber data' - str xzr, [x0, #0xb8] - - // third arg of make_fcontext() == address of context-function - // store address as x19 for trampoline - str x2, [x0, #0x40] - // store trampoline address as pc - adr x2, trampoline - str x2, [x0, #0xc0] - - // save address of finish as return-address for context-function - // will be entered after context-function returns (LR register) - adr x1, finish - str x1, [x0, #0x98] - - ret x30 // return pointer to context-data (x0) - -trampoline: - stp fp, lr, [sp, #-0x10]! - mov fp, sp - blr x19 - -finish: - // exit code is zero - mov x0, #0 - // exit application - bl _exit - -.seh_endproc - -.def _exit; .scl 2; .type 32; .endef /* standard C library function */ - -.section .drectve -.ascii " -export:\"make_fcontext\"" From 443953928d70bb39af6f514de83bc7ae219f669d Mon Sep 17 00:00:00 2001 From: kn1g78 Date: Sat, 4 Jul 2026 22:32:18 +0800 Subject: [PATCH 3/3] Trigger CI rerun