Skip to content

Commit

Permalink
Remove PAL_Random and move palrt APIs into the minipal (dotnet#108999)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored Oct 31, 2024
1 parent 0c67caf commit 1b27ee9
Show file tree
Hide file tree
Showing 64 changed files with 267 additions and 1,014 deletions.
4 changes: 0 additions & 4 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_H
add_subdirectory(utilcode)
add_subdirectory(inc)

if(CLR_CMAKE_HOST_UNIX)
add_subdirectory(palrt)
endif(CLR_CMAKE_HOST_UNIX)

add_subdirectory(ilasm)
add_subdirectory(ildasm)
add_subdirectory(gcinfo)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ ConvertString(const WCHAR* str)
if (str == nullptr)
return { };

size_t cch = u16_strlen(str) + 1;
size_t cch = minipal_u16_strlen((CHAR16_T*)str) + 1;
int len = minipal_get_length_utf16_to_utf8((CHAR16_T*)str, cch, 0);
if (len == 0)
return { };
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/debug/createdump/createdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef int T_CONTEXT;
#include <arrayholder.h>
#include <releaseholder.h>
#ifdef HOST_UNIX
#include <minipal/strings.h>
#include <minipal/utf8.h>
#include <dn-u16.h>
#include <dumpcommon.h>
Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/debug/createdump/createdumppal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,6 @@ RaiseException(
throw;
}

size_t u16_strlen(const WCHAR* str)
{
size_t nChar = 0;
while (*str++)
nChar++;
return nChar;
}

//
// Used by _ASSERTE
//
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/createdump/datatarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ DumpDataTarget::GetImageBase(
*baseAddress = 0;

char tempModuleName[MAX_PATH];
size_t cch = u16_strlen(moduleName) + 1;
size_t cch = minipal_u16_strlen((CHAR16_T*)moduleName) + 1;
int length = minipal_convert_utf16_to_utf8((CHAR16_T*)moduleName, cch, tempModuleName, sizeof(tempModuleName), 0);
if (length > 0)
{
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/debug/inc/dbgtransportsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#endif // !RIGHT_SIDE_COMPILE

#include <minipal/guid.h>

#if defined(FEATURE_DBGIPC_TRANSPORT_VM) || defined(FEATURE_DBGIPC_TRANSPORT_DI)

#include <twowaypipe.h>
Expand Down Expand Up @@ -519,7 +521,7 @@ class DbgTransportSession
// Struct defining the format of the data block sent with a SessionRequest.
struct SessionRequestData
{
GUID m_sSessionID; // Unique session ID. Treated as byte blob so no endian-ness
minipal_guid_t m_sSessionID; // Unique session ID. Treated as byte blob so no endian-ness
};

// Struct used to track a message that is being (or will soon be) sent but has not yet been acknowledged.
Expand Down Expand Up @@ -674,7 +676,7 @@ class DbgTransportSession
// Session ID randomly allocated by the right side and sent over in the SessionRequest message. This
// serves to disambiguate a re-send of the SessionRequest due to a network error versus a SessionRequest
// from a different debugger.
GUID m_sSessionID;
minipal_guid_t m_sSessionID;

// Lock used to synchronize sending messages and updating the session state. This ensures message bytes
// don't become interleaved on the transport connection, the send queue is updated consistently across
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/debug/shared/dbgtransportsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ HRESULT DbgTransportSession::Init(DebuggerIPCControlBlock *pDCB, AppDomainEnumer
// The RS randomly allocates a session ID which is sent to the LS in the SessionRequest message. In the
// case of network errors during session formation this allows the LS to tell SessionRequest re-sends from
// a new request from a different RS.
HRESULT hr = CoCreateGuid(&m_sSessionID);
if (FAILED(hr))
return hr;
if (!minipal_guid_v4_create(&m_sSessionID))
return E_FAIL;
#endif // RIGHT_SIDE_COMPILE


Expand Down
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ else(CLR_CMAKE_HOST_WIN32)
mscorrc
${START_WHOLE_ARCHIVE} # force all PAL objects to be included so all exports are available
coreclrpal
palrt
coreclrminipal
${END_WHOLE_ARCHIVE}
)
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ nativeStringResourceTable_mscorrc
#PAL_CloseProcessMemory
#PAL_ReadProcessMemory
#PAL_ProbeMemory
#PAL_Random
#PAL__wcstoui64
#PAL_wcstoul
#PAL_wcstod
Expand Down Expand Up @@ -147,3 +146,5 @@ nativeStringResourceTable_mscorrc
#WaitForSingleObjectEx
#WideCharToMultiByte
#WriteFile

#GUID_NULL
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ if(CLR_CMAKE_HOST_WIN32)
elseif(CLR_CMAKE_HOST_UNIX)

list(APPEND COREDBI_LIBRARIES
palrt
# share the PAL in the dac module
mscordaccore
)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ else()
coreclrpal
${END_WHOLE_ARCHIVE}
mscorrc
palrt
)
endif(CLR_CMAKE_TARGET_WIN32)

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/dlls/mscorpe/pewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ HRESULT PEWriter::write(void ** ppImage)
size_t lSize = filePos;

// allocate the block we are handing back to the caller
void * pImage = (void *) ::CoTaskMemAlloc(lSize);
void * pImage = (void *) CoTaskMemAlloc(lSize);
if (NULL == pImage)
{
return E_OUTOFMEMORY;
Expand Down Expand Up @@ -1622,7 +1622,7 @@ HRESULT PEWriter::write(void ** ppImage)
// make sure we wrote the exact numbmer of bytes expected
_ASSERTE(lSize == (size_t) (pCur - (char *)pImage));

// give pointer to memory image back to caller (who must free with ::CoTaskMemFree())
// give pointer to memory image back to caller (who must free with CoTaskMemFree())
*ppImage = pImage;

// all done
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/ilasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ else()
list(APPEND ILASM_LINK_LIBRARIES
coreclrpal
mscorrc
palrt
coreclrminipal
)
endif(CLR_CMAKE_TARGET_WIN32)
Expand All @@ -116,7 +115,6 @@ if(CLR_CMAKE_HOST_UNIX)
utilcodestaticnohost
mscorrc
coreclrpal
palrt
${CMAKE_DL_LIBS}
)
else()
Expand Down
9 changes: 0 additions & 9 deletions src/coreclr/ilasm/assem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,20 +1064,11 @@ BOOL Assembler::EmitClass(Class *pClass)
LPCUTF8 szFullName;
WCHAR* wzFullName=&wzUniBuf[0];
HRESULT hr = E_FAIL;
GUID guid;
size_t L;
mdToken tok;

if(pClass == NULL) return FALSE;

hr = CoCreateGuid(&guid);
if (FAILED(hr))
{
printf("Unable to create GUID\n");
m_State = STATE_FAIL;
return FALSE;
}

if(pClass->m_pEncloser)
szFullName = strrchr(pClass->m_szFQN,NESTING_SEP) + 1;
else
Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/ilasm/portable_pdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ HRESULT PortablePdbWriter::Init(IMetaDataDispenserEx2* mdDispenser)
time_t now;
time(&now);
m_pdbStream.id.pdbTimeStamp = (ULONG)now;
hr = CoCreateGuid(&m_pdbStream.id.pdbGuid);

if (FAILED(hr)) goto exit;
if (!minipal_guid_v4_create(reinterpret_cast<minipal_guid_t*>(&m_pdbStream.id.pdbGuid)))
{
hr = E_FAIL;
goto exit;
}

hr = mdDispenser->DefinePortablePdbScope(
CLSID_CorMetaDataRuntime,
Expand Down Expand Up @@ -176,7 +178,7 @@ HRESULT PortablePdbWriter::DefineDocument(char* name, GUID* language)
mdDocument docToken = mdDocumentNil;

if (FAILED(hr = m_pdbEmitter->DefineDocument(
name, // will be tokenized
name, // will be tokenized
&hashAlgorithmUnknown,
hashValue,
cbHashValue,
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/ildasm/exe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ else()
list(APPEND ILDASM_LINK_LIBRARIES
coreclrpal
mscorrc
palrt
coreclrminipal
)
endif(CLR_CMAKE_HOST_WIN32)
Expand All @@ -105,7 +104,6 @@ if(CLR_CMAKE_HOST_UNIX)
${ILDASM_LINK_LIBRARIES}
mscorrc
coreclrpal
palrt
${CMAKE_DL_LIBS}
)
else()
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/inc/holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "staticcontract.h"
#include "volatile.h"
#include "palclr.h"
#include <minipal/com/memory.h>

#include <utility>
#include <type_traits>
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/md/compiler/regmeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "posterror.h"
#include "stgio.h"
#include "sstring.h"
#include <minipal/guid.h>

#include "mdinternalrw.h"

Expand Down Expand Up @@ -246,7 +247,7 @@ RegMeta::CreateNewMD()
ModuleRec *pModule;
GUID mvid;
IfFailGo(m_pStgdb->m_MiniMd.AddModuleRecord(&pModule, &iRecord));
IfFailGo(CoCreateGuid(&mvid));
IfFailGo(minipal_guid_v4_create(&mvid) ? S_OK : E_FAIL);
IfFailGo(m_pStgdb->m_MiniMd.PutGuid(TBL_Module, ModuleRec::COL_Mvid, pModule, mvid));

// Add the dummy module typedef which we are using to parent global items.
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/md/enc/metamodelrw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "../compiler/importhelper.h"
#include "metadata.h"
#include "streamutil.h"
#include <minipal/guid.h>

#ifdef _MSC_VER
#pragma intrinsic(memcpy)
Expand Down Expand Up @@ -1196,7 +1197,7 @@ CMiniMdRW::SetOption(
PutCol(TBL_Module, ModuleRec::COL_EncBaseId, pMod, uVal);
*/
// Allocate a new GUID for EncId.
IfFailGo(CoCreateGuid(&encid));
IfFailGo(minipal_guid_v4_create(&encid) ? S_OK : E_FAIL);
IfFailGo(PutGuid(TBL_Module, ModuleRec::COL_EncId, pMod, encid));
#else //!FEATURE_METADATA_EMIT
IfFailGo(E_INVALIDARG);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/md/inc/portablepdbmdds.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#endif

#include "corhdr.h"
#include <minipal/guid.h>

//-------------------------------------
//--- PDB stream data structure
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/minipal/Unix/dn-u16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ typedef char16_t WCHAR;

#include <dn-u16.h>
#include <string.h>
#include <minipal/strings.h>

size_t u16_strlen(const WCHAR* str)
{
size_t nChar = 0;
while (*str++)
nChar++;
return nChar;
return minipal_u16_strlen((CHAR16_T*)str);
}

int u16_strcmp(const WCHAR* str1, const WCHAR* str2)
Expand Down Expand Up @@ -192,4 +190,4 @@ uint64_t u16_strtoui64(const WCHAR* nptr, WCHAR** endptr, int base)
double u16_strtod(const WCHAR* nptr, WCHAR** endptr)
{
return PAL_wcstod(nptr, endptr);
}
}
40 changes: 0 additions & 40 deletions src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,46 +783,6 @@ void ep_rt_aot_os_environment_get_utf16 (dn_vector_ptr_t *env_array)
#endif
}

void ep_rt_aot_create_activity_id (uint8_t *activity_id, uint32_t activity_id_len)
{
// We call CoCreateGuid for windows, and use a random generator for non-windows
STATIC_CONTRACT_NOTHROW;
EP_ASSERT (activity_id != NULL);
EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE);
#ifdef HOST_WIN32
CoCreateGuid (reinterpret_cast<GUID *>(activity_id));
#else
if(minipal_get_cryptographically_secure_random_bytes(activity_id, activity_id_len)==-1)
{
*activity_id=0;
return;
}

const uint16_t version_mask = 0xF000;
const uint16_t random_guid_version = 0x4000;
const uint8_t clock_seq_hi_and_reserved_mask = 0xC0;
const uint8_t clock_seq_hi_and_reserved_value = 0x80;

// Modify bits indicating the type of the GUID
uint8_t *activity_id_c = activity_id + sizeof (uint32_t) + sizeof (uint16_t);
uint8_t *activity_id_d = activity_id + sizeof (uint32_t) + sizeof (uint16_t) + sizeof (uint16_t);

uint16_t c;
memcpy (&c, activity_id_c, sizeof (c));

uint8_t d;
memcpy (&d, activity_id_d, sizeof (d));

// time_hi_and_version
c = ((c & ~version_mask) | random_guid_version);
// clock_seq_hi_and_reserved
d = ((d & ~clock_seq_hi_and_reserved_mask) | clock_seq_hi_and_reserved_value);

memcpy (activity_id_c, &c, sizeof (c));
memcpy (activity_id_d, &d, sizeof (d));
#endif
}

ep_rt_thread_handle_t ep_rt_aot_thread_get_handle (void)
{
return ThreadStore::GetCurrentThreadIfAvailable();
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,6 @@ ep_rt_process_shutdown (void)
return false;
}

static
inline
void
ep_rt_create_activity_id (
uint8_t *activity_id,
uint32_t activity_id_len)
{
extern void ep_rt_aot_create_activity_id (uint8_t *activity_id, uint32_t activity_id_len);
ep_rt_aot_create_activity_id(activity_id, activity_id_len);
}

static
inline
bool
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ EXTERN_C int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t control

case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_ID:

ep_rt_create_activity_id(reinterpret_cast<uint8_t *>(pActivityId), EP_ACTIVITY_ID_SIZE);
ep_thread_create_activity_id(reinterpret_cast<uint8_t *>(pActivityId), EP_ACTIVITY_ID_SIZE);
break;

case ActivityControlCode::EVENT_ACTIVITY_CONTROL_GET_SET_ID:
Expand All @@ -212,7 +212,7 @@ EXTERN_C int QCALLTYPE EventPipeInternal_EventActivityIdControl(uint32_t control
case ActivityControlCode::EVENT_ACTIVITY_CONTROL_CREATE_SET_ID:

ep_rt_thread_get_activity_id (activityIdHandle, reinterpret_cast<uint8_t *>(pActivityId), EP_ACTIVITY_ID_SIZE);
ep_rt_create_activity_id(reinterpret_cast<uint8_t *>(&currentActivityId), EP_ACTIVITY_ID_SIZE);
ep_thread_create_activity_id(reinterpret_cast<uint8_t *>(&currentActivityId), EP_ACTIVITY_ID_SIZE);
ep_rt_thread_set_activity_id (activityIdHandle, reinterpret_cast<uint8_t *>(&currentActivityId), EP_ACTIVITY_ID_SIZE);
break;

Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,6 @@ PALAPI
PAL_UnregisterModule(
IN HINSTANCE hInstance);

PALIMPORT
VOID
PALAPI
PAL_Random(
IN OUT LPVOID lpBuffer,
IN DWORD dwLength);

PALIMPORT
BOOL
PALAPI
Expand Down
Loading

0 comments on commit 1b27ee9

Please sign in to comment.