* [PATCH] Cygwin: cygheap: fix fork error after heap has grown
@ 2023-04-13 2:35 David McFarland
2023-04-13 12:53 ` David McFarland
2023-04-13 16:16 ` Corinna Vinschen
0 siblings, 2 replies; 6+ messages in thread
From: David McFarland @ 2023-04-13 2:35 UTC (permalink / raw)
To: cygwin-developers; +Cc: David McFarland
2f9b8ff0 introduced a problem where forks would sometimes fail with:
child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows pid 14032, Win32 error 299
When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be set to
allocsize(cygheap_max), which is an address, not a size. VirtualAlloc would be
called to commit commit_size bytes, which would fail, and then child_copy would
be called with zero as the base address.
---
winsup/cygwin/mm/cygheap.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc
index 6a20c159a..d614fc7a9 100644
--- a/winsup/cygwin/mm/cygheap.cc
+++ b/winsup/cygwin/mm/cygheap.cc
@@ -87,7 +87,7 @@ cygheap_fixup_in_child (bool execed)
SIZE_T commit_size = CYGHEAP_STORAGE_INITIAL - CYGHEAP_STORAGE_LOW;
if (child_proc_info->cygheap_max > (void *) CYGHEAP_STORAGE_INITIAL)
- commit_size = allocsize (child_proc_info->cygheap_max);
+ commit_size = allocsize (child_proc_info->cygheap_max) - CYGHEAP_STORAGE_LOW;
cygheap = (init_cygheap *) VirtualAlloc ((LPVOID) CYGHEAP_STORAGE_LOW,
CYGHEAP_STORAGE_HIGH
- CYGHEAP_STORAGE_LOW,
--
2.39.0.windows.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Cygwin: cygheap: fix fork error after heap has grown
2023-04-13 2:35 [PATCH] Cygwin: cygheap: fix fork error after heap has grown David McFarland
@ 2023-04-13 12:53 ` David McFarland
2023-04-13 16:16 ` Corinna Vinschen
1 sibling, 0 replies; 6+ messages in thread
From: David McFarland @ 2023-04-13 12:53 UTC (permalink / raw)
To: cygwin-developers
David McFarland <corngood@gmail.com> writes:
> 2f9b8ff0 introduced a problem where forks would sometimes fail with:
>
> child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows pid 14032, Win32 error 299
>
> When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be set to
> allocsize(cygheap_max), which is an address, not a size. VirtualAlloc would be
> called to commit commit_size bytes, which would fail, and then child_copy would
> be called with zero as the base address.
> ---
> winsup/cygwin/mm/cygheap.cc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc
> index 6a20c159a..d614fc7a9 100644
> --- a/winsup/cygwin/mm/cygheap.cc
> +++ b/winsup/cygwin/mm/cygheap.cc
> @@ -87,7 +87,7 @@ cygheap_fixup_in_child (bool execed)
> SIZE_T commit_size = CYGHEAP_STORAGE_INITIAL - CYGHEAP_STORAGE_LOW;
>
> if (child_proc_info->cygheap_max > (void *) CYGHEAP_STORAGE_INITIAL)
> - commit_size = allocsize (child_proc_info->cygheap_max);
> + commit_size = allocsize (child_proc_info->cygheap_max) - CYGHEAP_STORAGE_LOW;
> cygheap = (init_cygheap *) VirtualAlloc ((LPVOID) CYGHEAP_STORAGE_LOW,
> CYGHEAP_STORAGE_HIGH
> - CYGHEAP_STORAGE_LOW,
It might be better to do the subtraction before the call to allocsize,
but this should still work in practice. I'll wait for more feedback
before I post another patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Cygwin: cygheap: fix fork error after heap has grown
2023-04-13 2:35 [PATCH] Cygwin: cygheap: fix fork error after heap has grown David McFarland
2023-04-13 12:53 ` David McFarland
@ 2023-04-13 16:16 ` Corinna Vinschen
2023-04-18 0:25 ` David McFarland
1 sibling, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2023-04-13 16:16 UTC (permalink / raw)
To: David McFarland; +Cc: cygwin-developers
Hi David,
On Apr 12 23:35, David McFarland wrote:
> 2f9b8ff0 introduced a problem where forks would sometimes fail with:
>
> child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows pid 14032, Win32 error 299
>
> When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be set to
> allocsize(cygheap_max), which is an address, not a size. VirtualAlloc would be
> called to commit commit_size bytes, which would fail, and then child_copy would
> be called with zero as the base address.
Can you please append
Fixes: 2f9b8ff00cce ("Cygwin: decouple cygheap from Cygwin DLL")
Signed-off-by: David McFarland <your email address>
?
> ---
> winsup/cygwin/mm/cygheap.cc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc
> index 6a20c159a..d614fc7a9 100644
> --- a/winsup/cygwin/mm/cygheap.cc
> +++ b/winsup/cygwin/mm/cygheap.cc
> @@ -87,7 +87,7 @@ cygheap_fixup_in_child (bool execed)
> SIZE_T commit_size = CYGHEAP_STORAGE_INITIAL - CYGHEAP_STORAGE_LOW;
>
> if (child_proc_info->cygheap_max > (void *) CYGHEAP_STORAGE_INITIAL)
> - commit_size = allocsize (child_proc_info->cygheap_max);
> + commit_size = allocsize (child_proc_info->cygheap_max) - CYGHEAP_STORAGE_LOW;
Good catch! Please move the subtraction of CYGHEAP_STORAGE_LOW into the
allocsize call, along the lines of the other usage of allocsize in _csbrk.
Is that what you mean in your followup mail, perhaps?
Thanks!
Corinna
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Cygwin: cygheap: fix fork error after heap has grown
2023-04-13 16:16 ` Corinna Vinschen
@ 2023-04-18 0:25 ` David McFarland
2023-04-18 0:41 ` David McFarland
0 siblings, 1 reply; 6+ messages in thread
From: David McFarland @ 2023-04-18 0:25 UTC (permalink / raw)
To: cygwin-developers
Corinna Vinschen <corinna-cygwin@cygwin.com> writes:
> Can you please append
>
> Fixes: 2f9b8ff00cce ("Cygwin: decouple cygheap from Cygwin DLL")
> Signed-off-by: David McFarland <your email address>
>
> ?
Sure.
>
> Good catch! Please move the subtraction of CYGHEAP_STORAGE_LOW into the
> allocsize call, along the lines of the other usage of allocsize in _csbrk.
>
> Is that what you mean in your followup mail, perhaps?
Yeah, exactly. I'll follow up with a new patch.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] Cygwin: cygheap: fix fork error after heap has grown
2023-04-18 0:25 ` David McFarland
@ 2023-04-18 0:41 ` David McFarland
2023-04-18 8:14 ` Corinna Vinschen
0 siblings, 1 reply; 6+ messages in thread
From: David McFarland @ 2023-04-18 0:41 UTC (permalink / raw)
To: cygwin-developers; +Cc: David McFarland
2f9b8ff0 introduced a problem where forks would sometimes fail with:
child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows pid 14032, Win32 error 299
When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be set to
allocsize(cygheap_max), which is an address, not a size. VirtualAlloc would be
called to commit commit_size bytes, which would fail, and then child_copy would
be called with zero as the base address.
Fixes: 2f9b8ff00cce ("Cygwin: decouple cygheap from Cygwin DLL")
Signed-off-by: David McFarland <corngood@gmail.com>
---
winsup/cygwin/mm/cygheap.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/mm/cygheap.cc b/winsup/cygwin/mm/cygheap.cc
index 6a20c159a..a20ee5972 100644
--- a/winsup/cygwin/mm/cygheap.cc
+++ b/winsup/cygwin/mm/cygheap.cc
@@ -87,7 +87,8 @@ cygheap_fixup_in_child (bool execed)
SIZE_T commit_size = CYGHEAP_STORAGE_INITIAL - CYGHEAP_STORAGE_LOW;
if (child_proc_info->cygheap_max > (void *) CYGHEAP_STORAGE_INITIAL)
- commit_size = allocsize (child_proc_info->cygheap_max);
+ commit_size = allocsize ((char *) child_proc_info->cygheap_max
+ - CYGHEAP_STORAGE_LOW);
cygheap = (init_cygheap *) VirtualAlloc ((LPVOID) CYGHEAP_STORAGE_LOW,
CYGHEAP_STORAGE_HIGH
- CYGHEAP_STORAGE_LOW,
--
2.39.0.windows.2.1.gf04e877035
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Cygwin: cygheap: fix fork error after heap has grown
2023-04-18 0:41 ` David McFarland
@ 2023-04-18 8:14 ` Corinna Vinschen
0 siblings, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2023-04-18 8:14 UTC (permalink / raw)
To: David McFarland; +Cc: cygwin-developers
Hi David,
On Apr 17 21:41, David McFarland wrote:
> 2f9b8ff0 introduced a problem where forks would sometimes fail with:
>
> child_copy: cygheap read copy failed, 0x0..0x80044C750, done 0, windows pid 14032, Win32 error 299
>
> When cygheap_max was > CYGHEAP_STORAGE_INITIAL, commit_size would be set to
> allocsize(cygheap_max), which is an address, not a size. VirtualAlloc would be
> called to commit commit_size bytes, which would fail, and then child_copy would
> be called with zero as the base address.
>
> Fixes: 2f9b8ff00cce ("Cygwin: decouple cygheap from Cygwin DLL")
> Signed-off-by: David McFarland <corngood@gmail.com>
> ---
> winsup/cygwin/mm/cygheap.cc | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Patch pushed.
Thanks,
Corinna
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-04-18 8:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 2:35 [PATCH] Cygwin: cygheap: fix fork error after heap has grown David McFarland
2023-04-13 12:53 ` David McFarland
2023-04-13 16:16 ` Corinna Vinschen
2023-04-18 0:25 ` David McFarland
2023-04-18 0:41 ` David McFarland
2023-04-18 8:14 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).