X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Recipient: dj AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=dsivDusxaaxjzrXgmaG3xi9w950gkHwXRZa0hn0gloQ=; b=e34zAb8Je+Kk kPcZ9vqzxBcw4tV1MORgHQRJY2krKLQvmK00YOVprY5sAt60sofDOhHFjZtv0Ell0FasZKKhNCHMK yI87gFkvCDA3hUQZ1Lv0S78A51zfqXHMrSnhke4w4cafUCeb4k1pM4MZNo50ifTLd5tK6cSnTXGa+ JhLpJhSRNEOG1u+Nf0q9i4JzmPyrgm/Qtj7OHqLj0X9ANk+KyJJxVlmFHlpuvBYljvPAgwL5ZOTSh yB4DB4xrr0fz5/Oh0WL5E+qOqWwX2L/e0I9MZsBx5ETRnDR5e94XljdSodVR94wd9cmQnwRGMUkoV luvtgAwzqxrnCGv11jSwdw==; Date: Thu, 21 Mar 2024 08:31:16 +0200 Message-Id: <86plvo2j0r.fsf@gnu.org> From: "Eli Zaretskii (eliz AT gnu DOT org) [via djgpp AT delorie DOT com]" To: Pali , "Charles Sandmann" Cc: dj AT delorie DOT com, sezeroz AT gmail DOT com, djgpp AT delorie DOT com In-Reply-To: <20240320203330.clmkn2s4rr4obq4u@pali> (message from Pali on Wed, 20 Mar 2024 21:33:30 +0100) Subject: Re: Error handling in __djgpp_nearptr_enable() References: <20240309111216 DOT fetp6m34nbe6u63y AT pali> <20240320203330 DOT clmkn2s4rr4obq4u AT pali> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Date: Wed, 20 Mar 2024 21:33:30 +0100 > From: Pali > Cc: djgpp AT delorie DOT com > > Hello, I observed strange issue that __djgpp_nearptr_enable() function > when running in NTVDM on Windows XP, on failure let segment limit in > some undefined/intermediate state. > > Test case: > > #include > #include > #include > #include > #include > > int main() { > unsigned long addr; > if (__dpmi_get_segment_base_address(_my_ds(), &addr) == 0) > printf("OLD BASE: 0x%lx\n", addr); > printf("OLD LIMIT: 0x%lx\n", __dpmi_get_segment_limit(_my_ds())); > printf("CALLING __djgpp_nearptr_enable()\n"); > if (__djgpp_nearptr_enable()) > printf("SUCCESS\n"); > else > printf("FAILED\n"); > if (__dpmi_get_segment_base_address(_my_ds(), &addr) == 0) > printf("NEW BASE: 0x%lx\n", addr); > printf("NEW LIMIT: 0x%lx\n", __dpmi_get_segment_limit(_my_ds())); > return 0; > } > > It prints: > > OLD BASE: 0x29e0000 > OLD LIMIT: 0x9ffff > CALLING __djgpp_nearptr_enable() > FAILED > NEW BASE: 0x29e0000 > NEW LIMIT: 0x7d60ffff > > I know that Windows NT kernel does not allow userspace to create a > segment with access to kernel memory space (above 0x7fff0000 limit). > So failure from the __djgpp_nearptr_enable() call in NTVDM is expected. > But I was not expecting that DJGPP in some cases may let segment limit > in some intermediate state. > > What about following DJGPP change? I think it can improve failure > behavior of __djgpp_nearptr_enable() when 4 GB DS limit is not allowed. > > --- src/libc/pc_hw/nearptr/nearptr.c > +++ src/libc/pc_hw/nearptr/nearptr.c > @@ -14,7 +14,10 @@ int __djgpp_nearptr_enable(void) > { > if(!__dpmi_set_segment_limit(_my_ds(), 0xffffffffU)) { > if(__dpmi_get_segment_limit(_my_ds()) != 0xffffffffU) > + { > + __dpmi_set_segment_limit(_my_ds(), __djgpp_selector_limit | 0xfff); > return 0; /* We set it but DPMI ignored/truncated it */ > + } > __dpmi_set_segment_limit(__djgpp_ds_alias, 0xffffffffU); > __dpmi_set_segment_limit(_my_cs(), 0xffffffffU); > _crt0_startup_flags |= _CRT0_FLAG_NEARPTR; What are the implications of this change, in plain English, in particular for DPMI hosts other than NTVDM? (It would be best to actually test this with at least the popular hosts, including CWSDPMI and perhaps also versions of Windows newer than XP that still support DPMI in a reasonable enough manner that allows running |DJGPP programs.) I'm CC'ing Charles, in the hope that he is available and can comment on this. Btw, the DJGPP FAQ explicitly says that __djgpp_nearptr_enable fails on Windows NT family (i.e. with NTVDM). So strictly speaking, a program that calls __djgpp_nearptr_enable in that case is shooting itself in the foot...