Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ include_directories(${CLR_SRC_NATIVE_DIR}/libs/Common)
add_definitions(-DUNICODE)
add_definitions(-D_UNICODE)

if(NOT CLR_CMAKE_TARGET_APPLE AND NOT CLR_CMAKE_TARGET_ARCH_WASM AND NOT CLR_CMAKE_TARGET_OPENBSD)
add_definitions(-DFEATURE_READONLY_GS_COOKIE)
endif()
Comment on lines +20 to +22

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.

The PR title should be updated


if(CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_OPENBSD)
# OpenBSD's ld.so cannot resolve native TLS relocations in shared objects and has no
# __tls_get_addr, so the runtime must use emulated TLS (like Android).
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/ceemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ void InitGSCookie()

volatile GSCookie * pGSCookiePtr = GetProcessGSCookiePtr();

#ifdef FEATURE_READONLY_GS_COOKIE
// The GS cookie is stored in a read only data segment
DWORD oldProtection;
if(!ClrVirtualProtect((LPVOID)pGSCookiePtr, sizeof(GSCookie), PAGE_READWRITE, &oldProtection))
Expand All @@ -481,6 +482,7 @@ void InitGSCookie()
// PAL layer is unable to extract old protection for regions that were not allocated using VirtualAlloc
oldProtection = PAGE_READONLY;
#endif // TARGET_UNIX
#endif // FEATURE_READONLY_GS_COOKIE

#ifndef TARGET_UNIX
// The GSCookie cannot be in a writeable page
Expand All @@ -507,10 +509,12 @@ void InitGSCookie()
val ++;
*pGSCookiePtr = val;

#ifdef FEATURE_READONLY_GS_COOKIE
if(!ClrVirtualProtect((LPVOID)pGSCookiePtr, sizeof(GSCookie), oldProtection, &oldProtection))
{
ThrowLastError();
}
#endif // FEATURE_READONLY_GS_COOKIE
}

Volatile<BOOL> g_bIsGarbageCollectorFullyInitialized = FALSE;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ void OBJECTREF_EnumMemoryRegions(OBJECTREF ref)
//
// We need the following to be the compiler's notion of volatile.
//
#ifdef FEATURE_READONLY_GS_COOKIE
extern "C" RAW_KEYWORD(volatile) const GSCookie s_gsCookie = 0;
#else
extern "C" RAW_KEYWORD(volatile) GSCookie s_gsCookie = 0;
#endif

#else
__GlobalVal< GSCookie > s_gsCookie(&DacGlobals::dac__s_gsCookie);
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@ typedef DPTR(GSCookie) PTR_GSCookie;
// volatile is so that accesses to it do not get optimized away because of the const
//

#ifdef FEATURE_READONLY_GS_COOKIE
extern "C" RAW_KEYWORD(volatile) READONLY_ATTR const GSCookie s_gsCookie;
#else
extern "C" RAW_KEYWORD(volatile) GSCookie s_gsCookie;
#endif

inline
GSCookie * GetProcessGSCookiePtr() { return const_cast<GSCookie *>(&s_gsCookie); }
Expand Down
Loading