Add the Windows CHICKEN 6 build and release scripts.

Upstream does not ship a Windows binary, so this tree fetches a release tarball, applies the MinGW patches, and publishes a UCRT64 prefix.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-09 01:09:55 +03:00
commit 4683bd4839
10 changed files with 452 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
--- a/chicken.h
+++ b/chicken.h
@@ -980,7 +980,15 @@
# ifdef HAVE_SIGPROCMASK
# define C_sigprocmask sigprocmask
# endif
-# define C_setjmp setjmp
-# define C_longjmp longjmp
+/* MinGW's setjmp longjmps through SEH and crashes in RtlVirtualUnwind
+ on the alloca frames the compiler emits. CHICKEN uses longjmp only to
+ drop back to the trampoline, so the builtin jump is the right tool. */
+# if defined(__MINGW32__) && defined(__GNUC__)
+# define C_setjmp __builtin_setjmp
+# define C_longjmp __builtin_longjmp
+# else
+# define C_setjmp setjmp
+# define C_longjmp longjmp
+# endif
# define C_alloca alloca
# define C_strerror strerror

View File

@@ -0,0 +1,38 @@
--- a/posixwin.scm
+++ b/posixwin.scm
@@ -386,10 +386,15 @@
{
if (f_share_io[i])
{
+ /* bInheritHandle is independent of DUPLICATE_SAME_ACCESS.
+ STARTF_USESTDHANDLES needs an inheritable duplicate;
+ FALSE fails CreateProcess with ERROR_INVALID_HANDLE
+ when stderr is not a console. Not the SetHandleInformation
+ pass removed for ticket 765. */
success = DuplicateHandle(
cur_process, standard_io_handles[i],
cur_process, &child_io_handles[i],
- 0, FALSE, DUPLICATE_SAME_ACCESS);
+ 0, TRUE, DUPLICATE_SAME_ACCESS);
}
else
{
--- a/posixwin.c
+++ b/posixwin.c
@@ -458,10 +458,15 @@
{
if (f_share_io[i])
{
+ /* bInheritHandle is independent of DUPLICATE_SAME_ACCESS.
+ STARTF_USESTDHANDLES needs an inheritable duplicate;
+ FALSE fails CreateProcess with ERROR_INVALID_HANDLE
+ when stderr is not a console. Not the SetHandleInformation
+ pass removed for ticket 765. */
success = DuplicateHandle(
cur_process, standard_io_handles[i],
cur_process, &child_io_handles[i],
- 0, FALSE, DUPLICATE_SAME_ACCESS);
+ 0, TRUE, DUPLICATE_SAME_ACCESS);
}
else
{

View File

@@ -0,0 +1,37 @@
To: chicken-hackers@nongnu.org
Subject: [PATCH] MinGW: use __builtin_setjmp for the GC trampoline
Hi,
On MinGW-w64 with gcc, a garbage collection that longjmps back to the trampoline can access-violate inside ntdll!RtlVirtualUnwind. I hit this with CHICKEN 6.0.0, MSYS2 UCRT64, gcc 16.2.0, on 64-bit Windows 10. The first-chance and second-chance exceptions are the same instruction: RtlVirtualUnwind reads address 0 while walking the stack. There is no earlier user-mode fault. lldb can walk that same stack by frame pointers.
C_longjmp is only used to drop back to C_restart or gc_restart (runtime.c). MinGW's setjmp/longjmp are __intrinsic_setjmpex and unwind through SEH. That unwinder faults on the alloca frames the compiler emits. Recompiling library.c at -O0 or -O1 -fno-optimize-sibling-calls does not avoid it, and raising the PE stack reserve does not either: the nursery still fills and reclaim still runs.
A cons loop that forces a major collection exits 0. Calling current-directory enough times to collect does not. That procedure allocates a C_MAX_PATH bytevector with alloca, and the fatal C_save_and_reclaim happens on that frame. Earlier reclamations in the same run succeed. The same loop crashes in a static binary and in one linked against libchicken.dll.
__builtin_setjmp / __builtin_longjmp do not run the SEH unwinder. They only restore the stack, which is what the trampoline needs. The MinGW jmp_buf is larger than the five words the builtin uses. With that change in chicken.h, and runtime.c rebuilt, the current-directory loop and a normal static program that collects during current-directory both run. Other units do not call C_setjmp.
The same substitution was attached to ticket 1453 in 2018, guarded with __MINGW64__, for an MSVC executable loading a MinGW libchicken.dll. That ticket was closed wontfix on 27 September 2026 because MSVC is unsupported, and the change was never merged. The crash here is a MinGW-hosted binary. __MINGW32__ is defined for both 32-bit and 64-bit MinGW gcc; this was observed on x86-64.
--- a/chicken.h
+++ b/chicken.h
@@ -980,7 +980,15 @@
# ifdef HAVE_SIGPROCMASK
# define C_sigprocmask sigprocmask
# endif
-# define C_setjmp setjmp
-# define C_longjmp longjmp
+/* MinGW's setjmp longjmps through SEH and crashes in RtlVirtualUnwind
+ on the alloca frames the compiler emits. CHICKEN uses longjmp only to
+ drop back to the trampoline, so the builtin jump is the right tool. */
+# if defined(__MINGW32__) && defined(__GNUC__)
+# define C_setjmp __builtin_setjmp
+# define C_longjmp __builtin_longjmp
+# else
+# define C_setjmp setjmp
+# define C_longjmp longjmp
+# endif
# define C_alloca alloca
# define C_strerror strerror

View File

@@ -0,0 +1,53 @@
To: chicken-hackers@nongnu.org
Subject: [PATCH] Windows: pass inheritable standard handles to CreateProcess
Hi,
C_process, in the C embedded in posixwin.scm, duplicates a shared standard handle with bInheritHandle = FALSE, then calls CreateProcessW with bInheritHandles = TRUE and STARTF_USESTDHANDLES. Those handles have to be inheritable. DUPLICATE_SAME_ACCESS copies the access mask only; it does not keep the inherit flag. The pipe path already sets HANDLE_FLAG_INHERIT on the child's end. The share path does not.
Commit 2477220 (ticket 765) removed a later SetHandleInformation pass that tried to mark these duplicates inheritable, because Windows 7 rejects that on some parent handles. This patch does not restore that pass. DuplicateHandle itself is allowed to create the duplicate inheritable.
When standard error is not a console, the nested call fails with ERROR_INVALID_HANDLE, which this runtime maps to EBADF. Scheme reports it as (process) cannot execute process, errno 9. A console handle often still works, so a direct csc looks fine and a program spawned with (process ...) -- stderr shared, not (process* ...) -- fails when it spawns the next process. I saw this as a static compiler whose (process "cc" ...) failed only under a piped parent. After the flag is TRUE, the same nested spawn succeeded on 12 consecutive runs.
The 6.0.0 tarball also ships this function already translated into posixwin.c. The edit there is the same, and is included below so a release tree does not keep compiling the old copy.
--- a/posixwin.scm
+++ b/posixwin.scm
@@ -386,10 +386,15 @@
{
if (f_share_io[i])
{
+ /* bInheritHandle is independent of DUPLICATE_SAME_ACCESS.
+ STARTF_USESTDHANDLES needs an inheritable duplicate;
+ FALSE fails CreateProcess with ERROR_INVALID_HANDLE
+ when stderr is not a console. Not the SetHandleInformation
+ pass removed for ticket 765. */
success = DuplicateHandle(
cur_process, standard_io_handles[i],
cur_process, &child_io_handles[i],
- 0, FALSE, DUPLICATE_SAME_ACCESS);
+ 0, TRUE, DUPLICATE_SAME_ACCESS);
}
else
{
--- a/posixwin.c
+++ b/posixwin.c
@@ -458,10 +458,15 @@
{
if (f_share_io[i])
{
+ /* bInheritHandle is independent of DUPLICATE_SAME_ACCESS.
+ STARTF_USESTDHANDLES needs an inheritable duplicate;
+ FALSE fails CreateProcess with ERROR_INVALID_HANDLE
+ when stderr is not a console. Not the SetHandleInformation
+ pass removed for ticket 765. */
success = DuplicateHandle(
cur_process, standard_io_handles[i],
cur_process, &child_io_handles[i],
- 0, FALSE, DUPLICATE_SAME_ACCESS);
+ 0, TRUE, DUPLICATE_SAME_ACCESS);
}
else
{