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

Upstream findings from investigation of windows fault handler #7146

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MarkusPettersson98
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 commented Nov 7, 2024

This PR adds some fixes and comments that was found during my investigation of our exception handler on Windows that spawned from #7137. It contributes the following:

  • Don't redefine Windows API function signatures, import them from windows_sys
  • Get rid of unsafe where safety comments were missing and there were safe alternatives
  • Add SAFETY comments to unsafe code where there exists documentation around what properties that need to be upheld. Add appropriate checks of properties if they were missing

This change is Reviewable

Copy link

linear bot commented Nov 7, 2024

@MarkusPettersson98 MarkusPettersson98 changed the title Upstream findigns from investigate windows fault handler Upstream findings from investigation of windows fault handler Nov 7, 2024
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98)


mullvad-daemon/src/exception_logging/win.rs line 47 at r1 (raw file):

fn generate_minidump(
    dump_file: &Path,
    exception_pointers: *mut EXCEPTION_POINTERS,

Why did this change from immutable to mutable? According to the docs (https://learn.microsoft.com/en-us/windows/win32/api/minidumpapiset/nf-minidumpapiset-minidumpwritedump), this parameter is in, so I suspect that it is in fact fine to pass in an immutable ref, regardless of what the type says 🤷 .


mullvad-daemon/src/exception_logging/win.rs line 139 at r1 (raw file):

    static REENTRANCY_GUARD: AtomicBool = AtomicBool::new(false);
    if REENTRANCY_GUARD.swap(true, Ordering::SeqCst) {
        // `process::abort` is signal-safe, unlike `process::exit`.

This comment ("signal-safe") is probably not relevant here?

Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dlon)


mullvad-daemon/src/exception_logging/win.rs line 47 at r1 (raw file):

Previously, dlon (David Lönnhager) wrote…

Why did this change from immutable to mutable? According to the docs (https://learn.microsoft.com/en-us/windows/win32/api/minidumpapiset/nf-minidumpapiset-minidumpwritedump), this parameter is in, so I suspect that it is in fact fine to pass in an immutable ref, regardless of what the type says 🤷 .

Because MINIDUMP_EXCEPTION_INFORMATION expects a mutable pointer, so I reflected this in the signature of generate_minidump. What do you think is appropriate here?


mullvad-daemon/src/exception_logging/win.rs line 139 at r1 (raw file):

Previously, dlon (David Lönnhager) wrote…

This comment ("signal-safe") is probably not relevant here?

Probably not. But should we return EXCEPTION_CONTINUE_SEARCH instead of aborting maybe?

Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @MarkusPettersson98)


mullvad-daemon/src/exception_logging/win.rs line 47 at r1 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Because MINIDUMP_EXCEPTION_INFORMATION expects a mutable pointer, so I reflected this in the signature of generate_minidump. What do you think is appropriate here?

I think generate_minidump should take in *const EXCEPTION_POINTERS and convert it to a mut pointer when calling MiniDumpWriteDump. So we don't treat it as mutable for longer than we need to.


mullvad-daemon/src/exception_logging/win.rs line 139 at r1 (raw file):
That seems fine:

Proceed with normal execution of UnhandledExceptionFilter. That means obeying the SetErrorMode flags, or invoking the Application Error pop-up message box.

Or simply EXCEPTION_EXECUTE_HANDLER, which is what this function returns in the normal case. I'm not sure what the difference is in practice. I doubt that a message box will be shown given that it is a service.

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