X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/92f6e64a6da763c45ff9f4ab5eafcab3d8766dcb..b60166b327a9108b07e3069fa6568a451529ffd9:/lunaix-os/hal/rng/rngx86.c?ds=sidebyside diff --git a/lunaix-os/hal/rng/rngx86.c b/lunaix-os/hal/rng/rngx86.c index 2dd6d08..0b8a586 100644 --- a/lunaix-os/hal/rng/rngx86.c +++ b/lunaix-os/hal/rng/rngx86.c @@ -1,6 +1,8 @@ #include #include +#include + static inline void rng_fill(void* data, size_t len) { @@ -24,13 +26,20 @@ __rand_rd_pg(struct device* dev, void* buf, size_t offset) static int __rand_rd(struct device* dev, void* buf, size_t offset, size_t len) { - rng_fill(buf, len); + if (unlikely(len < 4)) { + int tmp_buf = 0; + rng_fill(&tmp_buf, 4); + memcpy(buf, &tmp_buf, len); + } else { + rng_fill(buf, len); + } return len; } int pdev_randdev_init(struct device_def* devdef) { + // FIXME add check on cpuid for presence of rdrand struct device* devrand = device_allocseq(NULL, NULL); devrand->ops.read = __rand_rd; devrand->ops.read_page = __rand_rd_pg;