printf("begin allocating\n");
mem = (char*)aligned_malloc(MSPACE);
char err = mprotect((void*)mem, page_size,PROT_READ|PROT_WRITE);
if (err<0) perror("mprotect");
printf("Done allocating mem0=%lx err=%d\n",mem,err);
printf("reading mem[0]%d\n",mem[0]);
printf("writing to mem[0]:\n");
mem[0]=20;
printf("mem[0] is now %d\n", mem[0]);
printf("All done!");
}
i get this error:
mem2.c: In function 'main':
mem2.c:22: error: too few arguments to function 'aligned_malloc'
mem2.c:32:2: warning: no newline at end of file
If anyone knows whats wrong please help and if you can be as specific as possible i would appreciate it.
what im trying to do with the program is to protect arbitrary memory adresses. I tried it using malloc and it didnt work so i added the aligned malloc function. All of this code was given to me by my professor and what he said i had to do was add the function and change the line in main to use aligned_malloc() instead of malloc(). I guess from what your saying i need to add size and psize,but i dont know what i have to do to do that with what im given.
What the function wants to do is allocate a piece of memory that is "size" bytes long and return a pointer to it, with the caveat that the returned pointer must be aligned on a "psize" byte boundary. ie, the address returned modulo psize must be zero.