Skip to content

fix(share): normalize shm_open names with leading slash (POSIX portability) - #52

Open
davidbudzynski wants to merge 5 commits into
fastverse:masterfrom
davidbudzynski:fix/40-posix-shm-name
Open

fix(share): normalize shm_open names with leading slash (POSIX portability)#52
davidbudzynski wants to merge 5 commits into
fastverse:masterfrom
davidbudzynski:fix/40-posix-shm-name

Conversation

@davidbudzynski

Copy link
Copy Markdown
Contributor

Fixes #40

Problem

On FreeBSD 15, R CMD check fails because shareData(mtcars, "share1") errors with:

shm_open error, errno(22): Invalid argument
Error in shareData(mtcars, "share1") : * Creating file mapping...ERROR

Root cause

POSIX requires shm_open() names of the form /somename. The package only prefixed the name with / on SunOS (R/call.R), and passed bare names like "share1" everywhere else:

  • Linux silently maps any name under /dev/shm/, masking the issue.
  • macOS accepts slash-less names (\u226431 chars), masking the issue.
  • FreeBSD strictly enforces the leading slash and returns EINVAL — documented in shm_open(2): "[EINVAL] The path does not begin with a slash ('/') character."
  • Solaris already required the special case.

Changes

  1. R/call.R — replace the SunOS-only branch with a general normalization helper shmName() that ensures exactly one leading slash, applied consistently in both shareData() and getData() so create/read/unlink always use matching object IDs. No behavior change on Linux/macOS/Solaris.
  2. src/share.c — fix a bug in getMappingObjectR(): the cleanup path called munmap(length, len*sizeof(Rbyte)) on the length mapping a second time instead of unmapping addr (leaked the data mapping + wrong-size unmap).
  3. src/share.c — close the file descriptors returned by shm_open() after mappings are established instead of leaking them.
  4. tests/test_kit.R — skip the shareData checks gracefully (with a message) when POSIX shared memory is unavailable (e.g. sandboxes without /dev/shm) so one unsupported platform no longer aborts the whole test run.
  5. DESCRIPTION / NEWS.md — version bump to 0.0.22 with changelog entries.

Verification

  • Local build on macOS (R 4.6.1): full tests/test_kit.R passes; shareData/getData/clearData roundtrip verified, including that "share2" and "/share2" resolve to the same object after normalization.
  • R CMD check: tests OK, compiled code OK, examples OK.
  • FreeBSD behavior follows from documented kernel semantics (no BSD runner in CI); CI will validate Linux/Windows/macOS matrices.

Dawid Budzyński added 5 commits August 25, 2026 14:10
…X platforms

shm_open() requires names of the form /somename per POSIX. FreeBSD
enforces this strictly and fails with EINVAL when the name lacks a
leading slash, breaking shareData()/getData() (fastverse#40).
Linux and macOS silently accept slash-less names, which masked the
portability issue until now.

Replace the SunOS-only special case with a general normalization that
ensures exactly one leading slash in both shareData() and getData(),
so creation, retrieval and unlink all use consistent object IDs.
The cleanup path called munmap() on the 'length' mapping a second time
(with the data size) instead of unmapping 'addr'. This leaked the data
mapping and unmapped an already-unmapped region with a wrong size.
The descriptors returned by shm_open() were kept open for the lifetime
of the mapping although mmap() does not need them afterwards. Close
them once mappings are established to avoid leaking file descriptors
in createMappingObjectR and getMappingObjectR.
Platforms or sandboxes without working POSIX shared memory (no /dev/shm,
restricted shm_open) previously aborted the whole test run with an
unconditional error. Fall back to a skip message so the remaining
checks still execute and R CMD check can report a meaningful result.
@davidbudzynski
davidbudzynski marked this pull request as ready for review August 25, 2026 12:22
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.

testunit fails: Error in shareData(mtcars, "share1") : * Creating file mapping...ERROR

1 participant