-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Remove PAL_Random and move palrt APIs into the minipal #108999
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
Changes from 1 commit
8a13147
f96014a
5ccbb53
cbb3c4a
995c858
75c421d
4ab9fdf
d44224d
2b4779b
40077d5
9408aa6
aae4c86
9ccdb60
676c988
1be8d8a
4f39154
040549d
7ab733a
367612d
f31bcfd
329434f
337fcef
2d94d0a
460b8e5
a907e73
1f5573e
2ef0a5a
5f4df82
c84060e
05d141b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…the CoreCLR PAL to also use it. Also remove dangling references to DNCP and remove dead standalone-DNMD infra
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #include "guid.h" | ||
| #include "random.h" | ||
| #include <string.h> | ||
| #ifdef HOST_WINDOWS | ||
| #include <Windows.h> | ||
| #endif | ||
|
|
||
| // Define some well-known GUIDs on non-Windows platforms. | ||
jkoritzinsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #ifndef HOST_WINDOWS | ||
| // 00000000-0000-0000-0000-000000000000 | ||
| minipal_guid_t const GUID_NULL = { 0x0, 0x0, 0x0, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; | ||
|
|
||
| // 00000000-0000-0000-C000-000000000046 | ||
| minipal_guid_t const IID_IUnknown = { 0x0, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; | ||
|
|
||
| // 00000001-0000-0000-C000-000000000046 | ||
| minipal_guid_t const IID_IClassFactory = { 0x1, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; | ||
|
|
||
| // 0c733a30-2a1c-11ce-ade5-00aa0044773d | ||
| minipal_guid_t const IID_ISequentialStream = { 0x0c733a30, 0x2a1c, 0x11ce, { 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d } }; | ||
|
|
||
| // 0000000C-0000-0000-C000-000000000046 | ||
| minipal_guid_t const IID_IStream = { 0xC, 0x0, 0x0, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; | ||
| #endif | ||
|
|
||
| // See RFC-4122 section 4.4 on creation of random GUID. | ||
| // https://www.ietf.org/rfc/rfc4122.txt | ||
| // | ||
| // The version 4 UUID is meant for generating UUIDs from truly-random or | ||
| // pseudo-random numbers. | ||
| // | ||
| // The algorithm is as follows: | ||
| // | ||
| // o Set the two most significant bits (bits 6 and 7) of the | ||
| // clock_seq_hi_and_reserved to zero and one, respectively. | ||
| // | ||
| // o Set the four most significant bits (bits 12 through 15) of the | ||
| // time_hi_and_version field to the 4-bit version number from | ||
| // Section 4.1.3. | ||
| // | ||
| // o Set all the other bits to randomly (or pseudo-randomly) chosen | ||
| // values. | ||
| // | ||
| bool minipal_guid_v4_create(minipal_guid_t* guid) | ||
| { | ||
| #ifdef HOST_WINDOWS | ||
| // Windows has a built-in function for creating v4 GUIDs. | ||
| return SUCCEEDED(CoCreateGuid((GUID*)guid)); | ||
| #else | ||
| if (minipal_get_cryptographically_secure_random_bytes((uint8_t*)guid, sizeof(*guid)) != 0) | ||
| return false; | ||
|
|
||
| { | ||
| // time_hi_and_version | ||
| const uint16_t mask = 0xf000; // b1111000000000000 | ||
| const uint16_t value = 0x4000; // b0100000000000000 | ||
| guid->data3 = (guid->data3 & ~mask) | value; | ||
| } | ||
|
|
||
| { | ||
| // clock_seq_hi_and_reserved | ||
| const uint8_t mask = 0xc0; // b11000000 | ||
| const uint8_t value = 0x80; // b10000000 | ||
| guid->data4[0] = (guid->data4[0] & ~mask) | value; | ||
| } | ||
|
|
||
| return true; | ||
| #endif | ||
| } | ||
|
|
||
| bool minipal_guid_equals(minipal_guid_t const* g1, minipal_guid_t const* g2) | ||
| { | ||
| return memcmp(g1, g2, sizeof(minipal_guid_t)) == 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||
|
|
||||||
| #ifndef MINIPAL_GUID_H | ||||||
| #define MINIPAL_GUID_H | ||||||
|
|
||||||
| #include <stdint.h> | ||||||
| #include <stdbool.h> | ||||||
|
|
||||||
| #ifdef __cplusplus | ||||||
| extern "C" | ||||||
| { | ||||||
| #endif // __cplusplus | ||||||
|
|
||||||
| typedef struct minipal_guid__ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We get a slightly better experience in debuggers by giving a name to the struct instead of just naming the typedef (without the name on the struct, you just get "anonymous struct" which is a little annoying). |
||||||
| { | ||||||
| uint32_t data1; | ||||||
| uint16_t data2; | ||||||
| uint16_t data3; | ||||||
| uint8_t data4[8]; | ||||||
| } minipal_guid_t; | ||||||
|
|
||||||
| bool minipal_guid_v4_create(minipal_guid_t* guid); | ||||||
|
|
||||||
| bool minipal_guid_equals(minipal_guid_t const* g1, minipal_guid_t const* g2); | ||||||
|
|
||||||
| #ifdef __cplusplus | ||||||
| } | ||||||
| #endif // __cplusplus | ||||||
|
|
||||||
| #ifdef __cplusplus | ||||||
| inline bool operator==(minipal_guid_t const& a, minipal_guid_t const& b) | ||||||
| { | ||||||
| return minipal_guid_equals(&a, &b); | ||||||
| } | ||||||
|
|
||||||
| inline bool operator!=(minipal_guid_t const& a, minipal_guid_t const& b) | ||||||
| { | ||||||
| return !(a == b); | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| #endif // MINIPAL_GUID_H | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #include "memory.h" | ||
|
|
||
| #ifdef HOST_WINDOWS | ||
| #include <Windows.h> | ||
|
|
||
| void* minipal_co_task_mem_alloc(size_t cb) | ||
jkoritzinsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return CoTaskMemAlloc(cb); | ||
| } | ||
|
|
||
| void minipal_co_task_mem_free(void* pv) | ||
| { | ||
| CoTaskMemFree(pv); | ||
| } | ||
| #else | ||
| // CoTaskMemAlloc always aligns on an 8-byte boundary. | ||
| #define ALIGN 8 | ||
|
|
||
| void* minipal_co_task_mem_alloc(size_t cb) | ||
| { | ||
| // Ensure malloc always allocates. | ||
| if (cb == 0) | ||
| cb = ALIGN; | ||
|
|
||
| // Align the allocation size. | ||
jkoritzinsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| size_t cb_safe = (cb + (ALIGN - 1)) & ~(ALIGN - 1); | ||
| if (cb_safe < cb) // Overflow | ||
| return NULL; | ||
|
|
||
| return aligned_alloc(ALIGN, cb_safe); | ||
jkoritzinsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void minipal_co_task_mem_free(void* pv) | ||
| { | ||
| free(pv); | ||
| } | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #ifndef MINIPAL_MEMORY_H | ||
| #define MINIPAL_MEMORY_H | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| // Allocate memory on the platform equivalent of the CoTaskMem heap. | ||
| void* minipal_co_task_mem_alloc(size_t cb); | ||
|
|
||
| // Free memory allocated on the platform equivalent of the CoTaskMem heap. | ||
| void minipal_co_task_mem_free(void* pv); | ||
|
|
||
| #endif // MINIPAL_MEMORY_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #include "strings.h" | ||
|
|
||
| size_t minipal_u16_strlen(const CHAR16_T* str) | ||
| { | ||
| size_t len = 0; | ||
| while (*str++) | ||
| { | ||
| len++; | ||
| } | ||
| return len; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.