Skip to content

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

Closed
@espadolini

Description

@espadolini

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions