From c3f79872f16fb625bab8c4edc451f2029ffcad25 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Wed, 3 Aug 2022 09:59:08 -0700 Subject: [PATCH] Update memory allocator function (#434) * Missing include unistd.h for getpagesize() * Update from valloc() to posix_memalign() for large aligned allocations --- src/ldsout.c | 3 +-- src/llcolor.c | 1 + src/truecolor.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ldsout.c b/src/ldsout.c index 5102461..6b25c6f 100644 --- a/src/ldsout.c +++ b/src/ldsout.c @@ -172,8 +172,7 @@ int sysout_loader(const char *sysout_file_name, int sys_size) { /* allocate Virtual Memory Space */ - lispworld_scratch = valloc(sys_size * MBYTE); - if (lispworld_scratch == NULL) { + if (posix_memalign((void *)&lispworld_scratch, getpagesize(), sys_size * MBYTE) != 0) { fprintf(stderr, "sysout_loader: can't allocate Lisp %dMBytes VM \n", sys_size); exit(-1); } diff --git a/src/llcolor.c b/src/llcolor.c index b80cd70..595b44a 100644 --- a/src/llcolor.c +++ b/src/llcolor.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "lispemul.h" #include "lispmap.h" diff --git a/src/truecolor.c b/src/truecolor.c index e85b15a..c8bb453 100644 --- a/src/truecolor.c +++ b/src/truecolor.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "lispemul.h" #include "lsptypes.h" @@ -309,7 +310,6 @@ void truecolor_before_exit() { } /* truecolor_before_exit */ -char *valloc(); char *HideOverlayRegion; #ifdef VIDEO char *HideVideoEnableRegion; @@ -323,8 +323,8 @@ void truecolor_before_raid() { if (Inited_TrueColor) { size = ((displaywidth * displayheight / 8 + (getpagesize() - 1)) & -getpagesize()); - if ((HideOverlayRegion = valloc(size)) == 0) { - printf("can't valloc hide space\n"); + if (posix_memalign((void *)&HideOverlayRegion, getpagesize(), size) != 0) { + printf("can't allocate hide space\n"); return (-1); } /* end if( HideOverlayRegion ) */ @@ -343,8 +343,8 @@ void truecolor_before_raid() { #ifdef VIDEO if (Inited_Video) { if ((video_onoff = Video_OnOff_Flg)) Video_OnOff(FALSE); - if ((HideVideoEnableRegion = valloc(size)) == 0) { - printf("can't valloc hide space\n"); + if (posix_memalign((void *)&HideVideoEnableRegion, getpagesize(), size) != 0) { + printf("can't allocate hide space\n"); return (-1); } /* end if( HideVideoEnableRegion ) */