Commit Graph

130 Commits

Author SHA1 Message Date
Jinoh Kang 1886b3d322 ntdll: Fix valid frame address range in ARM/ARM64.
Signed-off-by: Jinoh Kang <jinoh.kang.kr@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-12-09 17:14:59 +01:00
Alexandre Julliard b56a4b3efc ntdll: Implement KiUserCallbackDispatcher().
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-08-17 11:55:39 +02:00
Alexandre Julliard 3a32ea8e91 ntdll: Add support for LdrSystemDllInitBlock.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-07-07 16:33:29 +02:00
Alexandre Julliard a2fce84a8b ntdll: Fix some exception test failures on ARM64.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-06-10 19:54:33 +02:00
Alexandre Julliard 72ace07c6f ntdll: Pass an extra context arguments to APC functions on 64-bit.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-05-25 21:13:00 +02:00
Paul Gofman 66a819ef0c ntdll: Print an ERR for assertion exceptions only.
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-03-03 21:54:44 +01:00
Jacek Caban bdf4b3b400 ntdll: Use NtContinue in RtlRestoreContext.
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-22 20:19:12 +01:00
Rémi Bernon da3be6b0b6 ntdll: Print a warning or an error for other exceptions.
Depending on EH_NONCONTINUABLE.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-08 11:04:17 +01:00
Rémi Bernon 30ecf517e4 ntdll: Print a warning for debug print exceptions.
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-08 11:00:25 +01:00
Rémi Bernon 6edf3d3b09 ntdll: Print a warning for thread rename exceptions.
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2021-02-08 11:00:20 +01:00
Martin Storsjo a1955bfb6e ntdll: Implement a no-op __chkstk for arm64.
Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-12-21 16:55:53 +01:00
Paul Gofman 71a43335ab ntdll: Save unwind information in KiUserApcDispatcher() on x64.
Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-12-17 10:35:46 +01:00
Martin Storsjo 0a6e46e436 ntdll: Fix nested exceptions on arm64.
This mirrors ae07938ba6 (from x86_64)
to arm64.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-10-06 11:57:05 +02:00
Martin Storsjo b09acd526d ntdll: Clear ExceptionFlags on arm64 after running an exception handler.
This applies the beahviour from a69762541a
(on x86_64) to arm64 as well.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-10-06 11:57:03 +02:00
Martin Storsjo df794f3425 ntdll: Unwind to the LR register if no unwind info is available.
Try to keep the behaviour from ea9f47a767 of erroring out if
unwinding ends up out of bounds (with pc==lr, where setting pc
to lr doesn't progress the unwind), but support unwinding from
functions without unwind info.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-10-05 12:33:31 +02:00
Martin Storsjo 2693e6662d ntdll: Implement __C_specific_handler and _local_unwind for arm64.
Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-17 20:54:16 +02:00
Martin Storsjo 3395ee3631 ntdll: Fix more corner cases for arm64 packed info unwinding.
Make sure to restore sp from fp for CR == 3.

Fix unwinding of partial prologues/epilogues - the previous logic
had an off-by-one for the pos/skip handling; fix a few more
corner cases with odd number of saved registers.

Functions with the H flag set (saving x0-x7 on the stack) should
be considred having 4 nops (for the instructions saving the
registers) in the prologue for unwind purposes. When unwinding
through a partial epilogue, the same 4 nops should also be
considered to be there (even though no sane epilogue would restore
the registers there) based on how windows handles partial epilogue
unwinding in those cases.

Uncomment prologue/epilogue cases in an existing test and add
tests for many more cases.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-07 21:08:26 +02:00
Martin Storsjo 36ebdfc6b6 ntdll: Add ARM64 SEH unwind directives for assembly functions in PE builds.
This fixes unwinding through RtlRaiseException and
call_consolidate_callback in PE builds.

Adjust the call_consolidate_callback function to store the whole
context on the stack, and use the seh "context" opcode for
unwinding to that context instead of the parent. Adjust the dwarf
escape codes for reading from the context on the stack.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-09-04 15:47:27 +02:00
Alexandre Julliard 3863b243fe ntdll: Clear the thread stack by hand instead of remapping zero pages.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-27 12:24:05 +02:00
Martin Storsjo a9639dd605 ntdll: Capture vector registers in arm64 RtlCaptureContext.
Since 5b3842451b we set the flag indicating that the context
contained float registers, but we didn't actually populate them yet.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-25 19:31:44 +02:00
Martin Storsjo 99a6ae5b86 ntdll: Fix arm64 jump buffer float restoration.
Fix a typo in copying fields from the jump buffer to the context,
use the right type of long in the struct.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-25 19:31:44 +02:00
Martin Storsjo bc3284f818 ntdll: Implement the arm64 machine frame and context unwind opcodes.
Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-25 13:34:31 +02:00
Martin Storsjo a729af0e9c ntdll: Set handler_data correctly in arm64 RtlVirtualUnwind.
This matches what tests show is done on actual windows, in the
current testcases; in all currently tested cases, handler_data is
reset to NULL when no handler is returned.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-25 13:21:01 +02:00
Martin Storsjo 5b3842451b include: Update ARM64 context flag definitions to match current SDKs.
CONTEXT_FLOATING_POINT should be included in CONTEXT_FULL, and
there's a new flag CONTEXT_ARM64_X18 (not available without
the arch specific prefix) that only is part of CONTEXT_ALL.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-21 15:01:56 +02:00
Alexandre Julliard 4a7cd0f492 ntdll: Call NtContinue() from LdrInitializeThunk() instead of returning.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-20 18:23:44 +02:00
Martin Storsjo 00b4a51fcc ntdll: Remove a stray duplicate instruction.
Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-08-14 22:02:04 +02:00
Alexandre Julliard eee92591bc ntdll/tests: Add thread context test for ARM platforms.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-07-28 14:16:53 +02:00
Alexandre Julliard 8a169390c9 ntdll: Build with msvcrt.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-30 12:25:08 +02:00
Alexandre Julliard c031662fd0 ntdll: Always set the thread context through NtSetContextThread().
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-25 23:08:30 +02:00
Alexandre Julliard 10dbd1edd1 ntdll: Move the libunwind support to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-25 23:08:30 +02:00
Rémi Bernon f5a8ed47a3 ntdll: Leave some space around DbgBreakPoint and DbgUserBreakPoint.
CoD: Black Ops 3 and CoD: WWII modify these (and several others) and
expect to have enough space for a few instructions.

