I have 2GiB RAM, running Perl 5.8.8 on Linux 2.6.

Whenever I open /dev/mem the call succeeds (that is I can get a filehandle on it), but also error 25 "Inappropriate ioctl for device" is returned. I don't know what that is supposed to mean.

$ok = sysopen my $mem, '/dev/mem', O_RDWR;

Following some suggestions in the open(2) manpage I tried to get rid of it by |ing (binary or) the mode with O_DIRECT and O_NONBLOCK and variations thereof, but it only made it worse, I get 22 "Invalid argument" and the call fails.

sysread()ing works up to address hex 38000000 (only ~896 MiB), then fails with error 14 "Bad address". Experiment from the shell supports it:

$ sudo cat /dev/mem > memdump cat: /dev/mem: Bad address

However, I can successfully sysseek() to any address in the file (even though error 25 is set again).

sysread()ing from /proc/$pid/mem is totally useless, it always fails with error 3 "No such process", even though sysopen()ing and sysseek()ing do succeed.

How comes all that strange behaviour, and why is that so?

How do I know where each program is located, anyway? I had a look at /proc/$pid/maps, but it's impossible that dozens of processes occupy overlapping or even exact same space after hex 8000000. Reading from /dev/mem at that point also returns garbage, well, at least not the garbage I expect.


In reply to messing with memory by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.