Skip to content

x/sys/unix: add PthreadChdir and PthreadFchdir for darwin #68226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
espadolini opened this issue Jun 27, 2024 · 2 comments
Closed

x/sys/unix: add PthreadChdir and PthreadFchdir for darwin #68226

espadolini opened this issue Jun 27, 2024 · 2 comments
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@espadolini
Copy link
Contributor

Proposal Details

Darwin has __pthread_chdir and __pthread_fchdir syscalls, wrapped (for internal use) in libpthread as pthread_chdir_np and pthread_fchdir_np (https://opensource.apple.com/source/libpthread/libpthread-454.80.2/src/pthread_cwd.c.auto.html), and used (as the latter) by projects such as Chromium. Documentation for the wrappers is also available in a private header file (https://opensource.apple.com/source/libpthread/libpthread-454.80.2/private/pthread/private.h.auto.html).

With runtime.{Lock,Unlock}OSThread and those syscalls, it's possible to handle unix sockets with absolute paths longer than the maximum for a sockaddr_un, by changing the current directory for a single thread and using a relative path, and I'm sure the ability to temporarily change directory without affecting the rest of the program can be useful in other scenarios too.

I'm opening this as a proposal because the fact that the wrappers are internal and the syscalls are double-underscored is a bit sketchy, and I'm not sure if it's ok to go:cgo_import_dynamic the wrapper functions from libSystem.B.dylib even though technically they're in libpthread.

Of note is that x/sys/unix includes the SYS___PTHREAD_CHDIR and SYS___PTHREAD_FCHDIR constants already, but using syscall numbers is deprecated on darwin, afaict.

@gopherbot gopherbot added this to the Proposal milestone Jun 27, 2024
@ianlancetaylor
Copy link
Member

Thanks. It's not necessary to open a proposal to add simple syscall wrappers to x/sys/unix. You can just send a patch. Taking this out of the proposal process.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. and removed Proposal labels Jun 27, 2024
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Unreleased Jun 27, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595677 mentions this issue: unix: add PthreadChdir and PthreadFchdir on darwin

@ianlancetaylor ianlancetaylor changed the title proposal: x/sys/unix: add PthreadChdir and PthreadFchdir for darwin x/sys/unix: add PthreadChdir and PthreadFchdir for darwin Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants