2
0
mirror of https://github.com/boostorg/context.git synced 2026-01-24 17:52:41 +00:00
Commit Graph

298 Commits

Author SHA1 Message Date
Claudio Jeker
17945a28a2 Implement the fcontext asm for sparc64
This implements the required asm functions for sparc64_sysv_elf and
was tested on an OpenBSD/sparc64 system.

Jump_fcontext uses an extra C call frame to store the frame-pointer and
return address. Because of this the code is simply a save (to new reg
window), then forcing a window flush and finally switch stack and restore
from there.

Since jump_fcontext() uses a register window and stack frame, make_fcontext()
reserves two call frames on the stack (one for jump_fcontext() and the other
for the callback function).

OpenBSD/sparc64 uses stackghost which prevents userland from overriding the
return-address on the stack. Because of this make_fcontext() uses an extra
trampoline to implement the _exit(0) call if the callback returns.

All tests pass with this on OpenBSD/sparc64 (also the tests for fiber,
coroutine and coroutine2).
2024-02-13 11:16:42 +01:00
David Carlier
a2dd396dd9 fix solaris/illumos build on make/jump assembly directives.
on those platforms, albeit being 64 bits, they produce 32 bits binaries by default.
2024-02-04 08:07:39 +00:00
David Seifert
922e033fa1 Fix x32 build on x86-64 2024-01-23 13:23:29 +01:00
Mohammad Bahoosh
dcf037830b Suppressing -Wsign-conversion warnings 2023-10-28 21:02:03 -08:00
Oliver Kowalke
033ea19511 PPC64 file was accidentally commented out 2023-10-01 16:49:31 +02:00
ltrk2
3bedb2d779 Improve ABI conformance of s390x fcontext 2023-05-15 12:47:56 -07:00
ltrk2
e4e3014f3e Store entry point arguments in fibre's own context (s390x) 2023-05-11 12:14:47 -07:00
Niels Dossche
0eb4263705 Make sure the i386 sysv stack is aligned
The previous fix had a typo in which the wrong offset was used which
meant that the alignment still wasn't correct. Fix this properly now.
2023-01-27 23:36:15 +01:00
Niels Dossche
e286649f08 Make sure the i386 sysv stack is aligned
SysV ABI requires a stack alignment of 16 bytes. Currently, for i386
with SysV ABI, the trampoline function is entered with an unaligned
stack. This causes problems for the context-function that is jumped to
as its stack is also unaligned. This causes a crash for our use-case
because the context function contains an SSE instruction which reads
from the stack. The SSE instruction requires the correct alignment.
Fix it by changing the 0x2c offset to 0x30, such that the stack remains
aligned.
2023-01-25 22:07:30 +01:00
Evan Miller
070d03fc7e Fixes for Darwin PPC32
For make_fcontext, use the diff provided here:

https://github.com/boostorg/context/issues/211#issuecomment-1328154669

For ontop_context, adapt the Linux PPC32 fixes from here:

df8fb6b528

Co-authored-by: George Koehler <kernigh@gmail.com>
2022-12-27 10:47:41 -05:00
Sergey Fedorov
a3b0224b0c Darwin make_ppc32: fix addi in l1 2022-10-06 13:01:18 +08:00
PeterYang12
3484575878 Add shadow stack support for fcontext
Shadow stack is part of Intel's Control-Flow Enforcement Technology.

    Whenever a function is called, the return address is pushed onto both
    the regular stack and the shadow stack. When that function returns, the
    return addresses are popped off both stacks and compared; if they fail
    to match, #CP raised.

    Backport this commit from https://github.com/php/php-src/pull/9283
    With this commit, we create shadow stack with syscall map_shadow_stack
    (no.451) for each fiber context and switch the shadow stack accordingly
    during fcontext switch.

Signed-off-by: PeterYang12 <yuhan.yang@intel.com>
Signed-off-by: chen-hu-97 <hu1.chen@intel.com>
2022-09-29 22:58:22 -07:00
Oliver Kowalke
97a0054999 Merge pull request #205 from apolukhin/antoshkka/stack-protector
Support for stack protection
2022-09-18 16:25:02 +02:00
Antony Polukhin
f96d65bc37 fix again 2022-09-18 11:19:22 +03:00
Antony Polukhin
a6e3302f91 fix 2022-09-18 11:02:23 +03:00
Antony Polukhin
2f0b5034b7 Support for stack protection 2022-09-17 18:38:12 +03:00
Sergey Fedorov
5f7e1f216c powerpc-darwin: does not use TOC on ppc64 2022-09-06 04:44:16 +07:00
Sergey Fedorov
1cdfb35343 powerpc-darwin: fix broken code in make_ppc* assembler 2022-09-06 02:54:06 +07:00
Sergey Fedorov
5f2c355042 powerpc-darwin: fix assembler comment character 2022-09-06 02:47:32 +07:00
dixyes
abf8e04e23 Spport Windows arm64 cpp exception
Windows C++ exception unwinding needs TEB(TIB) stack info matching real
stack.
2022-06-26 09:53:11 +08:00
dixyes
697299ea55 Add windows arm64 fcontext support 2022-06-26 09:51:30 +08:00
PeterYang12
b62a991ee6 Add support for Indirect Branch Tracking (IBT)
Indirect Branch Tracking(IBT) is part of Intel's Control-Flow
Enforcement Technology(CET). IBT is hardware based, forward edge
Control-Flow-Integrity mechanism where any indirect CALL/JMP must
target an ENDBR instruction or suffer #CP.

This commit inserts endbr64 instruction in assembly to support IBT.
2022-05-16 00:15:57 -07:00
Zhang Na
e1001c479e Add support for loongarch64 2022-02-15 17:28:33 +08:00
Clément Chigot
f7272bce6c asm: adjust XCOFF files for AIX assembler
AIX assembler is a bit more strict than GNU assembler. Thus, adjust
the XCOFF asm files to be able to accept both assembler.

For PPC64 jump and make files, most of the work have already been
made recently, only the functions' header needs to be updated.
For PPC64 ontop and PPC32 files, the algorithms where also wrong.
So the whole files have been reworked.

The PPC32 stack layout is based on AIX documentation:
https://www.ibm.com/docs/en/aix/7.2?topic=overview-runtime-process-stack
For PPC64, as it seems to work fine and is already being used in php,
I've kept the current layout based on PPC64 Linux version.

Tested with boost/context, boost/fiber and boost/coroutine2.
Note that the test_sscanf is still failing in ppc32 because of
float precision. (3.13999 is returned instead of 3.14).
2021-11-03 10:54:05 +01:00
Antony Polukhin
732ec07981 restore work with TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] on arm aapcs macho 2021-09-24 11:35:23 +03:00
Calvin Buckley
b701608477 Fix 64-bit XCOFF assembly
It should almost exactly match the ELFv1 ABI code now, except with
IBM assembler syntax.

Tested with PHP fibres. Fixes #180
2021-08-11 15:01:03 -03:00
Nikita Kniazev
8425e830ea Cease dependence on Thread
On C++11 static local variables are initialized in thread-safe manner, but even on C++03 it should not be a problem because in our case variables are of trivial types, which means double initialization is not an issue, and they are initialized with the same value in every thread.
2021-06-12 22:23:08 +03:00
Sean Baxter
08fb973e09 Update stack_traits.cpp 2021-06-04 22:27:43 -04:00
Oliver Kowalke
7c451db14a remove execution_context.hpp from contiunation.cpp 2021-06-01 17:42:50 +02:00
David CARLIER
739ee59db2 make_fcontext darwin arm64 removes workaround LLVM IR supports label to adr ins since couple of years already 2021-04-01 10:41:42 +01:00
Oliver Kowalke
0416c11f00 Merge pull request #160 from dixyes/combined-add-arms
Add arm and arm64 into combined asm codes
2021-03-01 07:39:05 +01:00
dixyes
1c763c9796 Add arm and arm64 into combined asm codes
Apple silicon M1 uses arm64 architecture, this commit will add arm and
arm64 architecture into combined asm code in order to support newer
apple's machine in combined asm codes.
2021-03-01 09:27:44 +08:00
Rosen Penev
275bf84228 fix softfloat support for MIPS64 ASM
Added define also found in the MIPS32 ASM files.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-02-12 18:00:04 -08:00
Eric Astor
e47fc8b730 Add variants for clang targeting Windows without MASM support
This is not an officially-supported Boost toolset, but is consumed by at least one user.
2020-08-24 11:55:14 -04:00
Julien Schueller
d52ce8ca89 Revert "Fix exports for 32-bit GNU assembler files targeting Windows."
This reverts 85783e8, as the wrong linker was used

Closes #136
2020-08-20 12:55:24 +02:00
Harald van Dijk
5ace4ff3a5 Fixes for x32 ABI.
In the x32 ABI, pointers take up 4 bytes, so a structure containing two
pointers is passed and returned in a single 8-byte register.
2020-06-28 22:11:44 +01:00
Andreas Krebbel
e0ba57928d IBM Z: Fix fcontext routines 2020-02-21 08:47:46 +01:00
YunQiang Su
e115983fdf mips64/n64: .align 3
The right align for mips64/n64 is 3 instead of 2.
2019-12-18 03:48:43 -08:00
Andreas Schwab
e86c66714c Fix non-PIC in RISC-V assembly
Since this ends up in a shared library we should use a PLT call.  Also,
the finish label is local, so we can use lla instead of la.
2019-12-06 22:49:43 +01:00
Eric Astor
bebf903239 Mark 32-bit GNU assembly files targeting Windows as /safeseh linking compatible.
We set the LSB of the magic symbol @feat.00 to 1.

This is used to communicate from the compiler to the linker, and specifically to express that the object file has opted into "safeseh"; any SEH handlers used in this file must be listed in the .sxdata section.

Since we don't have any SEH handlers in these files, this is trivially satisfied.

Reference: the PE-COFF specification, https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#the-sxdata-section
2019-11-27 22:30:46 -05:00
Eric Astor
85783e8cbb Fix exports for 32-bit GNU assembler files targeting Windows.
The incorrect exports can cause linker issues (at least when using LLVM's lld-link) claiming that these primitives are not available.
2019-11-22 11:08:41 -05:00
George Koehler
df8fb6b528 Fix ppc32 on Linux musl, NetBSD, OpenBSD; fixes #120
This fixes fcontext on my PowerBook G4 running Void Linux
ppc-musl-20190901, NetBSD/macppc 8.1, or OpenBSD/macppc 6.6-current,
all with g++.  These systems use fcontext for *ppc32_sysv_elf*
(PowerPC 32-bit System V ELF).  The assembly code was wrong for BSD
and crashing on Linux musl.

Linux returns a transfer_t in memory (through a hidden pointer in R3),
but other systems (at least NetBSD and OpenBSD) return a transfer_t in
registers R3:R4.  jump_fcontext() and ontop_fcontext() were always
using the hidden pointer.  Add checks for `#ifdef__linux__`; start
using R3:R4 on other systems.

make_fcontext() was calling _exit(0) through the insecure BSS PLT.
Set R30 to use the secure PLT.  This prevents a crash when musl's
ld.so loads the executable; musl seems to require the secure PLT.

Fix ontop_fcontext() to restore the hidden pointer on Linux.  It was
passing the wrong context's hidden pointer to the ontop-function fn(),
so fn() returned a transfer_t to the wrong stack.  When fn() was
context_exit() in <boost/context/continuation_fcontext.hpp>, it freed
the old stack, then returned `transfer_t{ nullptr, nullptr }` to free
memory.  This crashed on Linux musl.

Now that ontop_fcontext() restores the hidden pointer, it must stop
abusing the same pointer to pass a transfer_t argument to fn().  Add a
new ontop_fcontext_tail() in C++, which takes arguments in registers
and allocates a transfer_t.  The code is in C++ so it can free the
transfer_t argument if fn() throws a C++ exception.

Rearrange the context frame to shrink it from 244 to 240 bytes.  This
fixes the stack alignment: the ABI requires R1 % 16 == 0, and
make_fcontext() respects this, but jump_fcontext() was adding 244 to
R1, so the new context ran with a misaligned stack (244 % 16 == 4).

Remove R13 from the context frame, so new contexts stop loading R13
with garbage.  The ABI uses R13 to point to the executable's small
data, so R13 should have the same value in every context.

Add the backchain to the context frame; make room by moving LR to the
caller's frame.  Order CR, R14 to R31, F14 to F31 at the frame's end,
as is typical for this ABI.  Provide 8-byte alignment for FPSCR and
F14 to F31, to avoid a misalignment penalty.
2019-10-19 14:06:24 -04:00
Neale Ferguson
b90917eaed Optimize s390x instructions 2019-09-20 13:23:19 -04:00
Naveenaidu
adecfdc88c S390x: Add Support for s390x arch 2019-09-06 20:08:10 +05:30
Oliver Kowalke
0c754f90c5 execution_context removed 2019-08-29 13:42:03 +02:00
Oliver Kowalke
9c772a7830 Revert "S390x Implementation: WIP" 2019-08-03 08:33:17 +02:00
Naveenaidu
4d0cd2a6ce jump_s390x_sys_elf: Add jump_context for s390x 2019-07-31 18:51:49 +05:30
Naveenaidu
99a29956f3 s390x_make_context: Fix stack frame 2019-07-31 18:50:38 +05:30
Naveenaidu
81e26a1618 make_context: Add s390x arch 2019-07-22 22:53:43 +05:30
Shawn Anastasio
2354eca9b7 Fix ABI violation on ppc64 ELFv2, fixes #72
The existing ontop_fcontext implementation for ppc64 ELFv2
violates the ABI by not storing the callback entry address
in %r12 before branching. This results in crashes on this
platform.

This commit addresses this and allows the context library
to function as expected on ppc64 platforms using the ELFv2 ABI.
2019-05-03 20:18:11 -05:00