Chris Jacobson <fear@ATHENET.NET> writes: > I re-wrote parts of the stl.llist.h LList<> template, to use protected > memory on the nodes. It boiled down to protecting the nodes during add, > prepend, append, insertafter, insertbefore, with an unprotection to any > node requiring editing (at most, one node, and only in Append and the > Insert functions), which would be re-protected. > > I used two macros: > > #define PROTECT(a) mprotect(a, sizeof(*a), PROT_READ) > #define UNPROTECT(a) mprotect(a, sizeof(*a), PROT_READ | PROT_WRITE) You definitely should check the results... these will fail if *a doesn't use a multiple of pagesize bytes. From the man page: EINVAL addr is not a valid pointer, or not a multiple of PAGESIZE. So an mprotect on an improperly aligned buffer (ie not starting on a multiple of PAGESIZE and being a multiple of PAGESIZE) will fail and not change the protection of the memory. -- James Turner turnerjh@xtn.net http://www.vuse.vanderbilt.edu/~turnerjh/ +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST