Skip to content

Conversation

filipnavara
Copy link
Member

The current declaration of the exception handlers are incorrect on x86. They are missing __cdecl calling convention and the second parameter is declared as PVOID instead of struct _EXCEPTION_REGISTRATION_RECORD *.

We have two options - either we fix every single of these declarations to match the required prototype or we use the existing macros. The macros have the flexibility of chosing between struct _EXCEPTION_REGISTRATION_RECORD * and PVOID for the second parameter if we ever need that distinction.

I assume this won't break IntelliSense completions due to the use of src/coreclr/cpp.hint.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 24, 2025
}

EXTERN_C EXCEPTION_DISPOSITION
UMThunkStubUnwindFrameChainHandler(
Copy link
Member Author

Choose a reason for hiding this comment

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

This handler is no longer used.

@filipnavara
Copy link
Member Author

filipnavara commented Mar 24, 2025

This is extracted from the x86 funclet prototype (#113576). It's one of the changes that makes the diff quite unreadable and distracts from the imporant parts.

@filipnavara filipnavara force-pushed the exception_decl_impl branch from c042745 to fd2ea20 Compare March 24, 2025 10:30
@jkotas jkotas requested a review from janvorli March 24, 2025 17:12
Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

Overall, I would prefer just making the exception handlers have the __cdecl on x86 and not make any other changes. The functions definitions by the macro without the arguments are more difficult to follow. I don't also see a problem with the pEstablisherFrame being PVOID, as it is just a pointer to a stack location. The fact that it is some struct pointer on x86 doesn't seem to be a good reason for changing to that type everywhere. You can easily cast it to the struct pointer for x86 if you need it.

{
OBJECTREF oref = ExceptionTracker::CreateThrowable(pExceptionRecord, FALSE);
DispatchManagedException(oref, pContextRecord, pExceptionRecord);
DispatchManagedException(oref, pContext, pExceptionRecord);
Copy link
Member

Choose a reason for hiding this comment

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

A nit - can we please keep the name pContextRecord at places where you have renamed it? It would make this change much smaller and it would match the Windows naming (e.g. in RtlVirtualUnwind and other similar functions). It is also usually used in locations where the exception record so that the two names match.

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed it to follow the existing macro. If I were to change the macro then an equal number of places elsewhere would have the be modified.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer taking the non-x86 stuff as the standard. The x86 has always been a bit different at various places for historical reasons.

// Perform unwinding of the current frame
disposition = ProcessCLRException(exceptionRecord,
(void*)establisherFrame,
(struct _EXCEPTION_REGISTRATION_RECORD *)establisherFrame,
Copy link
Member

Choose a reason for hiding this comment

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

This looks strange, the establisherFrame isn't a struct like this. Is is purely a stack pointer.

@filipnavara
Copy link
Member Author

Overall, I would prefer just making the exception handlers have the __cdecl on x86 and not make any other changes.

I don't have strong preference. The macros were already there so I tried to reuse the existing infrastructure instead of inventing something else.

The functions definitions by the macro without the arguments are more difficult to follow. I don't also see a problem with the pEstablisherFrame being PVOID, as it is just a pointer to a stack location.

It's PVOID on non-x86, and it's struct _EXCEPTION_REGISTRATION_RECORD * on x86. I am fine with either definition and casting it as necessary. I simply reused an existing macro which used struct _EXCEPTION_REGISTRATION_RECORD *.

@filipnavara
Copy link
Member Author

Overall, I would prefer just making the exception handlers have the __cdecl on x86 and not make any other changes.

I'll try to rework my other PR to use that and then likely close this and submit the other variant.

@filipnavara filipnavara deleted the exception_decl_impl branch March 25, 2025 08:23
@github-actions github-actions bot locked and limited conversation to collaborators Apr 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-ExceptionHandling-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants