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 ?!
linux memory mmap
add a comment |
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 ?!
linux memory mmap
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
add a comment |
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 ?!
linux memory mmap
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
linux memory mmap
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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