X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1566092327; bh=HFvZUGKGcX82f5TU6+Lm3BPb5fAUNgIDV0prdC7ja04=; h=Subject:From:To:Date:Message-ID; b=YsMNdlxErZHUXLuNdI8dtAt5h06DslBZW2AJmfh546qijf2BQtG3Fhm9QdQqz5R1/ gUqYxi9Bnh7z5Wxv9n1YcIBrTwBqY3T7EgPyanHx6dzm+rOotO4RoAbydVVVvNH3/l CGUlRklWt/hA/JvjkwbaXE0UolyzIfoaR/F935Ck= Authentication-Results: mxback19o.mail.yandex.net; dkim=pass header.i=@yandex.ru To: djgpp AT delorie DOT com From: "Stas Sergeev (stsp2 AT yandex DOT ru) [via djgpp AT delorie DOT com]" Subject: [PATCH] process: make descriptor leak work-around conditional Message-ID: <6df014b9-33da-d336-7508-2034a8ef197a@yandex.ru> Date: Sun, 18 Aug 2019 04:38:46 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------24E1DCF9B6393E59B4E308BC" Content-Language: en-MW Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------24E1DCF9B6393E59B4E308BC Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit This patch replaces the patch I sent previously under the Subject [PATCH] exec: fix inversions in leak detection logic The logic was not inverted; rather that code tested __dpmi_free_ldt_descriptor() to see if it works. Since it always works, I would suggest to remove the tests. The attached patch doesn't mess with that and simply adds a variable to control the behaviour. --------------24E1DCF9B6393E59B4E308BC Content-Type: text/x-patch; name="0001-process-make-descriptor-leak-work-around-conditional.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-process-make-descriptor-leak-work-around-conditional.pa"; filename*1="tch" From 12d00dab0e179b4ec1c5a6a7d6e93eb907ef606d Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sat, 17 Aug 2019 19:00:10 +0300 Subject: [PATCH] process: make descriptor leak work-around conditional This patch adds the __spawn_flags variable and __spawn_leak_workaround flag to allow the software to control the leak work-around. Previous behaviour was to always enable the work-around unless the DPMI host is cwsdpmi. Without this patch it is not possible to spawn a prot-mode TSR program like 32rtm. djgpp treats it as a leak and wipes out of memory. With this patch things work properly if the DPMI server is smart enough to direct the control to prev client after 32rtm TSRed. The problem is that 32rtm just jumps to the realmode exit addr, so the DPMI server doesn't see the exit and may get confused unless the special logic is implemented for that case (i.e. not all DPMI servers treat that correctly even after that patch). --- include/process.h | 4 ++++ src/libc/dos/process/dosexec.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/process.h b/include/process.h index 2816ce25..e57467d4 100644 --- a/include/process.h +++ b/include/process.h @@ -52,6 +52,10 @@ int __djgpp_spawn(int _mode, const char *_path, char *const _argv[], char *const #define SPAWN_EXTENSION_SRCH 1 #define SPAWN_NO_EXTENSION_SRCH 2 +#define __spawn_leak_workaround 0x0001 /* free descriptor leaks */ + +extern int __spawn_flags; + #endif /* !_POSIX_SOURCE */ #endif /* !__STRICT_ANSI__ */ #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */ diff --git a/src/libc/dos/process/dosexec.c b/src/libc/dos/process/dosexec.c index 87d7fbd9..d547a31f 100644 --- a/src/libc/dos/process/dosexec.c +++ b/src/libc/dos/process/dosexec.c @@ -45,6 +45,7 @@ extern char **_environ; int __dosexec_in_system = 0; +int __spawn_flags = __spawn_leak_workaround; typedef struct { unsigned short eseg; @@ -492,7 +493,8 @@ static int direct_exec_tail (const char *program, const char *args, /* r5 as corresponding DPMI call is supported beginning with v5. */ ret = __dpmi_get_capabilities(&flags, dpmi_vendor); - if (ret == 0 && strcmp(dpmi_vendor + 2, "CWSDPMI") == 0) + if ((ret == 0 && strcmp(dpmi_vendor + 2, "CWSDPMI") == 0) + || (__spawn_flags & __spawn_leak_workaround) == 0) workaround_descriptor_leaks = 0; else { -- 2.20.1 --------------24E1DCF9B6393E59B4E308BC--