observe physical address content











up vote
0
down vote

favorite












I compile and run the pagemap_dump.c from here :



/proc/[pid]/pagemaps and /proc/[pid]/maps | linux



and another application attach a exist shared memory and every time I run pagemap_dump , the shared memory's physical address is really the same (virtual memory address is different each time I observe) :



./pagemap_dump.exe 2135  <== 2135 is pid  
./pagemap_dump.exe 5864 <== 5864 is pid
./pagemap_dump.exe 5110 <== 5110 is pid


the output :



7fabb37e1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7f0040fa1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7ffbd2869000 54edde 0 1 0 1 /dev/shm/memtest.shared


these 3 application attach memtest.shared and their physical address are all 0x54edde in my linux ,
then I try to access the contents from /dev/mem in this
physical address :



How to access physical addresses from user space in Linux?



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_RDONLY|O_SYNC);
unsigned char *mem = (unsigned char *) mmap(NULL, page_offset + len, PROT_READ , MAP_SHARED, 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;
} // main


chown root testz1.exe



chmod 4775 testz1.exe



./testz1.exe  5565918  16    <=== 0x54edde = 5565918


I got Can't map memory: Operation not permitted



./testz1.exe 54edde 16


I got some thing not like "hello world" what I strcpy to
/dev/shm/memtest.shared when I create it .



Since I seems to get the physical address of /dev/shm/memtest.shared , how can I get the right way to get the contents from /dev/mem of this physical address ?!



Edit :



After download devmem2.c and run :



./devmem2.exe 0x54edde w   


get the following message :



/dev/mem opened.
Error at line 75, file devmem2.c (1) [Operation not permitted]



Look like 0x54edde is not a physical address as I expect , but Why it happened?!
pagemap_dump.c really show the physical address of /dev/shm/memtest.shared
for all processes which attach it the value 0x54edde , then Why
devmem2.c can not access it right ?!










share|improve this question
























  • does the result differ with sudo?
    – Nikita Malyavin
    Nov 8 at 9:16










  • @Nikita , I use sudo or chown root && chmod 4775 to run this application , both get the same result , and not "hello world" .
    – barfatchen
    Nov 8 at 22:43















up vote
0
down vote

favorite












I compile and run the pagemap_dump.c from here :



/proc/[pid]/pagemaps and /proc/[pid]/maps | linux



and another application attach a exist shared memory and every time I run pagemap_dump , the shared memory's physical address is really the same (virtual memory address is different each time I observe) :



./pagemap_dump.exe 2135  <== 2135 is pid  
./pagemap_dump.exe 5864 <== 5864 is pid
./pagemap_dump.exe 5110 <== 5110 is pid


the output :



7fabb37e1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7f0040fa1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7ffbd2869000 54edde 0 1 0 1 /dev/shm/memtest.shared


these 3 application attach memtest.shared and their physical address are all 0x54edde in my linux ,
then I try to access the contents from /dev/mem in this
physical address :



How to access physical addresses from user space in Linux?



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_RDONLY|O_SYNC);
unsigned char *mem = (unsigned char *) mmap(NULL, page_offset + len, PROT_READ , MAP_SHARED, 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;
} // main


chown root testz1.exe



chmod 4775 testz1.exe



./testz1.exe  5565918  16    <=== 0x54edde = 5565918


I got Can't map memory: Operation not permitted



./testz1.exe 54edde 16


I got some thing not like "hello world" what I strcpy to
/dev/shm/memtest.shared when I create it .



Since I seems to get the physical address of /dev/shm/memtest.shared , how can I get the right way to get the contents from /dev/mem of this physical address ?!



Edit :



After download devmem2.c and run :



./devmem2.exe 0x54edde w   


get the following message :



/dev/mem opened.
Error at line 75, file devmem2.c (1) [Operation not permitted]



Look like 0x54edde is not a physical address as I expect , but Why it happened?!
pagemap_dump.c really show the physical address of /dev/shm/memtest.shared
for all processes which attach it the value 0x54edde , then Why
devmem2.c can not access it right ?!










share|improve this question
























  • does the result differ with sudo?
    – Nikita Malyavin
    Nov 8 at 9:16










  • @Nikita , I use sudo or chown root && chmod 4775 to run this application , both get the same result , and not "hello world" .
    – barfatchen
    Nov 8 at 22:43













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I compile and run the pagemap_dump.c from here :



/proc/[pid]/pagemaps and /proc/[pid]/maps | linux



and another application attach a exist shared memory and every time I run pagemap_dump , the shared memory's physical address is really the same (virtual memory address is different each time I observe) :



