Skip to content

Commit

Permalink
Libc-1583.0.14
Browse files Browse the repository at this point in the history
Imported from Libc-1583.0.14.tar.gz
  • Loading branch information
AppleOSSDistributions committed Sep 22, 2023
1 parent 7861c72 commit c5a3293
Show file tree
Hide file tree
Showing 208 changed files with 8,951 additions and 5,076 deletions.
10 changes: 9 additions & 1 deletion .upstream_base_commits
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ gen/FreeBSD/basename.c freebsd lib/libc/gen/basename.c 26f49abeef12bd43e9671edee
gen/FreeBSD/basename.3 freebsd lib/libc/gen/basename.3 26f49abeef12bd43e9671edee6df7b9905c97a47
gen/FreeBSD/clock.3 freebsd lib/libc/gen/clock.3 5b882020081a138285227631c46a406c08e17bc8
gen/FreeBSD/ctermid.3 freebsd lib/libc/gen/ctermid.3 5b882020081a138285227631c46a406c08e17bc8
gen/FreeBSD/exec.c freebsd lib/libc/gen/exec.c 301cb491ea417e54c29e63ebe00afbc8de47cd1f
gen/FreeBSD/fmtmsg.3 freebsd lib/libc/gen/fmtmsg.3 ae828962685b8ae9e5104ce8e7fe8b05effcb9ec
gen/FreeBSD/fmtmsg.c freebsd lib/libc/gen/fmtmsg.c 36ba9f409d639b3adcd1d2ab9672764f86f76d6b
gen/FreeBSD/getbsize.c freebsd lib/libc/gen/getbsize.c 5b882020081a138285227631c46a406c08e17bc8
gen/FreeBSD/getcwd.3 freebsd lib/libc/gen/getcwd.3 898928e8d0a0bab201c1ef232e01cafa27322dae
gen/FreeBSD/getcwd.c freebsd-src lib/libc/gen/getcwd.c c1920558b3c4efbeea4d0c833aa9cb4091533ff1
gen/FreeBSD/getpeereid.c freebsd lib/libc/gen/getpeereid.c 898928e8d0a0bab201c1ef232e01cafa27322dae
gen/FreeBSD/glob.c freebsd lib/libc/gen/glob.c ececcb3d95a00665500a1f799a118fc4eaf6750b
gen/FreeBSD/glob.3 freebsd lib/libc/gen/glob.3 ececcb3d95a00665500a1f799a118fc4eaf6750b
gen/FreeBSD/psignal.3 freebsd lib/libc/gen/psignal.3 fbbd9655e5107c68e4e0146ff22b73d7350475bc
gen/FreeBSD/psignal.c freebsd lib/libc/gen/psignal.c c1920558b3c4efbeea4d0c833aa9cb4091533ff1
gen/FreeBSD/raise3 freebsd lib/libc/gen/raise.3 6b42c90c1ff5f7c35431eced41b6213401521d3d
gen/FreeBSD/readpassphrase.c freebsd lib/libc/gen/readpassphrase.c 1f19a8fc755a14865a5a5b67d5fa895c4b7cf622
gen/FreeBSD/readpassphrase.3 freebsd lib/libc/gen/readpassphrase.3 e0a2d4f15ed9e93fcb62544ed65f7a98e2339c3b
Expand All @@ -29,6 +35,7 @@ gen/FreeBSD/vis.h freebsd-src contrib/libc-vis/unvis.3 303477d3253007bb5732deed2
gen/NetBSD/rbtree.3 netbsd share/man/man3/rbtree.3 a6d78d4a28be21d6006d3c609f31967c0e536779
gen/directory.3 freebsd lib/libc/gen/directory.3 7cbaa4254c0f10f7c00014ce9591ca60abfa57fb
gen/fts.c openbsd gen/fts.c 9936a0e983044822375a0d5cdebec20c3623866c
include/fmtmsg.h freebsd include/fmtmsg.h 9b1ae0815414ee59692bab67f726012900b3e143
include/glob.h freebsd include/glob.h ececcb3d95a00665500a1f799a118fc4eaf6750b
include/readpassphrase.h freebsd include/readpassphrase.h e0a2d4f15ed9e93fcb62544ed65f7a98e2339c3b
locale/FreeBSD/ascii.c freebsd lib/libc/locale/ascii.c 93e484e00e1e2dc498a7f4c45c0019e43b8ec5b2
Expand All @@ -53,7 +60,7 @@ stdlib/FreeBSD/atexit.3 freebsd lib/libc/stdlib/atexit 956381ee95fa01eefc74c9228
stdlib/FreeBSD/getenv.3 freebsd lib/libc/stdlib/getenv.3 3eb0ea4663f0ae19c4983e80963a121463224508
stdlib/FreeBSD/getopt.3 freebsd-src lib/libc/stdlib/getopt.3 74ba624bf0b7aa537262f12c97d487a8d8036821
stdlib/FreeBSD/getopt.c freebsd-src lib/libc/stdlib/getopt.c 0348c8fcfaa22d4f2bf548ad9c187c09ef90c533
stdlib/FreeBSD/getopt_long.3 freebsd-src lib/libc/stdlib/getopt_long.3 d50ff7de21069d65c972cb7d4e95d7fafc098117
stdlib/FreeBSD/getopt_long.3 freebsd-src lib/libc/stdlib/getopt_long.3 d646513e57c9d59a7c0cc27a4d41518110db4359
stdlib/FreeBSD/getopt_long.c freebsd-src lib/libc/stdlib/getopt_long.c 0348c8fcfaa22d4f2bf548ad9c187c09ef90c533
stdlib/FreeBSD/qsort.c freebsd lib/libc/stdlib/qsort.c 4127dd6b50348062f74679dbb43008d0a2985a09
stdlib/FreeBSD/reallocf.c freebsd lib/libc/stdlib/reallocf.c 3dc97c4341b6c5a0163c12badc7f50628cecf4e6
Expand All @@ -74,6 +81,7 @@ string/FreeBSD/strspn.3 freebsd lib/libc/string/strspn.3 5b882020081a13828522763
string/FreeBSD/strstr.3 freebsd lib/libc/string/strstr.3 cfc3df2b8f708ce8494d9d556e3472a5c8c21b8a
string/FreeBSD/timingsafe_bcmp.3 freebsd lib/libc/string/timingsafe_bcmp.3 408f4a1ab49f89368c80edb4485895658fc81598
string/FreeBSD/timingsafe_bcmp.c freebsd lib/libc/string/timingsafe_bcmp.c 408f4a1ab49f89368c80edb4485895658fc81598
tests/FreeBSD/gen/popen_test.c freebsd lib/libc/tests/gen/popen_test.c 397f4a0de5c2ffeda63fb81930d94a51bc248ff6
tests/freebsd_fmemopen.c freebsd lib/libc/tests/stdio/fmemopen2_test.c 89c1fcc0d088065021703b658ef547f46b5481f0
tests/freebsd_glob.c freebsd lib/libc/tests/gen/glob2_test.c ececcb3d95a00665500a1f799a118fc4eaf6750b
tests/freebsd_open_memstream.c freebsd lib/libc/tests/stdio/open_memstream2_test.c 89c1fcc0d088065021703b658ef547f46b5481f0
Expand Down
965 changes: 615 additions & 350 deletions Libc.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion collections/PublicHeader/_collections_set.in.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ IN_SET(,_clear)(os_set_t *s, OS_NOESCAPE IN_SET(,_payload_handler_t) handler);