It then verifies later that the patches are still in place, and
terminates if the byte sequence do not match. Having small symbols can
make the patches to overlap and the check to fail.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-24 18:31:09 +02:00
Alexandre Julliard 2333099c52 ntdll: Move signal handlers to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-09 15:25:52 +02:00
Alexandre Julliard 683583faf2 ntdll: Remove support for setting custom signal handlers.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-06 16:45:36 +02:00
Alexandre Julliard 7f28a1c521 ntdll: Use NtContinue() to restore context after an exception.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-06 15:17:07 +02:00
Alexandre Julliard e561ce4b92 ntdll: Move NtRaiseException() implementation to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-06 14:31:00 +02:00
Alexandre Julliard be0eb9c92e ntdll: Move the thread startup code to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-03 20:01:16 +02:00
Alexandre Julliard c96ef78b6d ntdll: Move the virtual memory functions to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-02 17:19:12 +02:00
Alexandre Julliard 7c32b2dd93 ntdll: Move NtGetContextThread() implementation to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-02 14:23:21 +02:00
Alexandre Julliard ac90898f72 ntdll: Move NtSetContextThread() implementation to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-02 14:01:10 +02:00
Alexandre Julliard 3e9f8c87e5 ntdll: Move the threading initialization functions to the Unix library.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-06-01 22:10:28 +02:00
Martin Storsjo e0c8c4c3cd ntdll: Implement RtlRaiseException in assembly to fix continuing from exceptions.
If the handlers returned ExceptionContinueExecution and we restore
the stored context, make sure it's a context that ends up returning
from the RtlRaiseException function.

This matches how it's done on x86_64.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo 763f15ccde ntdll: Fix unwinding through raise_generic_exception.
Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo a8a944c220 ntdll: Keep the previous iteration of NonVolatileRegisters in call_function_handlers.
Some language specific handlers, called by call_handler, can use
the NonVolatileRegisters to restore the context before running
code, and that assumes that NonVolatileRegisters contains the frame
pointer as it was within the function (before unwinding).

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo 6c11d1d745 ntdll: Implement RtlRestoreContext.
Call the consolidate frame callback before resuming. Before
calling the callback, fill in ExceptionInformation[10] with the
equivalent of dispatch.NonVolatileRegisters.

This fixes unwinding of MSVC C++ exceptions in a lot of cases.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo babbf352b6 ntdll: Fix unwinding functions that end with a branch instruction.
This happens with functions that aren't intended to return e.g. like
_Unwind_Resume. In these cases, the return address is outside of the
function (the first instruction in the next function).

Set the flag CONTEXT_UNWOUND_TO_CALL after unwinding to a callsite,
and if this flag is set, look up a RUNTIME_FUNCTION based on
Control.Pc - 4.

This isn't a complete (nor probably entirely correct) implementation
of the flag CONTEXT_UNWOUND_TO_CALL, but it practically seems to
work fine and fixes a large number of unwinding cases.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo 42a5885669 ntdll: Store the real stack pointer in RtlCaptureContext.
In most cases, unwinding will use the frame pointer anyway, so it
doesn't make much of a difference, but for cases where it won't,
capture the actual stack pointer.

(In most cases on arm64, calling the RtlCaptureContext won't cause
anything extra to be pushed on the stack at that point anyway).

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo 8e4f0b2a15 ntdll: Pass a nonnull handler_data in when continuing after a collided unwind.
This matches what was done for RtlUnwindEx in
93ecc54ae5, applying the same change
in call_function_handlers (when called from raise_exception).

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo d6e9795223 ntdll: Fix byte vs register units in unwind_packed_data.
restore_regs and restore_fpregs take offsets in units of registers,
not bytes.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo 8477f61b9f ntdll: Fix handling of the save_lrpair unwind opcode.
The register offset should be multiplied by 2, and the second
register is always Lr.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-28 20:18:32 +02:00
Martin Storsjo 5f14b6357b ntdll: Properly restore x29/x30 for arm64 packed unwind data with local stack.
For the CR == 3 case, x29/x30 should be restored from x29, not from
sp, which may have been decremented further for local stack storage.

This fixes uwinding the stack for C++ exceptions in code generated
by MSVC.

Signed-off-by: Martin Storsjo <martin@martin.st>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
2020-05-18 15:12:49 +02:00