I get a segmentation error on the first call to malloc () after protecting the memory area with mprotect (). This is a sniplet of code that allocates memory for protection:
#define PAGESIZE 4096 void* paalloc(int size){ // Allocates and aligns memory int type_size = sizeof(double); void* p; p = malloc(type_size*size+PAGESIZE-1); p = (void*)(((long) p + PAGESIZE-1) & ~(PAGESIZE-1)); return p; } void aprotect(int size, void* array){ // Protects memory after values are set int type_size = sizeof(double); if (mprotect(array, type_size*size, PROT_READ)) { perror("Couldn't mprotect"); } }
I want to use mprotect to avoid writing to my arrays (which are pre-calculated sine / cosine values). Is this a stupid idea?
mprotect , , , . , , , - , , .
mprotect
, mprotect ( ), , malloc , .
malloc
- PAGE_SIZE - 1 malloc PAGE_SIZE * 2.
PAGE_SIZE - 1
PAGE_SIZE * 2
mmap , mprotect . , . () . .
caf , .
, mprotect(): lookup.c ( ), double get_sine(int index);. , lookup.c get_sine(), .
mprotect()
lookup.c
double get_sine(int index);
get_sine()
, mprotect():
POSIX , mprotect() , mmap (2)
(-, Linux. ?)
Source: https://habr.com/ru/post/1722101/More articles:How to use common named_scope for all ActiveRecord models - ruby ββ| fooobar.comTClientDataSet and large insert - sql-serverHow do you generate random unique identifiers in a multi-process and multi-threaded environment? - pythonThe black meaning of the interface - design-patternshow to initialize singleton? - .netHow to create a solution 3.5 using MSBuild 4.0? - msbuildhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1722103/alternatives-to-mprotect&usg=ALkJrhhvzKakAkFWdmU1stf2rB1npWfiIwasp.net: individual session variables against an object stored in a session - asp.netBest ruby ββcode documentation wiki syntax and README project files - ruby ββ| fooobar.comAre there any Monodevelop add-ons that help with refactoring? - monodevelopAll Articles