Skip to content

Conversation

@gboddin
Copy link

@gboddin gboddin commented Jan 31, 2026

Description

This PR fixes a panic occurring on FreeBSD (and potentially macOS/other BSDs) where mmap fails with EINVAL (invalid argument).

The Issue

Currently, mmap_unix.go passes 0 as the file descriptor (fd) when calling syscall.SYS_MMAP with MAP_ANON.

  • On Linux: The kernel ignores the fd argument for anonymous mappings, so passing 0 works fine.
  • On FreeBSD: The kernel strictly adheres to POSIX behavior for MAP_ANON, which requires the fd to be -1. Passing 0 results in an immediate crash.

Panic Output (FreeBSD):

panic: invalid argument
goroutine 1 [running]:
[github.com/bytedance/sonic/loader.mmap](https://github.com/bytedance/sonic/loader.mmap)(...)
    .../loader/mmap_unix.go:35 +0x7b

@CLAassistant
Copy link

CLAassistant commented Jan 31, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants