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

Remove PAL_Random and move palrt APIs into the minipal #108999

Merged
merged 30 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8a13147
Remove PAL_Random
jkoritzinsky Oct 16, 2024
f96014a
Move the "COM minipal" APIs into the regular repo minipal and update …
jkoritzinsky Oct 16, 2024
5ccbb53
Remove direct CoCreateGuid usage from CoreCLR and instead use the min…
jkoritzinsky Oct 16, 2024
cbb3c4a
Remove CoTaskMemAlloc/Free usage from xplat code (and instead use the…
jkoritzinsky Oct 16, 2024
995c858
palrt is empty, so remove it.
jkoritzinsky Oct 17, 2024
75c421d
Use minipal_u16_strlen in more places.
jkoritzinsky Oct 17, 2024
4ab9fdf
Use minipal's random APIs instead of Mono having their own
jkoritzinsky Oct 17, 2024
d44224d
fixup! Use minipal_u16_strlen in more places.
jkoritzinsky Oct 17, 2024
2b4779b
Remove 'random' usage in eventpipe and unify all usages of the minipa…
jkoritzinsky Oct 17, 2024
40077d5
PR feedback
jkoritzinsky Oct 17, 2024
9408aa6
Link minipal to bcrypt and flow it so superpmi picks it up
jkoritzinsky Oct 17, 2024
aae4c86
Make the co-task-mem-alloc PAL just call malloc
jkoritzinsky Oct 17, 2024
9ccdb60
We're in C
jkoritzinsky Oct 17, 2024
676c988
Add casts for Windows
jkoritzinsky Oct 17, 2024
1be8d8a
Fix assert
jkoritzinsky Oct 18, 2024
4f39154
Remove u16_strlen from the CoreCLR minipal
jkoritzinsky Oct 21, 2024
040549d
PR feedback and fix dbgutil.cpp
jkoritzinsky Oct 21, 2024
7ab733a
Fix CoreCLR eventpipe runtime.
jkoritzinsky Oct 21, 2024
367612d
Fix windows build
jkoritzinsky Oct 22, 2024
f31bcfd
Move guid definitions out of the minipal and back to the CoreCLR PAL …
jkoritzinsky Oct 23, 2024
329434f
Fix include path now that we're in the PAL and not palrt
jkoritzinsky Oct 24, 2024
337fcef
Add rt include directory for guid.cpp
jkoritzinsky Oct 25, 2024
2d94d0a
Export GUID_NULL from the dac's copy of the PAL for the dbi.
jkoritzinsky Oct 25, 2024
460b8e5
Revert "Remove u16_strlen from the CoreCLR minipal"
jkoritzinsky Oct 29, 2024
a907e73
Merge branch 'more-minipal' of github.com:jkoritzinsky/runtime into m…
jkoritzinsky Oct 29, 2024
1f5573e
Merge branch 'main' into more-minipal
jkoritzinsky Oct 29, 2024
2ef0a5a
Go back to a CoTaskMemAlloc PAL
jkoritzinsky Oct 29, 2024
5f4df82
Use a prefixed name everywhere instead of shiming the Win32 API name …
jkoritzinsky Oct 29, 2024
c84060e
Fix target name change after merge
jkoritzinsky Oct 29, 2024
05d141b
Don't prefix the method but instead put the header in a subfolder.
jkoritzinsky Oct 30, 2024
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
Prev Previous commit
Next Next commit
Remove 'random' usage in eventpipe and unify all usages of the minipa…
…l guid API instead of having three separate implementation of the exact same function body
  • Loading branch information
jkoritzinsky committed Oct 17, 2024
commit 2b4779be9c758f5c22d8d9c660ae7c42c4a4a4da
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
14 changes: 0 additions & 14 deletions src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,20 +738,6 @@ ep_rt_process_shutdown (void)
return (bool)g_fEEShutDown;
}

static
inline
void
ep_rt_create_activity_id (
uint8_t *activity_id,
uint32_t activity_id_len)
{
STATIC_CONTRACT_NOTHROW;
EP_ASSERT (activity_id != NULL);
EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE);

minipal_guid_v4_create (reinterpret_cast<minipal_guid_t *>(activity_id));
}

static
inline
bool
Expand Down
9 changes: 0 additions & 9 deletions src/mono/mono/eventpipe/ep-rt-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <mono/metadata/profiler.h>
#include <mono/mini/mini-runtime.h>
#include <minipal/getexepath.h>
#include <minipal/random.h>
#include <runtime_version.h>
#include <clretwallmain.h>

Expand Down Expand Up @@ -59,14 +58,6 @@ EVENTPIPE_TRACE_CONTEXT MICROSOFT_DOTNETRUNTIME_MONO_PROFILER_PROVIDER_DOTNET_Co
void
ep_rt_mono_thread_exited (void);

bool
ep_rt_mono_rand_try_get_bytes (
uint8_t *buffer,
size_t buffer_size)
{
return minipal_get_cryptographically_secure_random_bytes(buffer, buffer_size);
}

char *
ep_rt_mono_get_managed_cmd_line (void)
{
Expand Down
37 changes: 0 additions & 37 deletions src/mono/mono/eventpipe/ep-rt-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ extern void ep_rt_mono_provider_config_init (EventPipeProviderConfiguration *pro
extern void ep_rt_mono_init_providers_and_events (void);
extern bool ep_rt_mono_providers_validate_all_disabled (void);
extern bool ep_rt_mono_sample_profiler_write_sampling_event_for_threads (ep_rt_thread_handle_t sampling_thread, EventPipeEvent *sampling_event);
extern bool ep_rt_mono_rand_try_get_bytes (uint8_t *buffer,size_t buffer_size);
extern void ep_rt_mono_execute_rundown (dn_vector_ptr_t *execution_checkpoints);
extern int64_t ep_rt_mono_perf_counter_query (void);
extern int64_t ep_rt_mono_perf_frequency_query (void);
Expand Down Expand Up @@ -772,42 +771,6 @@ ep_rt_process_shutdown (void)
return ep_rt_process_detach ();
}

static
inline
void
ep_rt_create_activity_id (
uint8_t *activity_id,
uint32_t activity_id_len)
{
EP_ASSERT (activity_id != NULL);
EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE);

ep_rt_mono_rand_try_get_bytes ((guchar *)activity_id, EP_ACTIVITY_ID_SIZE);

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));
}

static
inline
bool
Expand Down
2 changes: 1 addition & 1 deletion src/native/eventpipe/ds-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ds_ipc_advertise_cookie_v1_get (void)
void
ds_ipc_advertise_cookie_v1_init (void)
{
ep_rt_create_activity_id ((uint8_t *)&_ds_ipc_advertise_cooike_v1, EP_GUID_SIZE);
ep_thread_create_activity_id ((uint8_t *)&_ds_ipc_advertise_cooike_v1, EP_GUID_SIZE);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions src/native/eventpipe/ep-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,6 @@ static
bool
ep_rt_process_shutdown (void);

static
void
ep_rt_create_activity_id (
uint8_t *activity_id,
uint32_t activity_id_len);

static
bool
ep_rt_is_running (void);
Expand Down
5 changes: 4 additions & 1 deletion src/native/eventpipe/ep-thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ ep_thread_create_activity_id (
uint8_t *activity_id,
uint32_t activity_id_len)
{
ep_rt_create_activity_id (activity_id, activity_id_len);
EP_ASSERT (activity_id != NULL);
EP_ASSERT (activity_id_len == EP_ACTIVITY_ID_SIZE);

minipal_guid_v4_create (reinterpret_cast<minipal_guid_t *>(activity_id));
}

static
Expand Down
1 change: 1 addition & 0 deletions src/native/eventpipe/ep-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <containers/dn-list.h>
#include <containers/dn-queue.h>
#include <containers/dn-umap-t.h>
#include <minipal/guid.h>

/*
* EventFilterDescriptor.
Expand Down