From 1c5e4d066f6cfd65cc5ad729ce6e8aff53e20939 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sun, 12 Dec 2021 17:57:55 +0100 Subject: [PATCH] krnl386.exe: Page-align the GlobalAlloc() size when the selector limit is in pages. GlobalSize() uses the selector limit and that needs to match the allocated size. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52082 Signed-off-by: Alexandre Julliard --- dlls/krnl386.exe16/global.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dlls/krnl386.exe16/global.c b/dlls/krnl386.exe16/global.c index 0a8da28e99b..2eb02b8cef3 100644 --- a/dlls/krnl386.exe16/global.c +++ b/dlls/krnl386.exe16/global.c @@ -196,6 +196,7 @@ HGLOBAL16 GLOBAL_Alloc( UINT16 flags, DWORD size, HGLOBAL16 hOwner, unsigned cha { void *ptr; HGLOBAL16 handle; + DWORD align = 0x1f; TRACE("%d flags=%04x\n", size, flags ); @@ -205,8 +206,9 @@ HGLOBAL16 GLOBAL_Alloc( UINT16 flags, DWORD size, HGLOBAL16 hOwner, unsigned cha /* Fixup the size */ - if (size >= GLOBAL_MAX_ALLOC_SIZE - 0x1f) return 0; - size = (size + 0x1f) & ~0x1f; + if (size > 0x100000) align = 0xfff; /* selector limit will be in pages */ + if (size >= GLOBAL_MAX_ALLOC_SIZE - align) return 0; + size = (size + align) & ~align; /* Allocate the linear memory */ ptr = HeapAlloc( get_win16_heap(), 0, size );