Skip to content

Fix Thread::IsAddressInStack for interpreter #116818

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 3 commits into from
Jun 20, 2025

Conversation

janvorli
Copy link
Member

The check is used at several places to verify that e.g. StringHandleOnStack is really on stack. It needs to be updated to take the interpreter stack into account too.

The check is used at several places to verify that e.g.
`StringHandleOnStack` is really on stack. It needs to be updated to take
the interpreter stack into account tooo.
@janvorli janvorli self-assigned this Jun 19, 2025
@Copilot Copilot AI review requested due to automatic review settings June 19, 2025 13:55
@janvorli janvorli requested review from BrzVlad and kg as code owners June 19, 2025 13:55
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Thread methods to correctly account for the interpreter stack when checking if an address is within the stack range.

  • Removed inline implementations from the header and added function declarations.
  • Updated both IsAddressInCurrentStack and IsAddressInStack in the cpp file to handle interpreter-specific checks.
  • Changed pointer types in InterpThreadContext (in interpexec.h) from int8_t* to PTR_INT8 to enhance type safety.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/vm/threads.h Removed inline definitions; now only declares the functions.
src/coreclr/vm/threads.cpp Updated stack range checks to include interpreter stack support.
src/coreclr/vm/interpexec.h Changed pointer types to PTR_INT8 for interpreter contexts.

_ASSERTE(m_CacheStackLimit != NULL);
_ASSERTE(m_CacheStackLimit < m_CacheStackBase);
#ifdef FEATURE_INTERPRETER
if ((m_pInterpThreadContext != NULL) && ((PTR_VOID)m_pInterpThreadContext->pStackStart < addr) && (addr <= (PTR_VOID)m_pInterpThreadContext->pStackPointer))
Copy link
Member

Choose a reason for hiding this comment

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

I think the < and <= need to be reversed since the interp stack grows upwards, unlike the native stack.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the pStackStart is at smaller address than the pStackPointer (the pStackStart is the address at which we've allocated the memory for the stack), so the comparison is correct.

Copy link
Member

@BrzVlad BrzVlad Jun 19, 2025

Choose a reason for hiding this comment

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

On second thought, I'm not sure why the comparison is like that for the native stack pointer either. pStackStart is a valid address inside the interpreter stack. Why would it return false for this value ?

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'm not sure I understand. The point of this method is to check whether the address addr is on the stack or not. So we are comparing it to the lowest and highest address of the valid part of the stack.
This function is used in various asserts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Vlad is right, I've misunderstood his point. I'll fix it.

@janvorli janvorli merged commit 5ebfca2 into dotnet:main Jun 20, 2025
96 checks passed
@janvorli janvorli deleted the fix-is-address-in-stack-check branch June 20, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants