Skip to content

Instantly share code, notes, and snippets.

@run
Created February 19, 2015 06:22
Show Gist options
  • Save run/73848de4b159539f4612 to your computer and use it in GitHub Desktop.
Save run/73848de4b159539f4612 to your computer and use it in GitHub Desktop.

Revisions

  1. Runzhen created this gist Feb 19, 2015.
    32 changes: 32 additions & 0 deletions user.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #include <sys/mman.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdio.h>

    #define PAGE_SIZE (4 * 1024)

    #define KERNEL_PHY_ADDR 0x77128000
    int main()
    {
    char *buf;
    int fd;

    fd = open(“/dev/mem”,O_RDWR);
    if (fd == -1)
    perror(“open”);

    buf = mmap(0, PAGE_SIZE,
    PROT_READ|PROT_WRITE, MAP_SHARED,
    fd, KERNEL_PHY_ADDR);

    if (buf == MAP_FAILED)
    perror(“mmap”);

    puts(buf);

    munmap(buf,PAGE_SIZE);

    close(fd);
    return 0;
    }