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

Add writeable holders for executable memory #53934

Merged
merged 5 commits into from
Jun 10, 2021

Conversation

janvorli
Copy link
Member

@janvorli janvorli commented Jun 9, 2021

This change adds holders for writeable mappings for executable memory.
It is the largest part of the W^X support. The ExecutableWriterHolder
implementation is dummy in this change, but it was fully tested with
coreclr / libraries tests on Windows arm, arm64, x64 and x86 with the
real double memory mapping.
There are few concepts / conventions used:

  • When the writeable pointer isn't known at a place where it is needed
    and also not at the caller, the ExecutableWriterHolder instance is
    created.
  • When a callee needs writeable pointer to executable memory and caller
    knows RW and RX, the argument is doubled with RX and RW suffixes. For
    constructors and member methods when "this" is the RW one, we pass just
    extra RX argument.
  • Locals holding RW pointer use RW suffix.
  • Locals holding RX pointer usually have no suffix to minimize number of
    changes, but in some cases they have a RX suffix
    where I felt like it was better to make things clear.

Contributes to #50391

This change adds holders for writeable mappings for executable memory.
It is the largest part of the W^X support. The ExecutableWriterHolder
implementation is dummy in this change, but it was fully tested with
coreclr / libraries tests on Windows arm, arm64, x64 and x86 with the
real double memory mapping.
There are few concepts / conventions used:
* When the writeable pointer isn't known at a place where it is needed
  and also not at the caller, the ExecutableWriterHolder instance is
  created.
* When a callee needs writeable pointer to executable memory and caller
  knows RW and RX, the argument is doubled with RX and RW suffixes. For
  constructors and member methods when "this" is the RW one, we pass just
  extra RX argument.
* Locals holding RW  pointer use RW suffix.
* Locals holding RX pointer usually have no suffix to minimize number of
  changes, but in some cases they have a RX suffix
  where I felt like it was better to make things clear.
@janvorli janvorli added this to the 6.0.0 milestone Jun 9, 2021
@janvorli janvorli requested a review from jkotas June 9, 2021 15:38
@janvorli janvorli self-assigned this Jun 9, 2021
@janvorli
Copy link
Member Author

janvorli commented Jun 9, 2021

cc: @mangod9


#include "utilcode.h"
#include "ex.h"
#include <intrin.h>
Copy link
Member

Choose a reason for hiding this comment

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

Does this file really need intrin.h ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't, it is a remainder of other changes I have in the branch with the complete set of W^X changes. But it is used only for logging stuff that will go away.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM

// nop
m_code[1] = 0xbf00;
pThisRW->m_code[1] = 0xbf00;
Copy link
Member

Choose a reason for hiding this comment

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

not part of your change, but aren't there constants defined for standard opcodes?

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 am not aware of such a thing in our codebase.

There was a code that got writeable mapping to an address, but then
referenced data below that address in the GC stress C implementation for
ARM.
@janvorli janvorli closed this Jun 10, 2021
@janvorli janvorli reopened this Jun 10, 2021
@janvorli janvorli merged commit d617e83 into dotnet:main Jun 10, 2021
@janvorli janvorli deleted the wxorx-holders branch June 10, 2021 13:26
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants