Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack MDEI struct to fix issue #4407 #4474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tf2spi
Copy link
Contributor

@tf2spi tf2spi commented Nov 10, 2024

MINIDUMP_EXCEPTION_INFORMATION is expected to be packed (which is, of course, not documented by MSDN) so this packs it so that it can be used in MinidumpWriteDump.

@tf2spi
Copy link
Contributor Author

tf2spi commented Nov 10, 2024

Additional Note: I haven't looked at the AARCH64 headers for Windows yet so I don't know if that specific architecture also expects the struct to be packed or not.

@gingerBill
Copy link
Member

So it's technically not #packed but you need #max_field_align(4).

@@ -15,7 +15,7 @@ MINIDUMP_DIRECTORY :: struct {
Location: MINIDUMP_LOCATION_DESCRIPTOR,
}

MINIDUMP_EXCEPTION_INFORMATION :: struct {
MINIDUMP_EXCEPTION_INFORMATION :: struct #packed {
Copy link
Member

Choose a reason for hiding this comment

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

struct #max_field_align(4)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, cool! I didn't know that was a directive!

This seems good but I don't know if I'm applying the directive right? I'm getting alignment errors after using it.

Below is the disassembly from Visual Studio

        mdei: MINIDUMP_EXCEPTION_INFORMATION
00007FF74395AD64  movaps      xmmword ptr [rsp+1E0h],xmm0  
        mdei.ThreadId = GetCurrentThreadId()
00007FF74395AD6C  call        GetCurrentThreadId (07FF74395B412h)  
00007FF74395AD71  mov         ecx,eax  
00007FF74395AD73  mov         rax,qword ptr [rsp+0B8h]  
00007FF74395AD7B  mov         dword ptr [rsp+1E0h],ecx  
        mdei.ExceptionPointers = pException    // pass in 'nil' would make MiniDumpWriteDump() return TRUE
00007FF74395AD82  mov         qword ptr [rsp+1E8h],rax  
        mdei.ClientPointers = FALSE
00007FF74395AD8A  mov         dword ptr [rsp+1F0h],0  

Below is the LLVM IR

  %48 = getelementptr inbounds %sys_windows.MINIDUMP_EXCEPTION_INFORMATION, ptr %mdei, i32 0, i32 0, !dbg !341
  %49 = call x86_stdcallcc i32 @GetCurrentThreadId(), !dbg !341
  store i32 %49, ptr %48, align 4, !dbg !341
  %50 = getelementptr inbounds %sys_windows.MINIDUMP_EXCEPTION_INFORMATION, ptr %mdei, i32 0, i32 1, !dbg !342
  store ptr %0, ptr %50, align 8, !dbg !342
  %51 = getelementptr inbounds %sys_windows.MINIDUMP_EXCEPTION_INFORMATION, ptr %mdei, i32 0, i32 2, !dbg !343
  store i32 0, ptr %51, align 4, !dbg !343

This is the diff

diff --git a/core/sys/windows/dbghelp.odin b/core/sys/windows/dbghelp.odin
index 4bbad258d..e32b4c874 100644
--- a/core/sys/windows/dbghelp.odin
+++ b/core/sys/windows/dbghelp.odin
@@ -15,7 +15,7 @@ MINIDUMP_DIRECTORY :: struct {
        Location:   MINIDUMP_LOCATION_DESCRIPTOR,
 }

-MINIDUMP_EXCEPTION_INFORMATION :: struct #packed {
+MINIDUMP_EXCEPTION_INFORMATION :: struct #max_field_align(4) {
        ThreadId:          DWORD,
        ExceptionPointers: ^EXCEPTION_POINTERS,
        ClientPointers:    BOOL,

And here's the version to show I did update the compiler.

..\odin.exe version dev-2024-11:c4b273958

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other weirdness is also happening. The debug info says that it's packed.
image

and Odin code is crashing when using fmt.printf on the mdei
image

fmt.printf crashing is at least odd and I'll investigate this further

@tf2spi
Copy link
Contributor Author

tf2spi commented Dec 22, 2024

Now relies on #4611

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