mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-08 00:09:31 +03:00
older darwin have no CLOCK_MONOTONIC
use asm rdtsc then
This commit is contained in:
parent
06f8da4218
commit
50cef64bf8
1 changed files with 21 additions and 0 deletions
21
src/init.c
21
src/init.c
|
@ -140,6 +140,24 @@ uintptr_t _mi_random_shuffle(uintptr_t x) {
|
|||
return x;
|
||||
}
|
||||
|
||||
#if defined __APPLE__
|
||||
static int64_t rdtsc()
|
||||
{
|
||||
#ifdef __x86_64__
|
||||
unsigned int a, d;
|
||||
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
|
||||
return (unsigned long)a | ((unsigned long)d << 32);
|
||||
#elif defined(__i386__)
|
||||
unsigned long long int x;
|
||||
__asm__ volatile ("rdtsc" : "=A" (x));
|
||||
return x;
|
||||
#else
|
||||
#define NO_CYCLE_COUNTER
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
uintptr_t _mi_random_init(uintptr_t seed /* can be zero */) {
|
||||
// Hopefully, ASLR makes our function address random
|
||||
uintptr_t x = (uintptr_t)((void*)&_mi_random_init);
|
||||
|
@ -149,6 +167,9 @@ uintptr_t _mi_random_init(uintptr_t seed /* can be zero */) {
|
|||
LARGE_INTEGER pcount;
|
||||
QueryPerformanceCounter(&pcount);
|
||||
x ^= (uintptr_t)(pcount.QuadPart);
|
||||
#elif defined __APPLE__
|
||||
int64_t time = rdtsc();
|
||||
x ^= time;
|
||||
#else
|
||||
struct timespec time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||
|
|
Loading…
Add table
Reference in a new issue