Opened 15 months ago

Closed 13 months ago

Last modified 10 months ago

#71265 closed enhancement (fixed)

Adding pthread_[f]chdir_np to legacy-support - contribution guidelines?

Reported by: RJVB (René Bertin) Owned by: fhgwright (Fred Wright)
Priority: Normal Milestone:
Component: legacy-support Version:
Keywords: Cc: fhgwright (Fred Wright), mascguy (Christopher Nielsen)
Port: legacy-support

Description (last modified by RJVB (René Bertin))

I have come across an application (not currently in MacPorts; Firefox Dynasty for "legacy" systems) that can make an unprotected call to pthread_chdir_np or pthread_fchdir_np, two functions that were introduced in 10.12 but were available as syscalls from 10.5 onwards.

Based on old Chromium code it should be possible to provide these functions on 10.11 and earlier with a pair of simple wrappers:

int pthread_chdir_np(const char* dir)
{
  return syscall(SYS___pthread_chdir, dir);
}

int pthread_fchdir_np(int fd)
{
  return syscall(SYS___pthread_fchdir, fd);
}

I realise port:legacy-support is mainly intended for use with MacPorts and doesn't aim to provide every possible missing symbol, so I'd be perfectly happy with some guidelines or pointers how to add these 2 wrappers the proper way in a personal fork of the repo (i.e. in such a way that they only get included on 10.11 and earlier).

EDIT: I attached a proof of concept implementation that works for me on 10.9 , based on my understanding of the implementation for other added symbols.

Reason I'm filing a trac ticket is that there is no dedicated issue tracker, and the application in question could make a valuable new port for other owners of retro systems (i.e. Firefox v132 that runs on at least 10.8 and up).

(I did try to contribute a patch "upstream" but let's just say that my efforts weren't appreciated and the maintainer not particularly interested in bug reports but more in calling names on here).

Attachments (1)

patch-add-pthread_chdir_np.diff (4.6 KB) - added by RJVB (René Bertin) 15 months ago.
draft implementation

Download all attachments as: .zip

Change History (6)

Changed 15 months ago by RJVB (René Bertin)

draft implementation

comment:1 Changed 15 months ago by RJVB (René Bertin)

Description: modified (diff)

Re: the patch: I'm not certain about the "dummy symbols" (which is what they seem to be) in add_symbols.c, nor if __MPLS_SDK_SUPPORT_PTHREAD_CHDIR_NP__ should be used.

Judging from 3rd party code using these functions it would appear that they are not defined in any header files but are usually defined with availability macro:

extern "C" {
 int pthread_chdir_np(const char* dir) API_AVAILABLE(macosx(10.12));
 int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12));
}

Does this mean they should actually be defined conditionally to avoid compilation errors in case the above definitions evaluate to empty space?

Last edited 15 months ago by RJVB (René Bertin) (previous) (diff)

comment:2 Changed 13 months ago by fhgwright (Fred Wright)

Owner: set to fhgwright
Resolution: fixed
Status: newclosed

In bc334c521d2ab159429fba4587d2152297f10cb5/macports-legacy-support (master):

Provide pthread_[f]chdir_np() functions for 10.5+.

This provides both missing prototypes and missing function wrappers
for the pthread_[f]chdir_np() functions, which were introduced as
syscalls in 10.5, but not provided as functions until 10.12, and
not provided as prototypes at all in any SDK.

At present, no SDK for any OS version provides prototypes for these
functions, even when the functions themselves are included in
libSystem. For that reason, we condition the addition of the
prototypes on the flag _MACPORTS_LEGACY_PTHREAD_CHDIR. This is
ignored in the 10.4 SDK, since the functions themselves are not
available in 10.4.

The missing function wrappers are provided for 10.5-10.11. For 10.4,
dummy functions that always fail are provided, though no SDK
declarations are present in the 10.4 SDK, even with the enabling flag.

Closes: #71265

TESTED:
Passes all tests on all platforms, including the new test.

comment:3 Changed 13 months ago by fhgwright (Fred Wright)

In e5cdc7ae6e22afebb2a5df15e7588dfdc2662fd9/macports-ports (master):

legacy-support-devel: Update to latest master.

Notable changes since last -devel version:

  • Fixes 10.4 Rosetta bug in fstatx_np()
  • Makes renameat() available via stdio.h See: #71842
  • Implements interim clock_gettime_nsec_np() See: #61691
  • Implements clock_settime() See: #71399
  • Adds net/if_tun.h for <10.6 See: #70231
  • Provides pthread_[f]chdir_np() for 10.5+ See: #71265
  • Adds CPU_TYPE_ARM definition for 10.4 See: #71621

Also adds Portfile comments regarding suggested github.tarball_from
change.

Also, the prior addition of vdprintf() in v20241026 neglected to close
the related tickets:

Closes: #67598
Closes: #70118

TESTED:
Tested both normal and -devel versions -/+universal on 10.4-10.5 ppc,
10.5-10.6 ppc (i386 Rosetta), 10.4-10.6 i386, 10.4-12.x x86_64, and
11.x-15.x arm64.
Builds and passes all tests on all tested platforms.

comment:4 Changed 12 months ago by fhgwright (Fred Wright)

In a784d15ced04e75724ee259cec1f7a3d1ab696d3/macports-ports (master):

legacy-support: update to v1.4.0.

Notable changes since v1.3.0:

  • Works around Apple's broken versioning in the macOS 15 SDK
  • Implements scandir() compatibility feature
  • Fixes dprintf() bug and implements vdprintf() See: #67598 See: #70118
  • Mismatched SDK compatibility is extended to include 15.x SDK.
  • Broken 10.4 CLOCK_MONOTONIC is fixed.
  • Fixes stat inconsistency in some 32-bit 10.4 builds.
  • Adds stat64 header support for 10.4 SDK.
  • Adds INODE64 support for *stat*() on 10.4.
  • Reworks fstatat*() support, similar to previous item, fixing buffer overrun in some cases.
  • Backports 10.5 'which' to 10.4.
  • Adds support for code that can't tolerate the normal scandir() compatibility feature.
  • Replaces broken 10.4/10.5 copyfile wrapper with full 10.6 copyfile.
  • Extends 10.4 INODE64 support to *statx_np() functions.
  • Expands TARGET_* defaults. See: #70824
  • Fixes 10.4 Rosetta bug in fstatx_np()
  • Makes renameat() available via stdio.h See: #71842
  • Implements interim clock_gettime_nsec_np() See: #61691
  • Implements clock_settime() See: #71399
  • Adds net/if_tun.h for <10.6 See: #70231
  • Provides pthread_[f]chdir_np() for 10.5+ See: #71265
  • Adds CPU_TYPE_ARM definition for 10.4 See: #71621

TESTED:
Tested both normal and -devel versions -/+universal on 10.4-10.5 ppc,
10.5-10.6 ppc (i386 Rosetta), 10.4-10.6 i386, 10.4-12.x x86_64, and
11.x-15.x arm64.
Builds and passes all tests on all tested platforms.

comment:5 Changed 10 months ago by mascguy (Christopher Nielsen)

Component: portslegacy-support

Recategorize existing legacy-support lib tickets, to use new component definition.

Note: See TracTickets for help on using tickets.