From c7e373b0f84e1c2c0c6a5cbb44321ea8d991389b Mon Sep 17 00:00:00 2001 From: otya Date: Mon, 8 Mar 2021 17:10:08 +0900 Subject: [PATCH] krnl386.exe16: Fix heap size determination process. Improve #617 --- krnl386/ne_module.c | 3 --- krnl386/ne_segment.c | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/krnl386/ne_module.c b/krnl386/ne_module.c index f306b14ad64..983e56cd4ca 100644 --- a/krnl386/ne_module.c +++ b/krnl386/ne_module.c @@ -697,9 +697,6 @@ static HMODULE16 build_module( const void *mapping, SIZE_T mapping_size, LPCSTR if (!(pModule->ne_flags & NE_FFLAGS_LIBMODULE) && (pModule->ne_stack < 0x1400)) pModule->ne_stack = 0x1400; - if (pModule->ne_heap && (pModule->ne_heap < 0x800)) - pModule->ne_heap = 0x800; - pModule->self = hModule; pModule->mapping = mapping; pModule->mapping_size = mapping_size; diff --git a/krnl386/ne_segment.c b/krnl386/ne_segment.c index 4fa1113de71..fab38ddc075 100644 --- a/krnl386/ne_segment.c +++ b/krnl386/ne_segment.c @@ -1050,8 +1050,30 @@ BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum ) return TRUE; /* all but DGROUP only allocated once */ minsize = pSeg->minsize ? pSeg->minsize : 0x10000; - if ( segnum == pModule->ne_autodata ) minsize += pModule->ne_stack; - if ( segnum == pModule->ne_autodata ) minsize += pModule->ne_heap; + + minsize += 2; + + if ( segnum == pModule->ne_autodata ) + { + minsize += pModule->ne_stack; + if (pModule->ne_heap > 0 && pModule->ne_heap < 0x800) + { + if (minsize + 0x800 > 0x10000) + { + if (pModule->ne_heap < 0x100) + { + pModule->ne_heap = 0x100; + } + } + else + { + pModule->ne_heap = 0x800; + } + } + minsize += pModule->ne_heap; + if (!(pModule->ne_flags & NE_FFLAGS_BUILTIN) && minsize >= 0x10000) + return FALSE; + } selflags = (pSeg->flags & NE_SEGFLAGS_DATA) ? WINE_LDT_FLAGS_DATA : WINE_LDT_FLAGS_CODE; if (pSeg->flags & NE_SEGFLAGS_32BIT) selflags |= WINE_LDT_FLAGS_32BIT;