Skip to content

build: bring windows back#867

Merged
pkova merged 34 commits intojb/palloc-migratefrom
pkova/hehe
Sep 16, 2025
Merged

build: bring windows back#867
pkova merged 34 commits intojb/palloc-migratefrom
pkova/hehe

Conversation

@pkova
Copy link
Copy Markdown
Collaborator

@pkova pkova commented Sep 1, 2025

Based on the work in urbit/urbit#4675 with some upgrades.

The structured exception handling code in the original is crazy. It was originally done because libsigsegv installs a top level structured exception handler which means that every time we fault we end up unwinding a potentially very deep stack. We (and most likely libsigsegv too) can instead install a vectored exception handler that functions exactly as we want without unwinding the stack.

We still have cross-compilation from any of our supported targets to any of our supported targets.

Current known limitations:

Demand paging does not work.

The spin hint does not work.

JSON tracing does not work.

The jump buffer in the road struct needs to be 16 byte aligned on windows, we'll fix when merging @joemfb:s allocator work.

There are some strange padding zeroes at the end of south.bin breaking checkpoint version negotiation, fix same as above.

@pkova pkova requested a review from a team as a code owner September 1, 2025 14:05
@joemfb
Copy link
Copy Markdown
Collaborator

joemfb commented Sep 10, 2025

@pkova pkova changed the base branch from next/kelvin/409 to jb/palloc-migrate September 10, 2025 16:03
@pkova pkova merged commit ca97efd into jb/palloc-migrate Sep 16, 2025
2 checks passed
@pkova pkova deleted the pkova/hehe branch September 16, 2025 10:41
pkova added a commit that referenced this pull request Nov 12, 2025
A few days ago I decided to fix the ctrl-c interrupts that had been
broken on windows since I brought it back in #867. How hard could it be?

It turns out @locpyl-tidnyd was really cooking with gas here. The
fundamental mismatch between unix and windows here is the following:
ctrl-c on unix delivers a synchronous SIGINT signal whereas on windows
it starts a new thread to handle the interrupt. A new thread! We can't
deal with that!


https://github.com/urbit/vere/blob/25356bc2ba022492715741b444b61f2452510021/pkg/noun/platform/windows/rsignal.c#L52-L63

Ok looks like we suspend the main thread that's cool, what's `oldfn`?


https://github.com/urbit/vere/blob/25356bc2ba022492715741b444b61f2452510021/pkg/noun/platform/windows/rsignal.c#L117-L167

We replace the _instruction pointer_ on the _main thread_ with our
longjmp and pass it the first argument in rcx as per the windows x64
calling convention. If we are in the middle of an exception handler
already we unwind the stack and hijack the CONTEXT structure (on the
stack) that windows uses to restore execution state after the handler
has run.

It turns out we have to use `__builtin_longjmp` when we do this crazy
shit because the native longjmp on windows also tries to unwind the
stack and gets really confused.

All in all I hope that this writeup will be useful to the next poor soul
who looks at this stuff.
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.

2 participants