On 04/09/2020 14:15, Hans Leidekker wrote:
This will cause a performance regression. SystemFunction036 (RtlGenRandom) is already an order of magnitude slower than native because it opens and closes /dev/urandom on every call. Going through wineserver makes it 2 orders of magnitude slower:
int buf[4], i; for (i = 0; i < 100000; i++) RtlGenRandom(buf, sizeof(buf));
Windows: 16 ticks Wine/open(): 209 ticks Wine/NtCreateFile(): 3612 ticks Wine/NtCreateFile()/cached: 96 ticks
We could cache the file handle to mitigate that, but then there's the risk that an application accidentally closes the handle.
Ideally we'd implement this with getrandom() on Linux. We probably don't want to split advapi32 just for this, so maybe a private ntdll export is justified here?
Another idea would be to use the Linux syscall directly, with inline asm, which should work from PE too. Right?
And if it's not present (e.g. old kernel), fallback to slow implementation.