Ticket #9416: 0001-Added-capability-to-accept-writes-to-dev-random.patch

File 0001-Added-capability-to-accept-writes-to-dev-random.patch, 2.4 KB (added by fishpond, 7 years ago)
  • src/add-ons/kernel/drivers/random/driver.cpp

    From 7ea096298970b3084b3bc8dc7dfe9ca5bc272a48 Mon Sep 17 00:00:00 2001
    From: fishpond <kai.niessen@online.de>
    Date: Fri, 1 Feb 2013 22:24:50 +0100
    Subject: [PATCH] Added capability to accept writes to dev/random 
     modified:   driver.cpp
    
    ---
     src/add-ons/kernel/drivers/random/driver.cpp |   29 +++++++++++++++++++-------
     1 file changed, 21 insertions(+), 8 deletions(-)
    
    diff --git a/src/add-ons/kernel/drivers/random/driver.cpp b/src/add-ons/kernel/drivers/random/driver.cpp
    index a5853e4..920f3bf 100644
    a b reseed(ch_randgen *prandgen, const uint32 initTimes)  
    189189{
    190190    volatile uint32 i, j;
    191191    OCTET x, y;
     192   
     193    x.Q[0] = 0;
    192194
    193195    for (j = initTimes; j; j--) {
    194196        for (i = NK * initTimes; i; i--) {
    random_read(void *cookie, off_t position, void *_buffer, size_t *_numBytes)  
    402404    int32 *buffer = (int32 *)_buffer;
    403405    uint8 *buffer8 = (uint8 *)_buffer;
    404406    uint32 i, j;
    405     TRACE((DRIVER_NAME ": read(%Ld,, %d)\n", position, *_numBytes));
     407    TRACE((DRIVER_NAME ": read(%Ld,, %ld)\n", position, *_numBytes));
    406408
    407409    mutex_lock(&sRandomLock);
    408410    sRandomCount += *_numBytes;
    random_read(void *cookie, off_t position, void *_buffer, size_t *_numBytes)  
    430432static status_t
    431433random_write(void *cookie, off_t position, const void *buffer, size_t *_numBytes)
    432434{
    433     TRACE((DRIVER_NAME ": write(%Ld,, %d)\n", position, *_numBytes));
    434     *_numBytes = 0;
    435     return EINVAL;
     435    size_t i;
     436    OCTET* data;
     437    TRACE((DRIVER_NAME ": write(%Ld,, %ld)\n", position, *_numBytes));
     438    mutex_lock(&sRandomLock);
     439    data = (OCTET*)buffer;
     440    for (i = 0; i < *_numBytes / sizeof(OCTET); i++) {
     441        chseed(sRandomEnv, data->Q[0]);
     442        data++;
     443    }
     444    mutex_unlock(&sRandomLock);
     445    return B_OK;
    436446}
    437447
    438448
    439449static status_t
    440450random_control(void *cookie, uint32 op, void *arg, size_t length)
    441451{
    442     TRACE((DRIVER_NAME ": ioctl(%d)\n", op));
     452    TRACE((DRIVER_NAME ": ioctl(%ld)\n", op));
    443453    return B_ERROR;
    444454}
    445455
    random_select(void *cookie, uint8 event, uint32 ref, selectsync *sync)  
    473483        notify_select_event(sync, event);
    474484#endif
    475485    } else if (event == B_SELECT_WRITE) {
    476         /* we're not writable */
    477         return EINVAL;
     486        /* we're now writable */
     487#ifndef HAIKU_TARGET_PLATFORM_HAIKU
     488        notify_select_event(sync, ref);
     489#else
     490        notify_select_event(sync, event);
     491#endif
    478492    }
    479 
    480493    return B_OK;
    481494}
    482495