Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8415067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:20:23+00:00 2026-06-10T01:20:23+00:00

On a ARM based system running Linux, I have a device that’s memory mapped

  • 0

On a ARM based system running Linux, I have a device that’s memory mapped to a physical address. From a user space program where all addresses are virtual, how can I read content from this address?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:20:25+00:00Added an answer on June 10, 2026 at 1:20 am

    You can map a device file to a user process memory using mmap(2) system call. Usually, device files are mappings of physical memory to the file system.
    Otherwise, you have to write a kernel module which creates such a file or provides a way to map the needed memory to a user process.

    Another way is remapping parts of /dev/mem to a user memory.

    Edit:
    Example of mmaping /dev/mem (this program must have access to /dev/mem, e.g. have root rights):

    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    #include <unistd.h>
    
    int main(int argc, char *argv[]) {
        if (argc < 3) {
            printf("Usage: %s <phys_addr> <offset>\n", argv[0]);
            return 0;
        }
    
        off_t offset = strtoul(argv[1], NULL, 0);
        size_t len = strtoul(argv[2], NULL, 0);
    
        // Truncate offset to a multiple of the page size, or mmap will fail.
        size_t pagesize = sysconf(_SC_PAGE_SIZE);
        off_t page_base = (offset / pagesize) * pagesize;
        off_t page_offset = offset - page_base;
    
        int fd = open("/dev/mem", O_SYNC);
        unsigned char *mem = mmap(NULL, page_offset + len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, page_base);
        if (mem == MAP_FAILED) {
            perror("Can't map memory");
            return -1;
        }
    
        size_t i;
        for (i = 0; i < len; ++i)
            printf("%02x ", (int)mem[page_offset + i]);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ARM based machine with ubuntu distro on it and it often
I have an ARM project that I'm building with make. I'm creating the list
I have a requirement to integrate a web server into an embedded device running
I plan to develop a nice little application that will run on an arm-based
I'm using an ARM Cortex-A8 based processor called as i.MX515. There is linux Ubuntu
I'm making use of an ARM Cortex-A8 based processor and I have several places
I'm encountering the following error at unpredictable times in a linux-based (arm) communications application:
I'm trying to use MPU3000/3050 by Invensense with embedded linux (ARM-based LPC3141 board, Embedded
I've been hacking away on an ARM based device (Freescale i.MX27 ADS) with a
I'm looking for Microcontrollers based on the ARM Cortex-M3. The MCU should have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.