From: Florent Bruneau Date: Sun, 28 Sep 2008 09:34:38 +0000 (+0200) Subject: mprotect locked arrays. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=5973bedba6892b8100467801c39d1364a5bfd617;p=apps%2Fpfixtools.git mprotect locked arrays. Signed-off-by: Florent Bruneau --- diff --git a/common/array.h b/common/array.h index 86cf360..0ca70de 100644 --- a/common/array.h +++ b/common/array.h @@ -160,13 +160,20 @@ array_wipe(array); \ } while (0) +#define array_byte_len(array) (array).len * sizeof(*(array).data) + #define array_lock(array) \ - ((array).locked || \ - (mlock((array).data, (array).len * sizeof(*(array).data)) == 0 \ - && ((array).locked = true))) + ((array).locked \ + || (mprotect((array).data, array_byte_len(array), PROT_READ) == 0 \ + && mlock((array).data, array_byte_len(array)) == 0 \ + && ((array).locked = true)) \ + || (mprotect((array).data, array_byte_len(array), \ + PROT_READ | PROT_WRITE) > 0)) #define array_unlock(array) \ if ((array).locked) { \ - (void)munlock((array).data, (array).len * sizeof(*(array).data)); \ + (void)munlock((array).data, array_byte_len(array)); \ + (void)mprotect((array).data, array_byte_len(array), \ + PROT_READ | PROT_WRITE); \ (array).locked = false; \ }