none
When is it safe to read the memory returned by MmMapIoSpace from an ISR in other routine?

    Question

  • I am observing an issue while enabling interrupts in my serial driver. 

    I have two separate drivers. One controller driver for driving the controller and a serial driver which controls all the ports on that controller. Hence there will be multiple instances of serial port driver whose device contexts will be passed to the controller driver and stored during installation of serial drivers. these will be cleared during uninstallation of serial driver. 

    During installation of the serial driver i am enabling the interrupts on the serial port. because of this the serial port generates an interrupt which results in controller driver ISR being called. Controller ISR checks for an interrupt status register (using the mapped memory address passed to it by port driver during initialization of the driver) and and calls a function in serial port driver which does the actual job the servicing the interrupt.

    My serial port generates this interrupt "X" immediately after i enable it in the interrupt enable register of this port. 

    I am observing this crash in ISR only when i am enabling a specific interrupt "X' in DoEntry() function. When i enable this interrupt much later, i.e. in the first write request that comes to the driver, i am not facing any issue.
    Hence phrasing my issue and my question in a more straight forward way,

    Issue:
    I am unable to access device registers immediately after i enable interrupts in the serial port device. However i am able to access the device registers after some duration.
    Question:

    When exactly it is safe to access the memory returned by MmapIoSpace() function? Please note, I need to access this memory from another driver(controller driver).


    It looks like it is too soon to touch this memory even during DoEntry() function. I am currently mapping this physical memory in MmapIospace() function. 

    Saturday, August 09, 2014 7:09 AM

Answers

All replies

  • First why do you have an architecture that maps the I/O space in one driver then passes it for use by another driver?  This is legal but it is definitely unusual, since normally the physical address would be passed and the controller driver would map the registers.   It is safe to access the memory as soon as the call returns with a non-NULL pointer.  What may not be legal is how your device responds to memory access in some power states, but this is a function of your hardware, not the operating system.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Saturday, August 09, 2014 10:59 AM
  • The mapped address space is available immediately upon return from MmMapIoSpace

     -Brian


    Azius Developer Training www.azius.com Windows device driver, internals, security, & forensics training and consulting. Blog at www.azius.com/blog

    Tuesday, August 12, 2014 11:27 PM
    Moderator