Discussion:
[Libunwind-devel] libunwind and windows
Vincent Torri
2017-08-12 05:21:21 UTC
Permalink
Hello

i am planning to work a bit on porting libunwind on Windows. Note that
i don't know the internal of libunwind so my questions in that thread
could be naive.

First, I've got libunwind from the official github repo. I compile
with MSYS2 + mingw-w64 (64 bits toolchain). Configure options :
--host=x86_64-w64-mingw32 --disable-static. I did some changes in the
autotools so that configure passes

Running make, the first error is the ucontext.h header file which is
not found. Normal.

After some grep, it appears that you call only getcontext() function.
On Windows, the equivalent of ucontext_t type is the CONTEXT type and
getcontext() equivalent is GetThreadContext() on the current thread.

I can add a typedef for unw_tdep_context_t in libunwind-x86_64.h and
port getcontext() somewhere to change at least as possible the current
code.

question: In which file should I put this getcontext() port ?

Vincent Torri
Dave Watson
2017-08-14 14:15:48 UTC
Permalink
Post by Vincent Torri
Hello
i am planning to work a bit on porting libunwind on Windows. Note that
i don't know the internal of libunwind so my questions in that thread
could be naive.
Are you planning on writing full SEH support? For reference, libgcc's
unwind support for windows is here:

https://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-seh.c

vs. the equivalent dwarf that libunwind currently supports:

https://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-dw2-fde.c
Post by Vincent Torri
Running make, the first error is the ucontext.h header file which is
not found. Normal.
After some grep, it appears that you call only getcontext() function.
On Windows, the equivalent of ucontext_t type is the CONTEXT type and
getcontext() equivalent is GetThreadContext() on the current thread.
As far as I know, we only use the ucontext_t, so that we can be
comatible with the system getcontext() and setcontext(), the system
versions aren't actually called, and most platforms implement their
own, see the getcontext.S, etc.
Post by Vincent Torri
I can add a typedef for unw_tdep_context_t in libunwind-x86_64.h and
port getcontext() somewhere to change at least as possible the current
code.
question: In which file should I put this getcontext() port ?
Os-specific stuff goes in src/os-windows.c or arch & os specific in
src/arch/Gos-windows.c (either of which you'd have to create).

Good luck!
Vincent Torri
2017-08-15 05:14:39 UTC
Permalink
*hello
Post by Dave Watson
Post by Vincent Torri
Hello
i am planning to work a bit on porting libunwind on Windows. Note that
i don't know the internal of libunwind so my questions in that thread
could be naive.
Are you planning on writing full SEH support? For reference, libgcc's
https://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-seh.c
https://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-dw2-fde.c
i am only interested in having dwarf unwind with libunwind
Post by Dave Watson
Post by Vincent Torri
Running make, the first error is the ucontext.h header file which is
not found. Normal.
After some grep, it appears that you call only getcontext() function.
On Windows, the equivalent of ucontext_t type is the CONTEXT type and
getcontext() equivalent is GetThreadContext() on the current thread.
As far as I know, we only use the ucontext_t, so that we can be
comatible with the system getcontext() and setcontext(), the system
versions aren't actually called, and most platforms implement their
own, see the getcontext.S, etc.
is there a reason to not use the system functions ?
Post by Dave Watson
Post by Vincent Torri
I can add a typedef for unw_tdep_context_t in libunwind-x86_64.h and
port getcontext() somewhere to change at least as possible the current
code.
question: In which file should I put this getcontext() port ?
Os-specific stuff goes in src/os-windows.c or arch & os specific in
src/arch/Gos-windows.c (either of which you'd have to create).
if I use the system function, it's only os-specific.

thank you

Vincent Torri
Post by Dave Watson
Good luck!
Dave Watson
2017-08-15 21:20:55 UTC
Permalink
Post by Vincent Torri
Post by Dave Watson
Post by Vincent Torri
Running make, the first error is the ucontext.h header file which is
not found. Normal.
After some grep, it appears that you call only getcontext() function.
On Windows, the equivalent of ucontext_t type is the CONTEXT type and
getcontext() equivalent is GetThreadContext() on the current thread.
As far as I know, we only use the ucontext_t, so that we can be
comatible with the system getcontext() and setcontext(), the system
versions aren't actually called, and most platforms implement their
own, see the getcontext.S, etc.
is there a reason to not use the system functions ?
Usually getcontext() also saves the signal mask, which requires a
syscall, making it much slower than otherwise necessary - most uses of
libunwind don't require resetting the signal mask (at least, not to
the value where getcontext() was called for unwinding).

Loading...