Why driver in kernel mode must be very careful about directly reading from or writing to addresses in user space? -
from msdn:
drivers run in kernel mode must careful directly reading or writing addresses in user space. scenario illustrates why.
- a user-mode program initiates request read data device. program supplies starting address of buffer receive data.
- a device driver routine, running in kernel mode, starts read operation , returns control caller.
- later device interrupts whatever thread running read operation complete. interrupt handled kernel-mode driver routines running on arbitrary thread, belongs arbitrary process.
- at point, driver must not write data starting address user-mode program supplied in step 1. address in virtual address space of process initiated request, not same current process.
can explain in other words? points 2, 3, 4 not clear. thanks.
each process has own "context" of execution includes data structures (page tables) used in virtual physical address translation.
at point of time, virtual address physical address mapping depends on executing process @ time.
take following scenario :
a user-mode program (say "process-a" single thread) initiates read request , passes user-space buffer address.
this read request reaches device driver routine, running in kernel mode. likely, actual read operation device hardware take time complete. in case, driver routine may not wait completion of operation. instead, start read operation device, , return immedietly. in activity, operating system notified read opeartion has started not completed yet. os put process-a in waiting state, , schedule other process (thread) in execution.
later when device completes reading operation, raise interrupt notify this. @ time, arbitrary process (say "process-b") in execution. page tables reflecting virtual physical address space mapping process-b. driver routine called servicing interrupt running in context of process-b.
at point, accessing virtual address provided user-mode program @ step-1 access virtual address corresponding process-b , not of process-a.
see "methods accessing data buffers" different approches transfer data user-space kernel-mode routines.
Comments
Post a Comment