5

I am writing the driver that can directly write data to the frame buffer, so that I can show the secret message on the screen while the applications in user space can't get it. Below is my code that trying to write the value to the frame buffer, but after I write the value to the frame buffer, the values i retrieved from the frame buffer are all 0.

I am puzzled, anyone knows the reason? Or anyone knows how to display a message on the screen while the applications in the user space can't get the content of the message? Thanks a lot!

#define FRAME_BUFFER_PHYSICAL_ADDRESS 0xA0000
#define BUFFER_SIZE 0x20000

void showMessage()
{
    int i;
    int *vAddr;
    PHYSICAL_ADDRESS pAddr;

    pAddr.QuadPart = FRAME_BUFFER_PHYSICAL_ADDRESS;
    vAddr = (int *)MmMapIoSpace(pAddr, BUFFER_SIZE, MmNonCached);
    KdPrint(("Virtual address is %p", vAddr));

    for(i = 0; i < BUFFER_SIZE / 4; i++)
    {
        vAddr[i] = 0x11223344;
    }

    for(i = 0; i < 0x80; i++)
    {
        KdPrint(("Value: %d", vAddr[i])); // output are all zero
    }
    MmUnmapIoSpace(vAddr, BUFFER_SIZE);
}
yorath
  • 199
  • 1
  • 7

2 Answers2

1

You must map the shared memory during device start up. I assume that showMessage isn't called during the start up. See more here.

Regarding displaying message on the screen - it must involve user-space interaction since GUI is a user-space component. I suppose you could notify some GUI listener without other applications involvement.

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
1

Memory mapped IO isn't designed to act exactly like memory (retrieving data that is placed there in the same form it was stored). The writes into the 0xA0000+ range are writes into PORTS in the video device's IO space (from its perspective); So long as the appropriate writes result in the appropriate pixels lighting up, then the video device has done its job from the perspective of people that write drivers for screen rendering (or old DOS code where memory was a free-for-all without a user-space/kernel-space division). But such code never had a need to store data that would later be retrieved from the video segment. Therefore typical memory semantics would generally not have been implemented (waste of hardware and effort). Here, these randoms talk about it: Magic number with MmMapIoSpace

Community
  • 1
  • 1
Kthxbye
  • 11
  • 2