Skip to content

Prepare for AMD64_NT stackwalk. - #1259

Closed
jaykrell wants to merge 1 commit into
modula3:masterfrom
jaykrell:dev/jaykrell/less-try
Closed

jaykrell wants to merge 1 commit into
modula3:masterfrom
jaykrell:dev/jaykrell/less-try

Conversation

@jaykrell

@jaykrell jaykrell commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

There's really nothing to add stackwalk support.
It is all in the C++ runtime.
This PR does some things I thought would help, but are mostly not needed.

  • Add some m3makefile snippets for stackwalk, not yet enabled.
  • Add commented out stackwalk support, CurrentFrame, PreviousFrame, Unwind.
    It turns out, this is only for printing stackwalk. Actually doing this in Modula3 runtime would break language interup -- we'd skip C finally blocks and C++ destructors, unless we cloned all of RtlDispatchException, which would be bad.

@jaykrell
jaykrell marked this pull request as ready for review November 20, 2026 11:40
@jaykrell
jaykrell requested review from demoitem and hosking and a balanced review from Copilot November 20, 2026 11:40
@jaykrell
jaykrell force-pushed the dev/jaykrell/less-try branch from d6a31c4 to 4d4d157 Compare November 20, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Win64 fault redirection lacks a valid call frame, the CONTEXT layout is 96 bytes short, and the stack-walker build targets ARM64 instead of AMD64.

3 open issues
What changed in this PR

Prepares the Modula-3 Windows x64 runtime for stack-walk work while leaving stack walking disabled and relying on the C++ runtime for exception unwinding.

Changes:

  • Enables C++ exception handling for MSVC-compiled sources.
  • Adds and selects an AMD64-specific Windows thread-context definition.
  • Introduces stack-walker build scaffolding, runtime stubs, and a C++ exception helper.
File Description
m3-sys/​cminstall/​src/​config/​NT.common Adds the -EHs compiler option.
m3-sys/​cminstall/​src/​config/​AMD64_NT Adds a commented stack-walker opt-in.
m3-libs/​m3core/​src/​thread/​WIN32/​m3makefile Skips the generic thread context on AMD64.
m3-libs/​m3core/​src/​thread/​m3makefile Includes AMD64-specific thread definitions.
m3-libs/​m3core/​src/​thread/​AMD64_NT/​ThreadContext.i3 Defines the Windows x64 context record.
m3-libs/​m3core/​src/​thread/​AMD64_NT/​m3makefile Registers the AMD64 thread-context interface.
m3-libs/​m3core/​src/​runtime/​m3makefile Updates walker targets and Windows library linkage.
m3-libs/​m3core/​src/​runtime/​ex_stack/​RTExStack.m3 Comments out unfinished exception-scope checks.
m3-libs/​m3core/​src/​runtime/​AMD64_NT/​RTStackC.c Adds trace stubs and a C++ exception-throwing helper.
m3-libs/​m3core/​src/​runtime/​AMD64_NT/​RTMachine.i3 Defines AMD64 frame information and walker capability.
m3-libs/​m3core/​src/​runtime/​AMD64_NT/​m3makefile Declares AMD64 runtime build inputs.

Review effort: Balanced

Comment thread m3-libs/m3core/src/runtime/m3makefile Resolved

(* Program counter. *)
(* Hack for interop for 32bit RTSignal.m3. *)
Eip(*Rip*): INTEGER;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot steal my source code . . .

@jaykrell
jaykrell force-pushed the dev/jaykrell/less-try branch 8 times, most recently from 455b667 to 97edcd8 Compare November 20, 2026 14:04
@jaykrell
jaykrell force-pushed the dev/jaykrell/less-try branch from 97edcd8 to 3c4dff3 Compare November 20, 2026 14:08
@VictorMiasnikov

Copy link
Copy Markdown
Contributor

MinGw

new source -> compiling RTSignalC.c
../src\runtime\WIN32/RTSignalC.c: In function 'int RTSignalC_Raise(size_t, size_t, size_t, PCONTEXT)':
../src\runtime\WIN32/RTSignalC.c:34:3: error: '__try' was not declared in this scope
   34 |   __try  {
      |   ^~~~~
../src\runtime\WIN32/RTSignalC.c:36:5: error: '__except' was not declared in this scope
   36 |   } __except(1) {
      |     ^~~~~~~~
"D:/a/cm3/install/cm3/bin/config/AMD64_MINGW", line 34: quake runtime error: exit 1: x86_64-w64-mingw32-g++ -g -xc++ -c -I../src\unix/Common -I../src -I../src\Csupport -I../src\runtime\common -I../src\runtime\WIN32 -I../src\runtime\ex_frame -I../src\thread\Common -I../src\thread\WIN32 -I../src\win32 -I../src\unix\Common -I../src\C\Common -I../src\time\WIN32 ../src\runtime\WIN32/RTSignalC.c -o RTSignalC.obj

--procedure--  -line-  -file---
exec               --  <builtin>
compile_c          34  D:/a/cm3/install/cm3/bin/config/AMD64_MINGW
Library            --  <builtin>
include_dir        79  D:\a\cm3\cm3\m3-libs\m3core\src\m3makefile
                    8  D:\a\cm3\cm3\m3-libs\m3core\AMD64_MINGW\m3make.args


Fatal Error: procedure "compile_c" defined in "D:/a/cm3/install/cm3/bin\cm3.cfg" failed.

@VictorMiasnikov

Copy link
Copy Markdown
Contributor
{BF59BB6C-F964-4764-A981-FAD326180D90}

@VictorMiasnikov

Copy link
Copy Markdown
Contributor

Win64 fault redirection lacks a valid call frame, the CONTEXT layout is 96 bytes short,
and the stack-walker build targets ARM64 instead of AMD64.

In case ignoring Pool Request -- yes

@VictorMiasnikov

Copy link
Copy Markdown
Contributor

And what You planed about worked patch from #1190 ?

@hosking

hosking commented Nov 22, 2026

Copy link
Copy Markdown
Member

Closing this as superseded by #1271, which made ex_stack target-independent:

  • RTStack__ThrowM3Exc and _M3Exc now live in the shared ex_stack/RTExStackC.c, so an AMD64_NT/RTStackC.c copy would define them twice.
  • Targets without a libunwind walker get the CurFrame/PrevFrame/ProcName stubs from no_walker/. Those also return pc = NIL from GetThreadFrame rather than calling abort().
  • UNWIND is linked only for targets listed in HAS_STACK_WALKER, so the WIN32 guard isn't needed.

On master, turning on ex_stack for AMD64_NT only takes M3_USE_STACK_WALKER = TRUE in its config, which matches what you found in #1266. AMD64_NT CI only builds and doesn't run m3tests, so that switch is worth a test run before it lands.

@hosking hosking closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants