mmap might do most of what you want, if you're very careful. It will create a scalar tied to a specific region of memory allocated by the OS. If you are very careful with how you access it (see the docs), it will stay in that region. If OS permissions permit, you might be able to write a small module in XS or Inline::C which would use mlock to prevent the pages from being swapped out.

The biggest problem with all this is that it's very hard to tell if everything's working like it's supposed to. How do you write a test to make sure your data hasn't been exposed to the possibility of being written to swap?


In reply to Re: Can I do secure memory management in Perl scripts for cryptographic applications? by sgifford
in thread Can I do secure memory management in Perl scripts for cryptographic applications? by radiantmatrix

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.