File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -704,7 +704,22 @@ static void configure_memory()
704704 " mallopt(M_MMAP_MAX, -1) failed\n " );
705705 }
706706#endif
707- char *buf = static_cast <char *>(malloc (PRE_ALLOC_SIZE));
707+ /*
708+ * The following code seems pointless, but there is a non-observable effect
709+ * in the allocation and loop.
710+ *
711+ * The malloc() is forced to set brk() because mmap() allocation is
712+ * disabled in a call to mallopt() above. All touched pages become resident
713+ * and locked in the loop because of above mlockall() call (see notes in
714+ * mlockall(2)). The mallopt() trim setting prevents the brk() from being
715+ * reduced after free(), effectively creating an open space for future
716+ * allocations that will not generate page faults.
717+ *
718+ * The qualifier 'volatile' on the buffer pointer is required because newer
719+ * clang would remove the malloc(), for()-loop and free() completely.
720+ * Marking 'buf' volatile ensures that the code will remain in place.
721+ */
722+ volatile char *buf = static_cast <volatile char *>(malloc (PRE_ALLOC_SIZE));
708723 if (buf == NULL ) {
709724 rtapi_print_msg (RTAPI_MSG_WARN, " malloc(PRE_ALLOC_SIZE) failed\n " );
710725 return ;
@@ -717,7 +732,7 @@ static void configure_memory()
717732 * memory and never given back to the system. */
718733 buf[i] = 0 ;
719734 }
720- free (buf);
735+ free (( void *) buf);
721736}
722737
723738static int harden_rt ()
You can’t perform that action at this time.
0 commit comments