Skip to content

gh-133572: Disable error reporting for invalid memory access on unsupported WinAPI partitions #133573

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

Merged
merged 5 commits into from
May 15, 2025

Conversation

maxbachmann
Copy link
Contributor

@maxbachmann maxbachmann commented May 7, 2025

aside from the mimalloc fix that has to be downstreamed later on this is the last change required to get cpython to compile on the xbox again

@maxbachmann maxbachmann changed the title gh-133572: disable invalid memory error reporting on unsupported WinAPI partitions gh-133572: Disable error reporting for invalid memory access on unsupported WinAPI partitions May 7, 2025
@zooba
Copy link
Member

zooba commented May 14, 2025

An alternative would be something like DONT_USE_LSA to make clear we just don't support the lsa handling, but do support structured exceptions.

Oh, it's only the error number conversion that's a problem? Let's just shim that bit out then and keep the SEH. Perhaps add this just before the macro and then call it?

static void
_PyErr_SetFromNTSTATUS(NTSTATUS status) {
#if (macro here)
    PyErr_SetFromWindowsErr(LsaNtStatusToWinError(status));
#else
    if (status & 0x80000000) {
        // HRESULT-shaped codes are supported by PyErr_SetFromWindowsErr
        PyErr_SetFromWindowsErr((int)status);
    } else {
        // No mapping for NTSTATUS values, so just return it for diagnostic purposes
        // If we provide it as winerror it could incorrectly change the type of the exception.
        PyErr_Format(PyExc_OSError, "Operating system error NTSTATUS=0x%08lX", status & 0xFFFFFFFF);
    }
#endif
}

Or that function might even have a home with the other error setters, but I don't know that we've needed it anywhere else. If you want to put it in (IIRC) errors.c, don't make it static, but also don't use PyAPI_FUNC on it - no need for it to be exported from the DLL.

@zooba
Copy link
Member

zooba commented May 14, 2025

And sorry about multiple changes - my fault for giving direction without having fully understood the problem!

@maxbachmann
Copy link
Contributor Author

Both NTSTATUS and LsaNtStatusToWinError aren't defined in these partitions. I added your function and only do the conversion to NTSTATUS when performing the lsa to win error conversion

@zooba zooba merged commit 4341095 into python:main May 15, 2025
39 checks passed
@zooba
Copy link
Member

zooba commented May 15, 2025

Perfect, thanks!

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