+ if (pg) {
+ unsigned char *ptr;
+
+ if (posix_memalign((void *)&ptr, pg,
+ SILC_ST_GET_SIZE_ALIGN(size, pg) + pg))
+ return NULL;
+
+ /* The inaccessible page too will include the allocation information
+ so that we can get it when access violation occurs in that page. */
+ stack = (SilcStBlock)(ptr + SILC_ST_GET_SIZE_ALIGN(size, pg));
+ stack->size = size;
+
+ /* Protect the page */
+ if (mprotect(stack, pg, PROT_NONE))
+ silc_st_abort(NULL, file, line, "SILC_MALLOC: mprotect() error: %s\n",
+ errno == ENOMEM ? "Cannot allocate memory. \nYour program "
+ "leaks memory, allocates too much or system \n"
+ "is out of memory. The SILC_MALLOC_PROTECT cannot "
+ "be used." : strerror(errno));
+
+ /* Get the accessible page */
+ stack = SILC_ST_GET_STACK_ALIGN(ptr, size, pg);
+ } else {
+ stack = (SilcStBlock)malloc(SILC_ST_GET_SIZE(size));
+ if (!stack)
+ return NULL;
+ }