OS_OVERLOADABLE OS_ALWAYS_INLINE
static inline void
os_set_clear(os_set_t *s, OS_NOESCAPE IN_SET(,_payload_handler_t) handler) {
os_set_clear(os_set_t *s, OS_NOESCAPE IN_SET(,_payload_handler_t) _Nullable handler) {
IN_SET(,_clear)(s, handler);
}

Expand Down
6 changes: 6 additions & 0 deletions darwin/_libc_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ _libc_initializer(const struct _libc_functions *funcs,
const char *apple[],
const struct ProgramVars *vars);

extern void
_libc_fork_prepare(void);

extern void
_libc_fork_parent(void);

extern void
_libc_fork_child(void);

Expand Down
8 changes: 8 additions & 0 deletions darwin/libc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifndef __LIBC_PRIVATE_H__
#define __LIBC_PRIVATE_H__

#include <mach/vm_types.h>
#include <os/availability.h>
#include <sys/cdefs.h>
#include <stddef.h>
Expand Down Expand Up @@ -62,6 +63,13 @@ extern void environ_lock_np(void);
API_AVAILABLE(macos(12.3), ios(15.4), tvos(15.4), watchos(8.5))
extern void environ_unlock_np(void);


typedef void (*backtrace_get_pcs_func_t)(vm_address_t *buffer, unsigned max,
unsigned *nb, unsigned skip, void *startfp);

API_AVAILABLE(macos(13.3), ios(16.4), tvos(16.4), watchos(9.5))
extern void backtrace_set_pcs_func(backtrace_get_pcs_func_t func);

__END_DECLS

#endif // __LIBC_PRIVATE_H__
112 changes: 89 additions & 23 deletions darwin/subsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@

#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <subsystem.h>
#include <sys/errno.h>
#include <sys/syslimits.h>
#include <_simple.h>

#define SUBSYSTEM_ROOT_PATH_KEY "subsystem_root_path"
#define SUBSYSTEM_ROOT_PATH_DELIMETER ':'
#define MAX_SUBSYSTEM_ROOT_PATHS 8

void _subsystem_init(const char *apple[]);

static char * subsystem_root_path = NULL;
static const char * subsystem_root_path = NULL;
static size_t subsystem_root_path_len = 0;

/*
Expand All @@ -43,31 +46,74 @@ static size_t subsystem_root_path_len = 0;
void
_subsystem_init(const char **apple)
{
char * subsystem_root_path_string = _simple_getenv(apple, SUBSYSTEM_ROOT_PATH_KEY);
const char * subsystem_root_path_string = _simple_getenv(apple, SUBSYSTEM_ROOT_PATH_KEY);
if (subsystem_root_path_string) {
subsystem_root_path = subsystem_root_path_string;
subsystem_root_path_len = strnlen(subsystem_root_path, PATH_MAX);
}
}

/*
* Takes a buffer, a subsystem path, and a file path, and constructs the
* Takes a buffer containing a subsystem root path and a file path, and constructs the
* subsystem path for the given file path. Assumes that the subsystem root
* path will be "/" terminated.
*/
static bool
construct_subsystem_path(char * buf, size_t buf_size, const char * subsystem_root_path, const char * file_path)
append_path_to_subsystem_root(char * buf, size_t buf_size, const char * file_path)
{
size_t return_a = strlcpy(buf, subsystem_root_path, buf_size);
size_t return_b = strlcat(buf, file_path, buf_size);
size_t concatenated_length = strlcat(buf, file_path, buf_size);

if ((return_a >= buf_size) || (return_b >= buf_size)) {
if (concatenated_length >= buf_size) {
return false;
}

return true;
}

/*
* Takes a pointer to a part of the subsystem root path string and extracts
* the next viable path (from the start point to the NULL terminator or next ':'
* character). Populates this path into the provided buffer. Returns a pointer to
* the next root path if there is a following one, NULL if this was the last path.
*
* Note: It's not possible to use straight strsep(3) or similar because the subsystem
* root path is immutable.
*/
static const char *
extract_next_subsystem_root_path(char *buf, size_t buf_size, const char *root_path_begin)
{
bool found_delimeter = false;
size_t root_path_len = strlen(root_path_begin);

if (buf_size == 0) {
return root_path_begin;
}

const char *next_delimeter = memchr(root_path_begin, (int)SUBSYSTEM_ROOT_PATH_DELIMETER,
root_path_len);
if (next_delimeter != NULL) {
root_path_len = (size_t)(next_delimeter - root_path_begin);
found_delimeter = true;
}
if (root_path_len > (buf_size - 1)) {
// We either found a sub-path that was too long or there was only one
// path in the string and that was too long.
return NULL;
}
memcpy(buf, root_path_begin, root_path_len);
buf[root_path_len] = '\0';

// If we found a delimeter, this indicates there is another path
// after the one we just extracted. Return a pointer to the beginning
// of this path (which is the character after the delimeter). Otherwise
// that was the last component in the paths.
if (found_delimeter) {
return (next_delimeter + 1);
} else {
return NULL;
}
}

int
open_with_subsystem(const char * path, int oflag)
{
Expand All @@ -84,15 +130,25 @@ open_with_subsystem(const char * path, int oflag)
if ((result < 0) && (errno == ENOENT) && (subsystem_root_path)) {
/*
* If the file doesn't exist relative to root, search
* for it relative to the subsystem root.
* for it relative to the provided subsystem root paths.
*/
char subsystem_path[PATH_MAX];

if (construct_subsystem_path(subsystem_path, sizeof(subsystem_path), subsystem_root_path, path)) {
result = open(subsystem_path, oflag);
} else {
errno = ENAMETOOLONG;
}
const char *next_subsystem_root_path_begin = subsystem_root_path;
do {
char constructed_path[PATH_MAX];
next_subsystem_root_path_begin = extract_next_subsystem_root_path(constructed_path, sizeof(constructed_path), next_subsystem_root_path_begin);

if (append_path_to_subsystem_root(constructed_path, sizeof(constructed_path), path)) {
result = open(constructed_path, oflag);
if (result >= 0) {
break;
} else if (errno == ENOENT) {
continue;
}
} else {
errno = ENAMETOOLONG;
break;
}
} while (next_subsystem_root_path_begin != NULL);
}

return result;
Expand All @@ -108,15 +164,25 @@ stat_with_subsystem(const char *restrict path, struct stat *restrict buf)
if ((result < 0) && (errno == ENOENT) && (subsystem_root_path)) {
/*
* If the file doesn't exist relative to root, search
* for it relative to the subsystem root.
* for it relative to the provided subsystem root paths.
*/
char subsystem_path[PATH_MAX];

if (construct_subsystem_path(subsystem_path, sizeof(subsystem_path), subsystem_root_path, path)) {
result = stat(subsystem_path, buf);
} else {
errno = ENAMETOOLONG;
}
const char *next_subsystem_root_path_begin = subsystem_root_path;
do {
char constructed_path[PATH_MAX];
next_subsystem_root_path_begin = extract_next_subsystem_root_path(constructed_path, sizeof(constructed_path), next_subsystem_root_path_begin);

if (append_path_to_subsystem_root(constructed_path, sizeof(constructed_path), path)) {
result = stat(constructed_path, buf);
if (result >= 0) {
break;
} else if (errno == ENOENT) {
continue;
}
} else {
errno = ENAMETOOLONG;
break;
}
} while (next_subsystem_root_path_begin != NULL);
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion db/hash/FreeBSD/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ typedef struct htab { /* Memory resident data structure */
BUFHEAD bufhead; /* Header of buffer lru list */
SEGMENT *dir; /* Hash Bucket directory */
/* other flags */
int nextkey_eof :1; /* dbm_nextkey() reached EOF */
u_int nextkey_eof :1; /* dbm_nextkey() reached EOF */
} HTAB;

/*
Expand Down
16 changes: 4 additions & 12 deletions db/hash/FreeBSD/hash_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ u_int32_t (*__default_hash)(const void *, size_t) = hash4;
#define PRIME2 1048583

static u_int32_t
hash1(keyarg, len)
const void *keyarg;
size_t len;
hash1(const void *keyarg, size_t len)
{
const u_char *key;
u_int32_t h;
Expand All @@ -84,9 +82,7 @@ hash1(keyarg, len)
#define dcharhash(h, c) ((h) = 0x63c63cd9*(h) + 0x9c39c33d + (c))

static u_int32_t
hash2(keyarg, len)
const void *keyarg;
size_t len;
hash2(const void *keyarg, size_t len)
{
const u_char *e, *key;
u_int32_t h;
Expand All @@ -113,9 +109,7 @@ hash2(keyarg, len)
* OZ's original sdbm hash
*/
static u_int32_t
hash3(keyarg, len)
const void *keyarg;
size_t len;
hash3(const void *keyarg, size_t len)
{
const u_char *key;
size_t loop;
Expand Down Expand Up @@ -161,9 +155,7 @@ hash3(keyarg, len)

/* Hash function from Chris Torek. */
static u_int32_t
hash4(keyarg, len)
const void *keyarg;
size_t len;
hash4(const void *keyarg, size_t len)
{
const u_char *key;
size_t loop;
Expand Down

0 comments on commit c5a3293

Please sign in to comment.