Skip to content

purego: remove pooling of syscall (#452)#453

Merged
hajimehoshi merged 1 commit into
ebitengine:0.10from
hajimehoshi:pool
May 24, 2026
Merged

purego: remove pooling of syscall (#452)#453
hajimehoshi merged 1 commit into
ebitengine:0.10from
hajimehoshi:pool

Conversation

@hajimehoshi
Copy link
Copy Markdown
Member

What issue is this addressing?

Closes #451

What type of issue is this addressing?

bug

What this PR does | solves

This is the same as #452, but for 0.10. As a simple cherry-pick didn't work, I needed some work so I'd like to test with GitHub Actions. After the tests pass, I'll self-approve this.

(cherry picked from commit 11272d2)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 24, 2026 13:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes reuse/pooling of *syscall15Args during FFI calls to eliminate a concurrency bug where concurrent calls could observe swapped/corrupted return-value pointers (issue #451). It updates both the main RegisterFunc path and the SysV syscall_syscall15X path, and adds a regression test intended to exercise concurrent pointer returns.

Changes:

  • Remove the global sync.Pool of *syscall15Args and allocate a fresh syscall15Args per call in RegisterFunc.
  • Stop using the pool in syscall_syscall15X (SysV path) by allocating a new syscall15Args for each call.
  • Add a concurrent pointer-return regression test using malloc/free from the system C runtime.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
syscall_sysv.go Removes pooled syscall15Args usage in syscall_syscall15X to avoid cross-goroutine corruption.
func.go Removes sync.Pool usage and allocates syscall15Args per RegisterFunc invocation to fix the race.
func_test.go Adds a concurrent pointer-return test to help prevent regressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread func_test.go
Comment on lines +54 to +69
var wg sync.WaitGroup

for i := 0; i < runtime.NumCPU(); i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
for j := 0; j < 400_000; j++ {
ptr := alloc(5)
if ptr == nil {
continue
}
free(ptr)
}
}(i)
}

@hajimehoshi hajimehoshi merged commit eaff005 into ebitengine:0.10 May 24, 2026
46 checks passed
@hajimehoshi hajimehoshi deleted the pool branch May 24, 2026 13:19
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.

3 participants