|
| 1 | +From: Peter Kokot <peterkokot@gmail.com> |
| 2 | +Subject: Sync boost.context ASM files with upstream |
| 3 | + |
| 4 | +This fixes build errors on Solaris/illumos systems where system is |
| 5 | +32-bit ('uname -p' gives i386) but compiler supports 64-bit |
| 6 | +architecture. |
| 7 | + |
| 8 | +Fixes are ported from the upstream https://github.com/boostorg/context |
| 9 | +repository. |
| 10 | + |
| 11 | +There are some PHP specific adjustments only in php-src and not upstream |
| 12 | +which should be resolved in the future. |
| 13 | +--- |
| 14 | + Zend/asm/jump_s390x_sysv_elf_gas.S | 24 +++++++++++++---------- |
| 15 | + Zend/asm/jump_sparc64_sysv_elf_gas.S | 12 +++++++----- |
| 16 | + Zend/asm/jump_x86_64_ms_pe_gas.S | 4 ++++ |
| 17 | + Zend/asm/jump_x86_64_sysv_elf_gas.S | 8 -------- |
| 18 | + Zend/asm/make_s390x_sysv_elf_gas.S | 14 +++++++------- |
| 19 | + Zend/asm/make_sparc64_sysv_elf_gas.S | 4 ++-- |
| 20 | + Zend/asm/make_x86_64_ms_pe_gas.S | 4 ++++ |
| 21 | + Zend/asm/make_x86_64_sysv_elf_gas.S | 29 ---------------------------- |
| 22 | + 8 files changed, 38 insertions(+), 61 deletions(-) |
| 23 | + |
| 24 | +diff --git a/Zend/asm/jump_s390x_sysv_elf_gas.S b/Zend/asm/jump_s390x_sysv_elf_gas.S |
| 25 | +index c2a578b2663..fa71467756d 100644 |
| 26 | +--- a/Zend/asm/jump_s390x_sysv_elf_gas.S |
| 27 | ++++ b/Zend/asm/jump_s390x_sysv_elf_gas.S |
| 28 | +@@ -49,11 +49,12 @@ |
| 29 | + .type jump_fcontext, @function |
| 30 | + |
| 31 | + #define ARG_OFFSET 0 |
| 32 | +-#define GR_OFFSET 16 |
| 33 | +-#define FP_OFFSET 96 |
| 34 | +-#define FPC_OFFSET 160 |
| 35 | +-#define PC_OFFSET 168 |
| 36 | +-#define CONTEXT_SIZE 176 |
| 37 | ++#define GR_OFFSET 16 |
| 38 | ++#define R14_OFFSET 88 |
| 39 | ++#define FP_OFFSET 96 |
| 40 | ++#define FPC_OFFSET 160 |
| 41 | ++#define PC_OFFSET 168 |
| 42 | ++#define CONTEXT_SIZE 176 |
| 43 | + |
| 44 | + #define REG_SAVE_AREA_SIZE 160 |
| 45 | + |
| 46 | +@@ -131,11 +132,14 @@ jump_fcontext: |
| 47 | + ltg %r2,GR_OFFSET(%r15) |
| 48 | + jnz use_return_slot |
| 49 | + |
| 50 | +- /* We restore a make_fcontext context. Use the function |
| 51 | +- argument slot in the context we just saved and allocate the |
| 52 | +- register save area for the target function. */ |
| 53 | +- la %r2,ARG_OFFSET(%r1) |
| 54 | +- aghi %r15,-REG_SAVE_AREA_SIZE |
| 55 | ++ /* We're restoring a context created by make_fcontext. |
| 56 | ++ This is going to be the argument of the entry point |
| 57 | ++ of the fiber. We're placing it on top of the ABI |
| 58 | ++ defined register save area of the fiber's own stack. */ |
| 59 | ++ la %r2,REG_SAVE_AREA_SIZE(%r15) |
| 60 | ++ |
| 61 | ++ /* REG_SAVE_AREA_SIZE + sizeof(transfer_t) */ |
| 62 | ++ aghi %r15,-(REG_SAVE_AREA_SIZE+16) |
| 63 | + |
| 64 | + use_return_slot: |
| 65 | + /* Save the two fields in transfer_t. When calling a |
| 66 | +diff --git a/Zend/asm/jump_sparc64_sysv_elf_gas.S b/Zend/asm/jump_sparc64_sysv_elf_gas.S |
| 67 | +index 727687aad80..61101fb1f62 100644 |
| 68 | +--- a/Zend/asm/jump_sparc64_sysv_elf_gas.S |
| 69 | ++++ b/Zend/asm/jump_sparc64_sysv_elf_gas.S |
| 70 | +@@ -6,12 +6,14 @@ |
| 71 | + */ |
| 72 | + |
| 73 | + /* |
| 74 | +- * typedef struct { |
| 75 | +- * void *handle; |
| 76 | +- * zend_fiber_transfer *transfer; |
| 77 | +- * } boost_context_data; |
| 78 | ++ * typedef void* fcontext_t; |
| 79 | + * |
| 80 | +- * boost_context_data jump_fcontext(void *to, zend_fiber_transfer *transfer); |
| 81 | ++ * struct transfer_t { |
| 82 | ++ * fcontext_t fctx; |
| 83 | ++ * void * data; |
| 84 | ++ * }; |
| 85 | ++ * |
| 86 | ++ * transfer_t jump_fcontext(fcontext_t const to, void *vp); |
| 87 | + */ |
| 88 | + #define CC64FSZ 176 |
| 89 | + #define BIAS 2047 |
| 90 | +diff --git a/Zend/asm/jump_x86_64_ms_pe_gas.S b/Zend/asm/jump_x86_64_ms_pe_gas.S |
| 91 | +index 5ebc46f3640..ec4ecfe946d 100644 |
| 92 | +--- a/Zend/asm/jump_x86_64_ms_pe_gas.S |
| 93 | ++++ b/Zend/asm/jump_x86_64_ms_pe_gas.S |
| 94 | +@@ -89,6 +89,7 @@ |
| 95 | + .file "jump_x86_64_ms_pe_gas.asm" |
| 96 | + .text |
| 97 | + .p2align 4,,15 |
| 98 | ++.globl jump_fcontext |
| 99 | + .def jump_fcontext; .scl 2; .type 32; .endef |
| 100 | + .seh_proc jump_fcontext |
| 101 | + jump_fcontext: |
| 102 | +@@ -203,3 +204,6 @@ jump_fcontext: |
| 103 | + /* indirect jump to context */ |
| 104 | + jmp *%r10 |
| 105 | + .seh_endproc |
| 106 | ++ |
| 107 | ++.section .drectve |
| 108 | ++.ascii " -export:\"jump_fcontext\"" |
| 109 | +diff --git a/Zend/asm/jump_x86_64_sysv_elf_gas.S b/Zend/asm/jump_x86_64_sysv_elf_gas.S |
| 110 | +index be264bdc2e2..ff303bfa0e2 100644 |
| 111 | +--- a/Zend/asm/jump_x86_64_sysv_elf_gas.S |
| 112 | ++++ b/Zend/asm/jump_x86_64_sysv_elf_gas.S |
| 113 | +@@ -67,14 +67,6 @@ jump_fcontext: |
| 114 | + movq %rbx, 0x30(%rsp) /* save RBX */ |
| 115 | + movq %rbp, 0x38(%rsp) /* save RBP */ |
| 116 | + |
| 117 | +-#if BOOST_CONTEXT_SHADOW_STACK |
| 118 | +- /* grow the stack to reserve space for shadow stack pointer(SSP) */ |
| 119 | +- leaq -0x8(%rsp), %rsp |
| 120 | +- /* read the current SSP and store it */ |
| 121 | +- rdsspq %rcx |
| 122 | +- movq %rcx, (%rsp) |
| 123 | +-#endif |
| 124 | +- |
| 125 | + #if BOOST_CONTEXT_SHADOW_STACK |
| 126 | + /* grow the stack to reserve space for shadow stack pointer(SSP) */ |
| 127 | + leaq -0x8(%rsp), %rsp |
| 128 | +diff --git a/Zend/asm/make_s390x_sysv_elf_gas.S b/Zend/asm/make_s390x_sysv_elf_gas.S |
| 129 | +index e7e2d5f6e0c..4dd423e2a44 100644 |
| 130 | +--- a/Zend/asm/make_s390x_sysv_elf_gas.S |
| 131 | ++++ b/Zend/asm/make_s390x_sysv_elf_gas.S |
| 132 | +@@ -49,12 +49,12 @@ |
| 133 | + .type make_fcontext, @function |
| 134 | + |
| 135 | + #define ARG_OFFSET 0 |
| 136 | +-#define GR_OFFSET 16 |
| 137 | +-#define R14_OFFSET 88 |
| 138 | +-#define FP_OFFSET 96 |
| 139 | +-#define FPC_OFFSET 160 |
| 140 | +-#define PC_OFFSET 168 |
| 141 | +-#define CONTEXT_SIZE 176 |
| 142 | ++#define GR_OFFSET 16 |
| 143 | ++#define R14_OFFSET 88 |
| 144 | ++#define FP_OFFSET 96 |
| 145 | ++#define FPC_OFFSET 160 |
| 146 | ++#define PC_OFFSET 168 |
| 147 | ++#define CONTEXT_SIZE 176 |
| 148 | + |
| 149 | + /* |
| 150 | + |
| 151 | +@@ -72,7 +72,7 @@ r4 - The address of the context function |
| 152 | + make_fcontext: |
| 153 | + .machine "z10" |
| 154 | + /* Align the stack to an 8 byte boundary. */ |
| 155 | +- nill %r2,0xfff0 |
| 156 | ++ nill %r2,0xfff8 |
| 157 | + |
| 158 | + /* Allocate stack space for the context. */ |
| 159 | + aghi %r2,-CONTEXT_SIZE |
| 160 | +diff --git a/Zend/asm/make_sparc64_sysv_elf_gas.S b/Zend/asm/make_sparc64_sysv_elf_gas.S |
| 161 | +index 52ff70b996b..3e7ee809c91 100644 |
| 162 | +--- a/Zend/asm/make_sparc64_sysv_elf_gas.S |
| 163 | ++++ b/Zend/asm/make_sparc64_sysv_elf_gas.S |
| 164 | +@@ -6,7 +6,7 @@ |
| 165 | + */ |
| 166 | + |
| 167 | + /* |
| 168 | +- * void *make_fcontext(void *sp, size_t size, void (*fn)(boost_context_data)); |
| 169 | ++ * fcontext_t *make_fcontext(void *sp, size_t size, void (*fn)(transfer_t)); |
| 170 | + */ |
| 171 | + #define CC64FSZ 176 |
| 172 | + #define BIAS 2047 |
| 173 | +@@ -56,7 +56,7 @@ make_fcontext: |
| 174 | + trampoline: |
| 175 | + ldx [%sp + BIAS + I7], %l0 |
| 176 | + |
| 177 | +- # no need to setup boost_context_data, already in %o0 and %o1 |
| 178 | ++ # no need to setup transfer_t, already in %o0 and %o1 |
| 179 | + jmpl %l0, %o7 |
| 180 | + nop |
| 181 | + |
| 182 | +diff --git a/Zend/asm/make_x86_64_ms_pe_gas.S b/Zend/asm/make_x86_64_ms_pe_gas.S |
| 183 | +index 66a9bb39535..958a2a7b6d0 100644 |
| 184 | +--- a/Zend/asm/make_x86_64_ms_pe_gas.S |
| 185 | ++++ b/Zend/asm/make_x86_64_ms_pe_gas.S |
| 186 | +@@ -89,6 +89,7 @@ |
| 187 | + .file "make_x86_64_ms_pe_gas.asm" |
| 188 | + .text |
| 189 | + .p2align 4,,15 |
| 190 | ++.globl make_fcontext |
| 191 | + .def make_fcontext; .scl 2; .type 32; .endef |
| 192 | + .seh_proc make_fcontext |
| 193 | + make_fcontext: |
| 194 | +@@ -168,3 +169,6 @@ finish: |
| 195 | + .seh_endproc |
| 196 | + |
| 197 | + .def _exit; .scl 2; .type 32; .endef /* standard C library function */ |
| 198 | ++ |
| 199 | ++.section .drectve |
| 200 | ++.ascii " -export:\"make_fcontext\"" |
| 201 | +diff --git a/Zend/asm/make_x86_64_sysv_elf_gas.S b/Zend/asm/make_x86_64_sysv_elf_gas.S |
| 202 | +index b0d0c0341ef..df9472433cf 100644 |
| 203 | +--- a/Zend/asm/make_x86_64_sysv_elf_gas.S |
| 204 | ++++ b/Zend/asm/make_x86_64_sysv_elf_gas.S |
| 205 | +@@ -91,35 +91,6 @@ make_fcontext: |
| 206 | + /* will be entered after context-function returns */ |
| 207 | + movq %rcx, 0x38(%rax) |
| 208 | + |
| 209 | +-#if BOOST_CONTEXT_SHADOW_STACK |
| 210 | +- /* Populate the shadow stack and normal stack */ |
| 211 | +- /* get original SSP */ |
| 212 | +- rdsspq %r8 |
| 213 | +- /* restore new shadow stack */ |
| 214 | +- rstorssp -0x8(%r9) |
| 215 | +- /* save the restore token on the original shadow stack */ |
| 216 | +- saveprevssp |
| 217 | +- /* push the address of "jmp trampoline" to the new shadow stack */ |
| 218 | +- /* as well as the stack */ |
| 219 | +- call 1f |
| 220 | +- jmp trampoline |
| 221 | +-1: |
| 222 | +- /* save address of "jmp trampoline" as return-address */ |
| 223 | +- /* for context-function */ |
| 224 | +- pop 0x38(%rax) |
| 225 | +- /* Get the new SSP. */ |
| 226 | +- rdsspq %r9 |
| 227 | +- /* restore original shadow stack */ |
| 228 | +- rstorssp -0x8(%r8) |
| 229 | +- /* save the restore token on the new shadow stack. */ |
| 230 | +- saveprevssp |
| 231 | +- |
| 232 | +- /* reserve space for the new SSP */ |
| 233 | +- leaq -0x8(%rax), %rax |
| 234 | +- /* save the new SSP to this fcontext */ |
| 235 | +- movq %r9, (%rax) |
| 236 | +-#endif |
| 237 | +- |
| 238 | + #if BOOST_CONTEXT_SHADOW_STACK |
| 239 | + /* Populate the shadow stack */ |
| 240 | + |
0 commit comments