# include <unistd.h>
# include <sys/types.h>
# include <sys/mman.h>
+# if defined(OPENSSL_SYS_LINUX)
+# include <sys/syscall.h>
+# include <linux/mman.h>
+# include <errno.h>
+# endif
# include <sys/param.h>
# include <sys/stat.h>
# include <fcntl.h>
* These are the functions that must be implemented by a secure heap (sh).
*/
static int sh_init(size_t size, int minsize);
-static char *sh_malloc(size_t size);
-static void sh_free(char *ptr);
+static void *sh_malloc(size_t size);
+static void sh_free(void *ptr);
static void sh_done(void);
static size_t sh_actual_size(char *ptr);
static int sh_allocated(const char *ptr);
if (mprotect(sh.map_result + aligned, pgsize, PROT_NONE) < 0)
ret = 2;
+#if defined(OPENSSL_SYS_LINUX) && defined(MLOCK_ONFAULT) && defined(SYS_mlock2)
+ if (syscall(SYS_mlock2, sh.arena, sh.arena_size, MLOCK_ONFAULT) < 0) {
+ if (errno == ENOSYS) {
+ if (mlock(sh.arena, sh.arena_size) < 0)
+ ret = 2;
+ } else {
+ ret = 2;
+ }
+ }
+#else
if (mlock(sh.arena, sh.arena_size) < 0)
ret = 2;
+#endif
#ifdef MADV_DONTDUMP
if (madvise(sh.arena, sh.arena_size, MADV_DONTDUMP) < 0)
ret = 2;
return chunk;
}
-static char *sh_malloc(size_t size)
+static void *sh_malloc(size_t size)
{
ossl_ssize_t list, slist;
size_t i;
return chunk;
}
-static void sh_free(char *ptr)
+static void sh_free(void *ptr)
{
size_t list;
- char *buddy;
+ void *buddy;
if (ptr == NULL)
return;