Commits on Source 6

  • Nathan Herring's avatar
    feat: implement and export Windows CRT stat32i64 and stat64i32 · 3bdce13c
    Nathan Herring authored
    When transpiling SQLite 3.53.0 and its test harnesses (`testfixture`) for
    Windows targets (`windows/amd64`, `windows/386`, `windows/arm64`) using `ccgo`,
    SQLite's Windows VFS (`os_win.c`) references the MSVC/MinGW C runtime stat
    variants `_stat32i64`, `__stat32i64`, and `__stat64i32`.
    
    Previously, `modernc.org/libc` did not export these symbols, causing code
    generation and Go builds to fail with undefined symbol errors:
      * `undefined: libc.X_stat32i64`
      * `undefined: libc.X__stat32i64`
      * `undefined: libc.X__stat64i32`
    
    This change implements `X_stat32i64`, `X__stat32i64`, and `X__stat64i32` in
    `libc_windows.go` (routing to the underlying 64-bit stat implementation) and
    exports them across `capi_windows_386.go`, `capi_windows_amd64.go`, and
    `capi_windows_arm64.go`, allowing SQLite 3.53.0 and Windows test fixtures
    to link and generate successfully.
    3bdce13c
  • cznic's avatar
    Merge branch 'windows-crt-stat' into 'master' · b286527a
    cznic authored
    feat: implement and export Windows CRT stat32i64 and stat64i32
    
    See merge request !32
    b286527a
  • Nathan Herring's avatar
    feat: export Linux Open File Description (OFD) lock constants · 8c74913e
    Nathan Herring authored and cznic's avatar cznic committed
    Adds support for Linux Open File Description (OFD) locks (`F_OFD_GETLK = 36`,
    `F_OFD_SETLK = 37`, `F_OFD_SETLKW = 38`) to enable file-descriptor-scoped
    POSIX locking in downstream packages like `modernc.org/sqlite`.
    
    1. Exports `F_OFD_GETLK`, `F_OFD_SETLK`, and `F_OFD_SETLKW` in
       `fcntl/fcntl_linux_amd64.go` with C header provenance comments matching
       `ccgo -header` output.
    2. Updates `genheaders.go` to prepend `#define _GNU_SOURCE 1` when generating
       `fcntl` headers. Because Linux `F_OFD_*` constants are guarded by
       `#ifdef __USE_GNU` in `<bits/fcntl-linux.h>`, defining `_GNU_SOURCE`
       ensures these constants are not stripped during future regenerations.
    
       > [!NOTE]
       > While running `ccgo -header` with `_GNU_SOURCE` on `<fcntl.h>` exposes ~123 additional Linux/GNU extension symbols (such as `O_TMPFILE`, `O_PATH`, `SPLICE_F_*`, `FALLOC_FL_*`, and `F_SEAL_*`), we intentionally cherry-picked only the three `F_OFD_*` constants into `fcntl_linux_amd64.go` to keep the diff minimal and avoid slurping in unrelated API surface.
    
    3. Adds `internal/overlay/musl/src/fcntl/fcntl.c` as a musl overlay to route
       the new OFD commands through `SYS_fcntl` with `(void *)arg` pointer casting
       and cancellation point handling (`syscall_cp`).
    
    For reviewer convenience, the exact diff of the overlay against upstream musl's
    `src/fcntl/fcntl.c` is:
    
    ```diff
    --- a/src/fcntl/fcntl.c
    +++ b/src/fcntl/fcntl.c
    @@ -15,1 +15,1 @@
    -	if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
    +	if (cmd == F_SETLKW || cmd == F_OFD_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
    @@ -41,2 +41,4 @@
     	case F_SETLK:
     	case F_GETLK:
    +	case F_OFD_SETLK:
    +	case F_OFD_GETLK:
     	case F_GETOWN_EX:
    ```
    8c74913e
  • cznic's avatar
    Merge branch 'ofd-lock-constants' into 'master' · 9a5e53c7
    cznic authored
    feat: export Linux Open File Description (OFD) lock constants (sqlite#255)
    
    See merge request !33
    9a5e53c7
  • cznic's avatar
    fcntl: add F_OFD_{GETLK,SETLK,SETLKW} to the remaining linux targets · 2ad2e820
    cznic authored
    Completes !33, which added the open file description (OFD) lock command
    constants for linux/amd64 only. The values 36, 37 and 38 come from the
    kernel's asm-generic fcntl.h and are identical on all supported linux
    architectures, mips64le included.
    
    Co-Authored-By: default avatarClaude Fable 5 <noreply@anthropic.com>
    2ad2e820
  • cznic's avatar
    fix: restart sleep syscalls interrupted by the Go runtime's own signals · f4e070f6
    cznic authored
    A program translated to Go by ccgo shares its process with the Go runtime,
    which sends SIGURG to a thread to preempt goroutines asynchronously. The
    kernel then fails an in-progress nanosleep(2) with ERESTART_RESTARTBLOCK,
    which becomes EINTR for any signal that has a handler installed - the Go
    runtime's does - and SA_RESTART does not apply to that code. musl reports the
    interruption faithfully, but its callers routinely discard the return value.
    SQLite's unixSleep() is one, so its default busy handler loses whole steps of
    its 1, 2, 5, ... 25, 50, 100 ms back-off and gives up before the timeout the
    caller asked for: measured waits for a 1100 ms busy_timeout came out anywhere
    between 801 ms and 1101 ms, all a multiple of 25 ms short.
    
    That surfaces as sporadic, target-independent failures of upstream SQLite's
    timing assertions - busy2-2.2.* and walsetlk-2.2.* ("the busy wait must last
    longer than 900 ms") - in modernc.org/libsqlite3's Tcl suite. Interleaved runs
    of busy2.test + walsetlk.test on linux/amd64: 5 of 8 runs failed with libc as
    released, 0 of 8 with this change.
    
    ___syscall_cp() now restarts nanosleep(2) and clock_nanosleep(2), including
    the 32-bit time64 variant, for the time the kernel reports as remaining;
    TIMER_ABSTIME sleeps are simply re-issued, their deadline being unchanged.
    When the caller passed no place for the remaining time to be reported, one is
    supplied from the TLS: the kernel writes it in the same layout it reads the
    request in, so it can be handed back as the next request unchanged, which
    keeps this free of any per-target struct timespec knowledge.
    
    Note this makes sleeps on the musl targets uninterruptible by C-installed
    signal handlers too, which is already how the hand-written darwin, freebsd,
    netbsd and openbsd ports behave - their Xnanosleep sleeps in Go and can never
    be interrupted. Making it conditional on the translated program having
    installed a handler of its own is possible, but the two paths would then
    disagree, and a translated program cannot install one without displacing the
    Go runtime's handler for that signal anyway.
    
    Only sleeps are restarted here. Every other blocking syscall reached through
    ___syscall_cp() can still report a spurious EINTR to C code that does not
    retry; those need the same treatment if they turn up.
    
    Co-Authored-By: default avatarClaude Fable 5 <noreply@anthropic.com>
    f4e070f6
Loading
Loading