secmem.c on OS X

Gordon Worley redbird at rbisland.cx
Sat Sep 15 06:05:01 CEST 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 9:24 PM -0400 9/14/01, Gordon Worley wrote:
>Thanks to Laurie Brown <laurieb at mac.com> we have a version of
>secmem.c that makes mlock work on OS X.  I've pasted a diff below.
>Anyway, I'm brining this here to see what needs to be done to get
>this fix implemented (I realize that patching config.h is not the
>right thing to do, but it's the thing that she got working :-)).

A few minutes late, but better than never:  testing code:

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>

int main()
{
     char *pool;
     int err;
     long int pgsize = getpagesize();

     pool = malloc( 4096 + pgsize );
     if( !pool )
         return 2;
     pool += (pgsize - ((long int)pool % pgsize));

     err = mlock( pool, 4096 );
     if( !err || errno == EPERM ) {
         return 0; /* okay */
     } else {
         /* check to see if mlock needs the memory permissions set */
         mprotect( pool, 4096, PROT_EXEC | PROT_WRITE | PROT_READ);
         err = mlock( pool, 4096 );
         if ( !err || errno == EPERM )
              return 3; /* okay - but have to set memory permissions */
     return 1;  /* hmmm */
     }
}
- -- 
Gordon Worley                     `When I use a word,' Humpty Dumpty
http://www.rbisland.cx/            said, `it means just what I choose
redbird at rbisland.cx                it to mean--neither more nor less.'
PGP:  0xBBD3B003                                  --Lewis Carroll

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
Comment: keyserver http://pgpkeys.mit.edu:11371

iQA/AwUBO6LE627zd/e707ADEQJ5YQCgk85XUGGyKIVAmwQjsgffqjaBSpYAnjHr
wmjcwxwiiKUh75EqDEdwvfIx
=/6aY
-----END PGP SIGNATURE-----




More information about the Gnupg-devel mailing list