Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/coreclr/vm/threadsuspend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,13 @@ int RedirectedHandledJITCaseExceptionFilter(
pFrame->Pop();

// Copy the saved context record into the EH context;
ReplaceExceptionContextRecord(pExcepPtrs->ContextRecord, pCtx);
// NB: cannot use ReplaceExceptionContextRecord here.
// these contexts may contain extended registers and may have different format
// for reasons such as alignment or context compaction
//
// REVIEW: CopyContext may fail. in theory. How should we handle that? FailFast?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, FailFast is appropriate for failure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

However, be careful calling new functions from this function. If they have destructors and the compiler chooses to inline them, the runtime will start crashing.

@VSadov VSadov Feb 18, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was thinking of code like:

            if (!CopyContext(pTarget, pTarget->ContextFlags, pCtx))
            {
                STRESS_LOG1(LF_SYNC, LL_ERROR, "ERROR: Could not set context record, lastError = 0x%x\n", GetLastError());
                ThrowLastError();
            }

Would that fit here?

It is highly unlikely that copy would fail, but it'd be nice to have some diagnostics if that start happenning.

CONTEXT* pTarget = pExcepPtrs->ContextRecord;
CopyContext(pTarget, pTarget->ContextFlags, pCtx);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems it would make sense to modify the ReplaceExceptionContextRecord to use CopyContext instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was not sure if ReplaceExceptionContextRecord can be used outside of Windows. Can it?

@filipnavara filipnavara Feb 17, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not readily obvious but it's always guarded by HOST_WINDOWS and/or !TARGET_UNIX so it looks Windows-only. CopyContext is available on Windows 7 SP1+ which is the minimum target at the moment so that should be fine too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also wonder if ReplaceExceptionContextRecord needs to handle extended context at all if suspension resume switches completely to the RtlRestoreContext plan.

@VSadov VSadov Feb 17, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was not sure if ReplaceExceptionContextRecord can be used outside of Windows. Can it?

I have tried moving the fix into ReplaceExceptionContextRecord and that did not build on Linux, so that answers this.


DWORD espValue = pCtx->Esp;

Expand Down