From a662295409e812b208cb2a1957b37b2ef8bcc622 Mon Sep 17 00:00:00 2001 From: ParantezTech <12572227+par274@users.noreply.github.com> Date: Thu, 8 Oct 2026 23:44:39 +0300 Subject: [PATCH] [Kernel] Read random device descriptors from the host RNG Co-authored-by: Sekai <140012992+SekaixX@users.noreply.github.com> --- .../Kernel/KernelMemoryCompatExports.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SharpEmu.Libs/Kernel/KernelMemoryCompatExports.cs b/src/SharpEmu.Libs/Kernel/KernelMemoryCompatExports.cs index 6ad298e..dc1963c 100644 --- a/src/SharpEmu.Libs/Kernel/KernelMemoryCompatExports.cs +++ b/src/SharpEmu.Libs/Kernel/KernelMemoryCompatExports.cs @@ -14,6 +14,7 @@ using System.Threading; using System.Runtime.InteropServices; using System.Linq; using System.Globalization; +using System.Security.Cryptography; namespace SharpEmu.Libs.Kernel; @@ -2325,6 +2326,25 @@ public static partial class KernelMemoryCompatExports return (int)OrbisGen2Result.ORBIS_GEN2_OK; } + bool isRandomDevice; + lock (_fdGate) + { + isRandomDevice = _randomDeviceDescriptors.Contains(fd); + } + + if (isRandomDevice) + { + var randomBytes = GC.AllocateUninitializedArray(requested); + RandomNumberGenerator.Fill(randomBytes); + if (!ctx.Memory.TryWrite(bufferAddress, randomBytes)) + { + return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT; + } + + ctx[CpuRegister.Rax] = unchecked((ulong)requested); + return (int)OrbisGen2Result.ORBIS_GEN2_OK; + } + if (KernelSocketCompatExports.TryReadSocketFd( ctx, fd,