./pagemap_dump.exe 2135  <== 2135 is pid  
./pagemap_dump.exe 5864 <== 5864 is pid
./pagemap_dump.exe 5110 <== 5110 is pid


the output :



7fabb37e1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7f0040fa1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7ffbd2869000 54edde 0 1 0 1 /dev/shm/memtest.shared


these 3 application attach memtest.shared and their physical address are all 0x54edde in my linux ,
then I try to access the contents from /dev/mem in this
physical address :



How to access physical addresses from user space in Linux?



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_RDONLY|O_SYNC);
unsigned char *mem = (unsigned char *) mmap(NULL, page_offset + len, PROT_READ , MAP_SHARED, 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;
} // main


chown root testz1.exe



chmod 4775 testz1.exe



./testz1.exe  5565918  16    <=== 0x54edde = 5565918


I got Can't map memory: Operation not permitted



./testz1.exe 54edde 16


I got some thing not like "hello world" what I strcpy to
/dev/shm/memtest.shared when I create it .



Since I seems to get the physical address of /dev/shm/memtest.shared , how can I get the right way to get the contents from /dev/mem of this physical address ?!



Edit :



After download devmem2.c and run :



./devmem2.exe 0x54edde w   


get the following message :



/dev/mem opened.
Error at line 75, file devmem2.c (1) [Operation not permitted]



Look like 0x54edde is not a physical address as I expect , but Why it happened?!
pagemap_dump.c really show the physical address of /dev/shm/memtest.shared
for all processes which attach it the value 0x54edde , then Why
devmem2.c can not access it right ?!










share|improve this question















I compile and run the pagemap_dump.c from here :



/proc/[pid]/pagemaps and /proc/[pid]/maps | linux



and another application attach a exist shared memory and every time I run pagemap_dump , the shared memory's physical address is really the same (virtual memory address is different each time I observe) :



./pagemap_dump.exe 2135  <== 2135 is pid  
./pagemap_dump.exe 5864 <== 5864 is pid
./pagemap_dump.exe 5110 <== 5110 is pid


the output :



7fabb37e1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7f0040fa1000 54edde 0 1 0 1 /dev/shm/memtest.shared
7ffbd2869000 54edde 0 1 0 1 /dev/shm/memtest.shared


these 3 application attach memtest.shared and their physical address are all 0x54edde in my linux ,
then I try to access the contents from /dev/mem in this
physical address :



How to access physical addresses from user space in Linux?



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_RDONLY|O_SYNC);
unsigned char *mem = (unsigned char *) mmap(NULL, page_offset + len, PROT_READ , MAP_SHARED, 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;
} // main


chown root testz1.exe



chmod 4775 testz1.exe



./testz1.exe  5565918  16    <=== 0x54edde = 5565918


I got Can't map memory: Operation not permitted



./testz1.exe 54edde 16


I got some thing not like "hello world" what I strcpy to
/dev/shm/memtest.shared when I create it .



Since I seems to get the physical address of /dev/shm/memtest.shared , how can I get the right way to get the contents from /dev/mem of this physical address ?!



Edit :



After download devmem2.c and run :



./devmem2.exe 0x54edde w   


get the following message :



/dev/mem opened.
Error at line 75, file devmem2.c (1) [Operation not permitted]



Look like 0x54edde is not a physical address as I expect , but Why it happened?!
pagemap_dump.c really show the physical address of /dev/shm/memtest.shared
for all processes which attach it the value 0x54edde , then Why
devmem2.c can not access it right ?!







linux memory mmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 6:53

























asked Nov 8 at 5:00









barfatchen

631928




631928












  • does the result differ with sudo?
    – Nikita Malyavin
    Nov 8 at 9:16










  • @Nikita , I use sudo or chown root && chmod 4775 to run this application , both get the same result , and not "hello world" .
    – barfatchen
    Nov 8 at 22:43


















  • does the result differ with sudo?
    – Nikita Malyavin
    Nov 8 at 9:16










  • @Nikita , I use sudo or chown root && chmod 4775 to run this application , both get the same result , and not "hello world" .
    – barfatchen
    Nov 8 at 22:43
















does the result differ with sudo?
– Nikita Malyavin
Nov 8 at 9:16




does the result differ with sudo?
– Nikita Malyavin
Nov 8 at 9:16












@Nikita , I use sudo or chown root && chmod 4775 to run this application , both get the same result , and not "hello world" .
– barfatchen
Nov 8 at 22:43




@Nikita , I use sudo or chown root && chmod 4775 to run this application , both get the same result , and not "hello world" .
– barfatchen
Nov 8 at 22:43

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201804%2fobserve-physical-address-content%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53201804%2fobserve-physical-address-content%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings