diff --git a/src/native/entropy_cpu_stubs.c b/src/native/entropy_cpu_stubs.c index cef0c1cf..05375d83 100644 --- a/src/native/entropy_cpu_stubs.c +++ b/src/native/entropy_cpu_stubs.c @@ -111,14 +111,22 @@ static inline uint32_t read_virtual_count (void) #endif /* arm */ #if defined (__aarch64__) -#define isb() __asm__ __volatile__("isb" : : : "memory") +#if defined(__ocaml_freestanding__) || defined(__ocaml_solo5__) static inline uint64_t read_virtual_count(void) { uint64_t c; - isb(); - __asm__ __volatile__("mrs %0, cntvct_el0":"=r"(c)); + __asm__ __volatile__("mrs %0, PMCCNTR_EL0":"=r"(c)); return c; } +#else +/* see https://github.com/mirage/mirage-crypto/issues/216 */ +static inline uint64_t read_virtual_count (void) +{ + struct timespec now; + clock_gettime (CLOCK_MONOTONIC, &now); + return now.tv_nsec; +} +#endif /* __ocaml_freestanding__ || __ocaml_solo5__ */ #endif /* aarch64 */ #if defined (__powerpc64__)