]> git.saurik.com Git - apple/libc.git/commitdiff
Libc-1272.200.26.tar.gz macos-1014 macos-10141 macos-10142 macos-10143 v1272.200.26
authorApple <opensource@apple.com>
Thu, 4 Oct 2018 22:47:59 +0000 (22:47 +0000)
committerApple <opensource@apple.com>
Thu, 4 Oct 2018 22:47:59 +0000 (22:47 +0000)
120 files changed:
.upstream_base_commits
Libc.xcodeproj/project.pbxproj
db/db/FreeBSD/db.c
gen/FreeBSD/getcwd.c
gen/FreeBSD/glob.c
gen/FreeBSD/signal.c
gen/FreeBSD/timezone.c
gen/backtrace.3
gen/backtrace.c
gen/clock_gettime.3
gen/crypt.c
gen/disklabel.c
gen/execinfo.h
gen/fts.c
gen/getttyent.c
gen/thread_stack_pcs.c
gen/thread_stack_pcs.h [new file with mode: 0644]
i386/string/strcpy.s [deleted file]
i386/string/strlcat.s [deleted file]
i386/string/strlcpy.s [deleted file]
i386/string/strlen.s [deleted file]
i386/string/strncpy.s [deleted file]
include/fts.h
include/libkern/OSThermalNotification.h
include/stdlib.h
include/struct.h
include/sys/rbtree.h
include/xlocale/_wchar.h
libdarwin/bsd.c [new file with mode: 0644]
libdarwin/dirstat.c
libdarwin/dirstat.h [deleted file]
libdarwin/dirstat_collection.c
libdarwin/dirstat_collection.h [deleted file]
libdarwin/err.c [new file with mode: 0644]
libdarwin/exception.c [new file with mode: 0644]
libdarwin/h/bsd.h [new file with mode: 0644]
libdarwin/h/cleanup.h [new file with mode: 0644]
libdarwin/h/dirstat.h [new file with mode: 0644]
libdarwin/h/dirstat_collection.h [new file with mode: 0644]
libdarwin/h/err.h [new file with mode: 0644]
libdarwin/h/errno.h [new file with mode: 0644]
libdarwin/h/libdarwin_init.h [new file with mode: 0644]
libdarwin/h/mach_exception.h [new file with mode: 0644]
libdarwin/h/mach_utils.h [new file with mode: 0644]
libdarwin/h/stdio.h [new file with mode: 0644]
libdarwin/h/stdlib.h [new file with mode: 0644]
libdarwin/h/string.h [new file with mode: 0644]
libdarwin/init.c
libdarwin/internal.h [new file with mode: 0644]
libdarwin/mach.c [new file with mode: 0644]
libdarwin/stdio.c [new file with mode: 0644]
libdarwin/stdlib.c [new file with mode: 0644]
libdarwin/string.c [new file with mode: 0644]
libdarwin/variant.c
locale/FreeBSD/rune.c
locale/xlocale_private.h
man/manpages.lst
man/style.3 [new file with mode: 0644]
net/FreeBSD/inet_addr.c
net/FreeBSD/inet_network.c
net/inet_ntop.c
nls/FreeBSD/msgcat.h
os/api.h [new file with mode: 0644]
os/assumes.c
os/assumes.h
regex/TRE/lib/tre-compile.c
stdio/FreeBSD/findfp.c
stdio/FreeBSD/fopen.3
stdio/FreeBSD/makebuf.c
stdio/FreeBSD/open_memstream.c
stdio/FreeBSD/setbuf.3
stdio/FreeBSD/vfprintf.c
stdio/FreeBSD/vfscanf.c
stdio/xprintf_comp.c
stdio/xprintf_domain.c
stdio/xprintf_exec.c
stdlib/FreeBSD/abort.c
stdlib/FreeBSD/atexit.c
stdlib/FreeBSD/exit.c
stdlib/FreeBSD/heapsort.c
stdlib/FreeBSD/heapsort_r.c
stdlib/FreeBSD/merge.c
stdlib/FreeBSD/merge_b.c
stdlib/FreeBSD/strhash.c
stdlib/FreeBSD/system.c
stdlib/qsort_b.c
stdtime/FreeBSD/difftime.c
stdtime/FreeBSD/localtime.c
stdtime/FreeBSD/strftime.c
string/FreeBSD/index.c [deleted file]
string/FreeBSD/strlen.c [deleted file]
string/FreeBSD/strnlen.c [deleted file]
string/FreeBSD/strstr.c [deleted file]
string/strcpy.c [deleted file]
string/strlcat.c [deleted file]
string/strlcpy.c [deleted file]
string/strncpy.c [deleted file]
sys/_libc_fork_child.c
sys/sigaction.c
tests/assumes_legacy.c
tests/backtrace.c [new file with mode: 0644]
tests/envbuf.c [new file with mode: 0644]
tests/nxheap.c
tests/open_memstream.c [new file with mode: 0644]
tests/os_simple_hash.c [new file with mode: 0644]
util/login_tty.c
util/logout.c
x86_64/string/strcpy.s [deleted file]
x86_64/string/strlen.s [deleted file]
x86_64/string/strncpy.s [deleted file]
x86_64/string/strnlen.s [deleted file]
xcodescripts/alias.list
xcodescripts/force_libc_to_build.sh [changed mode: 0644->0755]
xcodescripts/generate_features.pl
xcodescripts/headers.sh
xcodescripts/libc.xcconfig
xcodescripts/manpages.sh [changed mode: 0644->0755]
xcodescripts/sanitise_headers.sh [changed mode: 0644->0755]
xcodescripts/skip_installhdrs.sh [changed mode: 0644->0755]
xcodescripts/variants.xcconfig

index d6b36ba9595d5ba82bf82887af90b704d49babe1..cfc62c50976c2ef7f85ed8db4e2b8a11fd012936 100644 (file)
@@ -37,6 +37,8 @@ stdio/FreeBSD/fmemopen.c      freebsd lib/libc/stdio/fmemopen.c       89c1fcc0d088065021703
 stdio/FreeBSD/open_memstream.3 freebsd lib/libc/stdio/open_memstream.3 89c1fcc0d088065021703b658ef547f46b5481f0
 stdio/FreeBSD/open_memstream.c freebsd lib/libc/stdio/open_memstream.c 89c1fcc0d088065021703b658ef547f46b5481f0
 stdio/FreeBSD/open_wmemstream.c        freebsd lib/libc/stdio/open_wmemstream.c        89c1fcc0d088065021703b658ef547f46b5481f0
+stdio/FreeBSD/makebuf.c        freebsd lib/libc/stdio/makebuf.c        c956a7530cd8282a920a11e1088adbb250169c06
+stdio/FreeBSD/makebuf.c        netbsd  lib/libc/stdio/makebuf.c        72b46443582ea9efbf25ede3b8f56c6646478d71
 stdio/FreeBSD/mktemp.3 freebsd lib/libc/stdio/mktemp.3 2895e1352cf3788606924d800c3a5c589520ea00
 stdio/FreeBSD/mktemp.c freebsd lib/libc/stdio/mktemp.c 2895e1352cf3788606924d800c3a5c589520ea00
 stdio/FreeBSD/printf.3 freebsd lib/libc/stdio/printf.3 cfc3df2b8f708ce8494d9d556e3472a5c8c21b8a
index 6802ba6191bfc1f0f0387780fbc5213aef872c0a..862e3a9e4c86330dfe80eaabb225e5fc8a07049b 100644 (file)
                3FD14575171D42B300B7BAF5 /* bcopy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3FD14572171D42B300B7BAF5 /* bcopy.c */; settings = {COMPILER_FLAGS = "-momit-leaf-frame-pointer"; }; };
                3FD14576171D42B300B7BAF5 /* bcopy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3FD14572171D42B300B7BAF5 /* bcopy.c */; settings = {COMPILER_FLAGS = "-momit-leaf-frame-pointer"; }; };
                3FD4D48E1472F4B200075CCE /* dirfd.c in Sources */ = {isa = PBXBuildFile; fileRef = 3FB7E1B4146EF2E000843438 /* dirfd.c */; };
+               4B075C8E208BE9F200FD4F23 /* variant_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 926F73991E03E8D6001E049D /* variant_private.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B0899BC2046258F001360A4 /* cleanup.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0899B920460FAC001360A4 /* cleanup.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B20DB4D202B81A4005C2327 /* bsd.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BA6E56A202ACF7A00F38D3A /* bsd.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B20DB50202B81A4005C2327 /* err.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BA6E563202AC0C200F38D3A /* err.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B20DB51202B81A4005C2327 /* errno.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BA6E55B202AB1F100F38D3A /* errno.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B20DB52202B81A4005C2327 /* stdio.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BA6E567202ACAFA00F38D3A /* stdio.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B20DB53202B81A4005C2327 /* stdlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BA6E564202AC43700F38D3A /* stdlib.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B20DB54202B81A4005C2327 /* string.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BA6E55D202AB31100F38D3A /* string.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4B2C64A315519BC300342BFA /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
                4B2C64A415519BC400342BFA /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
                4B2C64A515519BC600342BFA /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
                4B2C64A915519BC800342BFA /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
                4B2C64AA15519BCB00342BFA /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
                4B2C64BA1551B03700342BFA /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
-               6310518713D4D966004F7BA8 /* strcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518613D4D966004F7BA8 /* strcpy.c */; };
-               6310518A13D4D9E9004F7BA8 /* strcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518613D4D966004F7BA8 /* strcpy.c */; };
-               6310518C13D4DABD004F7BA8 /* strlcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518B13D4DABD004F7BA8 /* strlcpy.c */; };
-               6310518D13D4DABD004F7BA8 /* strlcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518B13D4DABD004F7BA8 /* strlcpy.c */; };
-               6310518F13D4DAEA004F7BA8 /* strncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518E13D4DAEA004F7BA8 /* strncpy.c */; };
-               6310519013D4DAEA004F7BA8 /* strncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518E13D4DAEA004F7BA8 /* strncpy.c */; };
-               63505E3B1548525D00B637D7 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = 63505E3A1548525D00B637D7 /* strnlen.s */; };
-               63505E3C1548525D00B637D7 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = 63505E3A1548525D00B637D7 /* strnlen.s */; };
-               63505E3D1548525D00B637D7 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = 63505E3A1548525D00B637D7 /* strnlen.s */; };
-               639D126A15595DDE00D0403A /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = 639D126615595DDE00D0403A /* strnlen.s */; };
-               639D126C15595DDE00D0403A /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = 639D126615595DDE00D0403A /* strnlen.s */; };
+               4B4E643F2069E94A00C4D8D5 /* internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B2C50E41F8453FA005DA2B6 /* internal.h */; };
+               4B69E81320800D47008D13D2 /* libdarwin_init.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B69E81220800BE9008D13D2 /* libdarwin_init.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B6CFC042065B9FF0022DBAD /* mach.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B6CFC032065B9FF0022DBAD /* mach.c */; };
+               4B6D181D206DEFBD00C00E37 /* mach_exception.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6D181C206DEFBD00C00E37 /* mach_exception.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4B6D181F206DF1E200C00E37 /* exception.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D181E206DF1E200C00E37 /* exception.c */; };
+               4B782979208926A80070E1FF /* api.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B782978208926A70070E1FF /* api.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4BA6E55F202AB35900F38D3A /* string.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BA6E55E202AB35900F38D3A /* string.c */; };
+               4BA6E562202AC06300F38D3A /* err.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BA6E561202AC06300F38D3A /* err.c */; };
+               4BA6E566202AC94800F38D3A /* stdlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BA6E565202AC94800F38D3A /* stdlib.c */; };
+               4BA6E569202ACDAA00F38D3A /* stdio.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BA6E568202ACDAA00F38D3A /* stdio.c */; };
+               4BA6E56C202AD02900F38D3A /* bsd.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BA6E56B202AD02900F38D3A /* bsd.c */; };
+               4BCC350F20659AD500A4CBAA /* mach_utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BCC350E20659AD500A4CBAA /* mach_utils.h */; settings = {ATTRIBUTES = (Private, ); }; };
                63D4060613DDEDF10094DD56 /* stpcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060513DDEDF10094DD56 /* stpcpy.c */; };
                63D4060813DDEDFF0094DD56 /* stpcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060513DDEDF10094DD56 /* stpcpy.c */; };
                63D4060A13DDEEA20094DD56 /* stpncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060913DDEEA10094DD56 /* stpncpy.c */; };
                63D4060E13DDF26A0094DD56 /* strcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060C13DDF26A0094DD56 /* strcat.c */; };
                63D4061013DDF4340094DD56 /* strncat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060F13DDF4340094DD56 /* strncat.c */; };
                63D4061113DDF4340094DD56 /* strncat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060F13DDF4340094DD56 /* strncat.c */; };
-               63D4061313DDF6A30094DD56 /* strlcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4061213DDF6A20094DD56 /* strlcat.c */; };
-               63D4061413DDF6A30094DD56 /* strlcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4061213DDF6A20094DD56 /* strlcat.c */; };
                926F73981E03E8C4001E049D /* variant.c in Sources */ = {isa = PBXBuildFile; fileRef = 926F73971E03E8C4001E049D /* variant.c */; };
-               926F739A1E03E8D6001E049D /* variant_private.h in Headers */ = {isa = PBXBuildFile; fileRef = 926F73991E03E8D6001E049D /* variant_private.h */; settings = {ATTRIBUTES = (Private, ); }; };
                92767C841E0A7E2700AB9C76 /* init.c in Sources */ = {isa = PBXBuildFile; fileRef = 92767C821E0A7E2100AB9C76 /* init.c */; };
                928841361EA75555001064D1 /* dirstat_collection.c in Sources */ = {isa = PBXBuildFile; fileRef = 928841341EA7554D001064D1 /* dirstat_collection.c */; };
                92888B161EA5BE7400BA923E /* fmemopen.c in Sources */ = {isa = PBXBuildFile; fileRef = 92888B0F1EA5BE6D00BA923E /* fmemopen.c */; };
                B19C64621450F90200032373 /* sync_volume_np.c in Sources */ = {isa = PBXBuildFile; fileRef = B19C645B1450F90200032373 /* sync_volume_np.c */; };
                B19C64631450F90200032373 /* sync_volume_np.c in Sources */ = {isa = PBXBuildFile; fileRef = B19C645B1450F90200032373 /* sync_volume_np.c */; };
                C0E343921C582ECB00E749C2 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53819138D9E990028D27C /* mcount.s */; };
-               C0E343931C582ECB00E749C2 /* strcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383D138D9E990028D27C /* strcpy.s */; };
-               C0E343941C582ECB00E749C2 /* strlcat.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383E138D9E990028D27C /* strlcat.s */; };
-               C0E343951C582ECB00E749C2 /* strlcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383F138D9E990028D27C /* strlcpy.s */; };
-               C0E343961C582ECB00E749C2 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53840138D9E990028D27C /* strlen.s */; };
-               C0E343971C582ECB00E749C2 /* strncpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53842138D9E990028D27C /* strncpy.s */; };
-               C0E343981C582ECB00E749C2 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535CF138D9E980028D27C /* strlen.s */; };
-               C0E343991C582ECB00E749C2 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D2138D9E980028D27C /* strnlen.s */; };
-               C0E3439A1C582ECB00E749C2 /* strstr.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D3138D9E980028D27C /* strstr.s */; };
                C0E3439B1C582ECB00E749C2 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DF9138D9E9A0028D27C /* mcount.s */; };
-               C0E3439C1C582ECB00E749C2 /* (null) in Sources */ = {isa = PBXBuildFile; };
-               C0E3439D1C582ECB00E749C2 /* (null) in Sources */ = {isa = PBXBuildFile; };
-               C0E3439E1C582ECB00E749C2 /* (null) in Sources */ = {isa = PBXBuildFile; };
-               C0E3439F1C582ECB00E749C2 /* (null) in Sources */ = {isa = PBXBuildFile; };
-               C0E343A01C582ECB00E749C2 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C0E343A11C582ECB00E749C2 /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C0E343A21C582ECB00E749C2 /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C0E343A31C582ECB00E749C2 /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C0E345621C582ECB00E749C2 /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C0E345631C582ECB00E749C2 /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS"; }; };
                C0E345641C582ECB00E749C2 /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C0E345651C582ECB00E749C2 /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C0E345661C582ECB00E749C2 /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C0E345671C582ECB00E749C2 /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C0E345681C582ECB00E749C2 /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C0E3456B1C582ECB00E749C2 /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C0E3456C1C582ECB00E749C2 /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C0E3456D1C582ECB00E749C2 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_STRERROR"; }; };
-               C0E3456E1C582ECB00E749C2 /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C0E3456F1C582ECB00E749C2 /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C0E345701C582ECB00E749C2 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C0E345711C582ECB00E749C2 /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C0E345721C582ECB00E749C2 /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C0E345731C582ECB00E749C2 /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C0E345741C582ECB00E749C2 /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C0E345751C582ECB00E749C2 /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C0E345761C582ECB00E749C2 /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C0E345771C582ECB00E749C2 /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C0E345781C582ECB00E749C2 /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C0E345791C582ECB00E749C2 /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C0E3457A1C582ECB00E749C2 /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C0E3457B1C582ECB00E749C2 /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C0E345C11C582ECB00E749C2 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C0E345C21C582ECB00E749C2 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C0E345C31C582ECB00E749C2 /* scandir_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB350E138F769B0075BB52 /* scandir_b.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -include gen/__dirent.h"; }; };
-               C0E345CA1C582ECB00E749C2 /* strcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518613D4D966004F7BA8 /* strcpy.c */; };
-               C0E345CB1C582ECB00E749C2 /* strlcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518B13D4DABD004F7BA8 /* strlcpy.c */; };
-               C0E345CC1C582ECB00E749C2 /* strncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518E13D4DAEA004F7BA8 /* strncpy.c */; };
                C0E345CD1C582ECB00E749C2 /* stpcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060513DDEDF10094DD56 /* stpcpy.c */; };
                C0E345CE1C582ECB00E749C2 /* stpncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060913DDEEA10094DD56 /* stpncpy.c */; };
                C0E345CF1C582ECB00E749C2 /* strcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060C13DDF26A0094DD56 /* strcat.c */; };
                C0E345D01C582ECB00E749C2 /* strncat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060F13DDF4340094DD56 /* strncat.c */; };
-               C0E345D11C582ECB00E749C2 /* strlcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4061213DDF6A20094DD56 /* strlcat.c */; };
                C0E345D21C582ECB00E749C2 /* sync_volume_np.c in Sources */ = {isa = PBXBuildFile; fileRef = B19C645B1450F90200032373 /* sync_volume_np.c */; };
                C0E345D31C582ECB00E749C2 /* dirfd.c in Sources */ = {isa = PBXBuildFile; fileRef = 3FB7E1B4146EF2E000843438 /* dirfd.c */; };
                C0E345D41C582ECB00E749C2 /* eos_stubs.c in Sources */ = {isa = PBXBuildFile; fileRef = C925D1FB151805C6003D315B /* eos_stubs.c */; };
-               C0E345D51C582ECB00E749C2 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = 63505E3A1548525D00B637D7 /* strnlen.s */; };
                C0E345D61C582ECB00E749C2 /* assumes.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B2C64A215519BAF00342BFA /* assumes.c */; };
                C0E345D71C582ECB00E749C2 /* inet_ntop.c in Sources */ = {isa = PBXBuildFile; fileRef = FC2ED60E157D4BE70098EC69 /* inet_ntop.c */; };
                C0E345D81C582ECB00E749C2 /* inet_pton.c in Sources */ = {isa = PBXBuildFile; fileRef = FC2ED60F157D4BE70098EC69 /* inet_pton.c */; };
                C9257F5C138E1C9700B3107C /* ascii.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53902138D9E990028D27C /* ascii.c */; };
                C9257F5D138E1C9700B3107C /* big5.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53905138D9E990028D27C /* big5.c */; };
                C9257F5E138E1C9700B3107C /* btowc.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53909138D9E990028D27C /* btowc.c */; };
-               C9257F5F138E1C9700B3107C /* collate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B5390B138D9E990028D27C /* collate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS $(COLLATE_C_CFLAGS_$(PLATFORM_NAME)_$(CURRENT_ARCH))"; }; };
+               C9257F5F138E1C9700B3107C /* collate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B5390B138D9E990028D27C /* collate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS"; }; };
                C9257F60138E1C9700B3107C /* collcmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B5390F138D9E990028D27C /* collcmp.c */; };
                C9257F61138E1C9700B3107C /* euc.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53916138D9E990028D27C /* euc.c */; };
                C9257F62138E1C9700B3107C /* fix_grouping.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53918138D9E990028D27C /* fix_grouping.c */; };
                C925800A138E1CC000B3107C /* strptime.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD3138D9E9A0028D27C /* strptime.c */; };
                C925800B138E1CC000B3107C /* time32.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD6138D9E9A0028D27C /* time32.c */; };
                C925800C138E1CC000B3107C /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
-               C9258010138E1CD200B3107C /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C9258015138E1CD200B3107C /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C9258018138E1CD200B3107C /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C925801B138E1CD200B3107C /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C9258022138E1CD200B3107C /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C9258023138E1CD200B3107C /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C9258024138E1CD200B3107C /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; };
-               C9258027138E1CD200B3107C /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C9258028138E1CD200B3107C /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C925802C138E1CD200B3107C /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C925802D138E1CD200B3107C /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C925802E138E1CD200B3107C /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C925802F138E1CD200B3107C /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C9258030138E1CD200B3107C /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C9258031138E1CD200B3107C /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C9258032138E1CD200B3107C /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C9258033138E1CD200B3107C /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C9258034138E1CD200B3107C /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C9258035138E1CD200B3107C /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C9258036138E1CD200B3107C /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C9258037138E1CD200B3107C /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C9421023138F2661004BA536 /* machdep_ldisdd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B536B8138D9E980028D27C /* machdep_ldisdd.c */; };
                C9421024138F2661004BA536 /* machdep_ldisQ.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B536BA138D9E980028D27C /* machdep_ldisQ.c */; };
                C9421025138F2661004BA536 /* machdep_ldisx.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B536BB138D9E980028D27C /* machdep_ldisx.c */; };
-               C942103213900C8A004BA536 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C942103913900C8A004BA536 /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C942103A13900C8A004BA536 /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C942103B13900C8A004BA536 /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C942124413900C8A004BA536 /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C942124513900C8A004BA536 /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS"; }; };
                C942124613900C8A004BA536 /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C942124A13900C8A004BA536 /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C942124F13900C8A004BA536 /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C942125213900C8A004BA536 /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C942125513900C8A004BA536 /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C942125C13900C8A004BA536 /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C942125D13900C8A004BA536 /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C942125E13900C8A004BA536 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_STRERROR"; }; };
-               C942126113900C8A004BA536 /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C942126213900C8A004BA536 /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C942126613900C8A004BA536 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C942126713900C8A004BA536 /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C942126813900C8A004BA536 /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C942126913900C8A004BA536 /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C942126A13900C8A004BA536 /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C942126B13900C8A004BA536 /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C942126C13900C8A004BA536 /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C942126D13900C8A004BA536 /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C942126E13900C8A004BA536 /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C942126F13900C8A004BA536 /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C942127013900C8A004BA536 /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C942127113900C8A004BA536 /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C94212BB13900C8A004BA536 /* unparse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE3138D9E9A0028D27C /* unparse.c */; };
                C94212C613900C8A004BA536 /* scandir_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB350E138F769B0075BB52 /* scandir_b.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -include gen/__dirent.h"; }; };
                C94212E413901595004BA536 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DF9138D9E9A0028D27C /* mcount.s */; };
-               C94212FA13901595004BA536 /* strcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53E17138D9E9A0028D27C /* strcpy.s */; };
-               C94212FD13901595004BA536 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53E1A138D9E9A0028D27C /* strlen.s */; };
-               C94212FF13901595004BA536 /* strncpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53E1C138D9E9A0028D27C /* strncpy.s */; };
-               C942131E13903959004BA536 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535CF138D9E980028D27C /* strlen.s */; };
-               C942132113903959004BA536 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D2138D9E980028D27C /* strnlen.s */; };
-               C942132213903959004BA536 /* strstr.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D3138D9E980028D27C /* strstr.s */; };
                C94213361390396E004BA536 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53819138D9E990028D27C /* mcount.s */; };
-               C942134C1390396E004BA536 /* strcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383D138D9E990028D27C /* strcpy.s */; };
-               C942134D1390396E004BA536 /* strlcat.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383E138D9E990028D27C /* strlcat.s */; };
-               C942134E1390396E004BA536 /* strlcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383F138D9E990028D27C /* strlcpy.s */; };
-               C942134F1390396E004BA536 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53840138D9E990028D27C /* strlen.s */; };
-               C94213511390396E004BA536 /* strncpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53842138D9E990028D27C /* strncpy.s */; };
                C95B7ED7138F3BEA004311DA /* rune.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53989138D9E990028D27C /* rune.c */; };
-               C95B7EDD138F3C55004311DA /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C95B7EE4138F3C55004311DA /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C95B7EE5138F3C55004311DA /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C95B7EE6138F3C55004311DA /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C95B80EF138F3C55004311DA /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C95B80F0138F3C55004311DA /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; };
                C95B80F1138F3C55004311DA /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C95B80F5138F3C55004311DA /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C95B80FA138F3C55004311DA /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C95B80FD138F3C55004311DA /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C95B8100138F3C55004311DA /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C95B8107138F3C55004311DA /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C95B8108138F3C55004311DA /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C95B8109138F3C55004311DA /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; };
-               C95B810C138F3C55004311DA /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C95B810D138F3C55004311DA /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C95B8111138F3C55004311DA /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C95B8112138F3C55004311DA /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C95B8113138F3C55004311DA /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C95B8114138F3C55004311DA /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C95B8115138F3C55004311DA /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C95B8116138F3C55004311DA /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C95B8117138F3C55004311DA /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C95B8118138F3C55004311DA /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C95B8119138F3C55004311DA /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C95B811A138F3C55004311DA /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C95B811B138F3C55004311DA /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C95B811C138F3C55004311DA /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C95B8164138F3C55004311DA /* parse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE1138D9E9A0028D27C /* parse.c */; };
                C95B8165138F3C55004311DA /* unpack.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE2138D9E9A0028D27C /* unpack.c */; };
                C95B8166138F3C55004311DA /* unparse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE3138D9E9A0028D27C /* unparse.c */; };
-               C95B8188138F52B0004311DA /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C95B818F138F52B0004311DA /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C95B8190138F52B0004311DA /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C95B8191138F52B0004311DA /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C95B839A138F52B0004311DA /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C95B839B138F52B0004311DA /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; };
                C95B839C138F52B0004311DA /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C95B83A0138F52B0004311DA /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C95B83A5138F52B0004311DA /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C95B83A8138F52B0004311DA /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C95B83AB138F52B0004311DA /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C95B83B2138F52B0004311DA /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C95B83B3138F52B0004311DA /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C95B83B4138F52B0004311DA /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; };
-               C95B83B7138F52B0004311DA /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C95B83B8138F52B0004311DA /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C95B83BC138F52B0004311DA /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C95B83BD138F52B0004311DA /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C95B83BE138F52B0004311DA /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C95B83BF138F52B0004311DA /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C95B83C0138F52B0004311DA /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C95B83C1138F52B0004311DA /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C95B83C2138F52B0004311DA /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C95B83C3138F52B0004311DA /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C95B83C4138F52B0004311DA /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C95B83C5138F52B0004311DA /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C95B83C6138F52B0004311DA /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C95B83C7138F52B0004311DA /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C95B840F138F52B0004311DA /* parse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE1138D9E9A0028D27C /* parse.c */; };
                C95B8410138F52B0004311DA /* unpack.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE2138D9E9A0028D27C /* unpack.c */; };
                C95B8411138F52B0004311DA /* unparse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE3138D9E9A0028D27C /* unparse.c */; };
-               C95B842E138F53DB004311DA /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C95B8435138F53DB004311DA /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C95B8436138F53DB004311DA /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C95B8437138F53DB004311DA /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C95B8640138F53DB004311DA /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C95B8641138F53DB004311DA /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; };
                C95B8642138F53DB004311DA /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C95B8646138F53DB004311DA /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C95B864B138F53DB004311DA /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C95B864E138F53DB004311DA /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C95B8651138F53DB004311DA /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C95B8658138F53DB004311DA /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C95B8659138F53DB004311DA /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C95B865A138F53DB004311DA /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; };
-               C95B865D138F53DB004311DA /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C95B865E138F53DB004311DA /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C95B8662138F53DB004311DA /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C95B8663138F53DB004311DA /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C95B8664138F53DB004311DA /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C95B8665138F53DB004311DA /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C95B8666138F53DB004311DA /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C95B8667138F53DB004311DA /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C95B8668138F53DB004311DA /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C95B8669138F53DB004311DA /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C95B866A138F53DB004311DA /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C95B866B138F53DB004311DA /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C95B866C138F53DB004311DA /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C95B866D138F53DB004311DA /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C95B86B5138F53DB004311DA /* parse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE1138D9E9A0028D27C /* parse.c */; };
                C95B86B6138F53DB004311DA /* unpack.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE2138D9E9A0028D27C /* unpack.c */; };
                C95B86B7138F53DB004311DA /* unparse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE3138D9E9A0028D27C /* unparse.c */; };
-               C9765EB2138EC61900741512 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C9765EB9138EC61900741512 /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C9765EBA138EC61900741512 /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C9765EBB138EC61900741512 /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C97660C4138EC61A00741512 /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C97660C5138EC61A00741512 /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; };
                C97660C6138EC61A00741512 /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C97660CA138EC61A00741512 /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C97660CF138EC61A00741512 /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C97660D2138EC61A00741512 /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C97660D5138EC61A00741512 /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C97660DC138EC61A00741512 /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C97660DD138EC61A00741512 /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C97660DE138EC61A00741512 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; };
-               C97660E1138EC61A00741512 /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C97660E2138EC61A00741512 /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C97660E6138EC61A00741512 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C97660E7138EC61A00741512 /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C97660E8138EC61A00741512 /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C97660E9138EC61A00741512 /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C97660EA138EC61A00741512 /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C97660EB138EC61A00741512 /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C97660EC138EC61A00741512 /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C97660ED138EC61A00741512 /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C97660EE138EC61A00741512 /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C97660EF138EC61A00741512 /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C97660F0138EC61A00741512 /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C97660F1138EC61A00741512 /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C976613A138EC61A00741512 /* unpack.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE2138D9E9A0028D27C /* unpack.c */; };
                C976613B138EC61A00741512 /* unparse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE3138D9E9A0028D27C /* unparse.c */; };
                C97A6F291517AF53005E1998 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53819138D9E990028D27C /* mcount.s */; };
-               C97A6F3F1517AF53005E1998 /* strcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383D138D9E990028D27C /* strcpy.s */; };
-               C97A6F401517AF53005E1998 /* strlcat.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383E138D9E990028D27C /* strlcat.s */; };
-               C97A6F411517AF53005E1998 /* strlcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383F138D9E990028D27C /* strlcpy.s */; };
-               C97A6F421517AF53005E1998 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53840138D9E990028D27C /* strlen.s */; };
-               C97A6F441517AF53005E1998 /* strncpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53842138D9E990028D27C /* strncpy.s */; };
-               C97A6F5A1517AF53005E1998 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535CF138D9E980028D27C /* strlen.s */; };
-               C97A6F5C1517AF53005E1998 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D2138D9E980028D27C /* strnlen.s */; };
-               C97A6F5D1517AF53005E1998 /* strstr.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D3138D9E980028D27C /* strstr.s */; };
                C97A6F6D1517AF53005E1998 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DF9138D9E9A0028D27C /* mcount.s */; };
                C97A6F761517AF53005E1998 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C97A6F791517AF53005E1998 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C97A6F7A1517AF53005E1998 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C97A6F7E1517AF53005E1998 /* (null) in Sources */ = {isa = PBXBuildFile; };
-               C97A6F8F1517AF53005E1998 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C97A6F961517AF53005E1998 /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C97A6F971517AF53005E1998 /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C97A6F981517AF53005E1998 /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C97A71821517AF53005E1998 /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C97A71831517AF53005E1998 /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS"; }; };
                C97A71841517AF53005E1998 /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C97A71881517AF53005E1998 /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C97A718D1517AF53005E1998 /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C97A71901517AF53005E1998 /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C97A71911517AF53005E1998 /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C97A71961517AF53005E1998 /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C97A71971517AF53005E1998 /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C97A71981517AF53005E1998 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_STRERROR"; }; };
-               C97A71991517AF53005E1998 /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C97A719A1517AF53005E1998 /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C97A719C1517AF53005E1998 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C97A719D1517AF53005E1998 /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C97A719E1517AF53005E1998 /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C97A719F1517AF53005E1998 /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C97A71A01517AF53005E1998 /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C97A71A11517AF53005E1998 /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C97A71A21517AF53005E1998 /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C97A71A31517AF53005E1998 /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C97A71A41517AF53005E1998 /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS)"; }; };
                C97A71A51517AF53005E1998 /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C97A71A61517AF53005E1998 /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C97A71A71517AF53005E1998 /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C97A71F91517AF53005E1998 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C97A71FA1517AF53005E1998 /* (null) in Sources */ = {isa = PBXBuildFile; };
                C97A71FD1517AF53005E1998 /* scandir_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB350E138F769B0075BB52 /* scandir_b.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -include gen/__dirent.h"; }; };
-               C97A720D1517AF53005E1998 /* strcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518613D4D966004F7BA8 /* strcpy.c */; };
-               C97A720E1517AF53005E1998 /* strlcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518B13D4DABD004F7BA8 /* strlcpy.c */; };
-               C97A720F1517AF53005E1998 /* strncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 6310518E13D4DAEA004F7BA8 /* strncpy.c */; };
                C97A72101517AF53005E1998 /* stpcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060513DDEDF10094DD56 /* stpcpy.c */; };
                C97A72111517AF53005E1998 /* stpncpy.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060913DDEEA10094DD56 /* stpncpy.c */; };
                C97A72121517AF53005E1998 /* strcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060C13DDF26A0094DD56 /* strcat.c */; };
                C97A72131517AF53005E1998 /* strncat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4060F13DDF4340094DD56 /* strncat.c */; };
-               C97A72141517AF53005E1998 /* strlcat.c in Sources */ = {isa = PBXBuildFile; fileRef = 63D4061213DDF6A20094DD56 /* strlcat.c */; };
                C97A72161517AF53005E1998 /* sync_volume_np.c in Sources */ = {isa = PBXBuildFile; fileRef = B19C645B1450F90200032373 /* sync_volume_np.c */; };
                C97A72171517AF53005E1998 /* dirfd.c in Sources */ = {isa = PBXBuildFile; fileRef = 3FB7E1B4146EF2E000843438 /* dirfd.c */; };
                C98373971395989E00E5C052 /* OSMemoryNotification.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DAC138D9E9A0028D27C /* OSMemoryNotification.c */; };
                C9AE91B81517D32200A2626C /* libvCancelable.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C9D94360138EC3E300FB7ACC /* libvCancelable.a */; };
                C9AE91B91517D32900A2626C /* libTRE.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B122F2AD1432B8E600AF95D0 /* libTRE.a */; };
                C9B53E5E138DA5910028D27C /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DF9138D9E9A0028D27C /* mcount.s */; };
-               C9B53E77138DA59F0028D27C /* strcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53E17138D9E9A0028D27C /* strcpy.s */; };
-               C9B53E7A138DA59F0028D27C /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53E1A138D9E9A0028D27C /* strlen.s */; };
-               C9B53E7C138DA59F0028D27C /* strncpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53E1C138D9E9A0028D27C /* strncpy.s */; };
                C9C2A959138E025700287F00 /* sigaltstk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B5360C138D9E980028D27C /* sigaltstk.c */; };
                C9C2A95A138E025700287F00 /* sigcompat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B5360E138D9E980028D27C /* sigcompat.c */; };
                C9C2A97D138E058200287F00 /* brk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B5366E138D9E980028D27C /* brk.c */; };
                C9D94359138EC0C600FB7ACC /* heapsort_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9D94357138EC0C600FB7ACC /* heapsort_b.c */; };
                C9D9435A138EC0C600FB7ACC /* heapsort_r.c in Sources */ = {isa = PBXBuildFile; fileRef = C9D94358138EC0C600FB7ACC /* heapsort_r.c */; };
                C9EB2F53138F68A80075BB52 /* mcount.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53819138D9E990028D27C /* mcount.s */; };
-               C9EB2F72138F68A80075BB52 /* strcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383D138D9E990028D27C /* strcpy.s */; };
-               C9EB2F73138F68A80075BB52 /* strlcat.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383E138D9E990028D27C /* strlcat.s */; };
-               C9EB2F74138F68A80075BB52 /* strlcpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B5383F138D9E990028D27C /* strlcpy.s */; };
-               C9EB2F75138F68A80075BB52 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53840138D9E990028D27C /* strlen.s */; };
-               C9EB2F77138F68A80075BB52 /* strncpy.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B53842138D9E990028D27C /* strncpy.s */; };
-               C9EB2F84138F68CB0075BB52 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
-               C9EB2F99138F68CB0075BB52 /* strlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535CF138D9E980028D27C /* strlen.s */; };
-               C9EB2F9C138F68CB0075BB52 /* strnlen.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D2138D9E980028D27C /* strnlen.s */; };
-               C9EB2F9D138F68CB0075BB52 /* strstr.s in Sources */ = {isa = PBXBuildFile; fileRef = C9B535D3138D9E980028D27C /* strstr.s */; };
                C9EB2FC1138F6BB00075BB52 /* merge_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB2FC0138F6BB00075BB52 /* merge_b.c */; };
                C9EB2FC4138F6C5C0075BB52 /* psort.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB2FC3138F6C5C0075BB52 /* psort.c */; };
                C9EB2FC7138F6CE10075BB52 /* psort_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB2FC5138F6CE10075BB52 /* psort_b.c */; settings = {COMPILER_FLAGS = "-DI_AM_PSORT_B"; }; };
                C9EB2FC8138F6CE10075BB52 /* psort_r.c in Sources */ = {isa = PBXBuildFile; fileRef = C9EB2FC6138F6CE10075BB52 /* psort_r.c */; settings = {COMPILER_FLAGS = "-DI_AM_PSORT_R"; }; };
-               C9EB2FCD138F6D880075BB52 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C9EB2FD4138F6D880075BB52 /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C9EB2FD5138F6D880075BB52 /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C9EB2FD6138F6D880075BB52 /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C9EB31DF138F6D880075BB52 /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C9EB31E0138F6D880075BB52 /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS"; }; };
                C9EB31E1138F6D880075BB52 /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C9EB31E5138F6D880075BB52 /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C9EB31EA138F6D880075BB52 /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C9EB31ED138F6D880075BB52 /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C9EB31F0138F6D880075BB52 /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C9EB31F7138F6D880075BB52 /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C9EB31F8138F6D880075BB52 /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C9EB31F9138F6D880075BB52 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_STRERROR"; }; };
-               C9EB31FC138F6D880075BB52 /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C9EB31FD138F6D880075BB52 /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C9EB3201138F6D880075BB52 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C9EB3202138F6D880075BB52 /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C9EB3203138F6D880075BB52 /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C9EB3204138F6D880075BB52 /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C9EB3205138F6D880075BB52 /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C9EB3206138F6D880075BB52 /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C9EB3207138F6D880075BB52 /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C9EB3208138F6D880075BB52 /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C9EB3209138F6D880075BB52 /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C9EB320A138F6D880075BB52 /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C9EB320B138F6D880075BB52 /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C9EB320C138F6D880075BB52 /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C9EB3254138F6D880075BB52 /* parse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE1138D9E9A0028D27C /* parse.c */; };
                C9EB3255138F6D880075BB52 /* unpack.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE2138D9E9A0028D27C /* unpack.c */; };
                C9EB3256138F6D880075BB52 /* unparse.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53DE3138D9E9A0028D27C /* unparse.c */; };
-               C9EB3274138F75580075BB52 /* init_cpu_capabilities.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */; };
                C9EB327B138F75580075BB52 /* creat.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535F8138D9E980028D27C /* creat.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_CREAT"; }; };
                C9EB327C138F75580075BB52 /* gethostid.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FC138D9E980028D27C /* gethostid.c */; };
                C9EB327D138F75580075BB52 /* getwd.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B535FE138D9E980028D27C /* getwd.c */; };
                C9EB3486138F75580075BB52 /* timelocal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CD7138D9E9A0028D27C /* timelocal.c */; };
                C9EB3487138F75580075BB52 /* getdate.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE0138D9E9A0028D27C /* getdate.c */; settings = {COMPILER_FLAGS = "-D_DARWIN_UNLIMITED_STREAMS"; }; };
                C9EB3488138F75580075BB52 /* timezone_unix03.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CE3138D9E9A0028D27C /* timezone_unix03.c */; };
-               C9EB348C138F75580075BB52 /* index.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CF7138D9E9A0028D27C /* index.c */; };
                C9EB3491138F75580075BB52 /* memmem.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D06138D9E9A0028D27C /* memmem.c */; };
                C9EB3494138F75580075BB52 /* rindex.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D10138D9E9A0028D27C /* rindex.c */; };
                C9EB3497138F75580075BB52 /* strcasecmp.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D15138D9E9A0028D27C /* strcasecmp.c */; };
                C9EB349E138F75580075BB52 /* strcspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D2D138D9E9A0028D27C /* strcspn.c */; };
                C9EB349F138F75580075BB52 /* strdup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D30138D9E9A0028D27C /* strdup.c */; };
                C9EB34A0138F75580075BB52 /* strerror.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D33138D9E9A0028D27C /* strerror.c */; settings = {COMPILER_FLAGS = "$(FreeBSD_CFLAGS) -DLIBC_ALIAS_STRERROR"; }; };
-               C9EB34A3138F75580075BB52 /* strlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D3C138D9E9A0028D27C /* strlen.c */; };
                C9EB34A4138F75580075BB52 /* strmode.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D40138D9E9A0028D27C /* strmode.c */; };
                C9EB34A8138F75580075BB52 /* strndup.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D44138D9E9A0028D27C /* strndup.c */; };
-               C9EB34A9138F75580075BB52 /* strnlen.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D45138D9E9A0028D27C /* strnlen.c */; };
                C9EB34AA138F75580075BB52 /* strnstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D46138D9E9A0028D27C /* strnstr.c */; };
                C9EB34AB138F75580075BB52 /* strpbrk.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D49138D9E9A0028D27C /* strpbrk.c */; };
                C9EB34AC138F75580075BB52 /* strrchr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4C138D9E9A0028D27C /* strrchr.c */; };
                C9EB34AD138F75580075BB52 /* strsep.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D4F138D9E9A0028D27C /* strsep.c */; };
                C9EB34AE138F75580075BB52 /* strsignal.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D50138D9E9A0028D27C /* strsignal.c */; };
                C9EB34AF138F75580075BB52 /* strspn.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D54138D9E9A0028D27C /* strspn.c */; };
-               C9EB34B0138F75580075BB52 /* strstr.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D57138D9E9A0028D27C /* strstr.c */; };
                C9EB34B1138F75580075BB52 /* strtok.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5A138D9E9A0028D27C /* strtok.c */; };
                C9EB34B2138F75580075BB52 /* strxfrm.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D5D138D9E9A0028D27C /* strxfrm.c */; };
                C9EB34B3138F75580075BB52 /* swab.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53D61138D9E9A0028D27C /* swab.c */; };
                C9FA334B138E4D040089A94B /* gcvt.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CB9138D9E9A0028D27C /* gcvt.c */; };
                C9FA334C138E4D040089A94B /* qsort_b.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CBD138D9E9A0028D27C /* qsort_b.c */; };
                C9FA334D138E4D0C0089A94B /* strfmon.c in Sources */ = {isa = PBXBuildFile; fileRef = C9B53CB2138D9E9A0028D27C /* strfmon.c */; };
+               E408425B20B585BF00CC87A7 /* forceLibcToBuild.c in Sources */ = {isa = PBXBuildFile; fileRef = C9D9432A138DB72000FB7ACC /* forceLibcToBuild.c */; };
                FC2ED610157D4BE80098EC69 /* inet_ntop.c in Sources */ = {isa = PBXBuildFile; fileRef = FC2ED60E157D4BE70098EC69 /* inet_ntop.c */; };
                FC2ED611157D4BE80098EC69 /* inet_ntop.c in Sources */ = {isa = PBXBuildFile; fileRef = FC2ED60E157D4BE70098EC69 /* inet_ntop.c */; };
                FC2ED612157D4BE80098EC69 /* inet_ntop.c in Sources */ = {isa = PBXBuildFile; fileRef = FC2ED60E157D4BE70098EC69 /* inet_ntop.c */; };
 /* Begin PBXFileReference section */
                147CDFCF1B7C14FA00831EC6 /* clock_gettime.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = clock_gettime.3; sourceTree = "<group>"; };
                147CDFD01B7C14FA00831EC6 /* clock_gettime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = clock_gettime.c; sourceTree = "<group>"; };
+               2B514AB3203E4D9500641A4B /* thread_stack_pcs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = thread_stack_pcs.h; sourceTree = "<group>"; };
                2DF67CDD184F9CBE00B83A3D /* debug_private.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = debug_private.c; path = os/debug_private.c; sourceTree = "<group>"; };
                2DF67CE7184F9CD000B83A3D /* debug_private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = debug_private.h; path = os/debug_private.h; sourceTree = "<group>"; };
+               3006CB0E20BF7482003C5C79 /* _stdio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _stdio.h; sourceTree = "<group>"; };
                3F169A3C1643B7BA0029E851 /* memccpy_chk.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memccpy_chk.c; sourceTree = "<group>"; };
                3F18DE1F162A732C008B15AC /* memset_s.3 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = memset_s.3; sourceTree = "<group>"; };
                3F18DE20162A732C008B15AC /* memset_s.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memset_s.c; sourceTree = "<group>"; };
                3FB7E1B4146EF2E000843438 /* dirfd.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dirfd.c; sourceTree = "<group>"; };
                3FD14572171D42B300B7BAF5 /* bcopy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bcopy.c; sourceTree = "<group>"; };
                3FF283231A4764240098AD2C /* sim-compat-symlink.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "sim-compat-symlink.sh"; sourceTree = "<group>"; };
+               4B0899B920460FAC001360A4 /* cleanup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cleanup.h; sourceTree = "<group>"; };
+               4B151E0B1F8574B400F3F52F /* style.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = style.3; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.man; };
+               4B2C50E41F8453FA005DA2B6 /* internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = internal.h; sourceTree = "<group>"; };
                4B2C64A215519BAF00342BFA /* assumes.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = assumes.c; path = os/assumes.c; sourceTree = "<group>"; };
                4B2C64AB15519C3400342BFA /* assumes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = assumes.h; path = os/assumes.h; sourceTree = "<group>"; };
-               6310518613D4D966004F7BA8 /* strcpy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strcpy.c; sourceTree = "<group>"; };
-               6310518B13D4DABD004F7BA8 /* strlcpy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strlcpy.c; sourceTree = "<group>"; };
-               6310518E13D4DAEA004F7BA8 /* strncpy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strncpy.c; sourceTree = "<group>"; };
-               63505E3A1548525D00B637D7 /* strnlen.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = strnlen.s; sourceTree = "<group>"; };
-               639D126615595DDE00D0403A /* strnlen.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = strnlen.s; sourceTree = "<group>"; };
+               4B69E81220800BE9008D13D2 /* libdarwin_init.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = libdarwin_init.h; sourceTree = "<group>"; };
+               4B6CFC032065B9FF0022DBAD /* mach.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mach.c; sourceTree = "<group>"; };
+               4B6D181C206DEFBD00C00E37 /* mach_exception.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mach_exception.h; sourceTree = "<group>"; };
+               4B6D181E206DF1E200C00E37 /* exception.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = exception.c; sourceTree = "<group>"; };
+               4B782978208926A70070E1FF /* api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = api.h; path = os/api.h; sourceTree = "<group>"; };
+               4BA6E55B202AB1F100F38D3A /* errno.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = errno.h; sourceTree = "<group>"; };
+               4BA6E55D202AB31100F38D3A /* string.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = string.h; sourceTree = "<group>"; };
+               4BA6E55E202AB35900F38D3A /* string.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = string.c; sourceTree = "<group>"; };
+               4BA6E561202AC06300F38D3A /* err.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = err.c; sourceTree = "<group>"; };
+               4BA6E563202AC0C200F38D3A /* err.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = err.h; sourceTree = "<group>"; };
+               4BA6E564202AC43700F38D3A /* stdlib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stdlib.h; sourceTree = "<group>"; };
+               4BA6E565202AC94800F38D3A /* stdlib.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stdlib.c; sourceTree = "<group>"; };
+               4BA6E567202ACAFA00F38D3A /* stdio.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stdio.h; sourceTree = "<group>"; };
+               4BA6E568202ACDAA00F38D3A /* stdio.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stdio.c; sourceTree = "<group>"; };
+               4BA6E56A202ACF7A00F38D3A /* bsd.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = bsd.h; sourceTree = "<group>"; };
+               4BA6E56B202AD02900F38D3A /* bsd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = bsd.c; sourceTree = "<group>"; };
+               4BCC350E20659AD500A4CBAA /* mach_utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mach_utils.h; sourceTree = "<group>"; };
                63D4060513DDEDF10094DD56 /* stpcpy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stpcpy.c; sourceTree = "<group>"; };
                63D4060913DDEEA10094DD56 /* stpncpy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stpncpy.c; sourceTree = "<group>"; };
                63D4060C13DDF26A0094DD56 /* strcat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strcat.c; sourceTree = "<group>"; };
                63D4060F13DDF4340094DD56 /* strncat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strncat.c; sourceTree = "<group>"; };
-               63D4061213DDF6A20094DD56 /* strlcat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strlcat.c; sourceTree = "<group>"; };
                926F73921E03E2A3001E049D /* libsystem_darwin.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libsystem_darwin.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
                926F73971E03E8C4001E049D /* variant.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = variant.c; sourceTree = "<group>"; };
                926F73991E03E8D6001E049D /* variant_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = variant_private.h; path = os/variant_private.h; sourceTree = "<group>"; };
                B1795372158B0E35008990E8 /* xprintf_exec.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xprintf_exec.c; sourceTree = "<group>"; };
                B19C64591450F8B900032373 /* sync_volume_np.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = sync_volume_np.3; sourceTree = "<group>"; };
                B19C645B1450F90200032373 /* sync_volume_np.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sync_volume_np.c; sourceTree = "<group>"; };
-               C00AC1181E04B7E000286B61 /* legacy_opendir_alias.list */ = {isa = PBXFileReference; lastKnownFileType = text; path = legacy_opendir_alias.list; sourceTree = "<group>"; };
                C06E02D11CA0C9CA00B07322 /* tests */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tests; sourceTree = "<group>"; };
                C0E343811C58299D00E749C2 /* skip_installhdrs.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = skip_installhdrs.sh; sourceTree = "<group>"; };
                C0E345E21C582ECB00E749C2 /* libc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libc.a; sourceTree = BUILT_PRODUCTS_DIR; };
                C9A288A71ACDBA95004A33A7 /* Makefile.inc */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.pascal; path = Makefile.inc; sourceTree = "<group>"; };
                C9AE91AE1517CDAC00A2626C /* eos.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = eos.xcconfig; sourceTree = "<group>"; };
                C9B535AE138D9E980028D27C /* APPLE_LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = APPLE_LICENSE; sourceTree = "<group>"; };
-               C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = init_cpu_capabilities.c; sourceTree = "<group>"; };
-               C9B535CF138D9E980028D27C /* strlen.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strlen.s; sourceTree = "<group>"; };
-               C9B535D2138D9E980028D27C /* strnlen.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strnlen.s; sourceTree = "<group>"; };
-               C9B535D3138D9E980028D27C /* strstr.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strstr.s; sourceTree = "<group>"; };
                C9B535F7138D9E980028D27C /* creat.2 */ = {isa = PBXFileReference; lastKnownFileType = text; path = creat.2; sourceTree = "<group>"; };
                C9B535F8138D9E980028D27C /* creat.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = creat.c; sourceTree = "<group>"; };
                C9B535FA138D9E980028D27C /* gethostid.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = gethostid.3; sourceTree = "<group>"; };
                C9B5380B138D9E990028D27C /* gmon.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = gmon.c; sourceTree = "<group>"; };
                C9B5380D138D9E990028D27C /* moncontrol.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = moncontrol.3; sourceTree = "<group>"; };
                C9B53819138D9E990028D27C /* mcount.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = mcount.s; sourceTree = "<group>"; };
-               C9B5383D138D9E990028D27C /* strcpy.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strcpy.s; sourceTree = "<group>"; };
-               C9B5383E138D9E990028D27C /* strlcat.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strlcat.s; sourceTree = "<group>"; };
-               C9B5383F138D9E990028D27C /* strlcpy.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strlcpy.s; sourceTree = "<group>"; };
-               C9B53840138D9E990028D27C /* strlen.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strlen.s; sourceTree = "<group>"; };
-               C9B53842138D9E990028D27C /* strncpy.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strncpy.s; sourceTree = "<group>"; };
                C9B53850138D9E990028D27C /* _locale.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _locale.h; sourceTree = "<group>"; };
                C9B53852138D9E990028D27C /* _types.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _types.h; sourceTree = "<group>"; };
                C9B53853138D9E990028D27C /* _wctype.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _wctype.h; sourceTree = "<group>"; };
                C9B53CED138D9E9A0028D27C /* bstring.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = bstring.3; sourceTree = "<group>"; };
                C9B53CEF138D9E9A0028D27C /* bzero.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = bzero.3; sourceTree = "<group>"; };
                C9B53CF5138D9E9A0028D27C /* index.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = index.3; sourceTree = "<group>"; };
-               C9B53CF7138D9E9A0028D27C /* index.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = index.c; sourceTree = "<group>"; };
                C9B53CF8138D9E9A0028D27C /* memccpy.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = memccpy.3; sourceTree = "<group>"; };
                C9B53CFB138D9E9A0028D27C /* memchr.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = memchr.3; sourceTree = "<group>"; };
                C9B53CFE138D9E9A0028D27C /* memcmp.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = memcmp.3; sourceTree = "<group>"; };
                C9B53D35138D9E9A0028D27C /* string.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = string.3; sourceTree = "<group>"; };
                C9B53D38138D9E9A0028D27C /* strlcpy.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strlcpy.3; sourceTree = "<group>"; };
                C9B53D3B138D9E9A0028D27C /* strlen.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strlen.3; sourceTree = "<group>"; };
-               C9B53D3C138D9E9A0028D27C /* strlen.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strlen.c; sourceTree = "<group>"; };
                C9B53D3E138D9E9A0028D27C /* strmode.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strmode.3; sourceTree = "<group>"; };
                C9B53D40138D9E9A0028D27C /* strmode.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strmode.c; sourceTree = "<group>"; };
                C9B53D44138D9E9A0028D27C /* strndup.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strndup.c; sourceTree = "<group>"; };
-               C9B53D45138D9E9A0028D27C /* strnlen.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strnlen.c; sourceTree = "<group>"; };
                C9B53D46138D9E9A0028D27C /* strnstr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strnstr.c; sourceTree = "<group>"; };
                C9B53D47138D9E9A0028D27C /* strpbrk.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strpbrk.3; sourceTree = "<group>"; };
                C9B53D49138D9E9A0028D27C /* strpbrk.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strpbrk.c; sourceTree = "<group>"; };
                C9B53D52138D9E9A0028D27C /* strspn.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strspn.3; sourceTree = "<group>"; };
                C9B53D54138D9E9A0028D27C /* strspn.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strspn.c; sourceTree = "<group>"; };
                C9B53D55138D9E9A0028D27C /* strstr.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strstr.3; sourceTree = "<group>"; };
-               C9B53D57138D9E9A0028D27C /* strstr.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strstr.c; sourceTree = "<group>"; };
                C9B53D58138D9E9A0028D27C /* strtok.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strtok.3; sourceTree = "<group>"; };
                C9B53D5A138D9E9A0028D27C /* strtok.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = strtok.c; sourceTree = "<group>"; };
                C9B53D5B138D9E9A0028D27C /* strxfrm.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = strxfrm.3; sourceTree = "<group>"; };
                C9B53DEB138D9E9A0028D27C /* uuid_unparse.3.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = uuid_unparse.3.in; sourceTree = "<group>"; };
                C9B53DED138D9E9A0028D27C /* uuidP.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = uuidP.h; sourceTree = "<group>"; };
                C9B53DF9138D9E9A0028D27C /* mcount.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = mcount.s; sourceTree = "<group>"; };
-               C9B53E17138D9E9A0028D27C /* strcpy.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strcpy.s; sourceTree = "<group>"; };
-               C9B53E1A138D9E9A0028D27C /* strlen.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strlen.s; sourceTree = "<group>"; };
-               C9B53E1C138D9E9A0028D27C /* strncpy.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = strncpy.s; sourceTree = "<group>"; };
                C9B53E2C138DA0610028D27C /* libPlatform.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPlatform.a; sourceTree = BUILT_PRODUCTS_DIR; };
                C9C2A948138DF7DD00287F00 /* libc.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = libc.xcconfig; sourceTree = "<group>"; };
                C9C2A94D138DFFD900287F00 /* libBase.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBase.a; sourceTree = BUILT_PRODUCTS_DIR; };
                        path = NetBSD;
                        sourceTree = "<group>";
                };
+               4B2C50DE1F8453A6005DA2B6 /* h */ = {
+                       isa = PBXGroup;
+                       children = (
+                               4BA6E56A202ACF7A00F38D3A /* bsd.h */,
+                               4B0899B920460FAC001360A4 /* cleanup.h */,
+                               4BA6E563202AC0C200F38D3A /* err.h */,
+                               4BA6E55B202AB1F100F38D3A /* errno.h */,
+                               4B6D181C206DEFBD00C00E37 /* mach_exception.h */,
+                               4BCC350E20659AD500A4CBAA /* mach_utils.h */,
+                               4BA6E567202ACAFA00F38D3A /* stdio.h */,
+                               4BA6E564202AC43700F38D3A /* stdlib.h */,
+                               4BA6E55D202AB31100F38D3A /* string.h */,
+                               92D763E41EA6F887001467FC /* dirstat_collection.h */,
+                               92D763E51EA6F887001467FC /* dirstat.h */,
+                               4B69E81220800BE9008D13D2 /* libdarwin_init.h */,
+                       );
+                       path = h;
+                       sourceTree = "<group>";
+               };
                4B2C64A015519B0500342BFA /* os */ = {
                        isa = PBXGroup;
                        children = (
+                               4B782978208926A70070E1FF /* api.h */,
                                926F73991E03E8D6001E049D /* variant_private.h */,
                                2DF67CE7184F9CD000B83A3D /* debug_private.h */,
                                2DF67CDD184F9CBE00B83A3D /* debug_private.c */,
                926F73961E03E8C4001E049D /* libdarwin */ = {
                        isa = PBXGroup;
                        children = (
+                               4B2C50DE1F8453A6005DA2B6 /* h */,
                                9280EA171E59BC8A007A6F58 /* AppleInternalVariant.plist */,
-                               928841341EA7554D001064D1 /* dirstat_collection.c */,
-                               92D763E41EA6F887001467FC /* dirstat_collection.h */,
+                               4B2C50E41F8453FA005DA2B6 /* internal.h */,
+                               4BA6E56B202AD02900F38D3A /* bsd.c */,
+                               4B6D181E206DF1E200C00E37 /* exception.c */,
+                               4BA6E561202AC06300F38D3A /* err.c */,
+                               4B6CFC032065B9FF0022DBAD /* mach.c */,
+                               4BA6E568202ACDAA00F38D3A /* stdio.c */,
+                               4BA6E565202AC94800F38D3A /* stdlib.c */,
+                               4BA6E55E202AB35900F38D3A /* string.c */,
                                92D763DC1EA6D9FB001467FC /* dirstat.c */,
-                               92D763E51EA6F887001467FC /* dirstat.h */,
-                               92767C821E0A7E2100AB9C76 /* init.c */,
+                               928841341EA7554D001064D1 /* dirstat_collection.c */,
                                926F73971E03E8C4001E049D /* variant.c */,
+                               92767C821E0A7E2100AB9C76 /* init.c */,
                        );
                        path = libdarwin;
                        sourceTree = "<group>";
                C9B53595138D9A690028D27C = {
                        isa = PBXGroup;
                        children = (
-                               926F73961E03E8C4001E049D /* libdarwin */,
                                C9B535AE138D9E980028D27C /* APPLE_LICENSE */,
                                C9B535AF138D9E980028D27C /* arm */,
-                               C9B535E2138D9E980028D27C /* arm64 */,
                                C9B535F5138D9E980028D27C /* compat-43 */,
                                C9B53612138D9E980028D27C /* darwin */,
                                C9B5361D138D9E980028D27C /* db */,
                                C9B5380A138D9E990028D27C /* gmon */,
                                C9B5380F138D9E990028D27C /* i386 */,
                                C9B5384F138D9E990028D27C /* include */,
+                               926F73961E03E8C4001E049D /* libdarwin */,
                                C9B538FE138D9E990028D27C /* locale */,
                                C9B53A04138D9E990028D27C /* man */,
                                C9B53A0E138D9E990028D27C /* nbsdcompat */,
                        isa = PBXGroup;
                        children = (
                                C9B535B0138D9E980028D27C /* gen */,
-                               C9B535BF138D9E980028D27C /* string */,
                        );
                        path = arm;
                        sourceTree = "<group>";
                        path = gen;
                        sourceTree = "<group>";
                };
-               C9B535BF138D9E980028D27C /* string */ = {
-                       isa = PBXGroup;
-                       children = (
-                               C9B535CF138D9E980028D27C /* strlen.s */,
-                               C9B535D2138D9E980028D27C /* strnlen.s */,
-                               C9B535D3138D9E980028D27C /* strstr.s */,
-                       );
-                       path = string;
-                       sourceTree = "<group>";
-               };
-               C9B535E2138D9E980028D27C /* arm64 */ = {
-                       isa = PBXGroup;
-                       children = (
-                               C9B535EB138D9E980028D27C /* string */,
-                       );
-                       path = arm64;
-                       sourceTree = "<group>";
-               };
-               C9B535EB138D9E980028D27C /* string */ = {
-                       isa = PBXGroup;
-                       children = (
-                               63505E3A1548525D00B637D7 /* strnlen.s */,
-                       );
-                       path = string;
-                       sourceTree = "<group>";
-               };
                C9B535F5138D9E980028D27C /* compat-43 */ = {
                        isa = PBXGroup;
                        children = (
                                C9ECE2761950E384008E8672 /* atexit_receipt.c */,
                                92ABC7E81D375FC2000DF880 /* compatibility_hacks.c */,
                                C9D9432A138DB72000FB7ACC /* forceLibcToBuild.c */,
-                               C9B535B6138D9E980028D27C /* init_cpu_capabilities.c */,
                                C9B53616138D9E980028D27C /* kvm.c */,
                                FC960EF21850F33A005B9A9A /* libc_private.h */,
                        );
                                C9B537FE138D9E990028D27C /* tcsetattr.3 */,
                                C9B537FF138D9E990028D27C /* tcsetpgrp.3 */,
                                C9B53800138D9E990028D27C /* thread_stack_pcs.c */,
+                               2B514AB3203E4D9500641A4B /* thread_stack_pcs.h */,
                                C9B53801138D9E990028D27C /* tzset.3 */,
                                C9B53802138D9E990028D27C /* uname.3 */,
                                C9B53803138D9E990028D27C /* uname.c */,
                        isa = PBXGroup;
                        children = (
                                C9B53810138D9E990028D27C /* gen */,
-                               C9B53829138D9E990028D27C /* string */,
                        );
                        path = i386;
                        sourceTree = "<group>";
                        path = gen;
                        sourceTree = "<group>";
                };
-               C9B53829138D9E990028D27C /* string */ = {
-                       isa = PBXGroup;
-                       children = (
-                               C9B5383D138D9E990028D27C /* strcpy.s */,
-                               C9B5383E138D9E990028D27C /* strlcat.s */,
-                               C9B5383F138D9E990028D27C /* strlcpy.s */,
-                               C9B53840138D9E990028D27C /* strlen.s */,
-                               C9B53842138D9E990028D27C /* strncpy.s */,
-                       );
-                       path = string;
-                       sourceTree = "<group>";
-               };
                C9B5384F138D9E990028D27C /* include */ = {
                        isa = PBXGroup;
                        children = (
+                               3006CB0E20BF7482003C5C79 /* _stdio.h */,
                                C9B53850138D9E990028D27C /* _locale.h */,
                                FC60BAD016555A4A00033196 /* _types */,
                                C9B53852138D9E990028D27C /* _types.h */,
                                C9B53A0B138D9E990028D27C /* gethostuuid.2 */,
                                C9B53A0D138D9E990028D27C /* utmp.5 */,
                                C942135A13905D1C004BA536 /* manpages.lst */,
+                               4B151E0B1F8574B400F3F52F /* style.3 */,
                        );
                        path = man;
                        sourceTree = "<group>";
                                63D4060513DDEDF10094DD56 /* stpcpy.c */,
                                63D4060913DDEEA10094DD56 /* stpncpy.c */,
                                63D4060C13DDF26A0094DD56 /* strcat.c */,
-                               6310518613D4D966004F7BA8 /* strcpy.c */,
-                               63D4061213DDF6A20094DD56 /* strlcat.c */,
-                               6310518B13D4DABD004F7BA8 /* strlcpy.c */,
                                63D4060F13DDF4340094DD56 /* strncat.c */,
-                               6310518E13D4DAEA004F7BA8 /* strncpy.c */,
                        );
                        path = string;
                        sourceTree = "<group>";
                                C9B53CED138D9E9A0028D27C /* bstring.3 */,
                                C9B53CEF138D9E9A0028D27C /* bzero.3 */,
                                C9B53CF5138D9E9A0028D27C /* index.3 */,
-                               C9B53CF7138D9E9A0028D27C /* index.c */,
                                C9B53CF8138D9E9A0028D27C /* memccpy.3 */,
                                C9B53CFB138D9E9A0028D27C /* memchr.3 */,
                                C9B53CFE138D9E9A0028D27C /* memcmp.3 */,
                                C9B53D35138D9E9A0028D27C /* string.3 */,
                                C9B53D38138D9E9A0028D27C /* strlcpy.3 */,
                                C9B53D3B138D9E9A0028D27C /* strlen.3 */,
-                               C9B53D3C138D9E9A0028D27C /* strlen.c */,
                                C9B53D3E138D9E9A0028D27C /* strmode.3 */,
                                C9B53D40138D9E9A0028D27C /* strmode.c */,
                                C9B53D44138D9E9A0028D27C /* strndup.c */,
-                               C9B53D45138D9E9A0028D27C /* strnlen.c */,
                                C9B53D46138D9E9A0028D27C /* strnstr.c */,
                                C9B53D47138D9E9A0028D27C /* strpbrk.3 */,
                                C9B53D49138D9E9A0028D27C /* strpbrk.c */,
                                C9B53D52138D9E9A0028D27C /* strspn.3 */,
                                C9B53D54138D9E9A0028D27C /* strspn.c */,
                                C9B53D55138D9E9A0028D27C /* strstr.3 */,
-                               C9B53D57138D9E9A0028D27C /* strstr.c */,
                                C9B53D58138D9E9A0028D27C /* strtok.3 */,
                                C9B53D5A138D9E9A0028D27C /* strtok.c */,
                                C9B53D5B138D9E9A0028D27C /* strxfrm.3 */,
                        isa = PBXGroup;
                        children = (
                                C9B53DF0138D9E9A0028D27C /* gen */,
-                               C9B53E07138D9E9A0028D27C /* string */,
                        );
                        path = x86_64;
                        sourceTree = "<group>";
                        path = gen;
                        sourceTree = "<group>";
                };
-               C9B53E07138D9E9A0028D27C /* string */ = {
-                       isa = PBXGroup;
-                       children = (
-                               C9B53E17138D9E9A0028D27C /* strcpy.s */,
-                               C9B53E1A138D9E9A0028D27C /* strlen.s */,
-                               C9B53E1C138D9E9A0028D27C /* strncpy.s */,
-                               639D126615595DDE00D0403A /* strnlen.s */,
-                       );
-                       path = string;
-                       sourceTree = "<group>";
-               };
                C9C2A946138DF66900287F00 /* xcodescripts */ = {
                        isa = PBXGroup;
                        children = (
                                E4A877A6174D82FB000DBB55 /* alias.list */,
-                               C00AC1181E04B7E000286B61 /* legacy_opendir_alias.list */,
                                C9C2A948138DF7DD00287F00 /* libc.xcconfig */,
                                C9766153138ECF0000741512 /* variants.xcconfig */,
                                C9AE91AE1517CDAC00A2626C /* eos.xcconfig */,
                        isa = PBXHeadersBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               926F739A1E03E8D6001E049D /* variant_private.h in Headers */,
+                               4B6D181D206DEFBD00C00E37 /* mach_exception.h in Headers */,
+                               4B20DB4D202B81A4005C2327 /* bsd.h in Headers */,
+                               4B20DB50202B81A4005C2327 /* err.h in Headers */,
+                               4B20DB51202B81A4005C2327 /* errno.h in Headers */,
+                               4B20DB52202B81A4005C2327 /* stdio.h in Headers */,
+                               4B0899BC2046258F001360A4 /* cleanup.h in Headers */,
+                               4BCC350F20659AD500A4CBAA /* mach_utils.h in Headers */,
+                               4B20DB53202B81A4005C2327 /* stdlib.h in Headers */,
+                               4B69E81320800D47008D13D2 /* libdarwin_init.h in Headers */,
+                               4B782979208926A80070E1FF /* api.h in Headers */,
+                               4B20DB54202B81A4005C2327 /* string.h in Headers */,
+                               4B075C8E208BE9F200FD4F23 /* variant_private.h in Headers */,
+                               4B4E643F2069E94A00C4D8D5 /* internal.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        buildPhases = (
                                926F738E1E03E2A3001E049D /* Sources */,
                                926F738F1E03E2A3001E049D /* Frameworks */,
+                               3F55A4D72062412800C15893 /* Create public header path (safe to remove once we start installing public headers) */,
                                926F73901E03E2A3001E049D /* Headers */,
                                9280EA241E5A5D6F007A6F58 /* Copy AppleInternalVariant.plist */,
                        );
                C9B53597138D9A690028D27C /* Project object */ = {
                        isa = PBXProject;
                        attributes = {
-                               LastUpgradeCheck = 0700;
+                               LastUpgradeCheck = 1000;
                                TargetAttributes = {
                                        925E7FE619E8945900AC7889 = {
                                                CreatedOnToolsVersion = 6.1;
                        shellScript = "perl \"$SRCROOT/xcodescripts/generate_features.pl\"";
                        showEnvVarsInLog = 0;
                };
+               3F55A4D72062412800C15893 /* Create public header path (safe to remove once we start installing public headers) */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                       );
+                       name = "Create public header path (safe to remove once we start installing public headers)";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = "/bin/bash -e -x";
+                       shellScript = "mkdir -p ${TAPI_PUBLIC_HEADER_PATH}";
+               };
                3FF283291A4764370098AD2C /* Simulator Build Compat Symlink */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 8;
                        files = (
                        );
                        inputPaths = (
+                               "$(SRCROOT)/xcodescripts/skip_installhdrs.sh",
                                "$(SRCROOT)/xcodescripts/manpages.sh",
                        );
                        name = "Install Manpages";
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                        shellPath = "/bin/bash -e";
-                       shellScript = ". \"${SCRIPT_INPUT_FILE_0}\"";
+                       shellScript = ". \"${SCRIPT_INPUT_FILE_0}\" \"${SCRIPT_INPUT_FILE_1}\"";
                        showEnvVarsInLog = 0;
                };
                C95B7EDA138F3C55004311DA /* Generate libc-features.h */ = {
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               4B6CFC042065B9FF0022DBAD /* mach.c in Sources */,
                                926F73981E03E8C4001E049D /* variant.c in Sources */,
+                               4BA6E566202AC94800F38D3A /* stdlib.c in Sources */,
                                92D763E01EA6DA3A001467FC /* dirstat.c in Sources */,
+                               4BA6E569202ACDAA00F38D3A /* stdio.c in Sources */,
+                               4B6D181F206DF1E200C00E37 /* exception.c in Sources */,
                                92767C841E0A7E2700AB9C76 /* init.c in Sources */,
+                               4BA6E562202AC06300F38D3A /* err.c in Sources */,
+                               4BA6E56C202AD02900F38D3A /* bsd.c in Sources */,
                                928841361EA75555001064D1 /* dirstat_collection.c in Sources */,
+                               4BA6E55F202AB35900F38D3A /* string.c in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        buildActionMask = 2147483647;
                        files = (
                                C0E343921C582ECB00E749C2 /* mcount.s in Sources */,
-                               C0E343931C582ECB00E749C2 /* strcpy.s in Sources */,
-                               C0E343941C582ECB00E749C2 /* strlcat.s in Sources */,
-                               C0E343951C582ECB00E749C2 /* strlcpy.s in Sources */,
                                928BD1011D76072200EC01FC /* timingsafe_bcmp.c in Sources */,
-                               C0E343961C582ECB00E749C2 /* strlen.s in Sources */,
-                               C0E343971C582ECB00E749C2 /* strncpy.s in Sources */,
-                               C0E343981C582ECB00E749C2 /* strlen.s in Sources */,
-                               C0E343991C582ECB00E749C2 /* strnlen.s in Sources */,
-                               C0E3439A1C582ECB00E749C2 /* strstr.s in Sources */,
                                C0E3439B1C582ECB00E749C2 /* mcount.s in Sources */,
-                               C0E3439C1C582ECB00E749C2 /* (null) in Sources */,
-                               C0E3439D1C582ECB00E749C2 /* (null) in Sources */,
-                               C0E3439E1C582ECB00E749C2 /* (null) in Sources */,
-                               C0E3439F1C582ECB00E749C2 /* (null) in Sources */,
-                               C0E343A01C582ECB00E749C2 /* init_cpu_capabilities.c in Sources */,
                                C0E343A11C582ECB00E749C2 /* creat.c in Sources */,
                                C0E343A21C582ECB00E749C2 /* gethostid.c in Sources */,
                                C0E343A31C582ECB00E749C2 /* getwd.c in Sources */,
                                C0E345621C582ECB00E749C2 /* timelocal.c in Sources */,
                                C0E345631C582ECB00E749C2 /* getdate.c in Sources */,
                                C0E345641C582ECB00E749C2 /* timezone_unix03.c in Sources */,
-                               C0E345651C582ECB00E749C2 /* index.c in Sources */,
                                C0E345661C582ECB00E749C2 /* memmem.c in Sources */,
                                C0E345671C582ECB00E749C2 /* rindex.c in Sources */,
                                C0E345681C582ECB00E749C2 /* strcasecmp.c in Sources */,
                                C0E3456B1C582ECB00E749C2 /* strcspn.c in Sources */,
                                C0E3456C1C582ECB00E749C2 /* strdup.c in Sources */,
                                C0E3456D1C582ECB00E749C2 /* strerror.c in Sources */,
-                               C0E3456E1C582ECB00E749C2 /* strlen.c in Sources */,
                                C0E3456F1C582ECB00E749C2 /* strmode.c in Sources */,
                                C0E345701C582ECB00E749C2 /* strndup.c in Sources */,
-                               C0E345711C582ECB00E749C2 /* strnlen.c in Sources */,
                                C0E345721C582ECB00E749C2 /* strnstr.c in Sources */,
                                C0E345731C582ECB00E749C2 /* strpbrk.c in Sources */,
                                C0E345741C582ECB00E749C2 /* strrchr.c in Sources */,
                                C0E345751C582ECB00E749C2 /* strsep.c in Sources */,
                                C0E345761C582ECB00E749C2 /* strsignal.c in Sources */,
                                C0E345771C582ECB00E749C2 /* strspn.c in Sources */,
-                               C0E345781C582ECB00E749C2 /* strstr.c in Sources */,
                                C0E345791C582ECB00E749C2 /* strtok.c in Sources */,
                                C0E3457A1C582ECB00E749C2 /* strxfrm.c in Sources */,
                                C0E3457B1C582ECB00E749C2 /* swab.c in Sources */,
                                C0E345C11C582ECB00E749C2 /* (null) in Sources */,
                                C0E345C21C582ECB00E749C2 /* (null) in Sources */,
                                C0E345C31C582ECB00E749C2 /* scandir_b.c in Sources */,
-                               C0E345CA1C582ECB00E749C2 /* strcpy.c in Sources */,
-                               C0E345CB1C582ECB00E749C2 /* strlcpy.c in Sources */,
-                               C0E345CC1C582ECB00E749C2 /* strncpy.c in Sources */,
                                C0E345CD1C582ECB00E749C2 /* stpcpy.c in Sources */,
                                C0E345CE1C582ECB00E749C2 /* stpncpy.c in Sources */,
                                C0E345CF1C582ECB00E749C2 /* strcat.c in Sources */,
                                C0E345D01C582ECB00E749C2 /* strncat.c in Sources */,
-                               C0E345D11C582ECB00E749C2 /* strlcat.c in Sources */,
                                C0E345D21C582ECB00E749C2 /* sync_volume_np.c in Sources */,
                                C0E345D31C582ECB00E749C2 /* dirfd.c in Sources */,
                                C0E345D41C582ECB00E749C2 /* eos_stubs.c in Sources */,
-                               C0E345D51C582ECB00E749C2 /* strnlen.s in Sources */,
                                C0E345D61C582ECB00E749C2 /* assumes.c in Sources */,
                                C0E345D71C582ECB00E749C2 /* inet_ntop.c in Sources */,
                                C0E345D81C582ECB00E749C2 /* inet_pton.c in Sources */,
                                C925800A138E1CC000B3107C /* strptime.c in Sources */,
                                C925800B138E1CC000B3107C /* time32.c in Sources */,
                                C925800C138E1CC000B3107C /* timelocal.c in Sources */,
-                               C9258010138E1CD200B3107C /* index.c in Sources */,
                                C9258015138E1CD200B3107C /* memmem.c in Sources */,
                                C9258018138E1CD200B3107C /* rindex.c in Sources */,
                                C925801B138E1CD200B3107C /* strcasecmp.c in Sources */,
                                C9258022138E1CD200B3107C /* strcspn.c in Sources */,
                                C9258023138E1CD200B3107C /* strdup.c in Sources */,
                                C9258024138E1CD200B3107C /* strerror.c in Sources */,
-                               C9258027138E1CD200B3107C /* strlen.c in Sources */,
                                C9258028138E1CD200B3107C /* strmode.c in Sources */,
                                C925802C138E1CD200B3107C /* strndup.c in Sources */,
-                               C925802D138E1CD200B3107C /* strnlen.c in Sources */,
                                C925802E138E1CD200B3107C /* strnstr.c in Sources */,
                                C925802F138E1CD200B3107C /* strpbrk.c in Sources */,
                                C9258030138E1CD200B3107C /* strrchr.c in Sources */,
                                C9258031138E1CD200B3107C /* strsep.c in Sources */,
                                C9258032138E1CD200B3107C /* strsignal.c in Sources */,
                                C9258033138E1CD200B3107C /* strspn.c in Sources */,
-                               C9258034138E1CD200B3107C /* strstr.c in Sources */,
                                C9258035138E1CD200B3107C /* strtok.c in Sources */,
                                C9258036138E1CD200B3107C /* strxfrm.c in Sources */,
                                C9258037138E1CD200B3107C /* swab.c in Sources */,
                        buildActionMask = 2147483647;
                        files = (
                                C94213361390396E004BA536 /* mcount.s in Sources */,
-                               C942134C1390396E004BA536 /* strcpy.s in Sources */,
-                               C942134D1390396E004BA536 /* strlcat.s in Sources */,
-                               C942134E1390396E004BA536 /* strlcpy.s in Sources */,
-                               C942134F1390396E004BA536 /* strlen.s in Sources */,
-                               C94213511390396E004BA536 /* strncpy.s in Sources */,
-                               C942131E13903959004BA536 /* strlen.s in Sources */,
-                               C942132113903959004BA536 /* strnlen.s in Sources */,
-                               C942132213903959004BA536 /* strstr.s in Sources */,
                                C94212E413901595004BA536 /* mcount.s in Sources */,
-                               C94212FA13901595004BA536 /* strcpy.s in Sources */,
-                               C94212FD13901595004BA536 /* strlen.s in Sources */,
-                               C94212FF13901595004BA536 /* strncpy.s in Sources */,
-                               C942103213900C8A004BA536 /* init_cpu_capabilities.c in Sources */,
                                C942103913900C8A004BA536 /* creat.c in Sources */,
                                C942103A13900C8A004BA536 /* gethostid.c in Sources */,
                                C942103B13900C8A004BA536 /* getwd.c in Sources */,
                                C942124413900C8A004BA536 /* timelocal.c in Sources */,
                                C942124513900C8A004BA536 /* getdate.c in Sources */,
                                C942124613900C8A004BA536 /* timezone_unix03.c in Sources */,
-                               C942124A13900C8A004BA536 /* index.c in Sources */,
                                C942124F13900C8A004BA536 /* memmem.c in Sources */,
                                C942125213900C8A004BA536 /* rindex.c in Sources */,
                                C942125513900C8A004BA536 /* strcasecmp.c in Sources */,
                                C942125C13900C8A004BA536 /* strcspn.c in Sources */,
                                C942125D13900C8A004BA536 /* strdup.c in Sources */,
                                C942125E13900C8A004BA536 /* strerror.c in Sources */,
-                               C942126113900C8A004BA536 /* strlen.c in Sources */,
                                C942126213900C8A004BA536 /* strmode.c in Sources */,
                                C942126613900C8A004BA536 /* strndup.c in Sources */,
-                               C942126713900C8A004BA536 /* strnlen.c in Sources */,
                                C942126813900C8A004BA536 /* strnstr.c in Sources */,
                                C942126913900C8A004BA536 /* strpbrk.c in Sources */,
                                C942126A13900C8A004BA536 /* strrchr.c in Sources */,
                                C942126B13900C8A004BA536 /* strsep.c in Sources */,
                                C942126C13900C8A004BA536 /* strsignal.c in Sources */,
                                C942126D13900C8A004BA536 /* strspn.c in Sources */,
-                               C942126E13900C8A004BA536 /* strstr.c in Sources */,
                                C942126F13900C8A004BA536 /* strtok.c in Sources */,
                                C942127013900C8A004BA536 /* strxfrm.c in Sources */,
                                C942127113900C8A004BA536 /* swab.c in Sources */,
                                C94212BA13900C8A004BA536 /* unpack.c in Sources */,
                                C94212BB13900C8A004BA536 /* unparse.c in Sources */,
                                C94212C613900C8A004BA536 /* scandir_b.c in Sources */,
-                               6310518713D4D966004F7BA8 /* strcpy.c in Sources */,
-                               6310518C13D4DABD004F7BA8 /* strlcpy.c in Sources */,
-                               6310518F13D4DAEA004F7BA8 /* strncpy.c in Sources */,
                                63D4060813DDEDFF0094DD56 /* stpcpy.c in Sources */,
                                63D4060A13DDEEA20094DD56 /* stpncpy.c in Sources */,
                                63D4060D13DDF26A0094DD56 /* strcat.c in Sources */,
                                63D4061013DDF4340094DD56 /* strncat.c in Sources */,
-                               63D4061313DDF6A30094DD56 /* strlcat.c in Sources */,
                                B19C645C1450F90200032373 /* sync_volume_np.c in Sources */,
                                3FD4D48E1472F4B200075CCE /* dirfd.c in Sources */,
-                               63505E3B1548525D00B637D7 /* strnlen.s in Sources */,
                                4B2C64A315519BC300342BFA /* assumes.c in Sources */,
                                FC2ED610157D4BE80098EC69 /* inet_ntop.c in Sources */,
                                FC2ED619157D4BE80098EC69 /* inet_pton.c in Sources */,
-                               639D126A15595DDE00D0403A /* strnlen.s in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C95B7EDD138F3C55004311DA /* init_cpu_capabilities.c in Sources */,
                                C95B7EE4138F3C55004311DA /* creat.c in Sources */,
                                C95B7EE5138F3C55004311DA /* gethostid.c in Sources */,
                                C95B7EE6138F3C55004311DA /* getwd.c in Sources */,
                                C95B80EF138F3C55004311DA /* timelocal.c in Sources */,
                                C95B80F0138F3C55004311DA /* getdate.c in Sources */,
                                C95B80F1138F3C55004311DA /* timezone_unix03.c in Sources */,
-                               C95B80F5138F3C55004311DA /* index.c in Sources */,
                                C95B80FA138F3C55004311DA /* memmem.c in Sources */,
                                C95B80FD138F3C55004311DA /* rindex.c in Sources */,
                                C95B8100138F3C55004311DA /* strcasecmp.c in Sources */,
                                C95B8107138F3C55004311DA /* strcspn.c in Sources */,
                                C95B8108138F3C55004311DA /* strdup.c in Sources */,
                                C95B8109138F3C55004311DA /* strerror.c in Sources */,
-                               C95B810C138F3C55004311DA /* strlen.c in Sources */,
                                C95B810D138F3C55004311DA /* strmode.c in Sources */,
                                C95B8111138F3C55004311DA /* strndup.c in Sources */,
-                               C95B8112138F3C55004311DA /* strnlen.c in Sources */,
                                C95B8113138F3C55004311DA /* strnstr.c in Sources */,
                                C95B8114138F3C55004311DA /* strpbrk.c in Sources */,
                                C95B8115138F3C55004311DA /* strrchr.c in Sources */,
                                C95B8116138F3C55004311DA /* strsep.c in Sources */,
                                C95B8117138F3C55004311DA /* strsignal.c in Sources */,
                                C95B8118138F3C55004311DA /* strspn.c in Sources */,
-                               C95B8119138F3C55004311DA /* strstr.c in Sources */,
                                C95B811A138F3C55004311DA /* strtok.c in Sources */,
                                C95B811B138F3C55004311DA /* strxfrm.c in Sources */,
                                C95B811C138F3C55004311DA /* swab.c in Sources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C95B8188138F52B0004311DA /* init_cpu_capabilities.c in Sources */,
                                C95B818F138F52B0004311DA /* creat.c in Sources */,
                                C95B8190138F52B0004311DA /* gethostid.c in Sources */,
                                C95B8191138F52B0004311DA /* getwd.c in Sources */,
                                C95B839A138F52B0004311DA /* timelocal.c in Sources */,
                                C95B839B138F52B0004311DA /* getdate.c in Sources */,
                                C95B839C138F52B0004311DA /* timezone_unix03.c in Sources */,
-                               C95B83A0138F52B0004311DA /* index.c in Sources */,
                                C95B83A5138F52B0004311DA /* memmem.c in Sources */,
                                C95B83A8138F52B0004311DA /* rindex.c in Sources */,
                                C95B83AB138F52B0004311DA /* strcasecmp.c in Sources */,
                                C95B83B2138F52B0004311DA /* strcspn.c in Sources */,
                                C95B83B3138F52B0004311DA /* strdup.c in Sources */,
                                C95B83B4138F52B0004311DA /* strerror.c in Sources */,
-                               C95B83B7138F52B0004311DA /* strlen.c in Sources */,
                                C95B83B8138F52B0004311DA /* strmode.c in Sources */,
                                C95B83BC138F52B0004311DA /* strndup.c in Sources */,
-                               C95B83BD138F52B0004311DA /* strnlen.c in Sources */,
                                C95B83BE138F52B0004311DA /* strnstr.c in Sources */,
                                C95B83BF138F52B0004311DA /* strpbrk.c in Sources */,
                                C95B83C0138F52B0004311DA /* strrchr.c in Sources */,
                                C95B83C1138F52B0004311DA /* strsep.c in Sources */,
                                C95B83C2138F52B0004311DA /* strsignal.c in Sources */,
                                C95B83C3138F52B0004311DA /* strspn.c in Sources */,
-                               C95B83C4138F52B0004311DA /* strstr.c in Sources */,
                                C95B83C5138F52B0004311DA /* strtok.c in Sources */,
                                C95B83C6138F52B0004311DA /* strxfrm.c in Sources */,
                                C95B83C7138F52B0004311DA /* swab.c in Sources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C95B842E138F53DB004311DA /* init_cpu_capabilities.c in Sources */,
                                C95B8435138F53DB004311DA /* creat.c in Sources */,
                                C95B8436138F53DB004311DA /* gethostid.c in Sources */,
                                C95B8437138F53DB004311DA /* getwd.c in Sources */,
                                C95B8640138F53DB004311DA /* timelocal.c in Sources */,
                                C95B8641138F53DB004311DA /* getdate.c in Sources */,
                                C95B8642138F53DB004311DA /* timezone_unix03.c in Sources */,
-                               C95B8646138F53DB004311DA /* index.c in Sources */,
                                C95B864B138F53DB004311DA /* memmem.c in Sources */,
                                C95B864E138F53DB004311DA /* rindex.c in Sources */,
                                C95B8651138F53DB004311DA /* strcasecmp.c in Sources */,
                                C95B8658138F53DB004311DA /* strcspn.c in Sources */,
                                C95B8659138F53DB004311DA /* strdup.c in Sources */,
                                C95B865A138F53DB004311DA /* strerror.c in Sources */,
-                               C95B865D138F53DB004311DA /* strlen.c in Sources */,
                                C95B865E138F53DB004311DA /* strmode.c in Sources */,
                                C95B8662138F53DB004311DA /* strndup.c in Sources */,
-                               C95B8663138F53DB004311DA /* strnlen.c in Sources */,
                                C95B8664138F53DB004311DA /* strnstr.c in Sources */,
                                C95B8665138F53DB004311DA /* strpbrk.c in Sources */,
                                C95B8666138F53DB004311DA /* strrchr.c in Sources */,
                                C95B8667138F53DB004311DA /* strsep.c in Sources */,
                                C95B8668138F53DB004311DA /* strsignal.c in Sources */,
                                C95B8669138F53DB004311DA /* strspn.c in Sources */,
-                               C95B866A138F53DB004311DA /* strstr.c in Sources */,
                                C95B866B138F53DB004311DA /* strtok.c in Sources */,
                                C95B866C138F53DB004311DA /* strxfrm.c in Sources */,
                                C95B866D138F53DB004311DA /* swab.c in Sources */,
                        buildActionMask = 2147483647;
                        files = (
                                C97A6F291517AF53005E1998 /* mcount.s in Sources */,
-                               C97A6F3F1517AF53005E1998 /* strcpy.s in Sources */,
-                               C97A6F401517AF53005E1998 /* strlcat.s in Sources */,
-                               C97A6F411517AF53005E1998 /* strlcpy.s in Sources */,
-                               C97A6F421517AF53005E1998 /* strlen.s in Sources */,
-                               C97A6F441517AF53005E1998 /* strncpy.s in Sources */,
-                               C97A6F5A1517AF53005E1998 /* strlen.s in Sources */,
-                               C97A6F5C1517AF53005E1998 /* strnlen.s in Sources */,
-                               C97A6F5D1517AF53005E1998 /* strstr.s in Sources */,
                                C97A6F6D1517AF53005E1998 /* mcount.s in Sources */,
                                C97A6F761517AF53005E1998 /* (null) in Sources */,
                                C97A6F791517AF53005E1998 /* (null) in Sources */,
                                C97A6F7A1517AF53005E1998 /* (null) in Sources */,
                                C97A6F7E1517AF53005E1998 /* (null) in Sources */,
-                               C97A6F8F1517AF53005E1998 /* init_cpu_capabilities.c in Sources */,
                                C97A6F961517AF53005E1998 /* creat.c in Sources */,
                                C97A6F971517AF53005E1998 /* gethostid.c in Sources */,
                                C97A6F981517AF53005E1998 /* getwd.c in Sources */,
                                C97A71821517AF53005E1998 /* timelocal.c in Sources */,
                                C97A71831517AF53005E1998 /* getdate.c in Sources */,
                                C97A71841517AF53005E1998 /* timezone_unix03.c in Sources */,
-                               C97A71881517AF53005E1998 /* index.c in Sources */,
                                C97A718D1517AF53005E1998 /* memmem.c in Sources */,
                                C97A71901517AF53005E1998 /* rindex.c in Sources */,
                                C97A71911517AF53005E1998 /* strcasecmp.c in Sources */,
                                C97A71961517AF53005E1998 /* strcspn.c in Sources */,
                                C97A71971517AF53005E1998 /* strdup.c in Sources */,
                                C97A71981517AF53005E1998 /* strerror.c in Sources */,
-                               C97A71991517AF53005E1998 /* strlen.c in Sources */,
                                C97A719A1517AF53005E1998 /* strmode.c in Sources */,
                                C97A719C1517AF53005E1998 /* strndup.c in Sources */,
-                               C97A719D1517AF53005E1998 /* strnlen.c in Sources */,
                                C97A719E1517AF53005E1998 /* strnstr.c in Sources */,
                                C97A719F1517AF53005E1998 /* strpbrk.c in Sources */,
                                C97A71A01517AF53005E1998 /* strrchr.c in Sources */,
                                C97A71A11517AF53005E1998 /* strsep.c in Sources */,
                                C97A71A21517AF53005E1998 /* strsignal.c in Sources */,
                                C97A71A31517AF53005E1998 /* strspn.c in Sources */,
-                               C97A71A41517AF53005E1998 /* strstr.c in Sources */,
                                C97A71A51517AF53005E1998 /* strtok.c in Sources */,
                                C97A71A61517AF53005E1998 /* strxfrm.c in Sources */,
                                C97A71A71517AF53005E1998 /* swab.c in Sources */,
                                C97A71F91517AF53005E1998 /* (null) in Sources */,
                                C97A71FA1517AF53005E1998 /* (null) in Sources */,
                                C97A71FD1517AF53005E1998 /* scandir_b.c in Sources */,
-                               C97A720D1517AF53005E1998 /* strcpy.c in Sources */,
-                               C97A720E1517AF53005E1998 /* strlcpy.c in Sources */,
-                               C97A720F1517AF53005E1998 /* strncpy.c in Sources */,
                                C97A72101517AF53005E1998 /* stpcpy.c in Sources */,
                                C97A72111517AF53005E1998 /* stpncpy.c in Sources */,
                                C97A72121517AF53005E1998 /* strcat.c in Sources */,
                                C97A72131517AF53005E1998 /* strncat.c in Sources */,
-                               C97A72141517AF53005E1998 /* strlcat.c in Sources */,
                                C97A72161517AF53005E1998 /* sync_volume_np.c in Sources */,
                                C97A72171517AF53005E1998 /* dirfd.c in Sources */,
                                C925D1FD1518F4A2003D315B /* eos_stubs.c in Sources */,
-                               63505E3C1548525D00B637D7 /* strnlen.s in Sources */,
                                4B2C64A415519BC400342BFA /* assumes.c in Sources */,
                                FC2ED611157D4BE80098EC69 /* inet_ntop.c in Sources */,
                                FC2ED61A157D4BE80098EC69 /* inet_pton.c in Sources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C9EB2F84138F68CB0075BB52 /* init_cpu_capabilities.c in Sources */,
-                               C9EB2F99138F68CB0075BB52 /* strlen.s in Sources */,
-                               C9EB2F9C138F68CB0075BB52 /* strnlen.s in Sources */,
-                               C9EB2F9D138F68CB0075BB52 /* strstr.s in Sources */,
+                               E408425B20B585BF00CC87A7 /* forceLibcToBuild.c in Sources */,
                                C9EB2F53138F68A80075BB52 /* mcount.s in Sources */,
-                               C9EB2F72138F68A80075BB52 /* strcpy.s in Sources */,
-                               C9EB2F73138F68A80075BB52 /* strlcat.s in Sources */,
-                               C9EB2F74138F68A80075BB52 /* strlcpy.s in Sources */,
-                               C9EB2F75138F68A80075BB52 /* strlen.s in Sources */,
-                               C9EB2F77138F68A80075BB52 /* strncpy.s in Sources */,
                                C9B53E5E138DA5910028D27C /* mcount.s in Sources */,
-                               C9B53E77138DA59F0028D27C /* strcpy.s in Sources */,
-                               C9B53E7A138DA59F0028D27C /* strlen.s in Sources */,
-                               C9B53E7C138DA59F0028D27C /* strncpy.s in Sources */,
-                               63505E3D1548525D00B637D7 /* strnlen.s in Sources */,
-                               639D126C15595DDE00D0403A /* strnlen.s in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                C9EB355C138F81A40075BB52 /* kvm.c in Sources */,
                                C98373971395989E00E5C052 /* OSMemoryNotification.c in Sources */,
                                C98373981395989E00E5C052 /* OSThermalNotification.c in Sources */,
-                               6310518A13D4D9E9004F7BA8 /* strcpy.c in Sources */,
-                               6310518D13D4DABD004F7BA8 /* strlcpy.c in Sources */,
-                               6310519013D4DAEA004F7BA8 /* strncpy.c in Sources */,
                                63D4060613DDEDF10094DD56 /* stpcpy.c in Sources */,
                                63D4060B13DDEEA20094DD56 /* stpncpy.c in Sources */,
                                63D4060E13DDF26A0094DD56 /* strcat.c in Sources */,
                                63D4061113DDF4340094DD56 /* strncat.c in Sources */,
-                               63D4061413DDF6A30094DD56 /* strlcat.c in Sources */,
                                B19C645D1450F90200032373 /* sync_volume_np.c in Sources */,
                                3FB7E1B5146EF2E000843438 /* dirfd.c in Sources */,
                                4B2C64BA1551B03700342BFA /* assumes.c in Sources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C9765EB2138EC61900741512 /* init_cpu_capabilities.c in Sources */,
                                C9765EB9138EC61900741512 /* creat.c in Sources */,
                                C9765EBA138EC61900741512 /* gethostid.c in Sources */,
                                C9765EBB138EC61900741512 /* getwd.c in Sources */,
                                C97660C4138EC61A00741512 /* timelocal.c in Sources */,
                                C97660C5138EC61A00741512 /* getdate.c in Sources */,
                                C97660C6138EC61A00741512 /* timezone_unix03.c in Sources */,
-                               C97660CA138EC61A00741512 /* index.c in Sources */,
                                C97660CF138EC61A00741512 /* memmem.c in Sources */,
                                C97660D2138EC61A00741512 /* rindex.c in Sources */,
                                C97660D5138EC61A00741512 /* strcasecmp.c in Sources */,
                                C97660DC138EC61A00741512 /* strcspn.c in Sources */,
                                C97660DD138EC61A00741512 /* strdup.c in Sources */,
                                C97660DE138EC61A00741512 /* strerror.c in Sources */,
-                               C97660E1138EC61A00741512 /* strlen.c in Sources */,
                                C97660E2138EC61A00741512 /* strmode.c in Sources */,
                                C97660E6138EC61A00741512 /* strndup.c in Sources */,
-                               C97660E7138EC61A00741512 /* strnlen.c in Sources */,
                                C97660E8138EC61A00741512 /* strnstr.c in Sources */,
                                C97660E9138EC61A00741512 /* strpbrk.c in Sources */,
                                C97660EA138EC61A00741512 /* strrchr.c in Sources */,
                                C97660EB138EC61A00741512 /* strsep.c in Sources */,
                                C97660EC138EC61A00741512 /* strsignal.c in Sources */,
                                C97660ED138EC61A00741512 /* strspn.c in Sources */,
-                               C97660EE138EC61A00741512 /* strstr.c in Sources */,
                                C97660EF138EC61A00741512 /* strtok.c in Sources */,
                                C97660F0138EC61A00741512 /* strxfrm.c in Sources */,
                                C97660F1138EC61A00741512 /* swab.c in Sources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C9EB2FCD138F6D880075BB52 /* init_cpu_capabilities.c in Sources */,
                                C9EB2FD4138F6D880075BB52 /* creat.c in Sources */,
                                C9EB2FD5138F6D880075BB52 /* gethostid.c in Sources */,
                                C9EB2FD6138F6D880075BB52 /* getwd.c in Sources */,
                                C9EB31DF138F6D880075BB52 /* timelocal.c in Sources */,
                                C9EB31E0138F6D880075BB52 /* getdate.c in Sources */,
                                C9EB31E1138F6D880075BB52 /* timezone_unix03.c in Sources */,
-                               C9EB31E5138F6D880075BB52 /* index.c in Sources */,
                                C9EB31EA138F6D880075BB52 /* memmem.c in Sources */,
                                C9EB31ED138F6D880075BB52 /* rindex.c in Sources */,
                                C9EB31F0138F6D880075BB52 /* strcasecmp.c in Sources */,
                                C9EB31F7138F6D880075BB52 /* strcspn.c in Sources */,
                                C9EB31F8138F6D880075BB52 /* strdup.c in Sources */,
                                C9EB31F9138F6D880075BB52 /* strerror.c in Sources */,
-                               C9EB31FC138F6D880075BB52 /* strlen.c in Sources */,
                                C9EB31FD138F6D880075BB52 /* strmode.c in Sources */,
                                C9EB3201138F6D880075BB52 /* strndup.c in Sources */,
-                               C9EB3202138F6D880075BB52 /* strnlen.c in Sources */,
                                C9EB3203138F6D880075BB52 /* strnstr.c in Sources */,
                                C9EB3204138F6D880075BB52 /* strpbrk.c in Sources */,
                                C9EB3205138F6D880075BB52 /* strrchr.c in Sources */,
                                C9EB3206138F6D880075BB52 /* strsep.c in Sources */,
                                C9EB3207138F6D880075BB52 /* strsignal.c in Sources */,
                                C9EB3208138F6D880075BB52 /* strspn.c in Sources */,
-                               C9EB3209138F6D880075BB52 /* strstr.c in Sources */,
                                C9EB320A138F6D880075BB52 /* strtok.c in Sources */,
                                C9EB320B138F6D880075BB52 /* strxfrm.c in Sources */,
                                C9EB320C138F6D880075BB52 /* swab.c in Sources */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               C9EB3274138F75580075BB52 /* init_cpu_capabilities.c in Sources */,
                                C9EB327B138F75580075BB52 /* creat.c in Sources */,
                                C9EB327C138F75580075BB52 /* gethostid.c in Sources */,
                                C9EB327D138F75580075BB52 /* getwd.c in Sources */,
                                C9EB3486138F75580075BB52 /* timelocal.c in Sources */,
                                C9EB3487138F75580075BB52 /* getdate.c in Sources */,
                                C9EB3488138F75580075BB52 /* timezone_unix03.c in Sources */,
-                               C9EB348C138F75580075BB52 /* index.c in Sources */,
                                C9EB3491138F75580075BB52 /* memmem.c in Sources */,
                                C9EB3494138F75580075BB52 /* rindex.c in Sources */,
                                C9EB3497138F75580075BB52 /* strcasecmp.c in Sources */,
                                C9EB349E138F75580075BB52 /* strcspn.c in Sources */,
                                C9EB349F138F75580075BB52 /* strdup.c in Sources */,
                                C9EB34A0138F75580075BB52 /* strerror.c in Sources */,
-                               C9EB34A3138F75580075BB52 /* strlen.c in Sources */,
                                C9EB34A4138F75580075BB52 /* strmode.c in Sources */,
                                C9EB34A8138F75580075BB52 /* strndup.c in Sources */,
-                               C9EB34A9138F75580075BB52 /* strnlen.c in Sources */,
                                C9EB34AA138F75580075BB52 /* strnstr.c in Sources */,
                                C9EB34AB138F75580075BB52 /* strpbrk.c in Sources */,
                                C9EB34AC138F75580075BB52 /* strrchr.c in Sources */,
                                C9EB34AD138F75580075BB52 /* strsep.c in Sources */,
                                C9EB34AE138F75580075BB52 /* strsignal.c in Sources */,
                                C9EB34AF138F75580075BB52 /* strspn.c in Sources */,
-                               C9EB34B0138F75580075BB52 /* strstr.c in Sources */,
                                C9EB34B1138F75580075BB52 /* strtok.c in Sources */,
                                C9EB34B2138F75580075BB52 /* strxfrm.c in Sources */,
                                C9EB34B3138F75580075BB52 /* swab.c in Sources */,
                3F5120EF16C3174300AFB431 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(BASE_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Debug;
                3F5120F016C3174300AFB431 /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(BASE_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Release;
                925E7FE719E8945A00AC7889 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Debug;
                925E7FE819E8945A00AC7889 /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Release;
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                CLANG_ANALYZER_NONNULL = YES;
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                CLANG_WARN_BOOL_CONVERSION = YES;
                                CLANG_WARN_CONSTANT_CONVERSION = YES;
                                CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(inherited)",
                                        "_LIBC_NO_FEATURE_VERIFICATION=1",
+                                       "DARWIN_BUILDING_LIBSYSTEM_DARWIN=1",
                                );
                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
                                GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
                                GCC_WARN_UNUSED_FUNCTION = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
+                               HEADER_SEARCH_PATHS = (
+                                       "$($(TARGET_NAME)_SEARCH_PATHS)",
+                                       "$(DERIVED_FILES_DIR)/dtrace",
+                                       "$(SRCROOT_SEARCH_PATHS)",
+                                       "$(SYSTEM_FRAMEWORK_HEADERS)",
+                                       "$(SDKROOT)/usr/local/include",
+                                       "$(inherited)",
+                                       "$(PROJECT_DIR)/libdarwin/h",
+                               );
                                LIBRARY_SEARCH_PATHS = /usr/lib/system;
+                               LIBSYSTEM_DARWIN_LDFLAGS = "-all_load -nostdlib -L/usr/lib/system -umbrella System $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBM_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBC_LDFLAGS) $(LIBDISPATCH_LDFLAGS) $(LIBXPC_LDFLAGS) -Wl,-upward-lsystem_trace";
                                OTHER_LDFLAGS = "$(LIBSYSTEM_DARWIN_LDFLAGS)";
+                               OTHER_TAPI_FLAGS = "$(inherited) -extra-public-header $(SRCROOT)/libdarwin/h/dirstat.h -extra-public-header $(SRCROOT)/libdarwin/internal.h -DDARWIN_TAPI=1 -extra-public-header $(SRCROOT)/os/variant_private.h";
                                PRIVATE_HEADERS_FOLDER_PATH = "$(DARWIN_PRIVATE_HEADERS_FOLDER_PATH)";
                                PRODUCT_NAME = darwin;
-                               PUBLIC_HEADERS_FOLDER_PATH = "$(DARWIN_PUBLIC_HEADERS_FOLDER_PATH)";
                                SKIP_INSTALL = NO;
+                               SUPPORTS_TEXT_BASED_API = YES;
                                VERSIONING_SYSTEM = "apple-generic";
                        };
                        name = Debug;
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                CLANG_ANALYZER_NONNULL = YES;
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                CLANG_WARN_BOOL_CONVERSION = YES;
                                CLANG_WARN_CONSTANT_CONVERSION = YES;
                                CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(inherited)",
                                        "_LIBC_NO_FEATURE_VERIFICATION=1",
+                                       "DARWIN_BUILDING_LIBSYSTEM_DARWIN=1",
                                );
                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
                                GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
                                GCC_WARN_UNUSED_FUNCTION = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
+                               HEADER_SEARCH_PATHS = (
+                                       "$($(TARGET_NAME)_SEARCH_PATHS)",
+                                       "$(DERIVED_FILES_DIR)/dtrace",
+                                       "$(SRCROOT_SEARCH_PATHS)",
+                                       "$(SYSTEM_FRAMEWORK_HEADERS)",
+                                       "$(SDKROOT)/usr/local/include",
+                                       "$(inherited)",
+                                       "$(PROJECT_DIR)/libdarwin/h",
+                               );
                                LIBRARY_SEARCH_PATHS = /usr/lib/system;
+                               LIBSYSTEM_DARWIN_LDFLAGS = "-all_load -nostdlib -L/usr/lib/system -umbrella System $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBM_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBC_LDFLAGS) $(LIBDISPATCH_LDFLAGS) $(LIBXPC_LDFLAGS) -Wl,-upward-lsystem_trace";
                                OTHER_LDFLAGS = "$(LIBSYSTEM_DARWIN_LDFLAGS)";
+                               OTHER_TAPI_FLAGS = "$(inherited) -extra-public-header $(SRCROOT)/libdarwin/h/dirstat.h -extra-public-header $(SRCROOT)/libdarwin/internal.h -DDARWIN_TAPI=1 -extra-public-header $(SRCROOT)/os/variant_private.h";
                                PRIVATE_HEADERS_FOLDER_PATH = "$(DARWIN_PRIVATE_HEADERS_FOLDER_PATH)";
                                PRODUCT_NAME = darwin;
-                               PUBLIC_HEADERS_FOLDER_PATH = "$(DARWIN_PUBLIC_HEADERS_FOLDER_PATH)";
                                SKIP_INSTALL = NO;
+                               SUPPORTS_TEXT_BASED_API = YES;
                                VERSIONING_SYSTEM = "apple-generic";
                        };
                        name = Release;
                926F739F1E046E56001E049D /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Debug;
                926F73A01E046E56001E049D /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Release;
                928F25D21BEACED7007B13C7 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                        };
                        name = Debug;
                };
                928F25D31BEACED7007B13C7 /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                        };
                        name = Release;
                };
                B122F2AB1432B8E600AF95D0 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = (
                                        "$(FreeBSD_EXCLUDED_SOURCE_GDTOA)",
                                GCC_ENABLE_OBJC_EXCEPTIONS = YES;
                                GCC_OPTIMIZATION_LEVEL = 0;
                                GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = TRE;
                        };
                        name = Debug;
                B122F2AC1432B8E600AF95D0 /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = (
                                        "$(FreeBSD_EXCLUDED_SOURCE_GDTOA)",
                                EXECUTABLE_PREFIX = lib;
                                GCC_C_LANGUAGE_STANDARD = gnu99;
                                GCC_ENABLE_OBJC_EXCEPTIONS = YES;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = TRE;
                        };
                        name = Release;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C0E345E31C58300F00E749C2 /* libc_static.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                PRODUCT_NAME = "$(PRODUCT_NAME)";
                        };
                        name = Debug;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C0E345E31C58300F00E749C2 /* libc_static.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                PRODUCT_NAME = "$(PRODUCT_NAME)";
                        };
                        name = Release;
                C9257ED1138E1B5000B3107C /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = (
                                        "$(FreeBSD_EXCLUDED_SOURCE_GDTOA)",
                                GCC_ENABLE_OBJC_EXCEPTIONS = YES;
                                GCC_OPTIMIZATION_LEVEL = 0;
                                GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Debug;
                C9257ED2138E1B5000B3107C /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = (
                                        "$(FreeBSD_EXCLUDED_SOURCE_GDTOA)",
                                EXECUTABLE_PREFIX = lib;
                                GCC_C_LANGUAGE_STANDARD = gnu99;
                                GCC_ENABLE_OBJC_EXCEPTIONS = YES;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(FreeBSD_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Release;
                C9258103138E2D3100B3107C /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(BASE_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                                GCC_C_LANGUAGE_STANDARD = gnu11;
                C9258104138E2D3100B3107C /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(BASE_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                                GCC_C_LANGUAGE_STANDARD = gnu11;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
                                BUILD_VARIANTS = normal;
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
                                BUILD_VARIANTS = normal;
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9AE91AE1517CDAC00A2626C /* eos.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                        };
                        name = Debug;
                };
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9AE91AE1517CDAC00A2626C /* eos.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                        };
                        name = Release;
                };
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9C2A948138DF7DD00287F00 /* libc.xcconfig */;
                        buildSettings = {
+                               CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+                               CLANG_WARN_BOOL_CONVERSION = YES;
+                               CLANG_WARN_COMMA = YES;
+                               CLANG_WARN_CONSTANT_CONVERSION = YES;
+                               CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+                               CLANG_WARN_EMPTY_BODY = YES;
+                               CLANG_WARN_ENUM_CONVERSION = YES;
+                               CLANG_WARN_INFINITE_RECURSION = YES;
+                               CLANG_WARN_INT_CONVERSION = YES;
+                               CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+                               CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+                               CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+                               CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+                               CLANG_WARN_STRICT_PROTOTYPES = YES;
+                               CLANG_WARN_SUSPICIOUS_MOVE = YES;
+                               CLANG_WARN_UNREACHABLE_CODE = YES;
+                               CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                               ENABLE_STRICT_OBJC_MSGSEND = YES;
+                               ENABLE_TESTABILITY = YES;
+                               GCC_NO_COMMON_BLOCKS = YES;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_UNDECLARED_SELECTOR = YES;
+                               GCC_WARN_UNUSED_FUNCTION = YES;
+                               ONLY_ACTIVE_ARCH = YES;
                        };
                        name = Debug;
                };
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9C2A948138DF7DD00287F00 /* libc.xcconfig */;
                        buildSettings = {
+                               CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+                               CLANG_WARN_BOOL_CONVERSION = YES;
+                               CLANG_WARN_COMMA = YES;
+                               CLANG_WARN_CONSTANT_CONVERSION = YES;
+                               CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+                               CLANG_WARN_EMPTY_BODY = YES;
+                               CLANG_WARN_ENUM_CONVERSION = YES;
+                               CLANG_WARN_INFINITE_RECURSION = YES;
+                               CLANG_WARN_INT_CONVERSION = YES;
+                               CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+                               CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+                               CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+                               CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+                               CLANG_WARN_STRICT_PROTOTYPES = YES;
+                               CLANG_WARN_SUSPICIOUS_MOVE = YES;
+                               CLANG_WARN_UNREACHABLE_CODE = YES;
+                               CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                               ENABLE_STRICT_OBJC_MSGSEND = YES;
+                               GCC_NO_COMMON_BLOCKS = YES;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_UNDECLARED_SELECTOR = YES;
+                               GCC_WARN_UNUSED_FUNCTION = YES;
                        };
                        name = Release;
                };
                C9B53E2E138DA0610028D27C /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "*";
                                EXECUTABLE_PREFIX = lib;
                                GCC_SYMBOLS_PRIVATE_EXTERN = NO;
                C9B53E2F138DA0610028D27C /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "*";
                                EXECUTABLE_PREFIX = lib;
                                INCLUDED_SOURCE_FILE_NAMES = "$(Platform_INCLUDED_SOURCE_FILE_NAMES)";
                C9C2A94F138DFFDA00287F00 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(BASE_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Debug;
                C9C2A950138DFFDA00287F00 /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(BASE_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
-                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH))";
+                               INCLUDED_SOURCE_FILE_NAMES = "$(BASE_INCLUDED_SOURCE_FILE_NAMES)";
                                PRODUCT_NAME = "$(TARGET_NAME)";
                        };
                        name = Release;
                C9D94331138DB73300FB7ACC /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                COPY_PHASE_STRIP = YES;
                                DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
                                PRODUCT_NAME = c;
                                SKIP_INSTALL = NO;
                                STRIP_INSTALLED_PRODUCT = YES;
+                               SUPPORTS_TEXT_BASED_API = NO;
                                VERSIONING_SYSTEM = "apple-generic";
                        };
                        name = Debug;
                C9D94332138DB73300FB7ACC /* Release */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                COPY_PHASE_STRIP = YES;
                                DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
                                PRODUCT_NAME = c;
                                SKIP_INSTALL = NO;
                                STRIP_INSTALLED_PRODUCT = YES;
+                               SUPPORTS_TEXT_BASED_API = NO;
                                VERSIONING_SYSTEM = "apple-generic";
                        };
                        name = Release;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
                        isa = XCBuildConfiguration;
                        baseConfigurationReference = C9766153138ECF0000741512 /* variants.xcconfig */;
                        buildSettings = {
+                               CLANG_ENABLE_OBJC_WEAK = YES;
                                COMBINE_HIDPI_IMAGES = YES;
                                EXCLUDED_SOURCE_FILE_NAMES = "$(VARIANT_EXCLUDED_SOURCE_FILE_NAMES)";
                                EXECUTABLE_PREFIX = lib;
index 9c65e5520f8f49e3466b634b65d2242570d5bad0..bc89bb0ef49fa51f4e8bc7e0bf08086c032ae456 100644 (file)
@@ -31,6 +31,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)db.c       8.4 (Berkeley) 2/21/94";
 #endif /* LIBC_SCCS and not lint */
@@ -99,3 +102,4 @@ __dbpanic(dbp)
        dbp->seq = (int (*)())__dberr;
        dbp->sync = (int (*)())__dberr;
 }
+#pragma clang diagnostic pop
index c41854896a92042102e27f6120e2ddd422aacec7..4a1989026b67df4e10f5b768c946d1646b5612ee 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)getcwd.c   8.5 (Berkeley) 2/7/95";
 #endif /* LIBC_SCCS and not lint */
@@ -332,3 +335,4 @@ getcwd(pt, size)
 {
        return __private_getcwd(pt, size, 1);
 }
+#pragma clang diagnostic pop
index 8daab13a3b59699a30704de6b8c2867a2f889d01..9419e3dd02c85f52c4da9ebd293261f9e11c286f 100644 (file)
@@ -35,6 +35,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)glob.c     8.3 (Berkeley) 10/13/93";
 #endif /* LIBC_SCCS and not lint */
@@ -1171,3 +1174,4 @@ qprintf(const char *str, Char *s)
        }
 }
 #endif
+#pragma clang diagnostic pop
index a496863df0aa6ecfa8e18532f86b849be3bb2220..fd96452474758e9d088d7d1fbaf7fd3d75dc36e5 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)signal.c   8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -89,3 +92,4 @@ _signal_nobind(s, a)
     return signal__(s, a, 0);
 }
 #endif /* __DYNAMIC__ */
+#pragma clang diagnostic pop
index 3b2696767654ed739e0ccf0619cd3a9e0a605d11..6f0e68d83f92b35abac4ce4eb76023f7c7c4d4c3 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)timezone.c 8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -131,3 +134,4 @@ _tztab(zone,dst)
            "GMT%c%d:%02d",sign,zone / 60,zone % 60);
        return(czone);
 }
+#pragma clang diagnostic pop
index 0e7f6824300d69e18faacf8c0dc73d6a43a002bb..38b912528518f85c9e37465f009330bb5177cb86 100644 (file)
 .\" SUCH DAMAGE.
 .\"
 .\"
-.Dd February 15, 2007
+.Dd March 1, 2018
 .Dt backtrace 3
-.Os "Mac OS X"
+.Os "Darwin"
 .Sh NAME
 .Nm backtrace ,
 .Nm backtrace_symbols ,
-.Nm backtrace_symbols_fd
+.Nm backtrace_symbols_fd ,
+.Nm backtrace_image_offsets ,
+.Nm backtrace_from_fp
 .Nd call stack backtrace and display functions
 .Sh SYNOPSIS
 .In execinfo.h
 .Fa "int size"
 .Fa "int fd"
 .Fc
+.Ft void
+.Fo backtrace_image_offsets
+.Fa "void* const* array"
+.Fa "struct image_offset *image_offsets"
+.Fa "int size"
+.Fc
+.Ft int
+.Fo backtrace_from_fp
+.Fa "void* startfp"
+.Fa "void** array"
+.Fa "int size"
+.Fc
 .Sh DESCRIPTION
 These routines provide a mechanism to examine the current thread's call stack.
 .Pp
@@ -84,6 +98,21 @@ performs the same operation as
 but the resulting strings are immediately written to the file descriptor
 .Fa fd ,
 and are not returned.
+.Pp
+.Fn backtrace_image_offsets
+attempts to transform a call stack obtained by
+.Fn backtrace
+into an array of image offsets, for deferred symbolication.  Each entry in the
+array has an offset relative to the
+.Li __TEXT
+section of the image with the given UUID.  The results are written to
+.Fa image_offsets
+which should be an array of
+.Fa size
+length.
+.Pp
+.Fn backtrace_from_fp
+takes a backtrace of frames starting from the given frame pointer.
 .Sh EXAMPLE
 .Pp
     #include <execinfo.h>
@@ -99,8 +128,15 @@ and are not returned.
     ...
 .Pp
 .Sh HISTORY
-These functions first appeared in
-Mac OS X 10.5.
+.Fn backtrace ,
+.Fn backtrace_symbols ,
+and
+.Fn backtrace_symbols_fd
+first appeared in Mac OS X 10.5.
+.Fn backtrace_image_offsets
+and
+.Fn backtrace_from_fp
+first appeared macOS 10.14 and iOS 12.
 .Sh SEE ALSO
 .Xr dladdr 3 ,
 .Xr malloc 3
index 925dcb47bc0dfe301adb7e2f96ddb059a3e44a57..77192838fd76192228b8bbef6ea29feb962ae5da 100644 (file)
 #include <sys/uio.h>
 
 #include <dlfcn.h>
+#include <errno.h>
+#include <mach-o/dyld_priv.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <uuid/uuid.h>
 
 #include "stack_logging.h"
 #include "execinfo.h"
 
+extern void _thread_stack_pcs(vm_address_t *buffer, unsigned max,
+               unsigned *nb, unsigned skip, void *startfp);
+
 int backtrace(void** buffer, int size) {
-       extern void _thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb, unsigned skip);
        unsigned int num_frames;
-       _thread_stack_pcs((vm_address_t*)buffer, size, &num_frames, 1);
+       _thread_stack_pcs((vm_address_t*)buffer, size, &num_frames, 1, NULL);
+       while (num_frames >= 1 && buffer[num_frames-1] == NULL) num_frames -= 1;
+       return num_frames;
+}
+
+int
+backtrace_from_fp(void *startfp, void **buffer, int size)
+{
+       unsigned int num_frames;
+       _thread_stack_pcs((vm_address_t*)buffer, size, &num_frames, 1, startfp);
        while (num_frames >= 1 && buffer[num_frames-1] == NULL) num_frames -= 1;
        return num_frames;
 }
@@ -166,7 +180,19 @@ void backtrace_symbols_fd(void* const* buffer, int size, int fd) {
                dladdr(buffer[i], &info);
 
                iov[0].iov_len = _backtrace_snprintf(buf, sizeof(buf), i, buffer[i], &info);
-               
+
                writev(fd, iov, 2);
        }
 }
+
+void
+backtrace_image_offsets(void* const* buffer, struct image_offset *imgoffs, int size)
+{
+       struct dyld_image_uuid_offset infos[size];
+       _dyld_images_for_addresses(size, (const void **)buffer, infos);
+
+       for (int i = 0; i < size; i++) {
+               uuid_copy(imgoffs[i].uuid, infos[i].uuid);
+               imgoffs[i].offset = infos[i].offsetInImage;
+       };
+}
index e340b6441eabd40bfc29ef7cf31ecc7040171313..98e147a3b5fb073c8d3eccd2d53e2800b05d8720 100644 (file)
@@ -57,7 +57,7 @@ which is specified by
 .Pp
 .Fa clock_id
 can be a value from
-one of 5 predefined values:
+one of 8 predefined values:
 .Bl -tag -width Er
 .It Dv CLOCK_REALTIME
 the system's real time (i.e. wall time) clock, expressed as the amount of time
index 606431ab1a5d1f1bb9f85c3b75278307fdaa9786..ef2c601f7484faf9afcc8a265fc1ba0fdf5e0624 100644 (file)
@@ -56,6 +56,8 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
 
 #include <sys/cdefs.h>
 #include <unistd.h>
@@ -1044,3 +1046,5 @@ prtab(s, t, num_rows)
 }
 #endif
 #endif /* BUILDING_VARIANT */
+
+#pragma clang diagnostic pop
index fe90e212f5bec381be0408a1a145c0b8c86c1362..a4ba3058ca20a2d5d82c4f088b16b5cea09c3ac5 100644 (file)
@@ -70,6 +70,9 @@
 #include <unistd.h>
 #include <ctype.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #ifdef unused
 static int     error(int);
 #endif // unused
@@ -211,3 +214,5 @@ error(err)
        (void)write(STDERR_FILENO, "\n", 1);
 }
 #endif // unused
+#pragma clang diagnostic pop
+
index 259b92ee35099c94fe562d8231c398d880f7094c..97d942274c8dfb4654f87bb50bdfb5311c249704 100644 (file)
 
 #include <sys/cdefs.h>
 #include <Availability.h>
+#include <os/base.h>
+#include <os/availability.h>
+#include <stdint.h>
+#include <uuid/uuid.h>
 
 __BEGIN_DECLS
 
 int backtrace(void**,int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
+
+API_AVAILABLE(macosx(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT
+int backtrace_from_fp(void *startfp, void **array, int size);
+
 char** backtrace_symbols(void* const*,int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
 void backtrace_symbols_fd(void* const*,int,int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
 
+struct image_offset {
+       /*
+        * The UUID of the image.
+        */
+       uuid_t uuid;
+
+       /*
+        * The offset is relative to the __TEXT section of the image.
+        */
+       uint32_t offset;
+};
+
+API_AVAILABLE(macosx(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT
+void backtrace_image_offsets(void* const* array,
+               struct image_offset *image_offsets, int size);
+
 __END_DECLS
 
 #endif /* !_EXECINFO_H_ */
index 040abccb379df1552ae69bdd5da9f26fe90145a1..2377f498de5c909fec6b825f000afeccf1e58342 100644 (file)
--- a/gen/fts.c
+++ b/gen/fts.c
@@ -72,6 +72,9 @@
 #endif /* __BLOCKS__ */
 #include <malloc_private.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 static FTSENT  *fts_alloc(FTS *, char *, ssize_t);
 static FTSENT  *fts_build(FTS *, int);
 static void     fts_lfree(FTSENT *);
@@ -1576,3 +1579,4 @@ bail:
        errno = oerrno;
        return (ret);
 }
+#pragma clang diagnostic pop
index 25a1498483d3505b484b8697705a23a27aacfb16..50acdd1149dce5c385a2ca0863d9b32bb4832762 100644 (file)
@@ -63,6 +63,9 @@
 #include <regex.h>
 #include <limits.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 static char zapchar;
 static FILE *tf;
 
@@ -385,3 +388,5 @@ endttyent()
        }
        return (1);
 }
+#pragma clang diagnostic pop
+
index 53a7b5f2895d5e110bfd3911a9759c89e23bcfb2..18bbf21e3149fe76593950f8620c54aa43785ed6 100644 (file)
@@ -1,15 +1,15 @@
 /*
- * Copyright (c) 1999, 2007 Apple Inc. All rights reserved.
+ * Copyright (c) 1999-2018 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * compliance with the License. Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this
  * file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_LICENSE_HEADER_END@
  */
 
 #include <stdlib.h>
 #include "stack_logging.h"
 
+
 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)
 #define FP_LINK_OFFSET 1
-#elif defined(__ppc__) || defined(__ppc64__)
-#define FP_LINK_OFFSET 2
 #else
-#error  ********** Unimplemented architecture
+#error ********** Unimplemented architecture
 #endif
 
+
 #define        INSTACK(a)      ((a) >= stackbot && (a) <= stacktop)
-#if defined(__ppc__) || defined(__ppc64__) || defined(__x86_64__)
+#if defined(__x86_64__)
 #define        ISALIGNED(a)    ((((uintptr_t)(a)) & 0xf) == 0)
-#elif defined(__arm__) || defined(__arm64__)
-#define        ISALIGNED(a)    ((((uintptr_t)(a)) & 0x1) == 0)
 #elif defined(__i386__)
 #define        ISALIGNED(a)    ((((uintptr_t)(a)) & 0xf) == 8)
+#elif defined(__arm__) || defined(__arm64__)
+#define        ISALIGNED(a)    ((((uintptr_t)(a)) & 0x1) == 0)
 #endif
 
 __private_extern__  __attribute__((noinline))
 void
-_thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb, unsigned skip)
+_thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb,
+               unsigned skip, void *startfp)
 {
-    void *frame, *next;
-    pthread_t self = pthread_self();
-    void *stacktop = pthread_get_stackaddr_np(self);
-    void *stackbot = stacktop - pthread_get_stacksize_np(self);
+       void *frame, *next;
+       pthread_t self = pthread_self();
+       void *stacktop = pthread_get_stackaddr_np(self);
+       void *stackbot = stacktop - pthread_get_stacksize_np(self);
 
-    *nb = 0;
+       *nb = 0;
 
-    /* make sure return address is never out of bounds */
-    stacktop -= (FP_LINK_OFFSET + 1) * sizeof(void *);
+       /* make sure return address is never out of bounds */
+       stacktop -= (FP_LINK_OFFSET + 1) * sizeof(void *);
 
-    /*
-     * The original implementation called the first_frame_address() function,
-     * which returned the stack frame pointer.  The problem was that in ppc,
-     * it was a leaf function, so no new stack frame was set up with
-     * optimization turned on (while a new stack frame was set up without
-     * optimization).  We now inline the code to get the stack frame pointer,
-     * so we are consistent about the stack frame.
-     */
-#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__arm64__)
-    frame = __builtin_frame_address(0);
-#elif defined(__ppc__) || defined(__ppc64__)
-    /* __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421 */
-    __asm__ volatile("mr %0, r1" : "=r" (frame));
-#endif
-    if(!INSTACK(frame) || !ISALIGNED(frame))
-       return;
-#if defined(__ppc__) || defined(__ppc64__)
-    /* back up the stack pointer up over the current stack frame */
-    next = *(void **)frame;
-    if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
-       return;
-    frame = next;
-#endif
-    while (skip--) {
-       next = *(void **)frame;
-       if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
-           return;
-       frame = next;
-    }
-    while (max--) {
-        buffer[*nb] = *(vm_address_t *)(((void **)frame) + FP_LINK_OFFSET);
-        (*nb)++;
-       next = *(void **)frame;
-       if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
-           return;
-       frame = next;
-    }
+       frame = __builtin_frame_address(0);
+       if(!INSTACK(frame) || !ISALIGNED(frame))
+               return;
+       while ((startfp && startfp >= *(void **)frame) || skip--) {
+               next = *(void **)frame;
+               if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
+                       return;
+               frame = next;
+       }
+       while (max--) {
+               void *retaddr = (void *)*(vm_address_t *)
+                               (((void **)frame) + FP_LINK_OFFSET);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wint-conversion"
+               buffer[*nb] = retaddr;
+#pragma clang diagnostic pop
+               (*nb)++;
+               next = *(void **)frame;
+               if(!INSTACK(next) || !ISALIGNED(next) || next <= frame)
+                       return;
+               frame = next;
+       }
 }
 
+// Prevent thread_stack_pcs() from getting tail-call-optimized into
+// _thread_stack_pcs() on 64-bit environments, thus making the "number of hot
+// frames to skip" be more predictable, giving more consistent backtraces.
+//
+// See <rdar://problem/5364825> "stack logging: frames keep getting truncated"
+// for why this is necessary.
+__attribute__((disable_tail_calls))
 void
 thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb)
 {
-    _thread_stack_pcs(buffer, max, nb, 0);
-
-    // The following prevents thread_stack_pcs() from getting tail-call-optimized into _thread_stack_pcs() on 64-bit environments,
-    // thus making the "number of hot frames to skip" be more predictable, giving more consistent backtraces.
-    // See <rdar://problem/5364825> "stack logging: frames keep getting truncated" for why this is necessary.
-    __asm__ volatile("");
+       _thread_stack_pcs(buffer, max, nb, 0, NULL);
 }
diff --git a/gen/thread_stack_pcs.h b/gen/thread_stack_pcs.h
new file mode 100644 (file)
index 0000000..25d2ddf
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * "Portions Copyright (c) 2004 Apple Computer, Inc.  All Rights
+ * Reserved.  This file contains Original Code and/or Modifications of
+ * Original Code as defined in and that are subject to the Apple Public
+ * Source License Version 1.0 (the 'License').  You may not use this file
+ * except in compliance with the License.  Please obtain a copy of the
+ * License at http://www.apple.com/publicsource and read it before using
+ * this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#ifndef _LIBC_THREAD_STACK_PCS_H
+#define _LIBC_THREAD_STACK_PCS_H
+
+#include <sys/cdefs.h>
+#include <mach/vm_statistics.h>
+#include <mach/vm_types.h>
+
+__BEGIN_DECLS
+
+extern void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *num);
+
+__END_DECLS
+
+#endif // _LIBC_THREAD_STACK_PCS_H
diff --git a/i386/string/strcpy.s b/i386/string/strcpy.s
deleted file mode 100644 (file)
index 771eec4..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-
-// ***************
-// * S T R C P Y *
-// ***************
-//
-// char  *strcpy(const char *dst, const char *src);
-//
-// We optimize the move by doing it vector parallel.  This introduces
-// a complication: if we blindly did vector load/stores until finding
-// a 0, we might get a spurious page fault by touching bytes past it.
-// To avoid this, we never do a load that crosses a page boundary,
-// and never store a byte we don't have to.
-//
-// We align the destination, because unaligned vector stores are slow.
-
-        .text
-        .globl _strcpy
-
-        .align         4
-_strcpy:                               // char *strcpy(const char *dst, const char *src);
-       pushl   %edi
-       movl    8(%esp),%edi            // get dest ptr
-       movl    12(%esp),%ecx           // get source ptr
-       movl    %edi,%edx               // copy dest ptr
-       negl    %edx
-       andl    $15,%edx                // how many bytes to align dest ptr?
-       jnz     LLoopOverBytes          // not aligned, so go do so
-       
-       
-// In order to avoid spurious page faults, we loop until nearing the source page
-// end.  Then we revert to a byte-by-byte loop for 16 bytes until the page is crossed,
-// then resume the vector loop. 
-//     %ecx = source ptr (unaligned)
-//     %edi = dest ptr (aligned)
-
-LNextChunk:
-       movl    %ecx,%eax               // copy source ptr
-       movl    $4096,%edx
-       andl    $4095,%eax              // get offset into source page
-       subl    %eax,%edx               // get #bytes remaining in source page
-       shrl    $4,%edx                 // get #chunks till end of page
-       jnz     LLoopOverChunks         // enter vector loop
-       movl    $16,%edx                // move 16 bytes to cross page but keep dest aligned
-       jmp     LLoopOverBytes
-
-
-// Loop over bytes.
-//     %ecx = source ptr
-//     %edi = dest ptr
-//     %edx = byte count
-
-       .align  4,0x90                  // align inner loops to optimize I-fetch
-LLoopOverBytes:
-       movzb   (%ecx),%eax             // get source byte
-       inc     %ecx
-       movb    %al,(%edi)              // pack into dest
-       inc     %edi
-       testl   %eax,%eax               // 0?
-       jz      LDone                   // yes, we're done
-       dec     %edx                    // more to go?
-       jnz     LLoopOverBytes
-       
-       jmp     LNextChunk              // we've come to end of page
-
-
-// Loop over 16-byte chunks.
-//     %ecx = source ptr (unaligned)
-//     %edi = dest ptr (aligned)
-//     %edx = chunk count
-
-       .align  4,0x90                  // align inner loops to optimize I-fetch
-LLoopOverChunks:
-       movdqu  (%ecx),%xmm1            // get source
-       pxor    %xmm0,%xmm0             // get some 0s
-       addl    $16,%ecx
-       pcmpeqb %xmm1,%xmm0             // compare source to 0s
-       pmovmskb %xmm0,%eax             // get result mask for 0 check
-       testl   %eax,%eax               // any 0s?
-       jnz     LFound0                 // yes, exit loop
-       movdqa  %xmm1,(%edi)            // no 0s so do aligned store into destination
-       addl    $16,%edi
-       dec     %edx                    // more to go?
-       jnz     LLoopOverChunks
-       
-       movl    $16,%edx                // move 16 bytes
-       jmp     LLoopOverBytes          // cross page but keep dest aligned
-       
-
-// Found a zero in the vector.  Figure out where it is, and store the bytes
-// up to it.
-//     %edi = dest ptr (aligned)
-//     %eax = result mask
-//     %xmm1 = source vector
-
-LFound0:
-       bsf     %eax,%edx               // find first 0
-       inc     %edx                    // we need to store the 0 too
-       test    $16,%dl                 // was 0 last byte?
-       jz      8f                      // no
-       movdqa  %xmm1,(%edi)            // yes, store entire vector
-       jmp     LDone
-8:     
-       test    $8,%dl                  // 8-byte store required?
-       jz      4f                      // no
-       movq    %xmm1,(%edi)            // pack in 8 low bytes
-       psrldq  $8,%xmm1                // then shift vector down 8 bytes
-       addl    $8,%edi
-4:
-       test    $4,%dl                  // 4-byte store required?
-       jz      3f                      // no
-       movd    %xmm1,(%edi)            // pack in 4 low bytes
-       psrldq  $4,%xmm1                // then shift vector down 4 bytes
-       addl    $4,%edi
-3:
-       andl    $3,%edx                 // more to go?
-       jz      LDone                   // no
-       movd    %xmm1,%eax              // move remainders out of vector into %eax
-1:                                     // loop on up to three bytes
-       movb    %al,(%edi)              // pack in next byte
-       shrl    $8,%eax                 // shift next byte into position
-       inc     %edi
-       dec     %edx
-       jnz     1b
-       
-LDone:
-       movl    8(%esp),%eax            // original dest ptr is return value
-       popl    %edi
-       ret
diff --git a/i386/string/strlcat.s b/i386/string/strlcat.s
deleted file mode 100644 (file)
index d165cfc..0000000
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (c) 2007 Apple Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-
-// *****************
-// * S T R L C A T *
-// *****************
-//
-// size_t  strlcat(char *dst, const char *src, size_t size);
-//
-// We use SSE to do the initial strlen(), and word-parallel copies
-// to do the move.  This appears to be faster than either all SSE
-// or all word-parallel, at least on Core2 class machines.
-//
-// Using 4- or 16-byte parallel loops introduce a complication:
-// if we blindly did parallel load/stores until finding
-// a 0, we might get a spurious page fault by touching bytes past it.
-// To avoid this, we never do a load that crosses a page boundary,
-// or store unnecessary bytes.
-//
-// The word parallel test for 0s relies on the following inobvious
-// but very efficient test:
-//             x =  dataWord + 0xFEFEFEFF
-//             y = ~dataWord & 0x80808080
-//             if (x & y) == 0 then no zero found
-// The test maps any non-zero byte to zero, and any zero byte to 0x80,
-// with one exception: 0x01 bytes preceeding the first zero are also
-// mapped to 0x80.
-//
-// On Core2 class machines, this algorithm seems to be faster than the
-// naive byte-by-byte version for operands longer than about 10 bytes.  
-
-        .text
-        .globl _strlcat
-
-        .align         4
-_strlcat:                              // size_t *strlcat(char *dst, const char *src, size_t size);
-       pushl   %edi
-       pushl   %esi
-       pushl   %ebx
-       movl    16(%esp),%edi           // get dest ptr
-       movl    20(%esp),%esi           // get source ptr
-       movl    24(%esp),%ebx           // get length of buffer
-
-
-// Use SSE to find the 0-byte at current end of buffer.
-// This is just a minor variant of strlen().
-
-       movl    %edi,%ecx               // copy buffer ptr
-       andl    $(-16),%edi             // 16-byte align buffer ptr
-       pxor    %xmm0,%xmm0             // get some 0s
-       andl    $15,%ecx                // get #bytes in dq before start of buffer
-       movl    $16,%edx
-       orl     $(-1),%eax
-       subl    %ecx,%edx               // #bytes from buffer start to end of dq
-       subl    %edx,%ebx               // does buffer end before end of dq?
-       jb      LShortBuf1              // yes, drop into byte-by-byte mode
-       movdqa  (%edi),%xmm1            // get first aligned chunk of buffer
-       addl    $16,%edi
-       pcmpeqb %xmm0,%xmm1             // check for 0s
-       shl     %cl,%eax                // create mask for the bytes of aligned dq in operand
-       pmovmskb %xmm1,%ecx             // collect mask of 0-bytes
-       andl    %eax,%ecx               // mask out any 0s that occur before buffer start
-       jnz     2f                      // found end of buffer  
-1:
-       subl    $16,%ebx                // another dq in buffer?
-       jb      LShortBuf2              // no, drop into byte-by-byte mode
-       movdqa  (%edi),%xmm1            // get next chunk
-       addl    $16,%edi
-       pcmpeqb %xmm0,%xmm1             // check for 0s
-       pmovmskb %xmm1,%ecx             // collect mask of 0-bytes
-       testl   %ecx,%ecx               // any 0-bytes?
-       jz      1b                      // no
-2:
-       bsf     %ecx,%edx               // find first 1-bit (ie, first 0-byte)
-       subl    $16,%edi                // back up ptr into buffer
-       addl    $16,%ebx                // recover length remaining as of start of dq
-       addl    %edx,%edi               // point to 0-byte
-       subl    %edx,%ebx               // compute #bytes remaining in buffer
-
-
-// Copy byte-by-byte until source is 4-byte aligned.
-//     %edi = points to 1st byte available in buffer
-//     %esi = src ptr
-//     %ebx = buffer length remaining (ie, starting at %edi)
-//
-// NB: the rest of this code is cut-and-pasted from strlcpy().
-
-       movl    %esi,%edx               // copy source ptr
-       negl    %edx
-       andl    $3,%edx                 // how many bytes to align source ptr?
-       jz      LAligned                // already aligned
-
-
-// Loop over bytes.
-//     %edi = dest ptr
-//     %esi = source ptr
-//     %ebx = length remaining in buffer
-//     %edx = number of bytes to copy (>0, may not fit in buffer)
-
-LLoopOverBytes:
-       movzb   (%esi),%eax             // get source byte before checking buffer length
-       testl   %ebx,%ebx               // buffer full?
-       jz      L0NotFound              // yes
-       inc     %esi
-       dec     %ebx
-       movb    %al,(%edi)              // pack into dest
-       inc     %edi
-       testl   %eax,%eax               // 0?
-       jz      LDone                   // yes, done
-       dec     %edx                    // more to go?
-       jnz     LLoopOverBytes
-       
-
-// Source is aligned.  Loop over words until end of buffer.  We
-// align the source, rather than the dest, to avoid getting spurious page faults.
-//     %edi = dest ptr (unaligned)
-//     %esi = source ptr (word aligned)
-//     %ebx = length remaining in buffer
-
-LAligned:
-       movl    $5,%edx                 // if buffer almost exhausted, prepare to copy rest byte-by-byte
-       cmpl    $4,%ebx                 // enough for at least one word?
-       jb      LLoopOverBytes
-       
-
-// Loop over words.
-//     %edi = dest ptr (unaligned)
-//     %esi = source ptr (word aligned)
-//     %ebx = length remaining in buffer (>=4)
-
-LLoopOverWords:
-       movl    (%esi),%eax             // get next 4 bytes of source
-       subl    $4,%ebx
-       addl    $4,%esi
-       movl    %eax,%edx               // make 2 copies of word
-       movl    %eax,%ecx
-       notl    %edx                    // use magic word-parallel test for 0s
-       addl    $0xFEFEFEFF,%ecx
-       andl    $0x80808080,%edx
-       testl   %ecx,%edx
-       jnz     L0Found                 // one of the bytes of %eax is a 0
-       movl    %eax,(%edi)             // pack 4 bytes into destination
-       addl    $4,%edi
-       cmpl    $4,%ebx                 // room in buffer for another word?
-       jae     LLoopOverWords          // yes
-       
-       movl    %ebx,%edx               // copy leftovers in byte loop
-       jmp     LLoopOverBytes
-       
-// Found a 0-byte in the word of source.  Store a byte at a time until the 0.
-//     %edi = dest ptr (unaligned)
-//     %eax = last word of source, known to have a 0-byte
-
-LNextByte:
-       shrl    $8,%eax                 // next byte
-L0Found:
-       movb    %al,(%edi)              // pack in next byte
-       incl    %edi
-       testb   %al,%al                 // 0?
-       jnz     LNextByte
-       
-// Done storing string.
-//     %edi = ptr to byte after 0-byte
-
-LDone:
-       subl    16(%esp),%edi           // subtract original dest ptr to get length stored
-       decl    %edi                    // don't count the 0-byte
-       movl    %edi,%eax               // copy to return value
-LExit:
-       popl    %ebx
-       popl    %esi
-       popl    %edi
-       ret
-
-// Buffer filled but 0-byte not found.  We return the length of the buffer plus the length
-// of the source string.  This is not optimized, as it is an error condition.
-//     %edi = dest ptr (ie, 1 past end of buffer)
-//     %esi = source ptr (ptr to 1st byte that does not fit)
-       
-L0NotFound:
-       movl    24(%esp),%eax           // reload buffer length
-       testl   %eax,%eax               // null?
-       jz      LScanSourceTo0          // yes, cannot store a 0
-       xorl    %edx,%edx               // get a 0
-       movb    %dl,-1(%edi)            // store a 0 at end of buffer to delimit string
-LScanSourceTo0:
-       movzb   (%esi),%edx             // get next byte of source
-       incl    %esi
-       incl    %eax
-       testl   %edx,%edx               // 0?
-       jnz     LScanSourceTo0
-       decl    %eax                    // don't count the 0-byte
-       jmp     LExit
-
-
-// Buffer too short to reach end of even one 16-byte aligned chunk.
-//     %esi = src ptr
-
-LShortBuf1:
-       movl    16(%esp),%edi           // recover ptr to start of buffer
-       movl    24(%esp),%ebx           // recover buffer length
-       jmp     LShortBuf3
-       
-
-// Out of aligned dq's of buffer, 0-byte still not found.
-//     %esi = src ptr
-//     %edi = 1st buffer byte not checked for 0
-//     %ebx = length remaining - 16
-
-LShortBuf2:
-       addl    $16,%ebx                // length remaining
-LShortBuf3:
-       movl    24(%esp),%eax           // recover original buffer length, in case 0-byte not found
-       movl    $17,%edx                // buffer almost exhausted, prepare to copy byte-by-byte
-1:
-       testl   %ebx,%ebx               // no 0s in buffer at all?
-       jz      LScanSourceTo0          // yes, cannot store a 0
-       cmpb    $0,(%edi)               // is this the 0?
-       jz      LLoopOverBytes          // yes, append source
-       incl    %edi
-       decl    %ebx
-       jmp     1b                      // loop looking for 0
diff --git a/i386/string/strlcpy.s b/i386/string/strlcpy.s
deleted file mode 100644 (file)
index 21a366c..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2007 Apple Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-
-// *****************
-// * S T R L C P Y *
-// *****************
-//
-// size_t  strlcpy(char *dst, const char *src, size_t size);
-//
-// We optimize the move by doing it word parallel.  This introduces
-// a complication: if we blindly did word load/stores until finding
-// a 0, we might get a spurious page fault by touching bytes past it.
-// To avoid this, we never do a load that crosses a page boundary,
-// or store unnecessary bytes.
-//
-// The test for 0s relies on the following inobvious but very efficient
-// word-parallel test:
-//             x =  dataWord + 0xFEFEFEFF
-//             y = ~dataWord & 0x80808080
-//             if (x & y) == 0 then no zero found
-// The test maps any non-zero byte to zero, and any zero byte to 0x80,
-// with one exception: 0x01 bytes preceeding the first zero are also
-// mapped to 0x80.
-//
-// On Core2 class machines, this word-parallel implementation seems to
-// be slightly faster than using SSE up to about 100 bytes.
-// It is faster than the naive byte-by-byte implementation for
-// operands longer than about 8 bytes.
-
-        .text
-        .globl _strlcpy
-
-        .align         4
-_strlcpy:                              // size_t *strlcpy(char *dst, const char *src, size_t size);
-       pushl   %edi
-       pushl   %esi
-       pushl   %ebx
-       movl    16(%esp),%edi           // get dest ptr
-       movl    20(%esp),%esi           // get source ptr
-       movl    24(%esp),%ecx           // get length of buffer
-       movl    %esi,%edx               // copy source ptr
-       negl    %edx
-       andl    $3,%edx                 // how many bytes to align source ptr?
-       jz      LAligned                // already aligned
-
-
-// Loop over bytes.
-//     %edi = dest ptr
-//     %esi = source ptr
-//     %ecx = length remaining in buffer
-//     %edx = number of bytes to copy (>0, may not fit in buffer)
-
-LLoopOverBytes:
-       movzb   (%esi),%eax             // get source byte before checking buffer length
-       testl   %ecx,%ecx               // buffer full?
-       jz      L0NotFound              // yes
-       inc     %esi
-       dec     %ecx
-       movb    %al,(%edi)              // pack into dest
-       inc     %edi
-       testl   %eax,%eax               // 0?
-       jz      LDone                   // yes, done
-       dec     %edx                    // more to go?
-       jnz     LLoopOverBytes
-       
-
-// Source is aligned.  Loop over words until end of buffer.  We
-// align the source, rather than the dest, to avoid getting spurious page faults.
-//     %edi = dest ptr (unaligned)
-//     %esi = source ptr (word aligned)
-//     %ecx = length remaining in buffer
-
-LAligned:
-       movl    $5,%edx                 // if buffer almost exhausted, prepare to copy rest byte-by-byte
-       cmpl    $4,%ecx                 // enough for at least one word?
-       jb      LLoopOverBytes
-       
-
-// Loop over words.
-//     %edi = dest ptr (unaligned)
-//     %esi = source ptr (word aligned)
-//     %ecx = length remaining in buffer (>=4)
-
-LLoopOverWords:
-       movl    (%esi),%eax             // get next 4 bytes of source
-       subl    $4,%ecx
-       addl    $4,%esi
-       movl    %eax,%edx               // make 2 copies of word
-       movl    %eax,%ebx
-       notl    %edx                    // use magic word-parallel test for 0s
-       addl    $0xFEFEFEFF,%ebx
-       andl    $0x80808080,%edx
-       testl   %ebx,%edx
-       jnz     L0Found                 // one of the bytes of %eax is a 0
-       movl    %eax,(%edi)             // pack 4 bytes into destination
-       addl    $4,%edi
-       cmpl    $4,%ecx                 // room in buffer for another word?
-       jae     LLoopOverWords          // yes
-       
-       movl    %ecx,%edx               // copy leftovers in byte loop
-       jmp     LLoopOverBytes
-       
-// Found a 0-byte in the word of source.  Store a byte at a time until the 0.
-//     %edi = dest ptr (unaligned)
-//     %eax = last word of source, known to have a 0-byte
-
-LNextByte:
-       shrl    $8,%eax                 // next byte
-L0Found:
-       movb    %al,(%edi)              // pack in next byte
-       incl    %edi
-       testb   %al,%al                 // 0?
-       jnz     LNextByte
-       
-// Done storing string.
-//     %edi = ptr to byte after 0-byte
-
-LDone:
-       subl    16(%esp),%edi           // subtract original dest ptr to get length stored
-       decl    %edi                    // don't count the 0-byte
-       movl    %edi,%eax               // copy to return value
-LExit:
-       popl    %ebx
-       popl    %esi
-       popl    %edi
-       ret
-
-// Buffer filled but 0-byte not found.  We return the length of the source string.
-// This is not optimized, as it is an error condition.
-//     %edi = dest ptr (ie, 1 past end of buffer)
-//     %esi = source ptr (ptr to 1st byte that does not fit)
-       
-L0NotFound:
-       movl    24(%esp),%eax           // reload buffer length
-       testl   %eax,%eax               // null?
-       jz      1f                      // yes, cannot store a 0
-       xorl    %edx,%edx               // get a 0
-       movb    %dl,-1(%edi)            // store a 0 at end of buffer to delimit string
-1:
-       movzb   (%esi),%edx             // get next byte of source
-       incl    %esi
-       incl    %eax
-       testl   %edx,%edx               // 0?
-       jnz     1b
-       decl    %eax                    // don't count the 0-byte
-       jmp     LExit
diff --git a/i386/string/strlen.s b/i386/string/strlen.s
deleted file mode 100644 (file)
index b21bee5..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
- *
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-
-/*
- * Strlen, for processors with SSE3.
- *
- * Note that all memory references must be aligned, in order to avoid spurious
- * page faults.  Thus we have to load the aligned 16-byte chunk containing the
- * first byte of the operand, then mask out false 0s that may occur before the
- * first byte.
- *
- * We favor the fall-through (ie, short operand) path.
- */
-
-        .text
-        .globl  _strlen
-        .align  4, 0x90
-_strlen:                               // size_t strlen(char *b);
-       movl    4(%esp),%edx            // get ptr to string
-       pxor    %xmm0,%xmm0             // zero %xmm0
-       movl    %edx,%ecx               // copy ptr
-       andl    $(-16),%edx             // 16-byte align ptr
-       orl     $(-1),%eax
-       pcmpeqb (%edx),%xmm0            // check whole qw for 0s
-       andl    $15,%ecx                // get #bytes in aligned dq before operand
-       shl     %cl,%eax                // create mask for the bytes of aligned dq in operand
-       pmovmskb %xmm0,%ecx             // collect mask of 0-bytes
-       andl    %eax,%ecx               // mask out any 0s that occur before 1st byte
-       jz      LEnterLoop              // no 0-bytes (ie, 1-bits), so enter by-16 loop
-       
-// We've found a 0-byte.
-//     %edx = aligned address of 16-byte block containing the terminating 0-byte
-//     %ecx = compare bit vector
-
-LFoundIt:
-       bsf     %ecx,%eax               // find first 1-bit (ie, first 0-byte)
-       movl    4(%esp),%ecx            // recover ptr to 1st byte in string
-       addl    %edx,%eax               // get address of the 0-byte
-       subl    %ecx,%eax               // subtract address of 1st byte to get string length
-       ret
-       
-// Loop over aligned 16-byte blocks:
-//     %edx = address of previous block
-
-LEnterLoop:
-       pxor    %xmm0,%xmm0             // get some 0-bytes
-       addl    $16,%edx                // advance ptr
-LLoop:
-       movdqa  (%edx),%xmm1            // get next chunk
-       addl    $16,%edx
-       pcmpeqb %xmm0,%xmm1             // check for 0s
-       pmovmskb %xmm1,%ecx             // collect mask of 0-bytes
-       test    %ecx,%ecx               // any 0-bytes?
-       jz      LLoop                   // no 0-bytes, so get next dq
-
-       subl    $16,%edx                // back up ptr
-       jmp     LFoundIt
-       
-       
\ No newline at end of file
diff --git a/i386/string/strncpy.s b/i386/string/strncpy.s
deleted file mode 100644 (file)
index 9b1799d..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <machine/cpu_capabilities.h>
-
-
-// *****************
-// * S T R N C P Y *
-// *****************
-//
-// char  *strncpy(const char *dst, const char *src, size_t n);
-//
-// We optimize the move by doing it vector parallel.  This introduces
-// a complication: if we blindly did vector load/stores until finding
-// a 0, we might get a spurious page fault by touching bytes past it.
-// To avoid this, we never do a load that crosses a page boundary,
-// and never store a byte we don't have to.
-//
-// We align the destination, because unaligned vector stores are slow.
-//
-// Recall that strncpy() zero fills the remainder of the dest buffer,
-// and does not terminate the string if it's length is greater than or
-// equal to n.
-
-#define        kShort  31                      // too short to bother with vector loop
-
-        .text
-        .globl _strncpy
-
-        .align         4
-_strncpy:                              // char  *strncpy(const char *dst, const char *src, size_t n);
-       pushl   %edi
-       pushl   %esi
-       movl    12(%esp),%edi           // get dest ptr
-       movl    16(%esp),%esi           // get source ptr
-       movl    20(%esp),%ecx           // get length
-       movl    %edi,%edx               // copy dest ptr
-       negl    %edx
-       andl    $15,%edx                // how many bytes to align dest ptr?
-       jnz     LCheckShortCopy         // align destination first
-       
-       
-// In order to avoid spurious page faults, we loop until nearing the source page
-// end.  Then we revert to a byte-by-byte loop for 16 bytes until the page is crossed,
-// then resume the vector loop. 
-//     %esi = source ptr (unaligned)
-//     %edi = dest ptr (aligned)
-//     %ecx = buffer length remaining
-
-LNextChunk:                            // NB: can drop down to here
-       movl    %esi,%eax               // copy source ptr
-       movl    $4096,%edx
-       andl    $4095,%eax              // get offset into source page
-       subl    %eax,%edx               // get #bytes remaining in source page
-       cmpl    %ecx,%edx               // will buffer run out before the page end?
-       cmova   %ecx,%edx               // get min(length remaining, bytes to page end)
-       shrl    $4,%edx                 // get #chunks till end of page
-       jnz     LLoopOverChunks         // enter vector loop
-       
-// We can't use the chunk loop yet.  Check for short and empty buffers, then use byte loop.
-
-LCrossPage:                            // if buffer is large enough, cross source page
-       movl    $16,%edx                // move 16 bytes to cross page but keep dest aligned
-LCheckShortCopy:                       // we propose to copy %edx bytes in byte loop
-       cmpl    $(kShort),%ecx          // much left?
-       ja      LLoopOverBytes          // yes, loop over bytes then more chunks
-       movl    %ecx,%edx               // no, use the byte loop for everything
-       testl   %ecx,%ecx               // have we filled buffer?
-       jnz     LLoopOverBytes          // no
-       jmp     LDone
-
-
-// Loop over bytes.
-//     %esi = source ptr
-//     %edi = dest ptr
-//     %ecx = buffer length remaining
-//     %edx = count of bytes to loop over (<= buffer length)
-
-       .align  4,0x90                  // align inner loops to optimize I-fetch
-LLoopOverBytes:
-       movzb   (%esi),%eax             // get source byte
-       inc     %esi
-       dec     %ecx                    // decrement length
-       movb    %al,(%edi)              // pack into dest
-       inc     %edi
-       testl   %eax,%eax               // 0?
-       jz      LZeroBuffer             // yes, we're done copying string
-       dec     %edx                    // more to go?
-       jnz     LLoopOverBytes
-       
-       testl   %ecx,%ecx               // at end of buffer?
-       jnz     LNextChunk              // no, xfer chunks
-       jmp     LDone                   // yes
-
-
-// Loop over 16-byte chunks.
-//     %esi = source ptr (unaligned)
-//     %edi = dest ptr (aligned)
-//     %ecx = buffer length remaining
-//     %edx = chunk count
-
-       .align  4,0x90                  // align inner loops to optimize I-fetch
-LLoopOverChunks:
-       movdqu  (%esi),%xmm1            // get source
-       pxor    %xmm0,%xmm0             // get some 0s
-       addl    $16,%esi
-       pcmpeqb %xmm1,%xmm0             // compare source to 0s
-       pmovmskb %xmm0,%eax             // get result mask for 0 check
-       testl   %eax,%eax               // any 0s?
-       jnz     LFound0                 // yes, exit loop
-       movdqa  %xmm1,(%edi)            // no 0s so do aligned store into destination
-       addl    $16,%edi
-       subl    $16,%ecx                // decrement length remaining
-       dec     %edx                    // more to go?
-       jnz     LLoopOverChunks
-       
-       jmp     LCrossPage              // cross page but keep dest aligned
-       
-
-// Found a zero in the vector.  Figure out where it is, and store the bytes
-// up to it.  It is possible that we should check to be sure (%ecx >= 16), and
-// just do an aligned store of %xmm1 if so.  But if we did, we'd be doing byte
-// stores into the same double quadword in bzero(), which might hit a hazard.
-// Experimentation needed.
-//     %edi = dest ptr (aligned)
-//     %eax = result mask
-//     %ecx = buffer length remaining
-//     %xmm1 = source vector
-
-LFound0:
-       bsf     %eax,%edx               // find first 0
-       subl    %edx,%ecx               // decrement remaining buffer length
-       test    $8,%dl                  // 8-byte store required?
-       jz      4f                      // no
-       movq    %xmm1,(%edi)            // pack in 8 low bytes
-       psrldq  $8,%xmm1                // then shift vector down 8 bytes
-       addl    $8,%edi
-4:
-       test    $4,%dl                  // 4-byte store required?
-       jz      3f                      // no
-       movd    %xmm1,(%edi)            // pack in 4 low bytes
-       psrldq  $4,%xmm1                // then shift vector down 4 bytes
-       addl    $4,%edi
-3:
-       andl    $3,%edx                 // more to go?
-       jz      LZeroBuffer             // no
-       movd    %xmm1,%eax              // move remainders out of vector into %eax
-1:                                     // loop on up to three bytes
-       movb    %al,(%edi)              // pack in next byte
-       shrl    $8,%eax                 // shift next byte into position
-       inc     %edi
-       dec     %edx
-       jnz     1b
-
-// We've copied the string.  Now zero the rest of the buffer, using commpage bzero().
-//     %edi = dest ptr
-//     %ecx = buffer length remaining
-
-LZeroBuffer:
-//     The stack currently is aligned to 4 mod 16 (it was 0 mod 16 at the time of
-//     the call, and the return address, edi, and esi have been pushed).  It needs
-//     to aligned 0 mod 16 when we call bzero, so we subtract 20 from esp (not 4
-//     because we need to have 8 bytes for the arguments to bzero).
-       subl    $20,%esp
-       movl    %ecx,4(%esp)    // remaining buffer size
-       movl    %edi, (%esp)    // pointer to first unstored byte
-       call    _bzero
-       addl    $20,%esp
-
-LDone:
-       movl    12(%esp),%eax           // original dest ptr is return value
-       popl    %esi
-       popl    %edi
-       ret
index c91b09900c33be9b4f422791163b83971cb8a60f..0263b5e503f2c6b28301bb3a936b4517868a8ec4 100644 (file)
@@ -65,6 +65,9 @@
 
 #include <Availability.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 typedef struct {
        struct _ftsent *fts_cur;        /* current node */
        struct _ftsent *fts_child;      /* linked list of children */
@@ -226,4 +229,6 @@ int  fts_set(FTS *, FTSENT *, int) LIBC_INODE64(fts_set);
 //End-Libc
 __END_DECLS
 
+#pragma clang diagnostic pop
 #endif /* !_FTS_H_ */
+
index 9fe603e9cff18248ecc126e34cdba4d493c20bdc..e8581cc96639cd370581c3763ad5c957b0412f56 100644 (file)
 __BEGIN_DECLS
 
 /* Define pressure levels usable by OSThermalPressureLevel */
-#if TARGET_OS_IPHONE
 typedef enum {
+#if TARGET_OS_OSX || TARGET_OS_IOSMAC
+       kOSThermalPressureLevelNominal = 0,
+       kOSThermalPressureLevelModerate,
+       kOSThermalPressureLevelHeavy,
+       kOSThermalPressureLevelTrapping,
+       kOSThermalPressureLevelSleeping
+#else
        kOSThermalPressureLevelNominal = 0,
        kOSThermalPressureLevelLight = 10,
        kOSThermalPressureLevelModerate = 20,
        kOSThermalPressureLevelHeavy = 30,
        kOSThermalPressureLevelTrapping = 40,
        kOSThermalPressureLevelSleeping = 50
-} OSThermalPressureLevel;
-#else
-typedef enum {
-       kOSThermalPressureLevelNominal = 0,
-       kOSThermalPressureLevelModerate,
-       kOSThermalPressureLevelHeavy,
-       kOSThermalPressureLevelTrapping,
-       kOSThermalPressureLevelSleeping
-} OSThermalPressureLevel;
 #endif
+} OSThermalPressureLevel;
 
 /*
  ** External notify(3) string for thermal pressure level notification
index 12de65fb0f3503a37ee11b78402a42fdd9e5f627..5be3e041741bfe4b11389e5f539eb8b95a729012 100644 (file)
@@ -59,6 +59,7 @@
 #define _STDLIB_H_
 
 #include <Availability.h>
+#include <sys/cdefs.h>
 
 #include <_types.h>
 #if !defined(_ANSI_SOURCE)
@@ -129,13 +130,7 @@ extern int __mb_cur_max;
 #define LIBC_ABORT(f,...)      abort_report_np("%s:%s:%u: " f, __FILE__, __func__, __LINE__, ## __VA_ARGS__)
 //End-Libc
 
-#ifndef __alloc_size
-#if __has_attribute(alloc_size)
-#define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
-#else
-#define __alloc_size(...)
-#endif
-#endif // __alloc_size
+#include <malloc/_malloc.h>
 
 __BEGIN_DECLS
 void    abort(void) __dead2;
@@ -150,10 +145,10 @@ long long
 #endif /* !__DARWIN_NO_LONG_LONG */
 void   *bsearch(const void *__key, const void *__base, size_t __nel,
            size_t __width, int (* _Nonnull __compar)(const void *, const void *));
-void   *calloc(size_t __count, size_t __size) __result_use_check __alloc_size(1,2);
+/* calloc is now declared in _malloc.h */
 div_t   div(int, int) __pure2;
 void    exit(int) __dead2;
-void    free(void *);
+/* free is now declared in _malloc.h */
 char   *getenv(const char *);
 long    labs(long) __pure2;
 ldiv_t  ldiv(long, long) __pure2;
@@ -162,15 +157,15 @@ long long
         llabs(long long);
 lldiv_t         lldiv(long long, long long);
 #endif /* !__DARWIN_NO_LONG_LONG */
-void   *malloc(size_t __size) __result_use_check __alloc_size(1);
+/* malloc is now declared in _malloc.h */
 int     mblen(const char *__s, size_t __n);
 size_t  mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
 int     mbtowc(wchar_t * __restrict, const char * __restrict, size_t);
-int     posix_memalign(void **__memptr, size_t __alignment, size_t __size) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0);
+/* posix_memalign is now declared in _malloc.h */
 void    qsort(void *__base, size_t __nel, size_t __width,
            int (* _Nonnull __compar)(const void *, const void *));
 int     rand(void) __swift_unavailable("Use arc4random instead.");
-void   *realloc(void *__ptr, size_t __size) __result_use_check __alloc_size(2);
+/* realloc is now declared in _malloc.h */
 void    srand(unsigned) __swift_unavailable("Use arc4random instead.");
 double  strtod(const char *, char **) __DARWIN_ALIAS(strtod);
 float   strtof(const char *, char **) __DARWIN_ALIAS(strtof);
@@ -405,7 +400,7 @@ unsigned long long
         strtouq(const char *__str, char **__endptr, int __base);
 #endif /* !__DARWIN_NO_LONG_LONG */
 extern char *suboptarg;                /* getsubopt(3) external variable */
-void   *valloc(size_t) __alloc_size(1);
+/* valloc is now declared in _malloc.h */
 #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
 
 /* Poison the following routines if -fshort-wchar is set */
index f80ecd0771324cb396c6ff98ddb8304a28c09bbb..e8dab2c2a26957ea342a283f365fdbedc39a196a 100644 (file)
 #define        strbase(name, addr, field) \
        ((struct name *)((char *)(addr) - fldoff(name, field)))
 
+/* Number of elements in a statically-defined array */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && __GNUC__
+#define countof(arr) ({ \
+       _Static_assert( \
+                       !__builtin_types_compatible_p(typeof(arr), typeof(&(arr)[0])), \
+                       "array must be statically defined"); \
+       (sizeof(arr) / sizeof(arr[0])); \
+})
+#else
+#define countof(arr) \
+       (sizeof(arr) / sizeof(arr[0]))
+#endif
+
+/* Length of a statically-defined string (does not include null terminator) */
+#define lenof(str) \
+       (sizeof(str) - 1)
+
 #endif /* !_STRUCT_H_ */
index b57f32e11e66babd7640c06842de09866f0424fc..87988f214e47418904e8c9304c36eabdd5cce69e 100644 (file)
@@ -53,13 +53,13 @@ __BEGIN_DECLS
     for ((N) = RB_TREE_MIN(T); (N); \
        (N) = rb_tree_iterate((T), (N), RB_DIR_RIGHT))
 #define RB_TREE_FOREACH_SAFE(N, T, TVAR) \
-    for ((N) = RB_TREE_MIN(T); (N) && ((TVAR) = rb_tree_iterate((T), (N), RB_DIR_RIGHT)); \
+    for ((N) = RB_TREE_MIN(T); (N) && ((TVAR) = rb_tree_iterate((T), (N), RB_DIR_RIGHT), 1); \
        (N) = (TVAR))
 #define RB_TREE_FOREACH_REVERSE(N, T) \
     for ((N) = RB_TREE_MAX(T); (N); \
        (N) = rb_tree_iterate((T), (N), RB_DIR_LEFT))
 #define RB_TREE_FOREACH_REVERSE_SAFE(N, T, TVAR) \
-    for ((N) = RB_TREE_MAX(T); (N) && ((TVAR) = rb_tree_iterate((T), (N), RB_DIR_LEFT)); \
+    for ((N) = RB_TREE_MAX(T); (N) && ((TVAR) = rb_tree_iterate((T), (N), RB_DIR_LEFT), 1); \
        (N) = (TVAR))
 
 
index 2bd7da8a928e1a65d81c33ba6bc85ee7f39afead..45daf4b5d21fc28128d8e1f947abaa3b36aaeb61 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <_stdio.h>
 #include <_xlocale.h>
+#include <sys/_types/_mbstate_t.h>
 
 /* Initially added in Issue 4 */
 __BEGIN_DECLS
diff --git a/libdarwin/bsd.c b/libdarwin/bsd.c
new file mode 100644 (file)
index 0000000..30d915f
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark Utilities
+static int
+_sysctl_12809455(int mib[4], size_t mib_cnt, void *old, size_t *old_len,
+               void *new, size_t new_len)
+{
+       int error = -1;
+       int ret = -1;
+       size_t mylen = 0;
+       size_t *mylenp = NULL;
+#if RDAR_12809455
+       bool workaround_12809455 = false;
+#endif
+
+       if (old_len) {
+               mylen = *old_len;
+               mylenp = &mylen;
+       }
+
+       // sysctl(3) doesn't behave anything like its documentation leads you to
+       // believe. If the given buffer is too small to hold the requested data,
+       // what's supposed to happen is:
+       //
+       //   - as much data as possible is copied into the buffer
+       //   - the number of bytes copied is written to the len parameter
+       //   - errno is set to ENOMEM
+       //   - -1 is returned (to indicate that you should check errno)
+       //
+       // What actually happens:
+       //
+       //   - no data is copied
+       //   - len is set to zero
+       //   - errno is undefined
+       //   - zero is returned
+       //
+       // So... swing and a miss.
+       //
+       // Since it returns success in this case our only indication that something
+       // went wrong is if mylen is set to zero.
+       //
+       // So we do our best to sniff out the misbehavior and emulate sysctl(3)'s
+       // API contract until it's fixed.
+       //
+       // <rdar://problem/12809455>
+#if RDAR_12809455
+       if (old_len && *old_len > 0) {
+               // We can only work around the bug if the passed-in length was non-zero.
+               workaround_12809455 = true;
+       }
+#endif
+
+       ret = sysctl(mib, (u_int)mib_cnt, old, mylenp, new, new_len);
+#if RDAR_12809455
+       if (workaround_12809455 && old && ret == 0 && mylen == 0) {
+               ret = -1;
+               errno = ENOMEM;
+       }
+#endif // RDAR_12809455
+
+       if (ret == 0) {
+               error = 0;
+       } else {
+               error = errno;
+       }
+
+       if (old_len) {
+               *old_len = mylen;
+       }
+
+       return error;
+}
+
+static char *
+_strblk(const char *str)
+{
+       const char *cur = str;
+
+       while (*cur && !isblank(*cur)) {
+               cur++;
+       }
+
+       return (char *)cur;
+}
+
+static bool
+_get_boot_arg_value(const char *which, char *where, size_t max)
+{
+       // This is (very) loosely based on the implementation of
+       // PE_parse_boot_argn() (or at least the parts where I was able to easily
+       // decipher the policy).
+       bool found = false;
+       errno_t error = -1;
+       char *buff = NULL;
+       size_t buff_len = 0;
+       char *theone = NULL;
+       char *equals = NULL;
+
+       error = sysctlbyname_get_data_np("kern.bootargs", (void **)&buff,
+                       &buff_len);
+       if (error) {
+               goto __out;
+       }
+
+       theone = strstr(buff, which);
+       if (!theone) {
+               goto __out;
+       }
+
+       found = true;
+       if (!where) {
+               // Caller just wants to know whether the boot-arg exists.
+               goto __out;
+       }
+
+       equals = strchr(theone, '=');
+       if (!equals || isblank(equals[1])) {
+               strlcpy(where, "", max);
+       } else {
+               char *nextsep = NULL;
+               char nextsep_old = 0;
+
+               // Find the next separator and nerf it temporarily for the benefit of
+               // the underlying strcpy(3).
+               nextsep = _strblk(theone);
+               nextsep_old = *nextsep;
+               *nextsep = 0;
+               strlcpy(where, &equals[1], max);
+
+               *nextsep = nextsep_old;
+       }
+
+__out:
+       free(buff);
+       return found;
+}
+
+#pragma mark API
+errno_t
+sysctl_get_data_np(int mib[4], size_t mib_cnt, void **buff, size_t *buff_len)
+{
+       errno_t error = -1;
+       size_t needed = 0;
+       void *mybuff = NULL;
+
+       // We need to get the length of the parameter so we can allocate a buffer
+       // that's large enough.
+       error = _sysctl_12809455(mib, mib_cnt, NULL, &needed, NULL, 0);
+       if (error) {
+               goto __out;
+       }
+
+       mybuff = malloc(needed);
+       if (!mybuff) {
+               error = errno;
+               goto __out;
+       }
+
+       error = _sysctl_12809455(mib, mib_cnt, mybuff, &needed, NULL, 0);
+       if (error) {
+               // It's conceivable that some other process came along within this
+               // window and modified the variable to be even larger than we'd
+               // previously been told, but if that's the case, just give up.
+               goto __out;
+       }
+
+       *buff = mybuff;
+       *buff_len = needed;
+
+__out:
+       if (error) {
+               free(mybuff);
+       }
+       return error;
+}
+
+errno_t
+sysctlbyname_get_data_np(const char *mibdesc, void **buff, size_t *buff_len)
+{
+       int ret = -1;
+       int error = -1;
+       int mib[4];
+       size_t mib_cnt = countof(mib);
+
+       ret = sysctlnametomib(mibdesc, mib, &mib_cnt);
+       if (ret) {
+               error = errno;
+               goto __out;
+       }
+
+       error = sysctl_get_data_np(mib, mib_cnt, buff, buff_len);
+
+__out:
+       return error;
+}
+
+bool
+os_parse_boot_arg_int(const char *which, int64_t *where)
+{
+       bool found = false;
+       char buff[24] = {0};
+       char *endptr = NULL;
+       int64_t val = 0;
+
+       found = _get_boot_arg_value(which, buff, sizeof(buff));
+       if (!found || !where) {
+               goto __out;
+       }
+
+       // A base of zero handles bases 8, 10, and 16.
+       val = strtoll(buff, &endptr, 0);
+       if (*endptr == 0) {
+               *where = val;
+       } else {
+               // The boot-arg value was invalid, so say we didn't find it.
+               found = false;
+       }
+
+__out:
+       return found;
+}
+
+bool
+os_parse_boot_arg_string(const char *which, char *where, size_t maxlen)
+{
+       return _get_boot_arg_value(which, where, maxlen);
+}
index d0b5edf5faa26b3a948cbdaf4b66a0b606ca4376..89b0a83115c552cfca854b016959c95e31544da6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2017 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
diff --git a/libdarwin/dirstat.h b/libdarwin/dirstat.h
deleted file mode 100644 (file)
index d3235de..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2017 Apple Inc. All rights reserved.
- *
- * @APPLE_APACHE_LICENSE_HEADER_START@
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @APPLE_APACHE_LICENSE_HEADER_END@
- */
-
-#ifndef __DIRSTAT_H__
-#define __DIRSTAT_H__
-
-#include <sys/types.h>
-#include <stdint.h>
-
-__BEGIN_DECLS
-
-/* Fail if the file system does not support fast directory sizing on the provided directory */
-#define DIRSTAT_FAST_ONLY 0x1
-
-/* Do not use filesystem support for directory sizing. */
-#define DIRSTAT_FORCE_FALLBACK 0x2
-
-/*
- * NOT ABI: the size of this structure may grow.  You must pass the current
- * size of this structure in as the dirstat_size argument to the functions
- * below.
- */
-struct dirstat {
-       off_t total_size;
-       uint64_t descendants;
-};
-
-/* Returns -1 on error and sets errno.  Does not cross file-system boundaries. */
-__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
-int dirstat_np(const char *path, int flags, struct dirstat *ds, size_t dirstat_size);
-
-__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
-int dirstatat_np(int dfd, const char *path, int flags, struct dirstat *ds, size_t dirstat_size);
-
-__END_DECLS
-
-#endif // __DIRSTAT_H__
index 890cb454792bc183c92735e3c76dfc162a95c6f6..c91a2fe7762bbee5e68b711b88cad3925507f1d4 100644 (file)
@@ -34,7 +34,7 @@
  * SUCH DAMAGE.
  */
 /*
- * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2017 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
diff --git a/libdarwin/dirstat_collection.h b/libdarwin/dirstat_collection.h
deleted file mode 100644 (file)
index 18aff57..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <sys/cdefs.h>
-#include <stdint.h>
-#include <stdbool.h>
-
-__BEGIN_DECLS
-
-typedef struct dirstat_fileid_set_s dirstat_fileid_set_s;
-typedef dirstat_fileid_set_s *dirstat_fileid_set_t;
-
-dirstat_fileid_set_t _dirstat_fileid_set_create(void);
-void _dirstat_fileid_set_destroy(dirstat_fileid_set_t set);
-bool _dirstat_fileid_set_add(dirstat_fileid_set_t set, uint64_t fileid);
-
-__END_DECLS
diff --git a/libdarwin/err.c b/libdarwin/err.c
new file mode 100644 (file)
index 0000000..85849b5
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark Utilities
+static void
+_print_preamble(FILE *fp, const char *fmt, va_list ap)
+{
+       fprintf(fp, "%s: ", getprogname());
+       vfprintf(fp, fmt, ap);
+}
+
+#pragma mark API
+void
+err_np(errno_t code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       verr_np(code, fmt, ap);
+       va_end(ap);
+}
+
+void
+errc_np(int eval, errno_t code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       verrc_np(eval, code, fmt, ap);
+       va_end(ap);
+}
+
+void
+warn_np(errno_t code, const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       vwarn_np(code, fmt, ap);
+       va_end(ap);
+}
+
+void
+verr_np(errno_t code, const char *fmt, va_list ap)
+{
+       _print_preamble(stderr, fmt, ap);
+       fprintf(stderr, ": %s\n", strerror_np(code));
+       exit(sysexit_np(code));
+}
+
+void
+verrc_np(int eval, errno_t code, const char *fmt, va_list ap)
+{
+       _print_preamble(stderr, fmt, ap);
+       fprintf(stderr, ": %s\n", strerror_np(code));
+       exit(eval);
+}
+
+void
+vwarn_np(errno_t code, const char *fmt, va_list ap)
+{
+       _print_preamble(stderr, fmt, ap);
+       fprintf(stderr, ": %s\n", strerror_np(code));
+}
diff --git a/libdarwin/exception.c b/libdarwin/exception.c
new file mode 100644 (file)
index 0000000..7875000
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark Assertions
+static_assert(_OS_CRASH_LAST < OS_CRASH_PORT_ARRAY_COUNT,
+               "array not large enough");
+
+#pragma mark Private Utilities
+static thread_state_flavor_t
+_exception_thread_state_flavor(void)
+{
+       thread_state_flavor_t flavor = 0;
+#if defined(__i386__) || defined(__x86_64__)
+       flavor = x86_THREAD_STATE;
+#elif defined(__arm__) || defined(__arm64__)
+       flavor = ARM_THREAD_STATE;
+#else // defined(__i386__) || defined(__x86_64__)
+#error "unsupported architecture"
+#endif // defined(__i386__) || defined(__x86_64__)
+       return flavor;
+}
+
+static exception_mask_t
+_exception_mask(os_crash_flags_t flags)
+{
+       exception_mask_t mask = 0;
+       if (flags & OS_CRASH_FLAG_CRASH) {
+               mask |= EXC_MASK_CRASH;
+       }
+       if (flags & OS_CRASH_FLAG_GUARD) {
+               mask |= EXC_MASK_GUARD;
+       }
+       if (flags & OS_CRASH_FLAG_RESOURCE) {
+               mask |= EXC_MASK_RESOURCE;
+       }
+       if (flags & OS_CRASH_FLAG_CORPSE) {
+               mask |= EXC_MASK_CORPSE_NOTIFY;
+               mask &= (exception_mask_t)(~EXC_MASK_CRASH);
+       }
+       return mask;
+}
+
+static exception_behavior_t
+_exception_behavior(void)
+{
+       return (EXCEPTION_STATE_IDENTITY|MACH_EXCEPTION_CODES);
+}
+
+static void
+_os_exception_port_set(os_crash_port_t *ep,
+               os_crash_type_t type, mach_port_t p)
+{
+       kern_return_t kr = KERN_FAILURE;
+
+       ep->oep_type = type;
+       ep->oep_port = p;
+
+       kr = mach_port_mod_refs(mach_task_self(), p, MACH_PORT_RIGHT_SEND, 1);
+       if (kr == KERN_SUCCESS) {
+               ep->oep_port = p;
+       } else {
+               ep->oep_port = MACH_PORT_DEAD;
+       }
+}
+
+#pragma mark API
+kern_return_t
+os_crash_set_reporter_port(mach_port_t where,
+               os_crash_flags_t flags,  mach_port_t p)
+{
+       kern_return_t kr = KERN_FAILURE;
+       exception_mask_t mask = _exception_mask(flags);
+       exception_behavior_t bhvr = _exception_behavior();
+       thread_state_flavor_t flvr = _exception_thread_state_flavor();
+       mach_port_t host_priv = MACH_PORT_NULL;
+
+       // If we're not privleged to get the host-privileged port, no big deal, then
+       // the comparison below will fail.
+       (void)host_get_host_priv_port(mach_host_self(), &host_priv);
+
+       if (flags == OS_CRASH_FLAG_INIT) {
+               return KERN_SUCCESS;
+       }
+
+       if (where == mach_host_self() || where == host_priv) {
+               kr = host_set_exception_ports(where, mask, p, bhvr, flvr);
+       } else {
+               kr = task_set_exception_ports(where, mask, p, bhvr, flvr);
+       }
+
+       return kr;
+}
+
+kern_return_t
+os_crash_get_reporter_port_array(mach_port_t where, os_crash_port_array_t array)
+{
+       kern_return_t kr = KERN_FAILURE;
+       exception_mask_t masks[EXC_TYPES_COUNT];
+       mach_msg_type_number_t nmasks = 0;
+       exception_port_t ports[EXC_TYPES_COUNT];
+       exception_behavior_t behaviors[EXC_TYPES_COUNT];
+       thread_state_flavor_t flavors[EXC_TYPES_COUNT];
+       exception_mask_t mask = EXC_MASK_CRASH
+               | EXC_MASK_GUARD
+               | EXC_MASK_RESOURCE
+               | EXC_MASK_CORPSE_NOTIFY;
+       size_t i = 0;
+       size_t j = 0;
+       mach_port_t host_priv = MACH_PORT_NULL;
+
+       (void)host_get_host_priv_port(mach_host_self(), &host_priv);
+
+       if (where == mach_host_self() || where == host_priv) {
+               kr = host_get_exception_ports(mach_host_self(), mask,
+                               masks, &nmasks, ports, behaviors, flavors);
+       } else {
+               kr = task_get_exception_ports(where, mask,
+                               masks, &nmasks, ports, behaviors, flavors);
+       }
+
+       if (kr) {
+               goto __out;
+       }
+
+       bzero(array, sizeof(array[0]) * OS_CRASH_PORT_ARRAY_COUNT);
+       for (i = 0; i < nmasks; i++) {
+               if (masks[i] & EXC_MASK_CRASH) {
+                       _os_exception_port_set(&array[j], OS_CRASH_CRASH, ports[i]);
+                       j++;
+               }
+               if (masks[i] & EXC_MASK_GUARD) {
+                       _os_exception_port_set(&array[j], OS_CRASH_GUARD, ports[i]);
+                       j++;
+               }
+               if (masks[i] & EXC_MASK_RESOURCE) {
+                       _os_exception_port_set(&array[j], OS_CRASH_RESOURCE, ports[i]);
+                       j++;
+               }
+               if (masks[i] & EXC_MASK_CORPSE_NOTIFY) {
+                       _os_exception_port_set(&array[j], OS_CRASH_CORPSE, ports[i]);
+                       j++;
+               }
+               kr = mach_port_deallocate(mach_task_self(), ports[i]);
+               os_assert_mach("deallocate port", kr);
+       }
+
+__out:
+       return kr;
+}
+
+void
+os_crash_port_array_deallocate(os_crash_port_array_t array)
+{
+       size_t i = 0;
+
+       for (i = 0; i < 16; i++) {
+               if (MACH_PORT_VALID(array[i].oep_port)) {
+                       kern_return_t kr = KERN_FAILURE;
+                       kr = mach_port_deallocate(mach_task_self(), array[i].oep_port);
+                       os_assert_mach("deallocate port", kr);
+               }
+       }
+}
+
+kern_return_t
+os_crash_spawnattr_set_reporter_port(posix_spawnattr_t *psattr,
+               os_crash_flags_t flags,  mach_port_t p)
+{
+       int error = -1;
+       exception_mask_t mask = _exception_mask(flags);
+       exception_behavior_t bhvr = _exception_behavior();
+       thread_state_flavor_t flvr = _exception_thread_state_flavor();
+
+       if (!MACH_PORT_VALID(p)) {
+               return KERN_INVALID_NAME;
+       }
+
+       if (flags == OS_CRASH_FLAG_INIT) {
+               return KERN_SUCCESS;
+       }
+
+       error = posix_spawnattr_setexceptionports_np(psattr, mask, p, bhvr, flvr);
+       os_assert_zero(error);
+
+       return KERN_SUCCESS;
+}
diff --git a/libdarwin/h/bsd.h b/libdarwin/h/bsd.h
new file mode 100644 (file)
index 0000000..6fc247e
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Darwin-specific additions for FreeBSD APIs.
+ */
+#ifndef __DARWIN_BSD_H
+#define __DARWIN_BSD_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <sys/cdefs.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+__BEGIN_DECLS;
+
+/*!
+ * @function sysctl_get_data_np
+ * A convenience routine for getting a sysctl(3) property whose size is not
+ * known at compile-time.
+ *
+ * @param mib
+ * An array describing the property to manipulate. This is a "management
+ * information base"-style descriptor, as described in sysctl(3).
+ *
+ * @param mib_cnt
+ * The number of items in the MIB array.
+ *
+ * @param buff
+ * On successful return, a pointer to a newly-allocated buffer. The caller is
+ * responsible for free(3)ing this buffer when it is no longer needed.
+ *
+ * @param buff_len
+ * On successful return, the length of the returned buffer.
+ *
+ * @result
+ * See the sysctl(3) man page for possible return codes.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL3 OS_NONNULL4
+errno_t
+sysctl_get_data_np(int *mib, size_t mib_cnt, void **buff, size_t *buff_len);
+
+/*!
+ * @function sysctlbyname_get_data_np
+ * A convenience routine for getting a sysctl(3) property whose size is not
+ * known at compile-time.
+ *
+ * @param mibdesc
+ * An ASCII representation of the MIB vector describing the property to
+ * manipulate. Each element of the vector described is separated by a '.'
+ * character (e.g. "kern.ostype").
+ *
+ * @param buff
+ * On successful return, a pointer to a newly-allocated buffer. The caller is
+ * responsible for free(3)ing this buffer when it is no longer needed.
+ *
+ * @param buff_len
+ * On successful return, the length of the returned buffer.
+ *
+ * @result
+ * See the sysctl(3) man page for possible return codes.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL2 OS_NONNULL3
+errno_t
+sysctlbyname_get_data_np(const char *mibdesc, void **buff, size_t *buff_len);
+
+/*!
+ * @function os_parse_boot_arg_int
+ * A routine for extracting a boot-arg as an integer value that is semantically
+ * similar to the PE_parse_boot_argn() kernel routine.
+ *
+ * @param which
+ * The name of the boot-arg whose value is to be obtained. The caller may pass
+ * NULL to simply check for the existence of a boot-arg.
+ *
+ * @param where
+ * On successful return, the integer value of the given boot-arg.
+ *
+ * @result
+ * A Boolean indicating whether the named argument was found. If the discovered
+ * argument value was not convertible to an integer according to the contract
+ * in strtoll(3), the implementation will return false.
+ *
+ * @discussion
+ * Boot-args are expressed with an '=' sign as a separator between the name and
+ * value of an argument, e.g. "cs_enforcement_disable=1".
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1
+bool
+os_parse_boot_arg_int(const char *which, int64_t *where);
+
+/*!
+ * @function os_parse_boot_arg_string
+ * A routine for extracting a boot-arg's string value that is semantically
+ * similar to the PE_parse_boot_argn() kernel routine.
+ *
+ * @param which
+ * The name of the boot-arg whose value is to be obtained.
+ *
+ * @param where
+ * The buffer in which to place the extracted value on successful return. The
+ * caller may pass NULL to simply check for the existence of a boot-arg.
+ *
+ * @param maxlen
+ * The length of the {@link where} buffer. May be zero if the caller only wishes
+ * to check for the existence of a boot-arg.
+ *
+ * @result
+ * A Boolean indicating whether the named argument was found.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1
+bool
+os_parse_boot_arg_string(const char *which, char *where, size_t maxlen);
+
+__END_DECLS;
+
+#endif // __DARWIN_BSD_H
diff --git a/libdarwin/h/cleanup.h b/libdarwin/h/cleanup.h
new file mode 100644 (file)
index 0000000..c74c8f1
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Attributes to handle automatic clean-up of certain types of variables when
+ * they go out of scope.
+ *
+ * IMPORTANT: These attributes will NOT cause a variable to be cleaned up when
+ * its value changes. For example, this pattern would leak:
+ *
+ * void *__os_free ptr = malloc(10);
+ * ptr = somewhere_else;
+ * return;
+ *
+ * You should only use these attributes for very well-scoped, temporary
+ * allocations.
+ */
+#ifndef __DARWIN_CLEANUP_H
+#define __DARWIN_CLEANUP_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <os/assumes.h>
+#include <os/object_private.h>
+
+#include <sys/errno.h>
+#include <sys/cdefs.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <mach/mach_init.h>
+#include <mach/port.h>
+#include <mach/mach_port.h>
+#include <mach/kern_return.h>
+
+__BEGIN_DECLS;
+
+#if __has_attribute(cleanup)
+/*!
+ * @define __os_free
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to free(3) when it goes out of scope. Applying this
+ * attribute to variables that do not reference heap allocations will result in
+ * undefined behavior.
+ */
+#define __os_free __attribute__((cleanup(__os_cleanup_free)))
+static inline void
+__os_cleanup_free(void *__p)
+{
+       void **tp = (void **)__p;
+       void *p = *tp;
+       free(p);
+}
+
+/*!
+ * @define __os_close
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to close(2) when it goes out of scope. Applying
+ * this attribute to variables that do not reference a valid file descriptor
+ * will result in undefined behavior. If the variable's value is -1 upon going
+ * out-of-scope, no cleanup is performed.
+ */
+#define __os_close __attribute__((cleanup(__os_cleanup_close)))
+static inline void
+__os_cleanup_close(int *__fd)
+{
+       int fd = *__fd;
+       if (fd == -1) {
+               return;
+       }
+       posix_assert_zero(close(fd));
+}
+
+/*!
+ * @define __os_fclose
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to fclose(3) when it goes out of scope. Applying
+ * this attribute to variables that do not reference a valid FILE* will result
+ * in undefined behavior. If the variable's value is NULL upon going out-of-
+ * scope, no cleanup is performed.
+ */
+#define __os_fclose __attribute__((cleanup(__os_cleanup_fclose)))
+static inline void
+__os_cleanup_fclose(FILE **__fp)
+{
+       FILE *f = *__fp;
+       int ret = -1;
+
+       if (!f) {
+               return;
+       }
+
+       ret = fclose(f);
+       if (ret == EOF) {
+               os_assert_zero(errno);
+       }
+}
+
+/*!
+ * @define __os_close_mach_recv
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to {@link darwin_mach_port_close_recv} when it goes
+ * out of scope. Applying this attribute to variables that do not reference a
+ * valid Mach port receive right will result in undefined behavior. If the
+ * variable's value is MACH_PORT_NULL or MACH_PORT_DEAD upon going out-of-scope,
+ * no cleanup is performed.
+ */
+#define __os_close_mach_recv \
+               __attribute__((cleanup(__os_cleanup_close_mach_recv)))
+static inline void
+__os_cleanup_close_mach_recv(mach_port_t *__p)
+{
+       mach_port_t p = *__p;
+       kern_return_t kr = KERN_FAILURE;
+
+       if (!MACH_PORT_VALID(p)) {
+               return;
+       }
+
+       kr = mach_port_destruct(mach_task_self(), p, 0, 0);
+       os_assert_zero(kr);
+}
+
+/*!
+ * @define __os_release_mach_send
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to {@link darwin_mach_port_release} when it goes
+ * out of scope. Applying this attribute to variables that do not reference a
+ * valid Mach port send right or MACH_PORT_NULL or MACH_PORT_DEAD will result
+ * in undefined behavior. If the variable's value is MACH_PORT_NULL or
+ * MACH_PORT_DEAD upon going out-of-scope, no cleanup is performed.
+ */
+#define __os_release_mach_send \
+               __attribute__((cleanup(__os_cleanup_release_mach_send)))
+static inline void
+__os_cleanup_release_mach_send(mach_port_t *__p)
+{
+       mach_port_t p = *__p;
+       kern_return_t kr = KERN_FAILURE;
+
+       if (!MACH_PORT_VALID(p)) {
+               return;
+       }
+
+       kr = mach_port_deallocate(mach_task_self(), p);
+       os_assert_zero(kr);
+}
+
+/*!
+ * @define __os_preserve_errno
+ * An attribute that may be applied to a variable's type. This attribute sets
+ * the global errno to the value of the variable when the variable goes out of
+ * scope. This attribute is useful for preserving the value of errno upon entry
+ * to a function and guaranteeing that it is restored upon exit.
+ */
+#define __os_preserve_errno \
+               __unused __attribute__((cleanup(__os_cleanup_errno)))
+static inline void
+__os_cleanup_errno(int *__e)
+{
+       errno = *__e;
+}
+
+/*!
+ * @define __os_release
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to os_release() when it goes out of scope. Applying
+ * this attribute to a variable which does not reference a valid os_object_t
+ * object will result in undefined behavior. If the variable's value is NULL
+ * upon going out-of-scope, no cleanup is performed.
+ *
+ * This attribute may be applied to dispatch and XPC objects.
+ */
+#define __os_release __attribute__((cleanup(__os_cleanup_os_release)))
+static inline void
+__os_cleanup_os_release(void *__p)
+{
+       _os_object_t *tp = (_os_object_t *)__p;
+       _os_object_t o = *tp;
+       if (!o) {
+               return;
+       }
+       os_release(o);
+}
+
+#if __COREFOUNDATION__
+/*!
+ * @define __os_cfrelease
+ * An attribute that may be applied to a variable's type. This attribute causes
+ * the variable to be passed to CFRelease() when it goes out of scope. Applying
+ * this attribute to a variable which does not reference a valid CoreFoundation
+ * object will result in undefined behavior. If the variable's value is NULL
+ * upon going out-of-scope, no cleanup is performed.
+ */
+#define __os_cfrelease __attribute__((cleanup(__os_cleanup_cfrelease)))
+static inline void
+__os_cleanup_cfrelease(void *__p)
+{
+       CFTypeRef *tp = (CFTypeRef *)__p;
+       CFTypeRef cf = *tp;
+       if (!cf) {
+               return;
+       }
+       CFRelease(cf);
+}
+#endif // __COREFOUNDATION__
+
+#else // __has_attribute(cleanup)
+#define __os_free __attribute__((__os_not_supported))
+#define __os_close __attribute__((__os_not_supported))
+#define __os_fclose __attribute__((__os_not_supported))
+#define __os_close_mach_recv __attribute__((__os_not_supported))
+#define __os_release_mach_send __attribute__((__os_not_supported))
+#define __os_preserve_errno __attribute__((__os_not_supported))
+#define __os_release __attribute__((__os_not_supported))
+#define __os_cfrelease __attribute__((__os_not_supported))
+#endif // __has_attribute(cleanup)
+
+__END_DECLS;
+
+#endif // __DARWIN_CLEANUP_H
diff --git a/libdarwin/h/dirstat.h b/libdarwin/h/dirstat.h
new file mode 100644 (file)
index 0000000..6fa53c2
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 Apple Inc. All rights reserved.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_START@
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * @APPLE_APACHE_LICENSE_HEADER_END@
+ */
+
+#ifndef __DIRSTAT_H__
+#define __DIRSTAT_H__
+
+#include <Availability.h>
+#include <sys/types.h>
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+/* Fail if the file system does not support fast directory sizing on the provided directory */
+#define DIRSTAT_FAST_ONLY 0x1
+
+/* Do not use filesystem support for directory sizing. */
+#define DIRSTAT_FORCE_FALLBACK 0x2
+
+/*
+ * NOT ABI: the size of this structure may grow.  You must pass the current
+ * size of this structure in as the dirstat_size argument to the functions
+ * below.
+ */
+struct dirstat {
+       off_t total_size;
+       uint64_t descendants;
+};
+
+/* Returns -1 on error and sets errno.  Does not cross file-system boundaries. */
+__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
+int dirstat_np(const char *path, int flags, struct dirstat *ds, size_t dirstat_size);
+
+__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
+int dirstatat_np(int dfd, const char *path, int flags, struct dirstat *ds, size_t dirstat_size);
+
+__END_DECLS
+
+#endif // __DIRSTAT_H__
diff --git a/libdarwin/h/dirstat_collection.h b/libdarwin/h/dirstat_collection.h
new file mode 100644 (file)
index 0000000..554cd06
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2017 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sys/cdefs.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+__BEGIN_DECLS
+
+#pragma GCC visibility push(hidden)
+
+typedef struct dirstat_fileid_set_s dirstat_fileid_set_s;
+typedef dirstat_fileid_set_s *dirstat_fileid_set_t;
+
+dirstat_fileid_set_t _dirstat_fileid_set_create(void);
+void _dirstat_fileid_set_destroy(dirstat_fileid_set_t set);
+bool _dirstat_fileid_set_add(dirstat_fileid_set_t set, uint64_t fileid);
+
+#pragma GCC visibility pop
+
+__END_DECLS
diff --git a/libdarwin/h/err.h b/libdarwin/h/err.h
new file mode 100644 (file)
index 0000000..f33730a
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Non-standard, Darwin-specific additions to the err(3) family of APIs. The
+ * following additions are provided:
+ *
+ *    - support for the error code additions in os/errno.h
+ *    - automatic conversion of an error code into a sysexits(3) code
+ *    - a debug_*() family of routines
+ *
+ * There are no direct equivalents for err(3), warn(3), verr(3), or vwarn(3)
+ * because those routines query errno for error information, and it is not valid
+ * to store error codes from os/error.h in errno. Therefore when evaluating the
+ * output of normal POSIX routines, use the err(1) family of routines. When
+ * evaluating the output of routines that can return the error codes in
+ * os/error.h, you may use these routines and always explicitly pass the error
+ * code.
+ *
+ * There are no equivalents for errx(3), warnx(3), verrx(3), or vwarnx(3)
+ * because those routines do not query error information.
+ */
+#ifndef __DARWIN_ERR_H
+#define __DARWIN_ERR_H
+
+#include <os/base.h>
+#include <os/api.h>
+
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <uuid/uuid.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+
+__BEGIN_DECLS;
+
+/*!
+ * @function err_np
+ * Writes a formatted error message to stderr(4) and exits the program.
+ *
+ * @param code
+ * The error code to query in the output.
+ *
+ * @param fmt
+ * The printf(3)-like format string representing the message to print.
+ *
+ * @param ...
+ * The arguments corresponding to the format string.
+ *
+ * @discussion
+ * This routine will look up an appropriate sysexits(3) code using the given
+ * error code using {@link darwin_sysexit} and pass it to exit(3).
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NORETURN OS_NONNULL2 OS_FORMAT_PRINTF(2, 3)
+void
+err_np(errno_t code, const char *fmt, ...);
+
+/*!
+ * @function errc_np
+ * Writes a formatted error message to stderr(4) and exits the program.
+ *
+ * @param eval
+ * The code to pass to exit(3). This should be a code defined in sysexits(3).
+ *
+ * @param code
+ * The error code to query in the output.
+ *
+ * @param fmt
+ * The printf(3)-like format string representing the message to print.
+ *
+ * @param ...
+ * The arguments corresponding to the format string.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NORETURN OS_NONNULL3 OS_FORMAT_PRINTF(3, 4)
+void
+errc_np(int eval, errno_t code, const char *fmt, ...);
+
+/*!
+ * @function warn_np
+ * Writes a formatted warning message to stderr(4).
+ *
+ * @param code
+ * The error code to query in the output.
+ *
+ * @param fmt
+ * The printf(3)-like format string representing the message to print.
+ *
+ * @param ...
+ * The arguments corresponding to the format string.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NONNULL2 OS_FORMAT_PRINTF(2, 3)
+void
+warn_np(errno_t code, const char *fmt, ...);
+
+/*!
+ * @function verr_np
+ * Writes a formatted error message to stderr(4) and exits the program.
+ *
+ * @param code
+ * The error code to query in the output.
+ *
+ * @param fmt
+ * The printf(3)-like format string representing the message to print.
+ *
+ * @param ap
+ * The argument pointer corresponding to the format string.
+ *
+ * @discussion
+ * This routine will look up an appropriate sysexits(3) code using the given
+ * error code using {@link darwin_sysexit} and pass it to exit(3).
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NORETURN OS_NONNULL2 OS_NONNULL3
+void
+verr_np(errno_t code, const char *fmt, va_list ap);
+
+/*!
+ * @function verrc_np
+ * Writes a formatted error message to stderr(4) and exits the program.
+ *
+ * @param eval
+ * The code to pass to exit(3). This should be a code defined in sysexits(3).
+ *
+ * @param code
+ * The error code to query in the output.
+ *
+ * @param fmt
+ * The printf(3)-like format string representing the message to print.
+ *
+ * @param ap
+ * The argument pointer corresponding to the format string.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NORETURN OS_NONNULL3 OS_NONNULL4
+void
+verrc_np(int eval, errno_t code, const char *fmt, va_list ap);
+
+/*!
+ * @function vwarn_np
+ * Writes a formatted warning message to stderr(4).
+ *
+ * @param code
+ * The error code to query in the output.
+ *
+ * @param fmt
+ * The printf(3)-like format string representing the message to print.
+ *
+ * @param ap
+ * The arguments corresponding to the format string.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NONNULL2 OS_NONNULL3
+void
+vwarn_np(errno_t code, const char *fmt, va_list ap);
+
+__END_DECLS;
+
+#endif // __DARWIN_ERR_H
diff --git a/libdarwin/h/errno.h b/libdarwin/h/errno.h
new file mode 100644 (file)
index 0000000..4370b1e
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * @header
+ * Non-standard, Darwin-specific additions to the error codes enumerated in
+ * intro(2) and sys/errno.h.
+ */
+#ifndef __DARWIN_ERRNO_H
+#define __DARWIN_ERRNO_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <sys/errno.h>
+#include <sys/cdefs.h>
+#include <sysexits.h>
+
+/*!
+ * @enum
+ * Additional POSIX-flavor error codes that are meaningful to Darwin. These
+ * definitions all have a "_NP" suffix to distinguish them from POSIX error
+ * codes (meaning "not POSIX").
+ */
+#define EBASE_NP 200
+#define _ENPERR(__c) (EBASE_NP + __c)
+
+/*!
+ * @const ENOTENTITLED_NP
+ * The remote process lacked a required entitlement to perform the operation.
+ */
+#define ENOTENTITLED_NP _ENPERR(0)
+
+/*!
+ * @const ENOTPLATFORM_NP
+ * The operation may only be invoked by platform binaries.
+ */
+#define ENOTPLATFORM_NP _ENPERR(1)
+
+/*!
+ * @const EROOTLESS_NP
+ * The operation was denied by System Integrity Protection.
+ */
+#define EROOTLESS_NP _ENPERR(2)
+
+/*!
+ * @const ETAINTED_NP
+ * The operation may only be invoked by processes which are not tainted by
+ * debugging and introspection functionality (e.g. dyld(1) environment
+ * variables, debugger attachment, etc.).
+ */
+#define ETAINTED_NP _ENPERR(3)
+
+/*!
+ * @const EQUARANTINE_NP
+ * The operation is not permitted on quarantined file.
+ */
+#define EQUARANTINE_NP _ENPERR(4)
+
+/*!
+ * @const EBADUSER_NP
+ * The operation referenced a user name or identifier that was invalid.
+ */
+#define EBADUSER_NP _ENPERR(5)
+
+/*!
+ * @const EBADGROUP_NP
+ * The operation referenced a group name or identifier that was invalid.
+ */
+#define EBADGROUP_NP _ENPERR(6)
+
+/*!
+ * @const EOWNERSHIP_NP
+ * Ownership or access permissions on a file were too permissive.
+ */
+#define EOWNERSHIP_NP _ENPERR(7)
+
+/*!
+ * @const ENOOOO_NP
+ * A series of operations was executed in the improper order (no out-of-order
+ * operations allowed).
+ */
+#define ENOOOO_NP _ENPERR(8)
+
+/*!
+ * @const ENOTBUNDLE_NP
+ * The path given to the operation did not refer to a bundle.
+ */
+#define ENOTBUNDLE_NP _ENPERR(9)
+
+/*!
+ * @const EBADBUNDLE_NP
+ * The path given to the operation did not refer to a valid bundle.
+ */
+#define EBADBUNDLE_NP _ENPERR(10)
+
+/*!
+ * @const EBADPATH_NP
+ * The path given to the operation was not valid.
+ */
+#define EBADPATH_NP _ENPERR(11)
+
+/*!
+ * @const EBADPLIST_NP
+ * The plist given to the operation was invalid.
+ */
+#define EBADPLIST_NP _ENPERR(12)
+
+/*!
+ * @const EBADKEY_NP
+ * A key in the given plist was unrecognized.
+ */
+#define EBADKEY_NP _ENPERR(13)
+
+/*!
+ * @const EBADVAL_NP
+ * The value for a key in the given plist was either not present (and was
+ * required to be) or was present but not of the appropriate type.
+ */
+#define EBADVAL_NP _ENPERR(14)
+
+/*!
+ @const EBADSUBSYS_NP
+ * The request referenced a subsystem that did not exist.
+ */
+#define EBADSUBSYS_NP _ENPERR(15)
+
+/*!
+ * @const E2BIMPL_NP
+ * The operation has not yet been implemented.
+ */
+#define E2BIMPL_NP _ENPERR(16)
+
+/*!
+ * @const EDEPRECATED_NP
+ * The operation has been deprecated.
+ */
+#define EDEPRECATED_NP _ENPERR(17)
+
+/*!
+ * @const EREMOVED_NP
+ * The operation has been removed from the implementation.
+ */
+#define EREMOVED_NP _ENPERR(18)
+
+/*!
+ * @const EDROPPED_NP
+ * The request referenced a data structure that will never achieve the state
+ * required to perform the operation.
+ */
+#define EDROPPED_NP _ENPERR(19)
+
+/*!
+ * @const EDEFERRED_NP
+ * The request referenced a data structure that was not in the state required
+ * to perform the operation, and the request has been pended until the object
+ * reaches the required state. This code is meant to be used for control flow
+ * purposes in the server and should not be returned to the caller.
+ */
+#define EDEFERRED_NP _ENPERR(20)
+
+/*!
+ * @const EUSAGE_NP
+ * Improper command line usage. This code is meant to be used for control flow
+ * purposes in a command line tool so that routines may return an error code
+ * indicating improper usage without having to use EX_USAGE, which collides with
+ * the POSIX error space. It should not be passed to exit(3), _exit(2), et al.
+ * and should instead be translated into EX_USAGE either directly or with
+ * {@link darwin_sysexit}.
+ */
+#define EUSAGE_NP _ENPERR(21)
+
+/*!
+ * @const EUNKNOWN_NP
+ * An error occurred in a subsystem, and insufficient detail as to the nature of
+ * the failure was available to translate it into a more descriptive error code.
+ */
+#define EUNKNOWN_NP _ENPERR(22)
+#define __ELAST_NP _ENPERR(22)
+
+/*!
+ * @const EX_BADRECEIPT_NP
+ * An exit code indicating that the program could not verify its purchase
+ * receipt from the Mac App Store. This exit code is inspected by the system to
+ * trigger a re-validation of the purchase receipt. It must be passed to the
+ * exit(3) Libc API and not to _exit(2) system call. This exit code is only
+ * relevant to the macOS variant of Darwin.
+ */
+#define EX_BADRECEIPT_NP (173)
+
+__BEGIN_DECLS;
+
+/*!
+ * @function sysexit_np
+ * Translates a {@link errno_t} or POSIX error code into an exit code
+ * defined in sysexits(3).
+ *
+ * @param code
+ * The error code to translate.
+ *
+ * @result
+ * The sysexits(3) exit code most appropriate for the given error. If no
+ * appropriate exit code could be determined, the designated Â¯\_(ツ)_/¯ exit
+ * code, EX_UNAVAILABLE, is returned (cf. sysexits(3)).
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_CONST
+int
+sysexit_np(int code);
+
+__END_DECLS;
+
+#endif // __DARWIN_ERRNO_H
diff --git a/libdarwin/h/libdarwin_init.h b/libdarwin/h/libdarwin_init.h
new file mode 100644 (file)
index 0000000..d01f300
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * libdarwin initialization header.
+ */
+#ifndef __DARWIN_INIT_H
+#define __DARWIN_INIT_H
+
+#include <os/base.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS;
+
+OS_EXPORT
+void
+__libdarwin_init(void);
+
+__END_DECLS;
+
+#endif // __DARWIN_INIT_H
diff --git a/libdarwin/h/mach_exception.h b/libdarwin/h/mach_exception.h
new file mode 100644 (file)
index 0000000..ef4a62e
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Darwin-specific interfaces for manipulating Mach exception handling
+ * properties of a task.
+ */
+#ifndef __DARWIN_EXCEPTION_H
+#define __DARWIN_EXCEPTION_H
+
+#include <os/base.h>
+#include <os/api.h>
+
+#include <sys/cdefs.h>
+#include <spawn.h>
+
+#include <mach/mach.h>
+#include <mach/port.h>
+#include <mach/mach_port.h>
+#include <mach/kern_return.h>
+
+__BEGIN_DECLS;
+
+/*!
+ * @typedef os_crash_flags_t
+ * A flagset describing crash handling behaviors.
+ *
+ * @param OS_CRASH_FLAG_INIT
+ * Handle no exceptions.
+ *
+ * @param OS_CRASH_FLAG_CRASH
+ * Handle exceptions due to crashing conditions (e.g. segmentation violations,
+ * signals raise(3)ed manually, etc.). These exceptions will suspend the subject
+ * task until the exception handler has returned.
+ *
+ * @param OS_CRASH_FLAG_GUARD
+ * Handle exceptions due to the subject task violating guarded kernel handles
+ * (e.g. guarded mach port rights and file descriptors).
+ *
+ * @param OS_CRASH_FLAG_RESOURCE
+ * Handle exceptions due to the subject task exceeding resource usage limits
+ * (e.g. CPU spins, memory growth, etc.).
+ *
+ * @param OS_CRASH_FLAG_CORPSE
+ * Handle exceptions which create corpses. The subject task of these exceptions
+ * is a corpse of the original task, which is torn down asynchronously. Corpses
+ * are a limited representation of the original task that is suitable for most
+ * introspection needs.
+ *
+ * This flag is mutually exclusive with {@link OS_CRASH_FLAG_CRASH}, and if both
+ * are present, this flag will be preferred.
+ *
+ * @discussion
+ * There are other Mach exception types than the ones enumerated by these flags,
+ * but they are almost exclusively handled internally by the kernel, and
+ * therefore are of little interest to userspace. Those that are not handled by
+ * the kernel are only relevant to debuggers.
+ */
+OS_ENUM(os_crash_flags, uint32_t,
+       OS_CRASH_FLAG_INIT = 0,
+       OS_CRASH_FLAG_CRASH = (1 << 0),
+       OS_CRASH_FLAG_GUARD = (1 << 1),
+       OS_CRASH_FLAG_RESOURCE = (1 << 2),
+       OS_CRASH_FLAG_CORPSE = (1 << 3),
+);
+
+/*!
+ * @enum os_crash_type_t
+ * A type describing exception types relevant to userspace crash reporters.
+ * These values serve as indexes into a {@link os_crash_port_array_t}.
+ *
+ * @const OS_CRASH_NONE
+ * No exception type.
+ *
+ * @const OS_CRASH_CRASH
+ * A crashing exception with the behavior described in {@link OS_CRASH_FLAG_CRASH}.
+ *
+ * @const OS_CRASH_GUARD
+ * A guard exception with the behavior described in {@link OS_CRASH_FLAG_GUARD}.
+ *
+ * @const OS_CRASH_RESOURCE
+ * A resource exception with the behavior described in {@link OS_CRASH_FLAG_RESOURCE}.
+ *
+ * @const OS_CRASH_CORPSE
+ * A corpse exception with the behavior described in {@link OS_CRASH_FLAG_CORPSE}.
+ */
+OS_ENUM(os_crash_type, uint32_t,
+       OS_CRASH_NONE,
+       OS_CRASH_CRASH,
+       OS_CRASH_GUARD,
+       OS_CRASH_RESOURCE,
+       OS_CRASH_CORPSE,
+       _OS_CRASH_LAST,
+);
+
+/*!
+ * struct os_crash_port_t
+ * A type describing an exception port and the exception it handles.
+ *
+ * @property oep_type
+ * The type of exception handled by the port.
+ *
+ * @property oep_port
+ * A handle representing a send right to the exception port.
+ */
+DARWIN_API_AVAILABLE_20170407
+typedef struct _os_crash_port {
+       os_crash_type_t oep_type;
+       mach_port_t oep_port;
+} os_crash_port_t;
+
+/*!
+ * @define DARWIN_EXCEPTION_PORT_ARRAY_COUNT
+ * The maximum number of exception ports that an exception port array can
+ * accommodate.
+ */
+#define OS_CRASH_PORT_ARRAY_COUNT (16lu)
+
+/*!
+ * @typedef os_crash_port_array_t
+ * An array of exception ports. This array can accommodate all exception types
+ * described in the {@link os_crash_type_t} type and is sized to
+ * accommodate future exception types.
+ */
+DARWIN_API_AVAILABLE_20170407
+typedef os_crash_port_t os_crash_port_array_t[OS_CRASH_PORT_ARRAY_COUNT];
+
+/*!
+ * @function os_crash_set_reporter_port
+ * Routine to set the exception handler port for the exceptions given.
+ *
+ * @param where
+ * The task port or host port for which to set the exception handler. This
+ * routine will internally choose the proper method of setting the exception
+ * port based on whether this parameter represents the host or not.
+ *
+ * @param flags
+ * Flags describing which exceptions are to be handled by the port.
+ *
+ * @param p
+ * A send right to the desired exception handler port.
+ *
+ * @result
+ * A kernel return code.
+ *
+ * @discussion
+ * This routine automatically chooses the most expressive thread state to
+ * deliver in the exception message based on the current architecture.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT
+kern_return_t
+os_crash_set_reporter_port(mach_port_t where,
+               os_crash_flags_t flags, mach_port_t p);
+
+/*!
+ * @function os_crash_get_reporter_port_array
+ * Routine to get the ports which handle exceptions for all enumerated exception
+ * types in {@link os_crash_flags_t}.
+ *
+ * @param where
+ * The task port or host port for which to retrieve exception handler ports.
+ * This routine will internally choose the proper method of obtaining the
+ * exception ports based on whether this parameter represents the host or not.
+ *
+ * @param array
+ * An array describing the exception ports for the target host or task. This
+ * array must be disposed of with {@link os_crash_port_array_deallocate}
+ * when it is no longer needed.
+ *
+ * @result
+ * A kernel return code.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL2
+kern_return_t
+os_crash_get_reporter_port_array(mach_port_t where,
+               os_crash_port_array_t array);
+
+/*!
+ * @function os_crash_port_array_deallocate
+ * Routine to deallocate an array of exception port descriptors.
+ *
+ * @param array
+ * The array which is to be disposed of.
+ *
+ * @discussion
+ * This routine disposes of the resources represented by the kernel handles in
+ * the array. It does not manipulate the array's memory. The expectation is that
+ * the caller allocates {@link os_crash_port_array_t} from the stack.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NONNULL1
+void
+os_crash_port_array_deallocate(os_crash_port_array_t array);
+
+/*!
+ * @function os_crash_spawnattr_set_reporter_port
+ * Routine to set the exception handler port for the exceptions given in a
+ * posix_spawn(2) attributes structure.
+ *
+ * @param psattr
+ * The spawn attributes for which the exception port should be set.
+ *
+ * @param flags
+ * Flags describing which exceptions are to be handled by the port.
+ *
+ * @param p
+ * A send right to the desired exception handler port.
+ *
+ * @result
+ * A kernel return code. This routine will only fail if the port name given was
+ * invalid.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1
+kern_return_t
+os_crash_spawnattr_set_reporter_port(posix_spawnattr_t *psattr,
+               os_crash_flags_t flags, mach_port_t p);
+
+__END_DECLS;
+
+#endif // __DARWIN_EXCEPTION_H
diff --git a/libdarwin/h/mach_utils.h b/libdarwin/h/mach_utils.h
new file mode 100644 (file)
index 0000000..13ad410
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Defines additions to the Mach family of APIs.
+ */
+#ifndef __DARWIN_MACH_UTILS_H
+#define __DARWIN_MACH_UTILS_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <os/assumes.h>
+
+#include <sys/cdefs.h>
+
+#include <mach/mach.h>
+#include <mach/mach_init.h>
+#include <mach/port.h>
+#include <mach/mach_port.h>
+#include <mach/kern_return.h>
+
+/*!
+ * @define OS_MIG_SUBSYSTEM_MAXSIZE
+ * A macro that evaluates to the maximum size of a request or reply message in
+ * the given MIG subsystem.
+ *
+ * @param __subsystem
+ * The name of the MIG subsystem, defined by the "subsystem" keyword.
+ *
+ * @param __serverprefix
+ * The serverprefix of the MIG subsystem, defined by the "serverprefix" keyword.
+ */
+#define OS_MIG_SUBSYSTEM_MAXSIZE(__subsystem, __serverprefix) __extension__({ \
+       union __subsystem ## _RequestReplyUnion { \
+               union __RequestUnion__ ## __serverprefix ## __subsystem ## \
+                       _subsystem requests; \
+               union __ReplyUnion__ ## __serverprefix ## __subsystem ## \
+                       _subsystem replies; \
+       }; \
+       (sizeof(union __subsystem ## _RequestReplyUnion)); \
+})
+
+__BEGIN_DECLS;
+
+/*!
+ * @function os_mach_msg_get_trailer
+ * Obtains the trailer for the received Mach message.
+ *
+ * @param hdr
+ * The message header of the received Mach message.
+ *
+ * @result
+ * A pointer to the trailer that was received with the message.
+ *
+ * @discussion
+ * Every received Mach message has a minimal trailer which identifies its format
+ * and size (cf. mach_msg_trailer_t). Currently, there is one format,
+ * MACH_MSG_TRAILER_FORMAT_0. The caller is responsible for validating the
+ * returned trailer's format against this known value as well as the trailer's
+ * size before using any additional trailer fields.
+ *
+ * The result of passing a header to a message that was not received from a port
+ * is undefined.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1
+const mach_msg_trailer_t *
+os_mach_msg_get_trailer(const mach_msg_header_t *hdr);
+
+/*!
+ * @function os_mach_msg_get_audit_trailer
+ * Obtains the audit trailer for the received Mach message.
+ *
+ * @param hdr
+ * The message header of the received Mach message.
+ *
+ * @result
+ * A pointer to the audit trailer that was received with the message. If the
+ * message was not received with an audit trailer (by passing
+ * MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT) in the mach_msg() options),
+ * NULL is returned.
+ *
+ * @discussion
+ * The result of passing a header to a message that was not received from a port
+ * is undefined.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1
+const mach_msg_audit_trailer_t *
+os_mach_msg_get_audit_trailer(const mach_msg_header_t *hdr);
+
+/*!
+ * @function os_mach_msg_get_context_trailer
+ * Obtains the context trailer for the received Mach message.
+ *
+ * @param hdr
+ * The message header of the received Mach message.
+ *
+ * @result
+ * A pointer to the context trailer that was received with the message. If the
+ * message was not received with an context trailer (by passing
+ * MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_CTX) in the mach_msg() options),
+ * NULL is returned.
+ *
+ * @discussion
+ * The result of passing a header to a message that was not received from a port
+ * is undefined.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1
+const mach_msg_context_trailer_t *
+os_mach_msg_get_context_trailer(const mach_msg_header_t *hdr);
+
+/*!
+ * @const os_mach_msg_copy_description
+ * A routine for obtaining a human-readable description of a Mach message.
+ *
+ * @param msg
+ * The message for which to obtain the description.
+ *
+ * @result
+ * A human-readable string describing the given message header. This string is
+ * not intended to be machine-parseable, and the exact output format is not
+ * stable.
+ *
+ * The implementation does not attempt to introspect the contents of the
+ * message. If the implementation detects that the message is complex, it will
+ * examine the first 4 bytes past the header to obtain the descriptor count, as
+ * is specified by the Mach APIs. Therefore, you should not pass a complex
+ * header that is not part of a valid message buffer, or the output may contain
+ * garbage information.
+ *
+ * The caller is responsible for free(3)ing this string when it is no longer
+ * required.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_MALLOC OS_NONNULL1
+char *
+os_mach_msg_copy_description(const mach_msg_header_t *msg);
+
+/*!
+ * @function os_mach_msg_trailer_copy_description
+ * A routine for obtaining a human-readable description of the trailer of a Mach
+ * message.
+ *
+ * @param tlr
+ * The trailer for which to obtain the description.
+ *
+ * @result
+ * A human-readable string describing the given message trailer. This string is
+ * not intended to be machine-parseable, and the exact output format is not
+ * stable.
+ *
+ * The caller is responsible for free(3)ing this string when it is no longer
+ * required.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_MALLOC OS_NONNULL1
+char *
+os_mach_msg_trailer_copy_description(const mach_msg_trailer_t *tlr);
+
+/*!
+ * @function os_mach_port_copy_description
+ * A routine for obtaining a human-readable description string of a port right
+ * handle.
+ *
+ * @param port
+ * The port right for which to obtain the description.
+ *
+ * @result
+ * A human-readable string describing the given port right. This string is not
+ * intended to be machine-parseable, and the exact output format is not stable.
+ *
+ * The caller is responsible for free(3)ing this string when it is no longer
+ * required.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_MALLOC
+char *
+os_mach_port_copy_description(mach_port_t port);
+
+__END_DECLS;
+
+#endif // __DARWIN_MACH_UTILS_H
diff --git a/libdarwin/h/stdio.h b/libdarwin/h/stdio.h
new file mode 100644 (file)
index 0000000..3042ce2
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Non-standard, Darwin-specific additions for the stdio(3) family of APIs.
+ */
+#ifndef __DARWIN_STDIO_H
+#define __DARWIN_STDIO_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS;
+
+/*!
+ * @function zsnprintf_np
+ * snprintf(3) variant which returns the numnber of bytes written less the null
+ * terminator.
+ *
+ * @param buff
+ * The buffer in which to write the string.
+ *
+ * @param len
+ * The length of the buffer.
+ *
+ * @param fmt
+ * The printf(3)-like format string.
+ *
+ * @param ...
+ * The arguments corresponding to the format string.
+ *
+ * @result
+ * The number of bytes written into the buffer, less the null terminator. This
+ * routine is useful for successive string printing that may be lossy, as it
+ * will simply return zero when there is no space left in the destination
+ * buffer, i.e. enables the following pattern:
+ *
+ * char *cur = buff;
+ * size_t left = sizeof(buff);
+ * for (i = 0; i < n_strings; i++) {
+ *     size_t n_written = zsnprintf_np(buff, left, "%s", strings[i]);
+ *     cur += n_written;
+ *     left -= n_written;
+ * }
+ *
+ * This loop will safely terminate without any special care since, as soon as
+ * the buffer's space is exhausted, all further calls to zsnprintf_np() will
+ * write nothing and return zero.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_NONNULL1 OS_NONNULL3 OS_FORMAT_PRINTF(3, 4)
+size_t
+zsnprintf_np(char *buff, size_t len, const char *fmt, ...);
+
+__END_DECLS;
+
+#endif // __DARWIN_STDIO_H
diff --git a/libdarwin/h/stdlib.h b/libdarwin/h/stdlib.h
new file mode 100644 (file)
index 0000000..ed4d3ef
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Non-standard, Darwin-specific additions to the stdlib(3) family of APIs.
+ *
+ * The os_malloc() and os_strdup() routines are wrappers to be used for small,
+ * fixed-size allocations, the assumption being that such allocation should
+ * always succeed absent other critical problems. Thus, if the requested size is
+ * is a compile-time constant, the return value is asserted to be non-NULL.
+ * Otherwise, for sizes that are not known at compile-time, the implementations
+ * loop until the allocation succeeds, assuming the failure to be due to
+ * transient resource shortages. The implementation will not loop if the program
+ * has not become multi-threaded, under the assertion that there would be no
+ * point since no other thread could possibly free up resources for the calling
+ * thread to use. Thus, in a single-threaded program, all allocations will
+ * be treated like small, fixed-size allocations and be expected to succeed.
+ *
+ * These wrappers should not be used for large allocations whose bounds cannot
+ * be determined at compile-time. For such allocations, malloc(3), calloc(3), et
+ * al. (with appropriate error handling) are the appropriate interfaces.
+ */
+#ifndef __DARWIN_STDLIB_H
+#define __DARWIN_STDLIB_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <os/assumes.h>
+#include <dispatch/private.h>
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS;
+
+/*!
+ * @function __os_temporary_resource_shortage
+ * A function whose purpose is to appear in stack traces to indicate transient
+ * resource shortage conditions. Do not call.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NOT_TAIL_CALLED
+void
+__os_temporary_resource_shortage(void);
+
+/*!
+ * @functiongroup
+ * Internal inline definitions.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_ALWAYS_INLINE OS_WARN_RESULT OS_MALLOC __alloc_size(1)
+static inline void *
+_os_malloc_loop(size_t size)
+{
+       void *ptr = NULL;
+       while (!(ptr = malloc(size))) {
+               __os_temporary_resource_shortage();
+       }
+       return ptr;
+}
+
+DARWIN_API_AVAILABLE_20170407
+OS_ALWAYS_INLINE OS_WARN_RESULT OS_MALLOC __alloc_size(1)
+static inline void *
+_os_malloc_known(size_t size)
+{
+       return malloc(size);
+}
+
+DARWIN_API_AVAILABLE_20170407
+OS_ALWAYS_INLINE OS_WARN_RESULT OS_MALLOC __alloc_size(1, 2)
+static inline void *
+_os_calloc_loop(size_t cnt, size_t size)
+{
+       void *ptr = NULL;
+       while (!(ptr = calloc(cnt, size))) {
+               __os_temporary_resource_shortage();
+       }
+       return ptr;
+}
+
+DARWIN_API_AVAILABLE_20170407
+OS_ALWAYS_INLINE OS_WARN_RESULT OS_MALLOC __alloc_size(1, 2)
+static inline void *
+_os_calloc_known(size_t cnt, size_t size)
+{
+       return calloc(cnt, size);
+}
+
+DARWIN_API_AVAILABLE_20170407
+OS_ALWAYS_INLINE OS_WARN_RESULT OS_MALLOC
+static inline char *
+_os_strdup_loop(const char *str)
+{
+       char *ptr = NULL;
+       while (!(ptr = strdup(str))) {
+               __os_temporary_resource_shortage();
+       }
+       return ptr;
+}
+
+DARWIN_API_AVAILABLE_20170407
+OS_ALWAYS_INLINE OS_WARN_RESULT OS_MALLOC
+static inline char *
+_os_strdup_known(const char *str)
+{
+       return strdup(str);
+}
+
+/*!
+ * @function os_malloc
+ * Wrapper around malloc(3) which guarantees that the allocation succeeds.
+ *
+ * @param __size
+ * The size of the allocation.
+ *
+ * @result
+ * A new object that the caller is responsible for free(3)ing.
+ *
+ * This routine will never return NULL. If the size of the allocation is known
+ * at compile-time, a failure to allocate the object will abort the caller. If
+ * the size is not known at compile-time, the routine will retry until it is
+ * successful.
+ */
+#define os_malloc(__size) ({ \
+       void *ptr = NULL; \
+       size_t _size = (__size); \
+       if (__builtin_constant_p(__size) || !_dispatch_is_multithreaded()) { \
+               ptr = _os_malloc_known(_size); \
+               os_assert_malloc("known-constant allocation", ptr, _size); \
+       } else { \
+               ptr = _os_malloc_loop(_size); \
+       } \
+       (ptr); \
+})
+
+/*!
+ * @function os_calloc
+ * Wrapper around calloc(3) which guarantees that the allocation succeeds.
+ *
+ * @param __cnt
+ * The number of elements to allocate.
+ *
+ * @param __size
+ * The size of each element to allocate.
+ *
+ * @result
+ * A new object that the caller is responsible for free(3)ing.
+ *
+ * This routine will never return NULL. If the size of the allocation is known
+ * at compile-time, a failure to allocate the object will abort the caller. If
+ * the size is not known at compile-time, the routine will retry until it is
+ * successful.
+ */
+#define os_calloc(__cnt, __size) ({ \
+       void *ptr = NULL; \
+       size_t _size = (__size); \
+       size_t _cnt = (__size); \
+       if ((__builtin_constant_p(__cnt) && __builtin_constant_p(__size)) || \
+                        !_dispatch_is_multithreaded()) { \
+               ptr = _os_calloc_known(_cnt, _size); \
+               os_assert_malloc("known-constant allocation", ptr, _size); \
+       } else { \
+               ptr = _os_calloc_loop(_cnt, _size); \
+       } \
+       (ptr); \
+})
+
+/*!
+ * @function os_strdup
+ * A wrapper around strdup(3) which guarantees that the string duplication
+ * succeeds.
+ *
+ * @param __str
+ * The string to duplicate.
+ *
+ * @result
+ * A new string that the caller is responsible for free(3)ing.
+ *
+ * This routine will never return NULL. If the given string is a compile-time
+ * constant, a failure to duplicate it will abort the caller. If the string is
+ * not a compile-time constant, the routine will retry until it is successful.
+ *
+ * @discussion
+ * strdup(3) is found in the string(3) API family, but this interface is in the
+ * stdlib.h header because its semantic changes are solely related to the manner
+ * in which memory is allocated.
+ */
+#define os_strdup(__str) ({ \
+       char *ptr = NULL; \
+       const char *_str = (__str); \
+       if (__builtin_constant_p(__str) || !_dispatch_is_multithreaded()) { \
+               ptr = _os_strdup_known(_str); \
+               os_assert_malloc("known-constant allocation", ptr, strlen(_str)); \
+       } else { \
+               ptr = _os_strdup_loop(_str); \
+       } \
+       (ptr); \
+})
+
+/*!
+ * @function os_localtime_file
+ * A routine to generate a time stamp that is suitable for embedding in a file
+ * name.
+ *
+ * @param buff
+ * A pointer to a buffer where the resulting time stamp will be stored.
+ *
+ * @discussion
+ * The resulting time stamp will not include characters which require escaping
+ * in shells, such as spaces. The current implementation format is
+ *
+ * YYYY-MM-DD_HH.MM.SS.us
+ *
+ * e.g.
+ *
+ * 2017-04-24_12.45.15.045609
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT
+void
+os_localtime_file(char buff[32]);
+
+/*!
+ * @function os_simple_hash
+ * An implementation of a simple non-cryptographic hashing algorithm.
+ *
+ * @param buff
+ * A pointer to the buffer to hash.
+ *
+ * @param len
+ * The length of the buffer.
+ *
+ * @result
+ * The hashed value of the input.
+ *
+ * @discussion
+ * This routine is meant to be used as a simple way to obtain a value that can
+ * be used to choose a bucket in a simple hash table. Do not attach security
+ * assumptions to the output of this routine. Do not assume thst the computed
+ * hash is stable between hosts, OS versions, or boot sessions.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NONNULL1
+uint64_t
+os_simple_hash(const void *buff, size_t len);
+
+/*!
+ * @function os_simple_hash_string
+ * An implementation of a simple non-cryptographic hashing algorithm.
+ *
+ * @param string
+ * A pointer to the null-terminated string to hash.
+ *
+ * @result
+ * The hashed value of the input.
+ *
+ * @discussion
+ * This routine is the moral equivalent of a call to
+ *
+ * os_simple_hash(buff, strlen(buff));
+ *
+ * All the same considerations of {@link os_simple_hash} apply.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_NONNULL1
+uint64_t
+os_simple_hash_string(const char *string);
+
+__END_DECLS;
+
+#endif // __DARWIN_STDLIB_H
diff --git a/libdarwin/h/string.h b/libdarwin/h/string.h
new file mode 100644 (file)
index 0000000..8d16ac1
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * Non-standard, Darwin-specific additions to the string(3) family of APIs.
+ */
+#ifndef __DARWIN_STRING_H
+#define __DARWIN_STRING_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS;
+
+/*!
+ * @typedef os_flag_t
+ * A type describing a flag's human-readable name.
+ *
+ * @property ohf_flag
+ * The flag value.
+ *
+ * @property ohf_human
+ * The human-readable, string representation of the flag value.
+ */
+DARWIN_API_AVAILABLE_20170407
+typedef struct _os_flag {
+       const uint64_t ohf_flag;
+       const char *const ohf_human_flag;
+} os_flag_t;
+
+/*!
+ * @define OS_FLAGSET_COUNT
+ * The maximum number of flags that a flagset can represent.
+ */
+#define OS_FLAGSET_COUNT (sizeof(uint64_t) * BYTE_SIZE)
+
+/*!
+ * @typedef os_flagset_t
+ * A type describing an array of human flags. Can accommodate up to 64 flags.
+ */
+DARWIN_API_AVAILABLE_20170407
+typedef os_flag_t os_flagset_t[OS_FLAGSET_COUNT];
+
+/*!
+ * @macro os_flag_init
+ * Initializer for a {@link os_flag_t} structure which stringifies the
+ * flag value.
+ *
+ * @param __flag
+ * The name of the flag to initialize.
+ */
+#define os_flag_init(__flag) { \
+       .ohf_flag = __flag, \
+       .ohf_human_flag = #__flag, \
+}
+
+/*!
+ * @function strerror_np
+ * Returns a human-readable string for the given {@link errno_t} or
+ * POSIX error code.
+ *
+ * @param code
+ * The error code for which to obtain the string.
+ *
+ * @result
+ * A human-readable string describing the error condition. If a POSIX error code
+ * is given, this is equivalent to a call to strerror(3).
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_PURE
+const char *
+strerror_np(int code);
+
+/*!
+ * @function symerror_np
+ * Returns the token name of the given {@link errno_t} or POSIX error
+ * code.
+ *
+ * @param code
+ * The error code for which to obtain the token string.
+ *
+ * @result
+ * The string describing the error token. For example, if code 2 is passed, the
+ * string "EPERM" is returned.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_PURE
+const char *
+symerror_np(int code);
+
+/*!
+ * @function symexit_np
+ * Returns the token name of the given sysexits(3) code.
+ *
+ * @param code
+ * The sysexits(3) code for which to obtain the token string.
+ *
+ * @result
+ * The string describing the exit code. For example, if 64 is passed, the string
+ * "EX_USAGE" is returned. If the code is unrecognized, "EX_UNAVAILABLE" is
+ * returned, which is more or less documented in sysexits(3) as the Â¯\_(ツ)_/¯
+ * exit code.
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_PURE
+const char *
+symexit_np(int code);
+
+/*!
+ * @function os_flagset_copy_string
+ * Returns a human-readable representation of the flags set for a given word.
+ *
+ * @param flagset
+ * The human flagset which describes how to interpret the {@link flags}
+ * parameter.
+ *
+ * @param flags
+ * The flags to interpret.
+ *
+ * @result
+ * The human-readable representation of all flags set in the {@link flags}
+ * parameter, separated by the pipe character. The caller is responsible for
+ * calling free(3) on this object when it is no longer needed.
+ *
+ * @discussion
+ * This API is to be used in combination with {@link os_flag_init} to make
+ * printing the contents of flags fields simple. For example, this code can
+ * easily print a human-readable representation of the bits set in a Mach
+ * message header:
+ *
+ *     static const os_flagset_t _mach_msgh_bits = {
+ *          os_flag_init(MACH_MSGH_BITS_COMPLEX),
+ *          os_flag_init(MACH_MSGH_BITS_RAISEIMP),
+ *          os_flag_init(MACH_MSGH_BITS_IMPHOLDASRT),
+ *    };
+ *
+ *    char *flags_string = os_flagset_copy_string(&_mach_msgh_bits,
+ *            hdr->msgh_bits);
+ *
+ * For a message header with the MACH_MSGH_BITS_COMPLEX and
+ * MACH_MSGH_BITS_RAISEIMP bits set, this will return the string
+ *
+ *     MACH_MSGH_BITS_COMPLEX|MACH_MSGH_BITS_RAISEIMP
+ */
+DARWIN_API_AVAILABLE_20170407
+OS_EXPORT OS_WARN_RESULT OS_MALLOC
+char *
+os_flagset_copy_string(const os_flagset_t flagset, uint64_t flags);
+
+__END_DECLS;
+
+#endif // __DARWIN_STRING_H
index ba68629bc06a2e413d5d2dd3835361a803e5cad9..33cb44850cab0db81646d939b78a2e71085276e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2016 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
  *
  * @APPLE_LICENSE_HEADER_END@
  */
+#include "internal.h"
+
+#pragma mark API
+void
+__os_temporary_resource_shortage(void)
+{
+       (void)sleep(1);
+       _os_avoid_tail_call();
+}
 
 void
 __libdarwin_init(void)
 {
+       
 }
diff --git a/libdarwin/internal.h b/libdarwin/internal.h
new file mode 100644 (file)
index 0000000..12e64c7
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2017 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * libdarwin internal header.
+ */
+#ifndef __DARWIN_INTERNAL_H
+#define __DARWIN_INTERNAL_H
+
+#include <os/base.h>
+#include <os/api.h>
+#include <Availability.h>
+
+#include <mach/port.h>
+#include <mach/message.h>
+#include <mach/host_priv.h>
+#include <mach/host_reboot.h>
+#include <mach/mach_time.h>
+#include <mach/mach.h>
+#include <mach/port.h>
+#include <mach/message.h>
+#include <mach/host_priv.h>
+#include <mach/host_reboot.h>
+
+#include <sys/sysctl.h>
+#include <sys/reboot.h>
+#include <sys/syscall.h>
+#include <sys/errno.h>
+#include <sys/paths.h>
+#include <sys/spawn.h>
+#include <sys/proc_info.h>
+#include <sys/sysctl.h>
+#include <sys/reboot.h>
+#include <sys/syscall.h>
+#include <sys/errno.h>
+#include <sys/paths.h>
+#include <sys/spawn.h>
+#include <sys/proc_info.h>
+
+#define OS_CRASH_ENABLE_EXPERIMENTAL_LIBTRACE 1
+#include <os/assumes.h>
+#include <os/transaction_private.h>
+#include <os/log_private.h>
+#include <os/alloc_once_private.h>
+
+#include <mach-o/getsect.h>
+#include <bsm/libbsm.h>
+#include <sysexits.h>
+#include <spawn.h>
+#include <libproc.h>
+#include <string.h>
+#include <dlfcn.h>
+#include <err.h>
+#include <ctype.h>
+#include <struct.h>
+#include <bootstrap_priv.h>
+#include <assert.h>
+
+#define RDAR_12809455 1
+
+#include "h/bsd.h"
+#include "h/cleanup.h"
+#include "h/err.h"
+#include "h/errno.h"
+#include "h/mach_exception.h"
+#include "h/mach_utils.h"
+#include "h/stdio.h"
+#include "h/stdlib.h"
+#include "h/string.h"
+
+#if DARWIN_TAPI
+// Duplicate declarations to make TAPI happy. This header is included in the
+// TAPI build as an extra public header.
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT OS_NONNULL1
+void
+os_assert_mach(const char *op, kern_return_t kr);
+
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT
+void
+os_assert_mach_port_status(const char *desc, mach_port_t p,
+               mach_port_status_t *expected);
+#endif
+
+#endif //__DARWIN_INTERNAL_H
diff --git a/libdarwin/mach.c b/libdarwin/mach.c
new file mode 100644 (file)
index 0000000..08bf794
--- /dev/null
@@ -0,0 +1,485 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark Types
+typedef struct _os_mach_port_disposition {
+       mach_msg_bits_t ompd_bits;
+       const char *const ompd_human;
+} os_mach_port_disposition_t;
+
+#define os_mach_port_disposition_init(d) [d] = { \
+       .ompd_bits = (d), \
+       .ompd_human = #d, \
+}
+
+#pragma mark Top-Level Statics
+static const os_flagset_t _mach_msgh_bits = {
+       os_flag_init(MACH_MSGH_BITS_COMPLEX),
+       os_flag_init(MACH_MSGH_BITS_RAISEIMP),
+       // MACH_MSGH_BITS_DENAP is deprecated
+       os_flag_init(MACH_MSGH_BITS_IMPHOLDASRT),
+       // MACH_MSGH_BITS_DENAPHOLDASRT is deprecated
+       // MACH_MSGH_BITS_CIRCULAR is kernel-internal
+};
+
+static const os_mach_port_disposition_t _mach_port_dispositions[] = {
+       os_mach_port_disposition_init(MACH_MSG_TYPE_MOVE_RECEIVE),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_MOVE_SEND),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_MOVE_SEND_ONCE),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_COPY_SEND),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_MAKE_SEND),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_MAKE_SEND_ONCE),
+       // MACH_MSG_TYPE_COPY_RECEIVE is not a valid operation, so unclear why it's
+       // even defined
+       os_mach_port_disposition_init(MACH_MSG_TYPE_DISPOSE_RECEIVE),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_DISPOSE_SEND),
+       os_mach_port_disposition_init(MACH_MSG_TYPE_DISPOSE_SEND_ONCE),
+};
+
+static inline const char *
+_mach_port_disposition_string(mach_msg_bits_t d)
+{
+       if (d < MACH_MSG_TYPE_MOVE_RECEIVE) {
+               return "[invalid]";
+       }
+       if (d > MACH_MSG_TYPE_DISPOSE_SEND_ONCE) {
+               return "[invalid]";
+       }
+       return _mach_port_dispositions[d].ompd_human;
+}
+
+static const os_flagset_t _mach_port_rights = {
+       os_flag_init(MACH_PORT_TYPE_SEND),
+       os_flag_init(MACH_PORT_TYPE_RECEIVE),
+       os_flag_init(MACH_PORT_TYPE_SEND_ONCE),
+       os_flag_init(MACH_PORT_TYPE_PORT_SET),
+       os_flag_init(MACH_PORT_TYPE_DEAD_NAME),
+       // MACH_PORT_TYPE_LABELH is obsolete
+       // MACH_PORT_TYPE_DNREQUEST->_mach_port_requests
+       // MACH_PORT_TYPE_SPREQUEST->_mach_port_requests
+       // MACH_PORT_TYPE_SPREQUEST_DELAYED->_mach_port_requests
+       // MACH_PORT_RIGHT_NUMBER is obsolete
+};
+
+static const os_flagset_t _mach_port_requests = {
+       os_flag_init(MACH_PORT_TYPE_DNREQUEST),
+       os_flag_init(MACH_PORT_TYPE_SPREQUEST),
+       os_flag_init(MACH_PORT_TYPE_SPREQUEST_DELAYED),
+};
+
+static const os_flagset_t _mach_port_status = {
+       os_flag_init(MACH_PORT_STATUS_FLAG_TEMPOWNER),
+       os_flag_init(MACH_PORT_STATUS_FLAG_GUARDED),
+       os_flag_init(MACH_PORT_STATUS_FLAG_STRICT_GUARD),
+       os_flag_init(MACH_PORT_STATUS_FLAG_IMP_DONATION),
+       // MACH_PORT_STATUS_FLAG_REVIVE is obsolete
+       os_flag_init(MACH_PORT_STATUS_FLAG_TASKPTR),
+};
+
+static const os_flagset_t _mach_special_bits = {
+       os_flag_init(MACH_MSG_IPC_SPACE),
+       os_flag_init(MACH_MSG_VM_SPACE),
+       os_flag_init(MACH_MSG_IPC_KERNEL),
+       os_flag_init(MACH_MSG_VM_KERNEL),
+};
+
+#pragma mark API
+const mach_msg_trailer_t *
+os_mach_msg_get_trailer(const mach_msg_header_t *hdr)
+{
+       // The mach_msg() documentation states that the trailer will follow the
+       // message body on the next natural boundary. But when we moved to 64-bit,
+       // we kept the trailer alignment on a 4-byte boundary for compatibility
+       // reasons. Specifically, natural_t is still 32 bits on both 32- and 64-bit
+       // platforms.
+       return (mach_msg_trailer_t *)((uint8_t *)hdr + round_msg(hdr->msgh_size));
+}
+
+const mach_msg_audit_trailer_t *
+os_mach_msg_get_audit_trailer(const mach_msg_header_t *hdr)
+{
+       const mach_msg_trailer_t *tlr = NULL;
+       const mach_msg_audit_trailer_t *audit_tlr = NULL;
+
+       tlr = os_mach_msg_get_trailer(hdr);
+       if (tlr->msgh_trailer_type == MACH_MSG_TRAILER_FORMAT_0) {
+               if (tlr->msgh_trailer_size >= sizeof(mach_msg_audit_trailer_t)) {
+                       audit_tlr = (mach_msg_audit_trailer_t *)tlr;
+               }
+       }
+
+       return audit_tlr;
+}
+
+const mach_msg_context_trailer_t *
+os_mach_msg_get_context_trailer(const mach_msg_header_t *hdr)
+{
+       const mach_msg_trailer_t *tlr = NULL;
+       const mach_msg_context_trailer_t *ctx_tlr = NULL;
+
+       tlr = os_mach_msg_get_trailer(hdr);
+       if (tlr->msgh_trailer_type == MACH_MSG_TRAILER_FORMAT_0) {
+               if (tlr->msgh_trailer_size >= sizeof(mach_msg_context_trailer_t)) {
+                       ctx_tlr = (mach_msg_context_trailer_t *)tlr;
+               }
+       }
+
+       return ctx_tlr;
+}
+
+char *
+os_mach_msg_copy_description(const mach_msg_header_t *msg)
+{
+       int ret = -1;
+       mach_msg_bits_t local = MACH_MSGH_BITS_LOCAL(msg->msgh_bits);
+       mach_msg_bits_t remote = MACH_MSGH_BITS_REMOTE(msg->msgh_bits);
+       mach_msg_bits_t voucher = MACH_MSGH_BITS_VOUCHER(msg->msgh_bits);
+       char *__os_free bits_desc = NULL;
+       const char *local_desc = _mach_port_disposition_string(local);
+       const char *remote_desc = _mach_port_disposition_string(remote);
+       const char *voucher_desc = _mach_port_disposition_string(voucher);
+       char *desc = NULL;
+       mach_msg_size_t ool_cnt = 0;
+
+       if (msg->msgh_bits & MACH_MSGH_BITS_COMPLEX) {
+               ool_cnt = ((mach_msg_base_t *)msg)->body.msgh_descriptor_count;
+       }
+
+       bits_desc = os_flagset_copy_string(_mach_msgh_bits, msg->msgh_bits);
+       ret = asprintf(&desc, "id = %#x, size = %u, bits = %s, "
+                       "local disp = %s, local port = %#x, "
+                       "remote disp = %s, remote port = %#x, "
+                       "voucher disp = %s, voucher port = %#x, "
+                       "out-of-line descriptor cnt = %u",
+                       msg->msgh_id, msg->msgh_size, bits_desc,
+                       local_desc, msg->msgh_local_port,
+                       remote_desc, msg->msgh_remote_port,
+                       voucher_desc, msg->msgh_voucher_port,
+                       ool_cnt);
+       posix_assert_zero(ret);
+
+       return desc;
+}
+
+char *
+os_mach_msg_trailer_copy_description(const mach_msg_trailer_t *tlr)
+{
+       union {
+               int r;
+               size_t n;
+       } ret = {
+               .r = -1,
+       };
+       char *desc = NULL;
+       char buff[512];
+       char *cursor = buff;
+       size_t left = sizeof(buff);
+       // Yes we do not know the actual size of the trailer yet, so this is
+       // technically unsafe, but we only dereference members after determining
+       // that they are safe to dereference. Just us chickens and all that.
+       const mach_msg_mac_trailer_t *max = (const mach_msg_mac_trailer_t *)tlr;
+
+       if (tlr->msgh_trailer_type != MACH_MSG_TRAILER_FORMAT_0) {
+               ret.r = asprintf(&desc, "type = %u, size = %u",
+                               tlr->msgh_trailer_type, tlr->msgh_trailer_size);
+               os_assert_zero(ret.r);
+               goto __out;
+       }
+
+       if (tlr->msgh_trailer_size >= sizeof(mach_msg_trailer_t)) {
+               ret.r = snprintf(cursor, left, "format = %u, size = %u",
+                               tlr->msgh_trailer_type, tlr->msgh_trailer_size);
+               os_assert_sprintf(ret.r, left);
+
+               // Safe since the above assert has verified that ret is both positive
+               // and less than or equal to the size of the buffer.
+               cursor += ret.n;
+               left -= ret.n;
+       }
+
+       if (tlr->msgh_trailer_size >= sizeof(mach_msg_seqno_trailer_t)) {
+               ret.r = snprintf(cursor, left, ", seqno = %u", max->msgh_seqno);
+               os_assert_sprintf(ret.r, left);
+               cursor += ret.n;
+               left -= ret.n;
+       }
+
+       if (tlr->msgh_trailer_size >= sizeof(mach_msg_security_trailer_t)) {
+               ret.r = snprintf(cursor, left, ", security.uid = %u, security.gid = %u",
+                               max->msgh_sender.val[0], max->msgh_sender.val[1]);
+               os_assert_sprintf(ret.r, left);
+               cursor += ret.n;
+               left -= ret.n;
+       }
+
+       if (tlr->msgh_trailer_size >= sizeof(mach_msg_audit_trailer_t)) {
+               ret.r = snprintf(cursor, left, ", audit.auid = %u, "
+                               "audit.euid = %u, audit.egid = %u, "
+                               "audit.ruid = %u, audit.rgid = %u, "
+                               "audit.pid = %u, audit.asid = %u, audit.pidvers = %u",
+                               max->msgh_audit.val[0], max->msgh_audit.val[1],
+                               max->msgh_audit.val[2], max->msgh_audit.val[3],
+                               max->msgh_audit.val[4], max->msgh_audit.val[5],
+                               max->msgh_audit.val[6], max->msgh_audit.val[7]);
+               os_assert_sprintf(ret.r, left);
+               cursor += ret.n;
+               left -= ret.n;
+       }
+
+       if (tlr->msgh_trailer_size >= sizeof(mach_msg_context_trailer_t)) {
+               uint64_t ctx = max->msgh_context;
+               ret.r = snprintf(cursor, left, ", context = %#llx", ctx);
+               os_assert_sprintf(ret.r, left);
+               cursor += ret.n;
+               left -= ret.n;
+       }
+
+       if (tlr->msgh_trailer_size >= sizeof(mach_msg_mac_trailer_t)) {
+               ret.r = snprintf(cursor, left, ", labels.sender = %#x",
+                               max->msgh_labels.sender);
+               os_assert_sprintf(ret.r, left);
+               cursor += ret.n;
+               left -= ret.n;
+       }
+
+       desc = os_strdup(buff);
+
+__out:
+       return desc;
+}
+
+char *
+os_mach_port_copy_description(mach_port_t p)
+{
+       kern_return_t kr = KERN_FAILURE;
+       mach_port_right_t right = 0;
+       mach_port_type_t type = 0;
+       mach_port_urefs_t urefs = 0;
+       mach_port_status_t status;
+       mach_msg_type_number_t status_size = MACH_PORT_RECEIVE_STATUS_COUNT;
+       char *desc = NULL;
+       char *__os_free rightdesc = NULL;
+       char *__os_free requestdesc = NULL;
+       char *__os_free statusdesc = NULL;
+       char *__os_free urefsdesc = NULL;
+       char *which_urefs = "";
+       int ret = -1;
+
+       if (p == MACH_PORT_NULL) {
+               return os_strdup("null");
+       }
+       if (p == MACH_PORT_DEAD) {
+               return os_strdup("dead-name");
+       }
+
+       kr = mach_port_type(mach_task_self(), p, &type);
+       switch (kr) {
+       case KERN_SUCCESS:
+               rightdesc = os_flagset_copy_string(_mach_port_rights, type);
+               requestdesc = os_flagset_copy_string(_mach_port_requests, type);
+               break;
+       default:
+               ret = asprintf(&rightdesc, "[%#x]", kr);
+               posix_assert_zero(ret);
+       }
+
+       kr = mach_port_get_attributes(mach_task_self(), p,
+                       MACH_PORT_RECEIVE_STATUS, (mach_port_info_t)&status, &status_size);
+       switch (kr) {
+       case KERN_SUCCESS:
+               if (status.mps_flags) {
+                       statusdesc = os_flagset_copy_string(_mach_port_status,
+                                       status.mps_flags);
+               } else {
+                       statusdesc = os_strdup("[none]");
+               }
+
+               break;
+       case KERN_INVALID_RIGHT:
+               if (!(type & MACH_PORT_TYPE_RECEIVE)) {
+                       statusdesc = os_strdup("[none]");
+                       break;
+               }
+       default:
+               ret = asprintf(&statusdesc, "[%#x]", kr);
+               posix_assert_zero(ret);
+       }
+
+       if (type & MACH_PORT_TYPE_SEND) {
+               right = MACH_PORT_RIGHT_SEND;
+               which_urefs = "send";
+       } else if (type & MACH_PORT_TYPE_DEAD_NAME) {
+               right = MACH_PORT_RIGHT_DEAD_NAME;
+               which_urefs = "dead name";
+       }
+
+       if (which_urefs) {
+               kr = mach_port_get_refs(mach_task_self(), p, right, &urefs);
+               switch (kr) {
+               case KERN_SUCCESS:
+                       ret = asprintf(&urefsdesc, ", %s urefs = %u", which_urefs, urefs);
+                       break;
+               default:
+                       ret = asprintf(&urefsdesc, ", %s urefs = [%#x]",
+                                       which_urefs, kr);
+                       break;
+               }
+       }
+
+       ret = asprintf(&desc, "name = %#x, rights = %s, requests = %s, "
+                       "status = %s%s",
+                       p, rightdesc, requestdesc, statusdesc, urefsdesc);
+       posix_assert_zero(ret);
+
+       return desc;
+}
+
+#pragma mark API from <os/assumes.h>
+// These live here because the implementations uses functionality from
+// libdarwin, and we don't want to have a circular dependency between Libc and
+// libsystem_darwin. The long-term plan is to move assumes() and assert()
+// functionality into libdarwin anyway.
+void
+os_assert_mach(const char *op, kern_return_t kr)
+{
+       kern_return_t real_kr = (kern_return_t)(kr & (~MACH_MSG_MASK));
+       kern_return_t extra = (kern_return_t)(kr & MACH_MSG_MASK);
+       const char *err_string = NULL;
+       const char *err_type_string = NULL;
+       char err_buff[64];
+       char code_buff[16];
+       const char *special_desc = NULL;
+       int sys = err_get_system(real_kr);
+       int sub = err_get_sub(real_kr);
+       int code = err_get_code(real_kr);
+
+       if (kr == KERN_SUCCESS) {
+               return;
+       }
+
+       if (kr >= BOOTSTRAP_NOT_PRIVILEGED && kr <= BOOTSTRAP_NO_CHILDREN) {
+               err_string = bootstrap_strerror(kr);
+               snprintf(code_buff, sizeof(code_buff), "%d", kr);
+               err_type_string = "bootstrap";
+       } else {
+               err_string = mach_error_string(real_kr);
+               if (strcmp(err_string, "unknown error code") == 0) {
+                       snprintf(err_buff, sizeof(err_buff), "[%#x|%#x|%#x]",
+                                       sys, sub, code);
+                       err_string = err_buff;
+                       err_type_string = "unrecognized";
+               } else {
+                       err_type_string = "mach";
+               }
+
+               if (kr <= MIG_TYPE_ERROR && kr >= MIG_TRAILER_ERROR) {
+                       snprintf(code_buff, sizeof(code_buff), "%d", kr);
+               } else {
+                       snprintf(code_buff, sizeof(code_buff), "%#x", kr);
+                       special_desc = os_flagset_copy_string(_mach_special_bits, extra);
+               }
+       }
+
+       if (special_desc) {
+               os_crash("%s failed: %s error = %s [%s], special bits = %s",
+                               op, err_type_string, err_string, code_buff, special_desc);
+       } else {
+               os_crash("%s failed: %s error = %s [%s]",
+                               op, err_type_string, err_string, code_buff);
+       }
+}
+
+void
+os_assert_mach_port_status(const char *desc, mach_port_t p,
+               mach_port_status_t *expected)
+{
+       kern_return_t kr = KERN_FAILURE;
+       mach_port_status_t status;
+       mach_msg_type_number_t status_cnt = MACH_PORT_RECEIVE_STATUS_COUNT;
+
+       kr = mach_port_get_attributes(mach_task_self(), p, MACH_PORT_RECEIVE_STATUS,
+                       (mach_port_info_t)&status, &status_cnt);
+       os_assert_mach("get status", kr);
+
+       if (expected->mps_pset != UINT32_MAX) {
+               if (expected->mps_pset != status.mps_pset) {
+                       os_crash("port set mismatch: actual = %u, expected = %u",
+                                       status.mps_pset, expected->mps_pset);
+               }
+       }
+       if (expected->mps_seqno != UINT32_MAX) {
+               if (expected->mps_seqno != status.mps_seqno) {
+                       os_crash("sequence number mismatch: actual = %u, expected = %u",
+                                       status.mps_seqno, expected->mps_seqno);
+               }
+       }
+       if (expected->mps_mscount != UINT32_MAX) {
+               if (expected->mps_mscount != status.mps_mscount) {
+                       os_crash("make-send count mismatch: actual = %u, expected = %u",
+                                       status.mps_mscount, expected->mps_mscount);
+               }
+       }
+       if (expected->mps_qlimit != UINT32_MAX) {
+               if (expected->mps_qlimit != status.mps_qlimit) {
+                       os_crash("queue limit mismatch: actual = %u, expected = %u",
+                                       status.mps_qlimit, expected->mps_qlimit);
+               }
+       }
+       if (expected->mps_msgcount != UINT32_MAX) {
+               if (expected->mps_msgcount != status.mps_msgcount) {
+                       os_crash("message count mismatch: actual = %u, expected = %u",
+                                       status.mps_msgcount, expected->mps_msgcount);
+               }
+       }
+       if (expected->mps_sorights != UINT32_MAX) {
+               if (expected->mps_sorights != status.mps_sorights) {
+                       os_crash("send-once rights mismatch: actual = %u, expected = %u",
+                                       status.mps_sorights, expected->mps_sorights);
+               }
+       }
+       if (expected->mps_srights != INT32_MAX) {
+               if (expected->mps_srights != status.mps_srights) {
+                       os_crash("send rights mismatch: actual = %d, expected = %d",
+                                       status.mps_srights, expected->mps_srights);
+               }
+       }
+       if (expected->mps_pdrequest != INT32_MAX) {
+               if (expected->mps_pdrequest != status.mps_pdrequest) {
+                       os_crash("port-destroyed mismatch: actual = %d, expected = %d",
+                                       status.mps_pdrequest, expected->mps_pdrequest);
+               }
+       }
+       if (expected->mps_nsrequest != INT32_MAX) {
+               if (expected->mps_nsrequest != status.mps_nsrequest) {
+                       os_crash("no-senders mismatch: actual = %d, expected = %d",
+                                       status.mps_nsrequest, expected->mps_nsrequest);
+               }
+       }
+       if (expected->mps_flags) {
+               if (expected->mps_flags != status.mps_flags) {
+                       os_crash("flags mismatch: actual = %#x, expected = %#x",
+                                       status.mps_flags, expected->mps_flags);
+               }
+       }
+}
diff --git a/libdarwin/stdio.c b/libdarwin/stdio.c
new file mode 100644 (file)
index 0000000..49bfd85
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark API
+size_t
+zsnprintf_np(char *buff, size_t len, const char *fmt, ...)
+{
+       int np = 0;
+       va_list ap;
+
+       va_start(ap, fmt);
+       np = vsnprintf(buff, len, fmt, ap);
+       va_end(ap);
+
+       if (np < 0) {
+               np = 0;
+       } else if ((size_t)np >= len) {
+               np = (int)len - 1;
+       }
+
+       return (size_t)np;
+}
diff --git a/libdarwin/stdlib.c b/libdarwin/stdlib.c
new file mode 100644 (file)
index 0000000..d718a94
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark API
+void
+os_localtime_file(char buff[32])
+{
+       struct timeval tv;
+       struct tm curtime;
+
+       posix_assert_zero(gettimeofday(&tv, NULL));
+       (void)localtime_r(&tv.tv_sec, &curtime);
+
+       // Return a time representation that is ideal for use in filenames, so no
+       // spaces or things that need to be escaped.
+       snprintf(buff, 32, "%d-%02d-%02d_%02d.%02d.%02d.%06d",
+                       curtime.tm_year + 1900, curtime.tm_mon + 1, curtime.tm_mday,
+                       curtime.tm_hour, curtime.tm_min, curtime.tm_sec, tv.tv_usec);
+}
+
+// MurmurHash2 was written by Austin Appleby, and is placed in the public
+// domain. The author hereby disclaims copyright to this source code.
+uint64_t
+os_simple_hash(const void *buff, size_t len)
+{
+       const uint64_t seed = 0;
+#ifdef __LP64__
+       // MurmurHash64A
+       const uint64_t m = 0xc6a4a7935bd1e995;
+       const int r = 47;
+       uint64_t h = seed ^ (len * m);
+       const uint64_t * data = (const uint64_t *)buff;
+       const uint64_t * end = data + (len / 8);
+       while(data != end) {
+               uint64_t k = *data++;
+               k *= m;
+               k ^= k >> r;
+               k *= m;
+               h ^= k;
+               h *= m;
+       }
+       const unsigned char * data2 = (const unsigned char *)data;
+       switch(len & 7) {
+       case 7: h ^= ((uint64_t)data2[6]) << 48;
+       case 6: h ^= ((uint64_t)data2[5]) << 40;
+       case 5: h ^= ((uint64_t)data2[4]) << 32;
+       case 4: h ^= ((uint64_t)data2[3]) << 24;
+       case 3: h ^= ((uint64_t)data2[2]) << 16;
+       case 2: h ^= ((uint64_t)data2[1]) << 8;
+       case 1: h ^= ((uint64_t)data2[0]);
+                       h *= m;
+       };
+       h ^= h >> r;
+       h *= m;
+       h ^= h >> r;
+#else // __LP64__
+       // MurmurHash64B
+       const uint32_t m = 0x5bd1e995;
+       const int r = 24;
+
+       uint32_t h1 = (uint32_t)(seed) ^ len;
+       uint32_t h2 = (uint32_t)(seed >> 32);
+
+       const uint32_t * data = (const uint32_t *)buff;
+
+#define MIX(k, h) \
+       (k) *= m; (k) ^= (k) >> r; (k) *= m; (h) *= m; (h) ^= (k); len -= 4;
+
+       while(len >= 8) {
+               uint32_t k[2];
+               memcpy(k, (const char*)data, sizeof(k));
+               data += sizeof(k)/sizeof(k[0]);
+
+               MIX(k[0], h1)
+               MIX(k[1], h2)
+       }
+
+       if(len >= 4) {
+               uint32_t k[1];
+               memcpy(k, (const char *)data, sizeof(k));
+               data += sizeof(k)/sizeof(k[0]);
+
+               MIX(k[0], h1);
+       }
+
+#undef MIX
+
+       switch(len) {
+       case 3: h2 ^= ((unsigned char*)data)[2] << 16;
+       case 2: h2 ^= ((unsigned char*)data)[1] << 8;
+       case 1: h2 ^= ((unsigned char*)data)[0];
+                       h2 *= m;
+       };
+
+       h1 ^= h2 >> 18; h1 *= m;
+       h2 ^= h1 >> 22; h2 *= m;
+       h1 ^= h2 >> 17; h1 *= m;
+       h2 ^= h1 >> 19; h2 *= m;
+
+       uint64_t h = h1;
+
+       h = (h << 32) | h2;
+#endif // __LP64__
+       return h;
+}
+
+uint64_t
+os_simple_hash_string(const char *string)
+{
+       size_t len = strlen(string);
+       return os_simple_hash(string, len);
+}
diff --git a/libdarwin/string.c b/libdarwin/string.c
new file mode 100644 (file)
index 0000000..7dbf105
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#include "internal.h"
+
+#pragma mark Definitions
+#define __ENEG_ONE (-1)
+#define __ENONE 0
+#define __EBOGUS (ELAST + 1)
+
+#pragma mark Types
+OS_ENUM(errno_flags, uint32_t,
+       EDF_INIT = 0,
+       EDF_NONPOSIX = (1 << 0),
+       EDF_SYSEXIT = (1 << 1),
+);
+
+typedef struct _errno_desc {
+       int ed_error;
+       int ed_sysexit;
+       errno_flags_t ed_flags;
+       const char *ed_sym;
+       const char *ed_str;
+} errno_desc_t;
+
+#pragma mark Initializers
+#define errno_init(__err, __sysexit, __str) \
+       [__err] = { \
+               .ed_error = (__err), \
+               .ed_sysexit = (__sysexit), \
+               .ed_flags = 0, \
+               .ed_sym = #__err, \
+               .ed_str = (__str), \
+       }
+
+#define errno_init_np(__err, __sysexit, __str) \
+       [__err - EBASE_NP] = { \
+               .ed_error = (__err), \
+               .ed_sysexit = (__sysexit), \
+               .ed_flags = EDF_NONPOSIX, \
+               .ed_sym = #__err, \
+               .ed_str = (__str), \
+       }
+
+#define sysexit_init(__code, __str) \
+       [__code - EX__BASE] = { \
+               .ed_error = (__code), \
+               .ed_sysexit = (__code), \
+               .ed_flags = EDF_SYSEXIT, \
+               .ed_sym = #__code, \
+               .ed_str = (__str), \
+       }
+
+#pragma mark Top-Level Statics
+static const errno_desc_t _negative_one = {
+       .ed_error = __ENEG_ONE,
+       .ed_sysexit = EXIT_FAILURE,
+       .ed_flags = 0,
+       .ed_sym = "-1",
+       .ed_str = "[return code instead of error]",
+};
+
+static const errno_desc_t _badreceipt = {
+       .ed_error = EX_BADRECEIPT_NP,
+       .ed_sysexit = EX_BADRECEIPT_NP,
+       .ed_flags = EDF_SYSEXIT,
+       .ed_sym = "EX_BADRECEIPT_NP",
+       .ed_str = "bad purchase receipt",
+};
+
+static const errno_desc_t _posix_errors[] = {
+       errno_init(__ENONE, EX_OK, "[no error]"),
+       errno_init(EPERM, EX_NOPERM, "Operation not permitted"),
+       errno_init(ENOENT, EX_NOINPUT, "No such file or directory"),
+       errno_init(ESRCH, EX_IOERR, "No such process"),
+       errno_init(EINTR, EX_OSERR, "Interrupted system call"),
+       errno_init(EIO, EX_IOERR, "Input/output error"),
+       errno_init(ENXIO, EX_NOINPUT, "Device not configured"),
+       errno_init(E2BIG, EX_IOERR, "Argument list too long"),
+       errno_init(ENOEXEC, EX_DATAERR, "Exec format error"),
+       errno_init(EBADF, EX_OSERR, "Bad file descriptor"),
+       errno_init(ECHILD, EX_IOERR, "No child processes"),
+       errno_init(EDEADLK, EX_UNAVAILABLE, "Resource deadlock avoided"),
+       errno_init(ENOMEM, EX_TEMPFAIL, "Cannot allocate memory"),
+       errno_init(EACCES, EX_NOINPUT, "Permission denied"),
+       errno_init(EFAULT, EX_OSERR, "Bad address"),
+#if defined(ENOTBLK)
+       errno_init(ENOTBLK, EX_IOERR, "Block device required"),
+#endif
+       errno_init(EBUSY, EX_TEMPFAIL, "Device / Resource busy"),
+       errno_init(EEXIST, EX_CANTCREAT, "File exists"),
+       errno_init(EXDEV, EX_UNAVAILABLE, "Cross-device link"),
+       errno_init(ENODEV, EX_IOERR, "Operation not supported by device"),
+       errno_init(ENOTDIR, EX_DATAERR, "Not a directory"),
+       errno_init(EISDIR, EX_DATAERR, "Is a directory"),
+       errno_init(EINVAL, EX_NOINPUT, "Invalid argument"),
+       errno_init(ENFILE, EX_OSERR, "Too many open files in system"),
+       errno_init(EMFILE, EX_OSERR, "Too many open files"),
+       errno_init(ENOTTY, EX_PROTOCOL, "Inappropriate ioctl for device"),
+       errno_init(ETXTBSY, EX_TEMPFAIL, "Text file busy"),
+       errno_init(EFBIG, EX_NOINPUT, "File too large"),
+       errno_init(ENOSPC, EX_CANTCREAT, "No space left on device"),
+       errno_init(ESPIPE, EX_IOERR, "Illegal seek"),
+       errno_init(EROFS, EX_NOPERM, "Read-only file system"),
+       errno_init(EMLINK, EX_OSERR, "Too many links"),
+       errno_init(EPIPE, EX_IOERR, "Broken pipe"),
+       errno_init(EDOM, EX_DATAERR, "Numerical argument out of domain"),
+       errno_init(ERANGE, EX_DATAERR, "Result too large"),
+       errno_init(EAGAIN, EX_TEMPFAIL, "Resource temporarily unavailable"),
+       errno_init(EINPROGRESS, EX_TEMPFAIL, "Operation now in progress"),
+       errno_init(EALREADY, EX_TEMPFAIL, "Operation already in progress"),
+       errno_init(ENOTSOCK, EX_PROTOCOL, "Socket operation on non-socket"),
+       errno_init(EDESTADDRREQ, EX_PROTOCOL, "Destination address required"),
+       errno_init(EMSGSIZE, EX_PROTOCOL, "Message too long"),
+       errno_init(EPROTOTYPE, EX_PROTOCOL, "Protocol wrong type for socket"),
+       errno_init(ENOPROTOOPT, EX_PROTOCOL, "Protocol not available"),
+       errno_init(EPROTONOSUPPORT, EX_PROTOCOL, "Protocol not supported"),
+#if defined(ESOCKTNOSUPPORT)
+       errno_init(ESOCKTNOSUPPORT, EX_PROTOCOL, "Socket type not supported"),
+#endif
+       errno_init(ENOTSUP, EX_UNAVAILABLE, "Operation not supported"),
+#if defined(EPFNOSUPPORT)
+       errno_init(EPFNOSUPPORT, EX_PROTOCOL, "Protocol family not supported"),
+#endif
+       errno_init(EAFNOSUPPORT, EX_PROTOCOL,
+               "Address family not supported by protocol family"
+       ),
+       errno_init(EADDRINUSE, EX_PROTOCOL, "Address already in use"),
+       errno_init(EADDRNOTAVAIL, EX_OSERR, "Can't assign requested address"),
+       errno_init(ENETDOWN, EX_NOHOST, "Network is down"),
+       errno_init(ENETUNREACH, EX_NOHOST, "Network is unreachable"),
+       errno_init(ENETRESET, EX_NOHOST, "Network dropped connection on reset"),
+       errno_init(ECONNABORTED, EX_OSERR, "Software caused connection abort"),
+       errno_init(ECONNRESET, EX_PROTOCOL, "Connection reset by peer"),
+       errno_init(ENOBUFS, EX_TEMPFAIL, "No buffer space available"),
+       errno_init(EISCONN, EX_PROTOCOL, "Socket is already connected"),
+       errno_init(ENOTCONN, EX_PROTOCOL, "Socket is not connected"),
+#if defined(ESHUTDOWN)
+       errno_init(ESHUTDOWN, EX_PROTOCOL, "Can't send after socket shutdown"),
+       errno_init(ETOOMANYREFS, EX_PROTOCOL, "Too many references: can't splice"),
+#endif
+       errno_init(ETIMEDOUT, EX_TEMPFAIL, "Operation timed out"),
+       errno_init(ECONNREFUSED, EX_PROTOCOL, "Connection refused"),
+       errno_init(ELOOP, EX_DATAERR, "Too many levels of symbolic links"),
+       errno_init(ENAMETOOLONG, EX_DATAERR, "File name too long"),
+#if defined(EHOSTDOWN)
+       errno_init(EHOSTDOWN, EX_NOHOST, "Host is down"),
+#endif
+       errno_init(EHOSTUNREACH, EX_NOHOST, "No route to host"),
+       errno_init(ENOTEMPTY, EX_DATAERR, "Directory not empty"),
+#if defined(EPROCLIM)
+       errno_init(EPROCLIM, EX_TEMPFAIL, "Too many processes"),
+       errno_init(EUSERS, EX_NOUSER, "Too many users"),
+#endif
+       errno_init(EDQUOT, EX_CANTCREAT, "Disc quota exceeded"),
+       errno_init(ESTALE, EX_NOINPUT, "Stale NFS file handle"),
+#if defined(EREMOTE)
+       errno_init(EREMOTE, EX_DATAERR, "Too many levels of remote in path"),
+       errno_init(EBADRPC, EX_PROTOCOL, "RPC struct is bad"),
+       errno_init(ERPCMISMATCH, EX_PROTOCOL, "RPC version wrong"),
+       errno_init(EPROGUNAVAIL, EX_PROTOCOL, "RPC prog. not avail"),
+       errno_init(EPROGMISMATCH, EX_PROTOCOL, "Program version wrong"),
+       errno_init(EPROCUNAVAIL, EX_PROTOCOL, "Bad procedure for program"),
+#endif
+       errno_init(ENOLCK, EX_OSERR, "No locks available"),
+       errno_init(ENOSYS, EX_UNAVAILABLE, "Function not implemented"),
+#if defined(EFTYPE)
+       errno_init(EFTYPE, EX_DATAERR, "Inappropriate file type or format"),
+       errno_init(EAUTH, EX_NOPERM, "Authentication error"),
+       errno_init(ENEEDAUTH, EX_NOPERM, "Need authenticator"),
+       errno_init(EPWROFF, EX_UNAVAILABLE, "Device power is off"),
+       errno_init(EDEVERR, EX_UNAVAILABLE, "Device error, e.g. paper out"),
+#endif
+       errno_init(EOVERFLOW, EX_DATAERR,
+               "Value too large to be stored in data type"
+       ),
+#if defined(EBADEXEC)
+       errno_init(EBADEXEC, EX_DATAERR, "Bad executable"),
+       errno_init(EBADARCH, EX_DATAERR, "Bad CPU type in executable"),
+       errno_init(ESHLIBVERS, EX_DATAERR, "Shared library version mismatch"),
+       errno_init(EBADMACHO, EX_DATAERR, "Malformed Macho file"),
+#endif
+       errno_init(ECANCELED, EX_UNAVAILABLE, "Operation canceled"),
+       errno_init(EIDRM, EX_UNAVAILABLE, "Identifier removed"),
+       errno_init(ENOMSG, EX_UNAVAILABLE, "No message of desired type"),
+       errno_init(EILSEQ, EX_DATAERR, "Illegal byte sequence"),
+#if defined(ENOATTR)
+       errno_init(ENOATTR, EX_UNAVAILABLE, "Attribute not found"),
+#endif
+       errno_init(EBADMSG, EX_PROTOCOL, "Bad message"),
+       errno_init(EMULTIHOP, EX_UNAVAILABLE, "Reserved"),
+       errno_init(ENODATA, EX_NOINPUT, "No message available on STREAM"),
+       errno_init(ENOLINK, EX_UNAVAILABLE, "Reserved"),
+       errno_init(ENOSR, EX_TEMPFAIL, "No STREAM resources"),
+       errno_init(ENOSTR, EX_PROTOCOL, "Not a STREAM"),
+       errno_init(EPROTO, EX_PROTOCOL, "Protocol error"),
+       errno_init(ETIME, EX_TEMPFAIL, "STREAM ioctl timeout"),
+#if defined(EOPNOTSUPP)
+       errno_init(EOPNOTSUPP, EX_PROTOCOL, "Operation not supported on socket"),
+#endif
+       errno_init(ENOPOLICY, EX_UNAVAILABLE, "No such policy registered"),
+#if defined(ENOTRECOVERABLE)
+       errno_init(ENOTRECOVERABLE, EX_CONFIG, "State not recoverable"),
+       errno_init(EOWNERDEAD, EX_NOHOST, "Previous owner died"),
+#endif
+#if defined(EQFULL)
+       errno_init(EQFULL, EX_CANTCREAT, "Interface output queue is full"),
+#endif
+       errno_init(__EBOGUS, EX_UNAVAILABLE, "[invalid]"),
+};
+
+static const errno_desc_t _darwin_errors[] = {
+       errno_init_np(ENOTENTITLED_NP, EX_NOPERM, "Requestor not entitled"),
+       errno_init_np(ENOTPLATFORM_NP, EX_NOPERM, "Requestor not platform binary"),
+       errno_init_np(EROOTLESS_NP, EX_NOPERM,
+               "Operation disallowed by System Integrity Protection"
+       ),
+       errno_init_np(ETAINTED_NP, EX_NOPERM,
+               "Requestor is tainted and untrusthworthy"
+       ),
+       errno_init_np(EQUARANTINE_NP, EX_NOPERM,
+               "Operation not permitted on quarantined file"
+       ),
+       errno_init_np(EBADUSER_NP, EX_NOINPUT, "Invalid username or identifier"),
+       errno_init_np(EBADGROUP_NP, EX_NOINPUT, "Invalid group name or identifier"),
+       errno_init_np(EOWNERSHIP_NP, EX_NOINPUT,
+               "Ownership and/or permissions insufficiently restrictive"
+       ),
+       errno_init_np(ENOOOO_NP, EX_PROTOCOL, "Out-of-order operation rejected"),
+       errno_init_np(ENOTBUNDLE_NP, EX_NOINPUT, "Entity not a bundle"),
+       errno_init_np(EBADBUNDLE_NP, EX_DATAERR, "Malformed bundle"),
+       errno_init_np(EBADPATH_NP, EX_DATAERR, "Malformed path"),
+       errno_init_np(EBADPLIST_NP, EX_DATAERR, "Malformed property list"),
+       errno_init_np(EBADKEY_NP, EX_DATAERR, "Unrecognized key"),
+       errno_init_np(EBADVAL_NP, EX_DATAERR, "Invalid or missing value for key"),
+       errno_init_np(EBADSUBSYS_NP, EX_DATAERR,
+               "Routine referenced an invalid subsystem"
+       ),
+       errno_init_np(E2BIMPL_NP, EX_UNAVAILABLE, "Routine not yet implemented"),
+       errno_init_np(EDEPRECATED_NP, EX_UNAVAILABLE, "Routine deprecated"),
+       errno_init_np(EREMOVED_NP, EX_UNAVAILABLE, "Routine removed"),
+       errno_init_np(EDROPPED_NP, EX_PROTOCOL, "Routine invocation dropped"),
+       errno_init_np(EDEFERRED_NP, EX_TEMPFAIL, "Routine invocation deferred"),
+       errno_init_np(EUSAGE_NP, EX_USAGE, "Bad command line usage"),
+       errno_init_np(EUNKNOWN_NP, EX_UNAVAILABLE,
+               "Unknown error from another subsystem"
+       ),
+};
+
+static const errno_desc_t _sysexits[] = {
+       sysexit_init(EX_USAGE, "command line usage error"),
+       sysexit_init(EX_DATAERR, "data format error"),
+       sysexit_init(EX_NOINPUT, "cannot open input"),
+       sysexit_init(EX_NOUSER, "addressee unknown"),
+       sysexit_init(EX_NOHOST, "host name unknown"),
+       sysexit_init(EX_UNAVAILABLE, "service unavailable"),
+       sysexit_init(EX_SOFTWARE, "internal software error"),
+       sysexit_init(EX_OSERR, "system error (e.g., can't fork)"),
+       sysexit_init(EX_OSFILE, "critical OS file missing"),
+       sysexit_init(EX_CANTCREAT, "can't create (user) output file"),
+       sysexit_init(EX_IOERR, "input/output error"),
+       sysexit_init(EX_TEMPFAIL, "temp failure"),
+       sysexit_init(EX_PROTOCOL, "remote error in protocol"),
+       sysexit_init(EX_NOPERM, "permission denied"),
+       sysexit_init(EX_CONFIG, "configuration error"),
+};
+
+#pragma mark Utilities
+static const errno_desc_t *
+_find_error(int code)
+{
+       if (code < 0) {
+               return &_negative_one;
+       }
+
+       if (code >= EBASE_NP && code <= __ELAST_NP) {
+               return &_darwin_errors[code - EBASE_NP];
+       }
+
+       if (code >= 0 && code <= ELAST) {
+               return &_posix_errors[code];
+       }
+
+       return &_posix_errors[__EBOGUS];
+}
+
+static const errno_desc_t *
+_find_sysexit(int code)
+{
+       if (code == EX_BADRECEIPT_NP) {
+               return &_badreceipt;
+       }
+
+       if (code < EX__BASE || code > EX__MAX) {
+               return &_sysexits[EX_UNAVAILABLE - EX__BASE];
+       }
+
+       return &_sysexits[code - EX__BASE];
+}
+
+static void
+_writeflag(const char *humanflag, const char *sep, char *buff, size_t len,
+               char **track_buff, size_t *track_sz)
+{
+       size_t offs = 0;
+
+       if (*track_buff != buff) {
+               offs = zsnprintf_np(*track_buff, *track_sz, "%s", sep);
+               *track_buff += offs;
+               *track_sz -= offs;
+       }
+
+       offs = zsnprintf_np(*track_buff, *track_sz, "%s", humanflag);
+       *track_buff += offs;
+       *track_sz -= offs;
+}
+
+#pragma mark API
+int
+sysexit_np(int code)
+{
+       const errno_desc_t *de = _find_error(code);
+       return de->ed_sysexit;
+}
+
+const char *
+strerror_np(int code)
+{
+       if (code >= 0 && code <= ELAST) {
+               return strerror(code);
+       }
+
+       return _find_error(code)->ed_str;
+}
+
+const char *
+symerror_np(int code)
+{
+       const errno_desc_t *de = _find_error(code);;
+       return de->ed_sym;
+}
+
+const char *
+symexit_np(int code)
+{
+       const errno_desc_t *de = _find_sysexit(code);
+       return de->ed_sym;
+}
+
+char *
+os_flagset_copy_string(const os_flagset_t flagset, uint64_t flags)
+{
+       size_t i = 0;
+       const os_flag_t *fi = NULL;
+       char buff[1024] = "[none]";
+       char *cursor = buff;
+       size_t left = sizeof(buff);
+
+       while (i < OS_FLAGSET_COUNT && (fi = &flagset[i]) && fi->ohf_flag) {
+               if (flags & fi->ohf_flag) {
+                       _writeflag(fi->ohf_human_flag, "|", buff, sizeof(buff),
+                                       &cursor, &left);
+               }
+               i++;
+       }
+
+       return os_strdup(buff);
+}
+
index 927ac2885b5d4e63017039fe5c566326968517ce..f08b7875efe55e85a66d22ef53d5fbe461d8b9e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2016 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -327,9 +327,8 @@ static bool _check_internal_release_type(void)
 
 #else
 
-static bool _check_internal_diags_profile() {
-       static enum check_status internal_diags_profile = S_UNKNOWN;
-
+static bool _check_internal_diags_profile(void)
+{
        if (internal_diags_profile == S_UNKNOWN) {
                xpc_object_t profile_settings = read_plist(INTERNAL_DIAGS_PROFILE_PATH);
                if (profile_settings) {
index 59637617398c7cf6a623c19fe0c258e05f910aec..4264eb6dc624d83231d733759f194fb71342279f 100644 (file)
@@ -34,6 +34,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #ifndef RUNEOFF32
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)rune.c     8.1 (Berkeley) 6/4/93";
@@ -363,3 +366,4 @@ _Read_RuneMagi(fp)
        return (data);
 }
 #endif /* !RUNEOFF32 */
+#pragma clang diagnostic pop
index ba9feb2e51d4a4074e66de0029a52e66823c0e15..94f8ecc526931317dfe73e0b8567823247c40332 100644 (file)
@@ -32,6 +32,7 @@
 #include <locale.h>
 #include <libkern/OSAtomic.h>
 #include <pthread.h>
+#include <pthread/tsd_private.h>
 #include <limits.h>
 #include <os/lock.h>
 #include "setlocale.h"
@@ -211,9 +212,13 @@ __current_locale(void)
                return &__global_locale;
        }
 #endif
-
-       locale_t __locale = (locale_t)pthread_getspecific(__locale_key);
-       return (__locale ? __locale : &__global_locale);
+       void *__thread_locale;
+       if (_pthread_has_direct_tsd()) {
+               __thread_locale = _pthread_getspecific_direct(__locale_key);
+       } else {
+               __thread_locale = pthread_getspecific(__locale_key);
+       }
+       return (__thread_locale ? (locale_t)__thread_locale : &__global_locale);
 }
 
 static inline __attribute__((always_inline)) locale_t
index c4244a907fe078473ff1d04af6f54f08e32c961e..56b88c6020be25479f42bb5afa9d1bb577dc19fe 100644 (file)
@@ -56,7 +56,7 @@ atexit.3 atexit.3 atexit_b.3
 atof.3 atof.3 atof_l.3
 atoi.3 atoi.3 atoi_l.3
 atol.3 atol.3 atol_l.3 atoll.3 atoll_l.3
-backtrace.3 backtrace.3 backtrace_symbols.3 backtrace_symbols_fd.3
+backtrace.3 backtrace.3 backtrace_symbols.3 backtrace_symbols_fd.3 backtrace_from_fp.3 backtrace_image_offsets.3
 basename.3 basename.3 basename_r.3
 bcmp.3 bcmp.3
 bcopy.3 bcopy.3
@@ -287,6 +287,7 @@ strtol.3 strtol.3 strtoll.3 strtoq.3 strtoimax.3
 strtol_l.3 strtol_l.3 strtoimax_l.3 strtoll_l.3 strtoq_l.3 strtoul_l.3 strtoull_l.3 strtoumax_l.3 strtouq_l.3
 strtoul.3 strtoul.3 strtoull.3 strtoumax.3 strtouq.3
 strxfrm.3 strxfrm.3 strxfrm_l.3
+style.3 style.3
 swab.3 swab.3
 sync_volume_np.3 sync_volume_np.3 fsync_volume_np.3
 sysconf.3 sysconf.3
diff --git a/man/style.3 b/man/style.3
new file mode 100644 (file)
index 0000000..1be83b9
--- /dev/null
@@ -0,0 +1,1482 @@
+.\" Copyright (c) 2017 Apple Inc. All rights reserved.
+.Dd 12 January, 2018
+.Dt style 3
+.Os Darwin
+.Sh NAME
+.Nm style
+.Nd C language style guide for Darwin low-level userspace projects
+.Sh DESCRIPTION
+This style's primary objective is to be as friendly to the code review process
+as possible. Therefore, the style aims to ensure that code changes to the
+project produce diffs that are
+.Pp
+.Bl -bullet -compact -offset indent
+.It
+small
+.It
+unambiguous
+.It
+viewable in side-by-side comparison tools
+.El
+.Pp
+As a secondary objective, this style also aims to make code as clear as possible
+for an uninitiated programmer reading it. "Clever" syntactic shortcuts are
+actively discouraged in favor of code that is easy to understand, even if it is
+less concise. Coincidentally, this practice also tends to lend itself to
+generating more readable diffs.
+.Pp
+Like any style, consistent adherence across a project is a virtue in and of
+itself, resulting in less distraction for the reader. However, these guidelines
+should be taken as exactly that: guidelines. No style can be completely adhered
+to all the time. When you have convinced yourself that a deviation from the
+style is called for, just make sure it is for the greater good and maintains the
+style's aims of minimizing diffs and code complexity.
+.Sh GENERAL PRINCIPLES
+.Ss Vertical space is a commodity
+Scrolling vertically has always been easier than scrolling horizontally.
+Computer mouse manufacturers went so far as to dedicate hardware to the task of
+scrolling vertically when they came up with scroll wheels. Even on modern
+trackpads, while it is possible to scroll horizontally, it is far easier to
+scroll vertically. You just flick upwards. Do not be afraid to introduce extra
+lines of code if it will result in clearer, more human-parseable diffs when
+those lines are changed.
+.Ss Horizontal space is precious
+Scrolling horizontally is typically awkward, imprecise, and does not lend itself
+well toward reading on computers or even in print. (Academic journals frequently
+publish with two narrow columns per page to make reading easier, for example.)
+Lines should be wrapped consciously; this should not be left to the editor. A
+soft-wrapping scheme that looks good in your editor may not look good in someone
+else's editor (or with a different configuration for the same editor).
+.Pp
+Just as natural language comments are difficult to read in one, long line,
+so too are lines of code. Both natural languages and programming languages
+deserve conscious, deliberate wrapping to improve readability.
+.Pp
+Wrap at a column width narrow enough to accommodate side-by-side patch
+review. 80 is more likely to accommodate this, but 120 might be fine too. Pick a
+reasonable column width and stick to it. Think about the lines you are wrapping.
+If you have to wrap a line, do so in a way that is clear, and be willing to make
+changes to accommodate that (e.g. don't be afraid to declare a variable
+separately if having the declaration and assignment on the same line causes it
+to wrap in an unclear way).
+.Ss Indentation is for scope indication and nothing else
+Indentation's sole purpose is to indicate scope. You should not use indentation
+to align characters on two lines of source code (beyond, of course, aligning
+the first characters of each line if they are both in the same scope).
+.Pp
+Given this aspect of the style, it does not particularly matter whether the
+author chooses spaces or tabs for indentation, and therefore the style makes no
+prescription (other than to pick one and stick with it).
+.Pp
+This style also has another implication: tabs and spaces should never appear
+in sequence. Each line will be a series of tabs followed by the first character
+of code. Tabs will never appear after the initial indentation of the line.
+.Ss Don't require leaving the source to understand it
+Always think of future maintainers and document your thought process for them.
+Remember, a "future maintainer" might be you after you've forgotten why you did
+something. For non-trivial changes, you should not rely on linking to a
+ticket-tracking system to provide context and explanation for a piece of code.
+You should strive to ensure the reader of your code does not have to
+context-switch out of reading it in order to understand it.
+.Pp
+This is not to say that linking to external resources in code is bad, but
+if a change's purpose can be reasonably expressed without interrupting how the
+code reads and flows, just do it. You don't need to publish a whitepaper in
+comments, but don't just give a link or ticket number with no context.
+.Ss Each line of code should minimize entropy
+It is actually very difficult to construct a hash comparison scheme that humans
+can use without error consistently, and there have been successful social
+engineering attacks on getting humans to read two hashes that are "close enough"
+as identical. This means that humans need a lot of help telling the difference
+between two lines of text.
+.Pp
+For any expression, divide it up into fundamental atoms (variable declarations,
+conditionals, etc.) and then assign each of those atoms to its own line of code.
+If you do this, when you change a single atom, it is immediately obvious that
+.Em only
+that atom changed and nothing else did. The more atoms share lines of code, the
+more likely it is that changes to them will generate complex diffs that humans
+will have difficulty understanding.
+.Ss Don't assume a specific editor
+Assume people will be reading your code in a tool that you do not control and
+cannot influence. Try viewing your code in such a tool and make sure that it is
+understandable. If you follow the guidelines of this style, your code may appear
+different in another viewer (in terms of how many columns are required to
+display a single line), but its structure will appear identical.
+.Sh SPECIFIC GUIDELINES
+.Ss Column Width and Line Wrap
+80 columns opens the door for a three-way, side-by-side comparison, but it could
+be impractical for a number of reasons. 120 columns should provide a nice
+balance, but really all that matters is that you pick a width and stick to it.
+.Pp
+When indenting a continuation line, indent over by two additional tabs. This
+visually separates the indented line from the next line, which may itself be
+indented. If there is an operator in the middle of the line, the operator should
+.Em not
+be wrapped to the continuation line.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+if (some_condition && some_other_condition &&
+        yet_another_condition) {
+    exit(0);
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if (some_condition && some_other_condition &&
+    yet_another_condition) {
+    exit(0);
+}
+
+if (some_condition && some_other_condition
+    && yet_another_condition) {
+    exit(0);
+}
+.Ed
+.Pp
+Notice on the good example that the
+.Ic exit(0)
+line is made obviously distinct from the indented conditions above it. It's very
+clear on quick visual inspection that it's not a part of the conditional checks.
+The
+.Ic &&
+is left on the first line because, when reviewing a patch to this area, it will
+be immediately clear to the reviewer that that line continues to the next one.
+.Pp
+.Ss Avoid prettifying alignment
+Indentation is used only for indicating scope, so no consideration is given to
+visual alignment of equal signs, colons, etc. across multiple lines.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+typedef enum {
+    THING0 = 0,
+    THING1 = 1,
+    THING_THAT_IS_REALLY_LONG = 2,
+} thing_t;
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+enum {
+    THING0                    = 0,
+    THING1                    = 1,
+    THING_THAT_IS_REALLY_LONG = 2,
+};
+.Ed
+.Pp
+This creates bloated diffs. If you have to re-align a ton of lines after you've
+added something longer, you get a bunch of whitespace diffs. So for variable
+declarations, enumerations, assignments, etc. just keep every line independent.
+.Pp
+There is one exception to this rule, and that is if you choose to define a
+flagset in terms of its raw hexadecimal values and wish to align them. In this
+case, it is a significant benefit to have these values aligned, and you may do
+so with spaces.
+.Pp
+.Em Example
+.Bd -literal -offset indent
+typedef enum {
+       F_INIT   = 0x00,
+       F_FOO    = 0x01,
+       F_BARBAZ = 0x02,
+       F_CAD    = 0x04,
+       F_FAD    = 0x08,
+       F_FUD    = 0x10,
+       F_FLAME  = 0x20,
+       F_FOOD   = 0x40,
+} flag_t;
+.Ed
+.Ss Only one blank line at a time
+Use blank lines to separate logical chunks of code. Do not use more than one.
+.Ss Initialization
+C99 has named initializers for structures. Prefer those to initializing members
+one-by-one later on. Both structures and arrays should be initialized in the
+same style, with each element of the initializer being on its own line. This is
+so that when an element is added to or removed from the initialization list,
+that change gets its own line of diff.
+.Pp
+The exception to this is the string literal.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+struct my_struct baz = {
+    .ms_foo = 1,
+    .ms_bar = NULL,
+};
+
+char *strings[] = {
+    "string",
+    "other string",
+};
+.Ed
+.Em Bad
+.Bd -literal -offset indent
+struct my_struct baz = { 1, NULL };
+
+struct my_struct baz = {
+    1,
+    NULL
+};
+
+struct my_struct baz = { .ms_foo = 1, .ms_bar = NULL, };
+.Ed
+.Pp
+The last element of an initializer list should be followed by a comma. This is
+so that when you add a new element to that list, it's a one-line diff rather
+rather than a two-line diff (one line of diff to add the
+.Ic ,
+to the previous-last element, and another line of diff to add the new-last
+element).
+.Pp
+.Em Good
+.Bd -literal -offset indent
+enum {
+    THING0,
+    THING1,
+};
+
+struct my_point p = {
+    .x = 1,
+    .y = 0,
+    .z = 1,
+};
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+enum {
+    THING0, THING1,
+};
+
+enum {
+    THING0,
+    THING1
+};
+
+struct my_point p = { .x = 1, .y = 0, .z = 1 };
+.Ed
+.Pp
+Note that, if your project requires ANSI C compliance, you should disregard this
+guideline, as it will not work under C89.
+.Ss Avoid function name overloading
+The
+.Xr clang 1
+compiler supports extensions to the C language which allow for function name
+overloading. Name overloading generally leads to code which is difficult to
+read and introspect and should be avoided.
+.Ss Prefix `struct` members
+Any
+.Ic struct
+which is shared or exported should have a common prefix for each member. This
+helps avoid collisions with preprocessor macros.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+struct foobar {
+       int64_t fb_baz;
+       char *fb_string;
+};
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+struct foobar {
+       int64_t baz;
+       char *string;
+};
+.Ed
+.Pp
+.Ss Types end with `_t`
+A type is indicated with
+.Ic _t
+at the end of the
+.Ic typedef ,
+whether the type refers to a
+.Ic struct ,
+.Ic union ,
+.Ic enum ,
+etc. All types are indicated this way. Types are in all lower-case letters.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+typedef uint64_t handle_t;
+typedef enum foo foo_t;
+typedef union bar bar_t;
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+typedef uint64_t Handle;
+typedef enum foo foo_e;
+typedef union bar bar_u;
+.Ed
+.Ss Use explicitly-sized integer types
+Avoid integer types whose names do not indicate size, such as
+.Ic int
+or
+.Ic long .
+Instead, use the types from
+.Ic stdint.h
+(e.g.
+.Ic int64_t ,
+.Ic uint32_t ,
+etc.), which explicitly indicate size. You may use size-ambiguous integer types
+if an API requires it.
+.Ss Use `sizeof()` on variables rather than types where appropriate
+The
+.Ic sizeof()
+operator can take both types and variables as arguments. Where possible and
+relevant, always pass a variable. This ensures that if the variable's type
+changes, the proper size is used automatically.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+uuid_t ident;
+memcpy(ident, buff, sizeof(ident));
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+uuid_t ident;
+memcpy(ident, buff, sizeof(uuid_t));
+.Ed
+.Pp
+.Em IMPORTANT :
+When applied to a
+.Ic char * ,
+.Ic sizeof()
+will return the width of a pointer,
+.Em not
+the size of the string literal it points to, so take care to only use
+.Xr strlen 3
+for such cases.
+.Pp
+Relatedly, when applied to an array variable that is a parameter in a function's
+parameter list,
+.Ic sizeof()
+will return the width of a pointer,
+.Em not
+the size of the type.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+char *string = "the quick brown fox";
+size_t len = strlen(string);
+
+void
+foo(uuid_t u)
+{
+       uuid_t u2;
+       memcpy(u2, u, sizeof(uuid_t));
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+char *string = "the quick brown fox";
+size_t len = sizeof(string) - 1;
+
+void
+foo(uuid_t u)
+{
+       uuid_t u2;
+
+       // sizeof(u) == sizeof(void *) in this context.
+       memcpy(u2, u, sizeof(u));
+}
+.Ed
+.Ss Functions which take no parameters have a parameter list of `void`
+In C, an empty function parameter list means that
+.Em any
+set of parameters is acceptable. In virtually all cases where you do this, you
+mean to have a parameter list of
+.Ic void .
+.Pp
+.Em Good
+.Bd -literal -offset indent
+void
+foo(void)
+{
+    do_a_thing_without_arguments();
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+void
+foo()
+{
+    do_a_thing_without_arguments();
+}
+.Ed
+.Ss Preprocessor macros
+Preprocessor definitions are written in all-caps. Macros which are function-like
+may be lower-case provided they do not double-evaluate their arguments.
+Function-like macros that do double-evaluate their arguments should be in
+all-caps.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+#define FOO 1
+#define halt() abort()
+
+// Does not double-evaluate _a and _b such that max(i++, j) is safe.
+#define max(_a, _b) ({ \\
+    typeof(_a) a1 = (_a); \\
+    typeof(_b) b1 = (_b); \\
+    (a1 < b1 ? b1 : a1); \\
+})
+
+// Double-evaluates _a and _b, so MAX(i++, j) is not safe.
+#define MAX(_a, _b) ((_a) < (_b) ? (_b) : (_a))
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+#define kFoo 1
+
+// Double-evaluates _a and _b.
+#define max(_a, _b) ((_a) < (_b) ? (_b) : (_a))
+.Ed
+.Pp
+Where possible, you should prefer inline functions to preprocessor macros, or
+split a macro into a preprocessor piece and an inline function piece.
+.Pp
+.Em Example
+.Bd -literal -offset indent
+static inline void
+_debug_uint64_impl(const char *name, uint64_t val)
+{
+    fprintf(stderr, "%s = %llu\\n", name, val);
+}
+
+#define debug_uint64(_v) do { \\
+       _debug_uint64_impl(#_v, _v); \\
+} while (0)
+.Ed
+.Pp
+In this example, the preprocessor is used to do something that only the
+preprocessor can do: stringify the input variable's name. But once that work is
+done, the actual logging of the value is done by an inline function. This keeps
+the code much more readable.
+.Ss Preprocessor macro parameters should be distinguished
+Preprocessor macro expansion can run afoul of naming collisions with other
+variables that are in the same scope as the macro being expanded. To help avoid
+such collisions, parameters to preprocessor macros should have a prefix, suffix
+or both. Another good option is to use a
+.Ic _[A-Z]
+prefix, since it is reserved by the C standard and will not collide with
+preprocessor evaluation.
+.Pp
+.Em Example
+.Bd -literal -offset indent
+#define foo2(_x_) ((_x_) * 2)
+#define foo4(_x) ((_x) * 4)
+#define foo8(_X) ((_X) * 8)
+.Ed
+.Ss Preprocessor macro parameters should always be evaluated
+When passing a parameter to a preprocessor macro, it should always be referred
+to within parentheses to force evaluation. The exception is for parameters
+intended to be string literals.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+#define add2(__x) ((__x) + 2)
+#define println(__fmt, ...) printf(__fmt "\\n", ## __VA_ARGS__)
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+#define add2(__x) x + 2
+.Ed
+.Ss Preprocessor directives always start at column 0
+Preprocessor directives do not have scope, and therefore they always start at
+column zero.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+if (do_loop) {
+       for (i = 0; i < 10; i++) {
+#if CONFIG_FOOBAR
+               foobar(i);
+#else
+               foobaz(i);
+#endif
+       }
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if (do_loop) {
+       for (i = 0; i < 10; i++) {
+       #if CONFIG_FOOBAR
+               foobar(i);
+       #else
+               foobaz(i);
+       #endif
+       }
+}
+.Ed
+.Ss Always reference string length directly
+Do not hard-code the size of a string. Use either
+.Ic sizeof(str) - 1
+or
+.Ic strlen(str) .
+In the latter case,
+.Xr clang 1
+is smart enough to recognize when a constant string is being passed to
+.Xr strlen(3)
+and replace the function call with the string's actual length.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+char str[] = "string";
+frob_string(str, sizeof(str) - 1);
+frob_string(str, strlen(str));
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+char str[] = "string";
+frob_string(str, 6);
+.Ed
+.Ss Don't pointlessly validate inputs
+If you control all call sites for a function, then there is no point to
+validating the inputs to that function. If none of your call sites pass
+.Ic NULL ,
+to a pointer parameter, for example, then the a
+.Ic NULL
+input indicates that there is state corruption in your address space. You may
+think that it's good to catch such corruption, but
+.Ic NULL
+is just
+.Em one
+possible invalid pointer value. What if the invalid input is
+.Ic 0x1 ?
+What if it is
+.Ic 0x2 ?
+Should you also check for those?
+.Pp
+This kind of input checking complicates code. Because it indicates state
+corruption, the only sensible thing to do in that situation would be to abort.
+But the operating system has mechanisms in place to detect the reference of an
+invalid resource, such as virtual memory and use-after-free detection. There is
+no point to you duplicating these mechanisms.
+.Pp
+Of course, you should always validate inputs
+.Em when they come from untrusted external sources
+(such as a file or IPC message), but if the inputs only ever comes from your
+program, you should trust them.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+static foo_t *
+get_item(foo_t *arr, size_t idx)
+{
+       return &arr[idx];
+}
+
+int
+only_call_site(foo_t *f)
+{
+       foo_t *arr = calloc(10, sizeof(arr[0]));
+       if (!arr) {
+               return errno;
+       }
+
+       *f = get_item(arr, 0);
+       return 0;
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+static foo_t *
+get_item(foo_t *arr, size_t idx)
+{
+       if (!arr) {
+               // No point to this check since we'll abort immediately below when we
+               // try to dereference `arr`. The crash report will have more than enough
+               // information to diagnose the NULL pointer dereference if it ever
+               // happens.
+               abort();
+       }
+       return &arr[idx];
+}
+
+int
+only_call_site(foo_t *f)
+{
+       foo_t *arr = calloc(10, sizeof(arr[0]));
+       if (!arr) {
+               return errno;
+       }
+
+       *f = get_item(arr, 0);
+       return 0;
+}
+.Ed
+.Ss Abort on bad API inputs
+The C language provides precious few compile-time validation mechanisms, and so
+in many cases it is not possible to fully describe to the compiler the range of
+expected inputs for an API. So your API should validate input from its caller
+and abort on invalid input. Returning an error in such a case is pointless,
+since the caller probably isn't checking the return code anyway. The only sure
+way to get the programmer's attention is to abort the calling process with a
+helpful message. The
+.Ic os_crash
+routine allows you to supply such a message that the crash reporter on Darwin
+will display in its crash report.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+uint8_t
+foo_a_bar(uint8_t number)
+{
+       if (number > (UINT8_MAX / 2)) {
+               os_crash("number given to foo_a_bar() too large");
+       }
+       return (number * 2);
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+int
+foo_a_bar(uint8_t number, uint8_t *new_number)
+{
+       if (number > (UINT8_MAX / 2)) {
+               return EINVAL;
+       }
+       *new_number = (number * 2);
+       return 0;
+}
+.Ed
+.Ss Don't mingle POSIX return codes and errors
+Some POSIX routines have return values that indicate whether you should check
+.Ic errno ,
+and others just return the error directly. While POSIX generally documents what
+does what pretty well, there are lots of SPIs scattered around the system that
+use both conventions and aren't documented at all, leaving you to spelunk
+through the implementation to find out what's what.
+.Pp
+To avoid confusion, do not re-use the same variable for the return codes from
+these functions. If an API returns a code indicating that you should check
+.Ic errno ,
+name it
+.Ic ret
+or similar. If it returns the error directly, name it
+.Ic error
+or similar and make it of type
+.Ic errno_t .
+This makes it very clear to the person reading the code that you did the work to
+find out how the API worked. By naming the variable you store the return value
+in appropriately, a reader of your code (possibly Future You) can immediately
+know what's going on.
+.Pp
+If you are making new API or SPI that returns an error code, make it return
+.Ic errno_t
+and do not use the global
+.Ic errno
+for communicating error information.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+#include <sys/types.h>
+
+errno_t error = posix_spawn(NULL, "ls", NULL, NULL, argv, envp);
+switch (error) {
+case 0:
+    // Handle success.
+    break;
+case EACCES:
+    // Handle "permission denied".
+    break;
+}
+
+int ret = reboot(RB_AUTOBOOT);
+if (ret == -1) {
+    switch (errno) {
+    case EPERM:
+        // Handle "permission denied".
+        break;
+    case EBUSY:
+        // Handle "reboot already in progress".
+        break;
+    }
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+int ret = posix_spawn(NULL, "ls", NULL, NULL, argv, envp);
+switch (error) {
+case 0:
+    // Handle success.
+    break;
+case EACCES:
+    // Handle "permission denied".
+    break;
+}
+
+int error = reboot(RB_AUTOBOOT);
+if (error == -1) {
+    switch (errno) {
+    case EPERM:
+        // Handle "permission denied".
+        break;
+    case EBUSY:
+        // Handle "reboot already in progress".
+        break;
+    }
+}
+.Ed
+.Ss Avoid complex `if` statements and return distinct error codes
+Breaking up a single complex
+.Ic if
+statement
+into multiple distinct checks is both more readable and makes it possible to be
+more granular about handling failure cases. It also leads to smaller diffs if
+one of those conditions turns out to require special handling.
+.Pp
+Complex
+.Ic if
+statements are often associated with input validation and just returning an
+error code (usually
+.Ic EINVAL )
+if any input is invalid. While deciding which error to return in which case is
+more of an art than a science, that doesn't mean you should just give up and
+return a single error every time there isn't an immediately obvious fit to the
+case you've encountered.
+.Pp
+Ideally, every case where your routine may fail should be represented by a
+distinct error code, but this is often not practical. Still, you should attempt
+to distinguish each
+.Em likely
+failure case with its own error code. The POSIX error space is fairly rich, and
+error descriptions are brief enough that they can be liberally interpreted. For
+example,
+.Ic ESRCH
+can be used to apply to any situation where a resource could not be located, not
+just conditions where there is literally "No such process".
+.Pp
+This isn't to say that you should never have compound conditions in an
+.Ic if
+statement, but the groupings should almost always be small, and the grouped
+checks should be highly likely to require change as a group when change is
+needed.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+if (foo->f_int > 10 || foo->f_int < 5)
+       return ERANGE;
+}
+
+if (!foo->f_uaddr) {
+       return EFAULT;
+}
+
+if (foo->f_has_idx && foo->f_idx > 100) {
+       return ERANGE;
+}
+
+if (foo->f_state != FS_INITIALIZED) {
+       return EBUSY;
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if (foo->f_int > 10 || foo->f_int < 5 || !foo->f_uaddr || (foo->f_has_idx && foo->f_idx > 100) ||
+               foo->f_state != FS_INITIALIZED) {
+       return EINVAL;
+}
+.Ed
+.Pp
+See
+.Xr intro 2 ,
+.Ic <sys/errno.h> ,
+and
+.Ic <os/error.h>
+for the error codes supported on Darwin.
+.Ss Don't NULL-check when calling `free(3)`
+.Ic NULL
+is valid input to
+.Xr free 3 .
+It's part of the API contract. Armed with this knowledge, you can do things like
+avoid conditional memory calls, which are always weird.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+char buff[1024];
+char *ptr = buff;
+char *what2free = NULL;
+
+if (condition) {
+    ptr = malloc(8);
+    what2free = ptr;
+}
+
+free(what2free);
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+char buff[1024];
+char *ptr = buff;
+bool did_malloc = false;
+
+if (condition) {
+    ptr = malloc(8);
+    did_malloc = true;
+}
+
+if (did_malloc) {
+    free(ptr);
+}
+.Ed
+.Ss Distinguish exported and non-exported symbols
+Any non-exported symbols should be prefixed with a
+.Ic _ .
+Thus any
+.Ic static
+functions, project-local interfaces, etc. should have this prefix. Exported
+symbols (API or SPI) should
+.Em not
+have such a prefix.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+static const char *_thing = "thing";
+static void _foo(void);
+
+void
+_project_local_interface(void);
+.Ed
+.Em Bad
+.Bd -literal -offset indent
+static const char *thing = "thing";
+static void foo(void);
+
+void
+project_local_interface(void);
+.Ed
+.Pp
+Global variables should have a sensible prefix, preferably related to the
+project name -- e.g. globals in the
+.Xr libxpc 3
+project are prefixed with
+.Ic xpc_ .
+.Pp
+You may also consider declaring a global structure which contains all of your
+project's shared, unexported global state. This makes it very clear when code is
+referencing that state. Also, if your project is a library at the libSystem
+layer, this is required if you are ever to adopt
+.Xr os_alloc_once 3 .
+.Pp
+.Em Example
+.Bd -literal -offset indent
+typedef struct _foobar_globals {
+       uint64_t fg_global_int;
+       char *fg_global_string;
+} foobar_globals_t;
+
+foobar_globals_t _g;
+foobar_globals_t *g = &_g;
+.Ed
+.Ss Distinguish SPIs meant for one caller
+Sometimes projects must create bespoke SPIs for one particular caller, and these
+SPIs are not considered suitable for general use. Append a suffix to these SPIs
+to indicate their bespokeness and the intended caller with
+.Ic _4caller .
+For example, if you add an SPI specifically for IOKit, your suffix would likely
+be
+.Ic _4IOKit .
+.Ss Use `#if` instead of `#ifdef` where appropriate
+.Ic #ifdef
+is to check if a token is
+.Em defined at all to anything.
+.Ic #if
+is to check the token's value. The C standard specifies that when a token is
+undefined,
+.Ic #if
+will evaluate it as
+.Ic 0 .
+When checking for features, it's almost always more appropriate to use
+.Ic #if
+since the lack of a feature could still be communicated by setting the token's
+value to
+.Ic 0 ,
+which would pass the
+.Ic #ifdef
+check.
+.Ss Use Function Attributes from `<os/base.h>`
+If you're on Darwin,
+.Ic libplatform
+defines a lot of nice macros for compiler attributes. Use them to decorate your
+functions. This gives the compiler lots more information so it can do fancy
+optimizations. Things like
+.Ic OS_NONNULL
+let the compiler know that a parameter should never be
+.Ic NULL .
+.Ic OS_WARN_RESULT
+is great for enforcing that a caller always check the return value of a
+function.
+.Pp
+.Ic OS_MALLOC
+lets the compiler know that the function returns a heap allocation, and
+.Ic OS_OBJECT_RETURNS_RETAINED
+lets ARC know that the function returns an object with a reference that the
+caller is responsible for releasing.
+.Pp
+You can avoid having to decorate all your pointer parameters by using
+.Ic OS_ASSUME_NONNULL_BEGIN
+and
+.Ic OS_ASSUME_NONNULL_END
+and specifically annotating variables which
+.Em can
+be
+.Ic NULL
+with the
+.Ic _Nullable
+keyword. Either approach is acceptable.
+.Pp
+Generally, use these attributes on functions which will have callers who cannot
+view the implementation. Putting many of these attributes on (for example) an
+inline function is harmless, but the compiler can reason about things like
+.Ic OS_NONNULL
+and infer it when it can view the implementation at all call sites.
+.Pp
+So as a rule of thumb, if it's in a header, decorate it appropriately. These
+attributes can also serve as nice implicit documentation around API and SPI. For
+example, if you have a decoration of
+.Ic OS_NONNULL1 ,
+you don't have to spell out in the HeaderDoc that you can't pass
+.Ic NULL
+for that parameter; it'll be right there in the declaration, and the compiler
+will catch attempts to do so.
+.Ss Distinguish C function definitions from declarations
+In C, make the definition of a function findable and distinguishable from its
+declaration (if any) through regular expressions. This way, you can find the
+implementation of
+.Ic foo
+by doing a regex search for
+.Ic ^foo ,
+and you won't get the declaration as a result.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+static int foo(int bar);
+
+int
+foo(int bar)
+{
+    return bar;
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+static int foo(int bar);
+
+int foo(int bar)
+{
+    return bar;
+}
+.Ed
+.Pp
+This has the additional benefit of allowing you to change the name/parameter
+list of a function independently of the return type. A diff of either will not
+be confused with the rest of the function signature.
+.Ss Use HeaderDoc for API declarations
+Make them look nice. Include the appropriate decorations (including an explicit
+export attribute such as
+.Ic OS_EXPORT
+so it's very, very clear that it's intended to be API), availability attributes,
+and HeaderDoc. Put this stuff before the function.
+.Pp
+.Em Example
+.Bd -literal -offset indent
+/*!
+ * @function foo
+ * Returns `bar` and ignores another parameter.
+ *
+ * @param bar
+ * The value to return.
+ *
+ * @param baz
+ * The value to ignore.
+ *
+ * @result
+ * The value of `bar`. This routine cannot fail.
+ */
+__API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT OS_WARN_RESULT OS_NONNULL2
+int
+foo(int bar, char *baz);
+.Ed
+.Ss Comments
+In general, use C++/C99-style comments. But there may be good reasons to use the
+classic C-style comments, such as for HeaderDoc, which requires them, e.g.
+.Bd -literal -offset indent
+/*!
+ * Documentation
+ */
+.Ed
+.Pp
+Long, top-level comments may also use classic C-style comments.
+.Pp
+C++/C99-style comments may directly follow code on the same line only if they
+are extremely brief. Otherwise, in general, comments and code should not share
+a line.
+.Pp
+Also, do not get cute with
+.Ic /* */
+comments and embed them within code.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+// Comment on what the loop does.
+for (i = 0; i < cnt; i++) {
+    // some code...
+}
+
+/*
+ * A top-level or very long comment.
+ */
+
+int ret = esoteric_spi(); // returns -1 on failure, does not set errno
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+//Comment
+
+int ret = esoteric_spi(); // This SPI returns -1 on failure but does not set
+    // errno, so here is a comment explaining that that really should be above
+    // the line of code rather than immediately following it.
+
+foo(arg1, /* first argument */, arg2 /* second argument */);
+.Ed
+.Ss `case` and `switch` are indented at the same level
+.Ic case
+and
+.Ic switch
+belong at the same column indent because indentation indicates scope, and due to
+case fall-through, all cases are in the same scope -- one lower than the
+previous. (Unless you scope them explicitly with braces, but you should avoid
+doing that if at all possible.)
+.Pp
+.Em Good
+.Bd -literal -offset indent
+switch (thing) {
+case THING1:
+    exit(0);
+    break;
+case THING2:
+    exit(1);
+    break;
+default:
+    __builtin_unreachable();
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+switch (thing) {
+case THING1: {
+    exit(0);
+    break;
+}
+case THING2: {
+    exit(1);
+    break;
+}
+default:
+    __builtin_unreachable();
+}
+
+switch (thing) {
+    case THING1:
+        exit(0);
+        break;
+    case THING2:
+        exit(1);
+        break;
+    default: {
+        __builtin_unreachable();
+    }
+}
+.Ed
+.Ss Use typed `enum`s
+If you're declaring an
+.Ic enum ,
+you should
+.Ic typedef
+it so the compiler can reason about valid values and know the width of the
+.Ic enum
+type if possible. The
+.Ic OS_ENUM
+macro provides the correct behavior for C, C++, and Objective-C.
+.Ss Initialize all variables and fail closed
+If you pre-declare a variable before using it, initialize it to a sane value. If
+this value is something like the return value of the function, initialize it to
+a value which indicates failure of the operation. You should
+.Em always
+do this even if there are no code paths which fail to initialize the variable
+later. It's just good practice, and it gives the person reading your code an
+indication of what ranges of values the variable is expected to hold.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+int result = -1;
+
+if (success) {
+    result = 0;
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+int result;
+
+if (success) {
+    result = 0;
+}
+.Ed
+.Pp
+Any error variable should always be initialized to a non-success condition. In
+general, consider success as something that your code must
+.Em explicitly declare
+and that the absence of such a declaration indicates failure.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+int error = -1;
+
+if (is_root()) {
+    error = 0;
+} else {
+    error = EPERM;
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+int error = 0;
+
+if (!is_root()) {
+    error = EPERM;
+}
+.Ed
+.Pp
+Note that you may omit an initializer for a complex
+.Ic struct
+type (such as the
+.Xr stat 2
+.Ic struct )
+but then it is incumbent upon you to ensure that that variable is not used
+uninitialized except to populate it. For many
+.Ic struct
+types, you can initialize them with
+.Ic {0} .
+This will not work for structures with nested structures though. For those you
+can use
+.Xr bzero 3
+or similar.
+.Ss Using `goto` is fine
+.Ic goto
+has gotten a bad rap, but it's probably the best way in C to do lots of
+sequential error handling. You don't
+.Em have
+to use
+.Ic goto
+if you don't want to, but if you do, just keep a a couple things in mind.
+.Pp
+.Bl -bullet -compact -offset indent
+.It
+Compile with
+.Ic -Wsometimes-uninitialized .
+With this warning,
+.Xr clang 1
+will catch cases where a variable may be used uninitialized because a
+.Ic goto
+skipped the initialization.
+.It
+Never use
+.Ic goto
+as a looping construct. The C language has a few different control statements
+for looping and iteration. Use one of those; it's not the 70's anymore.
+.El
+.Pp
+These guidelines make it simple to use
+.Ic goto
+effectively while avoiding the
+most common pitfalls.
+.Ss Avoid magic Booleans
+Sometimes you have to pass a parameter to a function to trigger some sort of
+behavior. Avoid using a magic Boolean for these cases. Instead, use an invariant
+that describes the behavior you are triggering.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+replace_spaces(string, REPLACE_TABS_TOO);
+replace_spaces(string, REPLACE_ONLY_SPACES);
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+replace_spaces(string, true);
+replace_spaces(string, false);
+.Ed
+.Pp
+If you find yourself creating many such Boolean values for function parameters,
+you should seriously considering defining a set of flags and passing that as one
+parameter instead.
+.Ss Spaces around binary operators
+In general, avoid code that looks crunched together, especially around
+operators. Specifically:
+.Bl -bullet -compact -offset indent
+.It
+Unary operators should
+.Em not
+have spaces around them.
+.It
+Binary operators
+.Em should
+have spaces around them.
+.It
+The ternary operator
+.Em should
+have spacing around it.
+.El
+.Pp
+.Em Good
+.Bd -literal -offset indent
+i++;
+j = i + k;
+k += condition ? i : j;
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+i ++;
+j=i+k
+k+=condition?i:j;
+.Ed
+.Ss Reserve the ternary operator for trivial cases
+Don't use the ternary operator to choose between complex or long expressions.
+Reserve it for very trivial cases that are highly unlikely to change. In general
+if you've found yourself putting the expressions in your usage of ternary
+operator on multiple lines, you should just be using an
+.Ic if
+statement.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+i += condition ? j : k;
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+i += (i < j && j > k || i == j) ? foo(bar, baz, 0, NULL) : frob(bar, 0, NULL, baz);
+.Ed
+.Ss Spaces around parentheses
+.Bl -bullet -compact -offset indent
+.It
+Put a space between the control statement and the parenthesis indicating its
+condition.
+.It
+Do
+.Em not
+put a space between the end of a function name and the parenthesis
+indicating its argument list.
+.It
+Do
+.Em not
+put spaces between any parenthesis and its following content.
+.El
+.Pp
+.Em Good
+.Bd -literal -offset indent
+if (condition) {
+    do_thing();
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if(condition) {
+    do_thing ();
+}
+
+if ( condition ) {
+    do_thing ( argument );
+}
+.Ed
+.Pp
+.Em Worse
+.Bd -literal -offset indent
+while( condition) {
+    do_thing( );
+}
+.Ed
+.Ss Braces and statements
+Always, always, always use braces for your control statements. Lack of braces
+can and has led to serious security issues that were missed during code review,
+and putting the braces there from the start means that adding new statements to
+that clause does not require you to also add the braces.
+.Pp
+The clause should be indented on the next line with no blank lines in between.
+.Pp
+.Em Good
+.Bd -literal -offset indent
+if (condition) {
+    do_thing();
+}
+
+while (condition) {
+    do_thing();
+}
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if (condition) do_thing();
+
+if (condition)
+    do_thing();
+
+while (condition) do_thing();
+
+while (condition) {
+
+    do_thing();
+}
+.Ed
+.Pp
+Even trivial uses of braceless
+.Ic if
+statements are problematic. Consider the following:
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if (error) i++,
+i++;
+.Ed
+.Pp
+This is admittedly contrived, but it would be likely to escape code review
+because it's very easy to miss that the first line ends with a
+.Ic ,
+rather than a
+.Ic ; .
+Braces in
+.Ic if
+statements are sensitive enough to security that the best policy is to simply
+always use them, without exception.
+.Pp
+Specific rules for braces:
+.Bl -bullet -compact -offset indent
+.It
+.Ic else
+goes between two braces on the same line.
+.It
+The brace which indicates the expression associated with a control flow
+statement goes on the same line as that statement or the same line as the last
+continuation line of the statement.
+.It
+The brace which begins the definition of a
+.Ic struct ,
+.Ic union ,
+.Ic enum ,
+etc. goes on the same line as the declaration.
+.It
+The brace concluding the expression associated with a control flow statement
+is aligned with the same column as that control flow statement.
+.It
+The opening brace of a function definition goes on its own line and is
+immediately followed by a new line.
+.It
+Control statements with empty bodies should have empty braces.
+.El
+.Pp
+.Em Good
+.Bd -literal -offset indent
+if (condition) {
+    do_thing();
+} else {
+    do_other_thing();
+}
+
+void
+function(void)
+{
+    return;
+}
+
+struct my_struct {
+    uint32_t thing;
+};
+
+for (cur; cur; cur = cur->next) { }
+.Ed
+.Pp
+.Em Bad
+.Bd -literal -offset indent
+if (condition)
+{
+    do_thing();
+}
+else
+{
+    do_other_thing();
+}
+
+if (condition)
+{
+    do_thing();
+}
+else
+    do_other_thing();
+
+void
+function(void) {
+    return;
+}
+
+struct my_struct
+{
+    uint32_t thing;
+};
+
+for (cur; cur; cur = cur->next)
+.Ed
+.Pp
+.Em Worse
+.Bd -literal -offset indent
+if (condition)
+    {
+    do_thing();
+    }
+
+void
+function(void)
+{ return;
+}
+.Ed
+.Sh SEE ALSO
+.Xr style 9 ,
+.Xr intro 2 ,
+.Xr errno 3 ,
+.Xr types 5
+.Sh HISTORY
+This style was largely derived from the style that evolved through the
+.Xr launchd 8 ,
+.Xr libdispatch 3 ,
+and
+.Xr libxpc 3
+projects.
index e9654171b4c38efbdadaedd47de4dd5c9fb6d345..46519d817fc25706ef1230a91b69528a88e4506c 100644 (file)
@@ -64,6 +64,9 @@
  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static const char sccsid[] = "@(#)inet_addr.c  8.1 (Berkeley) 6/17/93";
 static const char rcsid[] = "$Id: inet_addr.c,v 1.4.18.1 2005/04/27 05:00:52 sra Exp $";
@@ -226,4 +229,5 @@ __weak_reference(__inet_addr, inet_addr);
 #undef inet_aton
 __weak_reference(__inet_aton, inet_aton);
 
+#pragma clang diagnostic pop
 /*! \file */
index 081a1cf2c8d94439a3bccc503752cba6c6bfb76f..e889f206b5dc92c0d66a902bddf96d47d262454a 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static const char sccsid[] = "@(#)inet_network.c       8.1 (Berkeley) 6/4/93";
 
@@ -112,4 +115,5 @@ again:
 #undef inet_network
 __weak_reference(__inet_network, inet_network);
 
+#pragma clang diagnostic pop
 /*! \file */
index a5ad5c60f7c6f453c2f619bfbb2f7a9a842ce752..600ecfd6ceecafeaebf3a77f6edf34873db3c7fe 100644 (file)
 #include <errno.h>
 #include <sys/socket.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+#pragma clang diagnostic ignored "-Wint-conversion"
+
 #define MAX_V4_ADDR_LEN 16
 #define MAX_V6_ADDR_LEN 64
 
@@ -239,3 +243,4 @@ inet_ntop4(const struct in_addr *addr, char *dst, socklen_t size)
        memcpy(dst, tmp, len);
        return dst;
 }
+#pragma clang diagnostic pop
index 1e9f1a0dddbf615a02cb1b1ac5841de3623782c8..d14d13915500392966f20c1517a8034d451898ef 100644 (file)
@@ -36,6 +36,9 @@ up-to-date.  Many thanks.
 
 ******************************************************************/
 
+#include <_stdio.h>
+#include <sys/_types/_off_t.h>
+
 /*
  * Magic definitions
  */
diff --git a/os/api.h b/os/api.h
new file mode 100644 (file)
index 0000000..59b870e
--- /dev/null
+++ b/os/api.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2018 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*!
+ * @header
+ * API macros. libdarwin provides APIs for low-level userspace projects in the
+ * Darwin operating system.
+ *
+ * - C language additions
+ * - POSIX and BSD API additions
+ * - POSIX and BSD convenience wrappers
+ * - Mach API additions and wrappers with clearer semantics
+ *
+ * Additions which extend the C language are not prefixed and are therefore not
+ * included by default when including this header.
+ *
+ * Additions to API families conforming to ANSI C carry the "os_" prefix.
+ *
+ * Additions to API families conforming to POSIX carry the "_np" ("Not POSIX")
+ * suffix.
+ *
+ * Additions to API families conforming to both POSIX and ANSI C carry the "_np"
+ * suffix.
+ *
+ * Convenience wrappers for POSIX and BSD APIs carry the "os_" prefix.
+ *
+ * New APIs formalizing Darwin workflows carry the "os_" prefix.
+ */
+#ifndef __DARWIN_API_H
+#define __DARWIN_API_H
+
+#include <os/availability.h>
+
+/*!
+ * @const DARWIN_API_VERSION
+ * The API version of the library. This version will be changed in accordance
+ * with new API introductions so that callers may submit code to the build that
+ * adopts those new APIs before the APIs land by using the following pattern:
+ *
+ * #if DARWIN_API_VERSION >= 20180424
+ * darwin_new_api();
+ * #endif
+ *
+ * In this example, the libdarwin maintainer and API adopter agree on an API
+ * version of 20180424 ahead of time for the introduction of
+ * darwin_new_api_call(). When a libdarwin with that API version is submitted,
+ * the project is rebuilt, and the new API becomes active.
+ *
+ * Breaking API changes will be both covered under this mechanism as well as
+ * individual preprocessor macros in this header that declare new behavior as
+ * required.
+ */
+#define DARWIN_API_VERSION 20170407lu
+
+#define DARWIN_API_AVAILABLE_20170407 \
+               API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+
+#endif // __DARWIN_API_H
index 455fd47570ab0102d37d40115b3e186cf2a8b89d..30fe420f2adbb5e8b656291c3560e7720bcef9f5 100644 (file)
@@ -267,7 +267,7 @@ _os_crash_fmt_impl(os_log_pack_t pack, size_t pack_size)
        if (!__os_log_default) return false;
 
        char *composed = _os_log_pack_send_and_compose(pack, __os_log_default,
-                       OS_LOG_TYPE_FAULT, NULL, 0);
+                       OS_LOG_TYPE_ERROR, NULL, 0);
 
        abort_with_payload(OS_REASON_LIBSYSTEM, OS_REASON_LIBSYSTEM_CODE_FAULT, pack, pack_size, composed, 0);
 }
index b25abbd7f024e411d81c433276274e589f3390f6..c68e87ed721a2270841b594a5f3d3d7fae77ecc4 100644 (file)
@@ -37,6 +37,7 @@ __BEGIN_DECLS
 #include <_simple.h>
 #include <errno.h>
 #include <os/base_private.h>
+#include <stdint.h>
 
 #if __GNUC__
 #define os_constant(x) __builtin_constant_p((x))
@@ -98,6 +99,133 @@ __BEGIN_DECLS
 extern void
 _os_crash_fmt(os_log_pack_t, size_t);
 
+/*!
+ * @function os_assert_sprintf
+ * A routine to assert the result of a call to snprintf(3) or vsnprintf(3).
+ *
+ * @param ret
+ * The return value from {v}snprintf(3).
+ *
+ * @param buff_size
+ * The size of the buffer given to {v}snprintf(3).
+ *
+ * @discussion
+ * If ret is less than zero or greater than size, the routine will abort the
+ * caller with a message indicating the nature of the failure in the Application
+ * Specific Information section of the resulting crash log.
+ *
+ * This routine is useful for printing paths that are expected to succeed with a
+ * statically-sized buffer.
+ */
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_ALWAYS_INLINE
+static inline void
+os_assert_sprintf(int ret, size_t buff_size)
+{
+       union {
+               size_t size;
+               int ret;
+       } myret = {
+               .ret = ret,
+       };
+
+       if (ret < 0) {
+               os_crash("error printing buffer: %s", strerror(errno));
+       }
+
+       if (myret.size > buff_size) {
+               os_crash("buffer too small: needed = %d, actual = %lu",
+                               ret, buff_size);
+       }
+}
+
+/*!
+ * @function os_assert_malloc
+ * A routine to assert the result of allocations which may fail.
+ *
+ * @param desc
+ * A string describing the object whose allocation was attempted.
+ *
+ * @param p
+ * The result of a call to malloc(3), calloc(3), et al.
+ *
+ * @param alloc_size
+ * The size of the attempted allocation.
+ *
+ * @discussion
+ * If {@link p} is NULL, the routine will abort the caller with a message
+ * indicating the nature of the failure in the Application Specific Information
+ * section of the resulting crash log.
+ */
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_ALWAYS_INLINE
+static inline void
+os_assert_malloc(const char *desc, const void *const p, size_t alloc_size)
+{
+       if (!p) {
+               os_crash("allocation failed: obj = %s, size = %lu, error = %s",
+                               desc, alloc_size, strerror(errno));
+       }
+}
+
+/*!
+ * @function os_assert_mach
+ * A routine to assert the result of a Mach kernel routine.
+ *
+ * @param op
+ * A human-readable description of the operation.
+ *
+ * @param kr
+ * The return code.
+ *
+ * @discsussion
+ * If {@link kr} is non-zero, this routine will abort the caller with a message
+ * indicating the nature of the failure in the Application Specific Information
+ * section of the resulting crash log.
+ */
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT OS_NONNULL1
+void
+os_assert_mach(const char *op, kern_return_t kr);
+
+/*!
+ * @function os_assert_mach_port_status
+ * A routine to assert the status of a Mach port.
+ *
+ * @param desc
+ * A human-readable description of the port's purpose.
+ *
+ * @param p
+ * The port.
+ *
+ * @param expected
+ * A pointer to a mach_port_status_t describing the expected attributes of the
+ * port. If no particular value is expected for a given field in the structure,
+ * a sentinel value may be provided for each expected field to indicate that its
+ * check should be elided. The sentival values are:
+ *
+ * mps_pset => UINT32_MAX
+ * mps_seqno => UINT32_MAX
+ * mps_mscount => UINT32_MAX
+ * mps_qlimit => UINT32_MAX
+ * mps_msgcount => UINT32_MAX
+ * mps_sorights => UINT32_MAX
+ * mps_srights => INT32_MAX
+ * mps_pdrequest => INT32_MAX
+ * mps_nsrequest => INT32_MAX
+ * mps_flags => 0
+ *
+ * @discussion
+ * If there are any mismatches in the expected and actual status of the port,
+ * the implementation will abort the caller. If status cannot be obtained for
+ * the given port, the implementation will abort the caller.
+ */
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT
+void
+os_assert_mach_port_status(const char *desc, mach_port_t p,
+               mach_port_status_t *expected);
+
 #else // OS_CRASH_ENABLE_EXPERIMENTAL_LIBTRACE
 
 #define os_crash(msg) __os_crash_simple(msg)
index f8741a098053bf1c7f709aef890178d1a133fb4e..8d7a4532ab03acef5f0e64a89b5d4b0155fa6659 100644 (file)
@@ -31,6 +31,9 @@
 #include "tre-last-matched.h"
 #include "xmalloc.h"
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+
 /*
   The bit_ffs() macro in bitstring.h is flawed.  Replace it with a working one.
 */
@@ -3475,5 +3478,5 @@ tre_config(int query, void *result)
 }
 #endif /* !__LIBC__ */
 
-
+#pragma clang diagnostic push
 /* EOF */
index f5a31f51756c802fc4d6b5b82dac883a031365a8..fe1110b0757ee51b9e0ed1fe82e23fbc150df431 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)findfp.c   8.2 (Berkeley) 1/4/94";
 #endif /* LIBC_SCCS and not lint */
@@ -292,3 +295,4 @@ __sinit(void)
        }
 #endif
 }
+#pragma clang diagnostic pop
index e057f350cae369371b938c6c8be2c69dcd523420..1edd25eb6fd76c51ce1862ba180d229849441c73 100644 (file)
@@ -238,6 +238,13 @@ is present in the second or third position of the
 argument). Buffers opened in text-mode make sure that writes are terminated with
 a NULL byte, if the last write hasn't filled up the whole buffer. Buffers
 opened in binary-mode never append a NULL byte.
+.Pp
+Input and output against the opened stream will be fully buffered, unless
+it refers to an interactive terminal device, or a different kind of buffering
+is specified in the environment.
+See
+.Xr setvbuf 3
+for additional details.
 .Sh RETURN VALUES
 Upon successful completion
 .Fn fopen ,
index 85bb73a7515b3faea2eaa96706039fa460b07275..e5ec5bd614045d2fb9fd8d1131c5e12e3ee83279 100644 (file)
@@ -1,4 +1,6 @@
 /*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
  * Copyright (c) 1990, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
@@ -13,7 +15,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -34,7 +36,7 @@
 static char sccsid[] = "@(#)makebuf.c  8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/makebuf.c,v 1.6 2007/01/09 00:28:07 imp Exp $");
+__FBSDID("$FreeBSD$");
 
 #include "namespace.h"
 #include <sys/types.h>
@@ -46,6 +48,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/makebuf.c,v 1.6 2007/01/09 00:28:07 imp E
 
 #include "libc_private.h"
 #include "local.h"
+#include <xlocale/_stdio.h>
+#include <xlocale/_stdlib.h>
+#include <os/once_private.h>
 
 #ifdef FEATURE_SMALL_STDIOBUF
 # define MAXBUFSIZE    (1 << 12)
@@ -54,6 +59,104 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/makebuf.c,v 1.6 2007/01/09 00:28:07 imp E
 #endif
 
 #define TTYBUFSIZE     4096
+#define MAXEVPSIZE 16
+
+static char __fallback_evp[MAXEVPSIZE];
+static char __stdout_evp[MAXEVPSIZE];
+
+static void
+__loadevp(const char* key, char destination[MAXEVPSIZE])
+{
+       char* evp = getenv(key);
+       if (evp != NULL) {
+               strlcpy(destination, evp, MAXEVPSIZE);
+       } else {
+               destination[0] = '\0';
+       }
+}
+
+static void
+__evpinit(void* __unused unused)
+{
+       __loadevp("STDBUF", __fallback_evp);
+       __loadevp("STDBUF1", __stdout_evp);
+}
+
+static char*
+__getevp(int fd)
+{
+       static os_once_t predicate;
+       os_once(&predicate, NULL, __evpinit);
+
+       if (fd == STDOUT_FILENO && __stdout_evp[0] != '\0') {
+               return __stdout_evp;
+       } else if (__fallback_evp[0] != '\0') {
+               return __fallback_evp;
+       } else {
+               return NULL;
+       }
+
+}
+
+/*
+ * Internal routine to determine environment override buffering for a file.
+ *
+ * Sections of the below taken from NetBSD's version of this file under the same license.
+ */
+static int
+__senvbuf(FILE *fp, size_t *bufsize, int *couldbetty)
+{
+       char* evp;
+       char* end;
+       int flags;
+       long size;
+
+       flags = 0; // Default to fully buffered
+
+       if ((evp = __getevp(fp->_file)) == NULL) {
+               return flags;
+       }
+
+       // Look at the first character only to determine buffering mode
+       switch (*evp) {
+               case 'u':
+               case 'U':
+                       flags |= __SNBF;
+                       break;
+               case 'l':
+               case 'L':
+                       flags |= __SLBF;
+                       break;
+               case 'f':
+               case 'F':
+                       // Default flags is fully buffered
+                       break;
+               default:
+                       // Unexpected buffering mode, use default fully buffered
+                       return flags;
+       }
+       // User specified envrionment defaults have higher priority than tty defaults
+       *couldbetty = 0;
+
+       // Advance the envrionment variable pointer, so we can attempt to parse the number
+       evp++;
+       if (!isdigit(*evp)) {
+               return flags; // No number found, this protects us from negative size values
+       }
+
+       size = strtol_l(evp, &end, 10, NULL); // No locale
+       if (*end != '\0') {
+               return flags;
+       }
+
+       if (size <= 0) {
+               return __SNBF; // Override with unbuffered if the buffer size is 0
+       }
+
+       // We had a non zero buffer, cap it and return the flags;
+       *bufsize = size > MAXBUFSIZE ? MAXBUFSIZE : size;
+       return flags;
+}
 
 /*
  * Allocate a file buffer, or switch to unbuffered I/O.
@@ -63,8 +166,7 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/makebuf.c,v 1.6 2007/01/09 00:28:07 imp E
  * optimisation) right after the _fstat() that finds the buffer size.
  */
 void
-__smakebuf(fp)
-       FILE *fp;
+__smakebuf(FILE *fp)
 {
        void *p;
        int flags;
@@ -77,6 +179,17 @@ __smakebuf(fp)
                return;
        }
        flags = __swhatbuf(fp, &size, &couldbetty);
+       if (fp->_file >= 0) {
+               flags |= __senvbuf(fp, &size, &couldbetty);
+
+               if (flags & __SNBF) {
+                       fp->_flags |= __SNBF;
+                       fp->_bf._base = fp->_p = fp->_nbuf;
+                       fp->_bf._size = 1;
+                       return;
+               }
+       }
+
        if (couldbetty && isatty(fp->_file)) {
                flags |= __SLBF;
                /* st_blksize for ttys is 128K, so make it more reasonable */
@@ -100,10 +213,7 @@ __smakebuf(fp)
  * Internal routine to determine `proper' buffering for a file.
  */
 int
-__swhatbuf(fp, bufsize, couldbetty)
-       FILE *fp;
-       size_t *bufsize;
-       int *couldbetty;
+__swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
 {
        struct stat st;
 
index a2d9bda9c2a0a4bad8fc06261753c6abc6294566..e36f3e62ea407e3b7843cf998bf75f4c7ce7cc3d 100644 (file)
@@ -31,12 +31,14 @@ __FBSDID("$FreeBSD$");
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
+#include <os/overflow.h>
 #ifdef DEBUG
 #include <stdint.h>
 #endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/param.h>
 #include <wchar.h>
 
 /* XXX: There is no FPOS_MAX.  This assumes fpos_t is an off_t. */
@@ -60,6 +62,18 @@ memstream_grow(struct memstream *ms, fpos_t newoff)
        else
                newsize = newoff;
        if (newsize > ms->len) {
+               /*
+                * Grow by 1.5x (15 / 10).
+                */
+               ssize_t growsize;
+               bool ovf = os_mul_overflow(ms->len, 15, &growsize);
+               if (ovf) {
+                       growsize = SSIZE_MAX - 1;
+               } else {
+                       growsize /= 10;
+               }
+               newsize = MAX(growsize, newsize);
+
                buf = realloc(*ms->bufp, newsize + 1);
                if (buf != NULL) {
 #ifdef DEBUG
@@ -79,7 +93,6 @@ memstream_grow(struct memstream *ms, fpos_t newoff)
 static void
 memstream_update(struct memstream *ms)
 {
-
        assert(ms->len >= 0 && ms->offset >= 0);
        *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
 }
index 466d8b34f03be9f17c833f343873bcf9191e5645..6a33459a5cf9a3278fdf38dd25f1a5cb94181889 100644 (file)
@@ -79,6 +79,24 @@ characters are saved up until a newline is output
 or input is read from any stream attached to a terminal device
 (typically
 .Dv stdin ) .
+.Pp
+The default buffer settings can be overwritten for stdout
+.Dv ( STDBUF1 )
+or for all descriptors
+.Dv ( STDBUF ) .
+The environment variable value is a letter followed by an optional numeric
+value indicating the size of the buffer.
+Valid sizes range from 0B to 64KB.
+Valid letters are:
+.Bl -tag -width X -indent
+.It Dv Li U
+Unbuffered.
+.It Dv Li L
+Line-buffered.
+.It Dv Li F
+Fully-buffered.
+.El
+.Pp
 The function
 .Xr fflush 3
 may be used to force the block out early.
index ff6162cfc50dc6bdb8dc4c0f8bec2da9fd9f490f..dd2bcfee465925dd1366bc252c8e8ffbc347132b 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wint-conversion"
+
 #define OS_CRASH_ENABLE_EXPERIMENTAL_LIBTRACE 1
 
 #if defined(LIBC_SCCS) && !defined(lint)
@@ -1448,4 +1451,4 @@ error:
        return (ret < 0 || ret >= INT_MAX) ? -1 : (int)ret;
        /* NOTREACHED */
 }
-
+#pragma clang diagnostic pop
index 618961e9c395b57c0202d460143bfcc98aab4c3b..eca276601f75f301aed8ca83ba2107095c6ea27b 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)vfscanf.c  8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -1194,3 +1197,4 @@ parsedone:
        return (commit - b);
 }
 #endif
+#pragma clang diagnostic push
index 6f5b549e3817cfa09751b8adeb59b4640332c8fe..75787ca38afd0a1b7c4e3cf13fea030742b7f73b 100644 (file)
@@ -30,6 +30,9 @@
 #include "xprintf_domain.h"
 #include "xprintf_private.h"
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpointer-bool-conversion"
+
 void
 free_printf_comp(printf_comp_t pc)
 {
@@ -84,3 +87,5 @@ new_printf_comp(printf_domain_t restrict domain, locale_t loc, const char * rest
     }
     return pc;
 }
+#pragma clang diagnostic pop
+
index 70c8d32f93dc0098d71289fa9c02ad20524a60f0..468f7adb7aeb19274b87aad7263d6303e3e20ce1 100644 (file)
@@ -28,6 +28,9 @@
 #include "xprintf_domain.h"
 #include "xprintf_private.h"
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpointer-bool-conversion"
+
 /* These are flag characters and can never be used as conversion specifiers */
 static const char _printf_tbl_flags[] = "#$'*+,-.0123456789:;L_hjlqtvz";
 
@@ -243,3 +246,5 @@ register_printf_domain_render_std(printf_domain_t d, const char *specs)
     }
     return (0);
 }
+#pragma clang diagnostic pop
+
index 9e831c06ea6b3ba537648e2d77ccc45f17edf8ae..2875212927b5a9cf4cb0c862eb5bf9159c18a1ff 100644 (file)
@@ -29,6 +29,9 @@
 #include <local.h>
 #include <xprintf_private.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpointer-bool-conversion"
+
 int
 asxprintf_exec(char ** __restrict ret,
     printf_comp_t __restrict pc, ...)
@@ -175,3 +178,4 @@ vxprintf_exec(printf_comp_t __restrict pc, va_list ap)
 
     return __xvprintf(pc, NULL, stdout, NULL, NULL, ap);
 }
+#pragma clang diagnostic pop
index 386572c4d429e1cbf5c5120785ff42e649b2aeb5..8758cf885f34b1565bfb814760cca360a30e7744 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)abort.c    8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -155,3 +158,4 @@ abort_report_np(const char *fmt, ...)
                CRSetCrashLogMessage(fmt); /* the format string is better than nothing */
        abort();
 }
+#pragma clang diagnostic pop
index 99f311f67f689720ed787192d89864d1bf771d3e..45b62ebda6d0a9c99a3058dd0dabde0db01d144c 100644 (file)
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wimplicit-function-declaration"
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+#pragma clang diagnostic ignored "-Winvalid-pp-token"
+#pragma clang diagnostic ignored "-Wint-conversion"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)atexit.c   8.2 (Berkeley) 7/3/94";
 #endif /* LIBC_SCCS and not lint */
@@ -324,3 +330,4 @@ __cxa_thread_atexit(void(*f)(void*), void* arg)
     _tlv_atexit(f, arg);
 }
 #endif
+#pragma clang diagnostic pop
index ba66bc6644ff357674b69163510e8ec001a4c9e8..03d8c093882bc073ee7d31d8b0f5eed7ad35544b 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)exit.c     8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -63,3 +66,4 @@ exit(int status)
                (*__cleanup)();
        __exit(status);
 }
+#pragma clang diagnostic pop
index 0a088cf57a943de0175c13a666b968220896abd8..c41865b24421c4e6fe2064af2fc8ec9f7b716fc9 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)heapsort.c 8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -179,3 +182,4 @@ heapsort(vbase, nmemb, size, compar)
        free(k);
        return (0);
 }
+#pragma clang diagnostic pop
index 2f0b26f2b4a3c3d3f5e466fb82579f55e495da8c..42388ab065126b32831a055fbe11f7a37bccc077 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)heapsort.c 8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -180,3 +183,4 @@ __heapsort_r(vbase, nmemb, size, thunk, compar)
        free(k);
        return (0);
 }
+#pragma clang diagnostic pop
index 319f307d58d3e3433caaaefaef5fbc7a58ded111..6a93bc1486ec4a6654a2fafbd310f0584dce0839 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)merge.c    8.2 (Berkeley) 2/14/94";
 #endif /* LIBC_SCCS and not lint */
@@ -350,3 +353,4 @@ insertionsort(a, n, size, cmp)
                        swap(u, t);
                }
 }
+#pragma clang diagnostic pop
index 6caebaa842d5692442b92058a49ef5e7a92cb7c7..e43791095545a37364076488d19c6cfc144940d5 100644 (file)
@@ -30,6 +30,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)merge.c    8.2 (Berkeley) 2/14/94";
 #endif /* LIBC_SCCS and not lint */
@@ -350,3 +353,4 @@ insertionsort(a, n, size, cmp)
                        swap(u, t);
                }
 }
+#pragma clang diagnostic push
index 60cacbd9a13f945ea82604d6d8162a20f970fd19..1d361b6953752ac2e9317450e080544d0a3f0484 100644 (file)
@@ -67,6 +67,9 @@
  *
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strhash.c,v 1.10 2002/03/22 21:53:10 obrien Exp $");
 
@@ -404,3 +407,4 @@ hash_stats(hash_table *table, int verbose)
     }
     return;
 }
+#pragma clang diagnostic pop
index b4e96eff751e1bb610d9fd0c3c1568d68392647d..8ab1ecac15de70315b66eccb1f1ceec9edd6f3b9 100644 (file)
@@ -27,6 +27,9 @@
  * SUCH DAMAGE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)system.c   8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
@@ -156,3 +159,5 @@ __system(command)
 
 __weak_reference(__system, system);
 __weak_reference(__system, _system);
+
+#pragma clang diagnostic pop
index 734070b5dcdc0aa2fee72c02c2a8523810ac9486..9645c975d4df778ac03b94932ce112223a8d45c0 100644 (file)
@@ -1,11 +1,17 @@
 #include <stdlib.h>
 #include <Block_private.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wimplicit-function-declaration"
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+#pragma clang diagnostic ignored "-Wint-conversion"
+
 typedef int cmp_t(const void *, const void *);
 
 void
 qsort_b(void *base, size_t nel, size_t width, cmp_t ^cmp_b)
 {
-    void *cmp_f = ((struct Block_layout *)cmp_b)->invoke;
+       void *cmp_f = ((struct Block_layout *)cmp_b)->invoke;
        qsort_r(base, nel, width, cmp_b, (void*)cmp_f);
 }
+#pragma clang diagnostic pop
index 350ee544cc984cad6799e40ecc46b9533f3a6554..8d51ae066894bd171718ec736823081c94cc417d 100644 (file)
@@ -3,6 +3,9 @@
 ** 1996-06-05 by Arthur David Olson.
 */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+
 #include <sys/cdefs.h>
 #ifndef lint
 #ifndef NOID
@@ -67,3 +70,4 @@ const time_t  time0;
        return -(double) ((unsigned long) time0 +
                (unsigned long) (-(time1 + 1)) + 1);
 }
+#pragma clang diagnostic pop
index 6c7bd19bb69727bcafbb21f423ab4094cc9df9d3..ab37c66b696c4b52efc8fdc32fe59e257aad0c20 100644 (file)
@@ -3,6 +3,9 @@
 ** 1996-06-05 by Arthur David Olson.
 */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+
 #include <sys/cdefs.h>
 #ifndef lint
 #ifndef NOID
@@ -184,6 +187,7 @@ struct rule {
 typedef struct {
        int token;
        int is_set;
+       int null_bootstrap;
 } notify_tz_t;
 
 #define NOTIFY_TZ_NAME         "com.apple.system.timezone"
@@ -378,8 +382,8 @@ __private_extern__ long             __darwin_altzone = 0;
 }
 #endif /* NOTIFY_TZ_LOG */
 
-static notify_tz_t     gmt_notify = {-1, 0};
-static notify_tz_t     lcl_notify = {-1, 0};
+static notify_tz_t     gmt_notify = {-1, 0, 0};
+static notify_tz_t     lcl_notify = {-1, 0, 0};
 static const char notify_tz_name[] = NOTIFY_TZ_NAME;
 #endif /* NOTIFY_TZ */
 
@@ -515,6 +519,34 @@ settzname(void)
 }
 
 #ifdef NOTIFY_TZ
+static int
+do_null_bootstrap_check(notify_tz_t *p)
+{
+       /*
+        * If we're running in a null bootstrap context (e.g. the bootstrap server),
+        * we will not be able to contact the notify server. In this case we want to
+        * avoid opening /etc/localtime every time the process does a asctime_r(3)
+        * or similar. But we have to do this once to get the right time zone.
+        *
+        * So first time through, we set a bit to indicate that we're in the null
+        * bootstrap context. The second time through, we force the "set" bit in the
+        * notify_tz_t structure to -1 and avoid the path where it can be set to
+        * zero (which would trigger opening and reloading the timezone file).
+        */
+       if (bootstrap_port != MACH_PORT_NULL) {
+               return -1;
+       }
+
+       if (!p->null_bootstrap) {
+               p->null_bootstrap = 1;
+               p->is_set = 0;
+               return -1;
+       }
+
+       p->is_set = -1;
+       return 0;
+}
+
 static void
 notify_check_tz(notify_tz_t *p)
 {
@@ -523,6 +555,9 @@ notify_check_tz(notify_tz_t *p)
 
        if (p->token < 0)
                return;
+       if (do_null_bootstrap_check(p) == 0) {
+               return;
+       }
        nstat = notify_check(p->token, &ncheck);
        if (nstat || ncheck) {
                p->is_set = 0;
@@ -544,6 +579,10 @@ notify_register_tz(char *file, notify_tz_t *p)
        unsigned int nstat;
        int ncheck;
 
+       if (do_null_bootstrap_check(p) == 0) {
+               return;
+       }
+
        /*----------------------------------------------------------------
         * Since we don't record the last time zone filename, just cancel
         * (which should remove the file monitor) and setup from scratch
@@ -2774,3 +2813,4 @@ posix2time(time_t t)
 
 #endif /* defined STD_INSPIRED */
 #endif /* !BUILDING_VARIANT */
+#pragma clang diagnostic pop
index ccf1d077670a509a371348328a181e4e0ec836c0..0300e2b45ba8af4d66ff4d0fc58d28bfce0bf8f9 100644 (file)
@@ -15,6 +15,9 @@
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+
 #if 0
 static const char      elsieid[] = "@(#)strftime.3     8.3";
 /*
@@ -657,3 +660,4 @@ locale_t            loc;
        return pt;
 }
 #endif /* !BUILDING_VARIANT */
+#pragma clang diagnostic pop
diff --git a/string/FreeBSD/index.c b/string/FreeBSD/index.c
deleted file mode 100644 (file)
index eab30b7..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)index.c    8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/index.c,v 1.8 2007/01/09 00:28:12 imp Exp $");
-
-#include <stddef.h>
-
-#ifdef STRCHR
-#include <string.h>
-
-char *
-strchr
-#else
-#include <strings.h>
-
-char *
-index
-#endif
-(const char *p, int ch)
-{
-       char c;
-
-       c = ch;
-       for (;; ++p) {
-               if (*p == c)
-                       return ((char *)p);
-               if (*p == '\0')
-                       return (NULL);
-       }
-       /* NOTREACHED */
-}
diff --git a/string/FreeBSD/strlen.c b/string/FreeBSD/strlen.c
deleted file mode 100644 (file)
index 66c9c6c..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*-
- * Copyright (c) 2009 Xin LI <delphij@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/strlen.c,v 1.7 2009/01/26 07:31:28 delphij Exp $");
-
-#include <limits.h>
-#include <sys/types.h>
-#include <string.h>
-
-/*
- * Portable strlen() for 32-bit and 64-bit systems.
- *
- * Rationale: it is generally much more efficient to do word length
- * operations and avoid branches on modern computer systems, as
- * compared to byte-length operations with a lot of branches.
- *
- * The expression:
- *
- *     ((x - 0x01....01) & ~x & 0x80....80)
- *
- * would evaluate to a non-zero value iff any of the bytes in the
- * original word is zero.  However, we can further reduce ~1/3 of
- * time if we consider that strlen() usually operate on 7-bit ASCII
- * by employing the following expression, which allows false positive
- * when high bit of 1 and use the tail case to catch these case:
- *
- *     ((x - 0x01....01) & 0x80....80)
- *
- * This is more than 5.2 times as fast as the raw implementation on
- * Intel T7300 under long mode for strings longer than word length.
- */
-
-/* Magic numbers for the algorithm */
-#if LONG_BIT == 32
-static const unsigned long mask01 = 0x01010101;
-static const unsigned long mask80 = 0x80808080;
-#elif LONG_BIT == 64
-static const unsigned long mask01 = 0x0101010101010101;
-static const unsigned long mask80 = 0x8080808080808080;
-#else
-#error Unsupported word size
-#endif
-
-#define        LONGPTR_MASK (sizeof(long) - 1)
-
-/*
- * Helper macro to return string length if we caught the zero
- * byte.
- */
-#define testbyte(x)                            \
-       do {                                    \
-               if (p[x] == '\0')               \
-                   return (p - str + x);       \
-       } while (0)
-
-size_t
-strlen(const char *str)
-{
-       const char *p;
-       const unsigned long *lp;
-
-       /* Skip the first few bytes until we have an aligned p */
-       for (p = str; (uintptr_t)p & LONGPTR_MASK; p++)
-           if (*p == '\0')
-               return (p - str);
-
-       /* Scan the rest of the string using word sized operation */
-       for (lp = (const unsigned long *)p; ; lp++)
-           if ((*lp - mask01) & mask80) {
-               p = (const char *)(lp);
-               testbyte(0);
-               testbyte(1);
-               testbyte(2);
-               testbyte(3);
-#if (LONG_BIT >= 64)
-               testbyte(4);
-               testbyte(5);
-               testbyte(6);
-               testbyte(7);
-#endif
-           }
-
-       /* NOTREACHED */
-       return (0);
-}
-
diff --git a/string/FreeBSD/strnlen.c b/string/FreeBSD/strnlen.c
deleted file mode 100644 (file)
index 06a47a4..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/strnlen.c,v 1.1 2009/02/28 06:00:58 das Exp $");
-
-#include <string.h>
-
-size_t
-strnlen(const char *s, size_t maxlen)
-{
-       size_t len;
-
-       for (len = 0; len < maxlen; len++, s++) {
-               if (!*s)
-                       break;
-       }
-       return (len);
-}
diff --git a/string/FreeBSD/strstr.c b/string/FreeBSD/strstr.c
deleted file mode 100644 (file)
index 030db2b..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *     The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strstr.c   8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/string/strstr.c,v 1.6 2009/02/03 17:58:20 danger Exp $");
-
-#include <string.h>
-
-/*
- * Find the first occurrence of find in s.
- */
-char *
-strstr(const char *s, const char *find)
-{
-       char c, sc;
-       size_t len;
-
-       if ((c = *find++) != '\0') {
-               len = strlen(find);
-               do {
-                       do {
-                               if ((sc = *s++) == '\0')
-                                       return (NULL);
-                       } while (sc != c);
-               } while (strncmp(s, find, len) != 0);
-               s--;
-       }
-       return ((char *)s);
-}
diff --git a/string/strcpy.c b/string/strcpy.c
deleted file mode 100644 (file)
index dda3813..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2011 Apple, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <string.h>
-
-char *
-strcpy(char * restrict dst, const char * restrict src) {
-       const size_t length = strlen(src);
-    //  The stpcpy() and strcpy() functions copy the string src to dst
-    //  (including the terminating '\0' character).
-    memcpy(dst, src, length+1);
-    //  The strcpy() and strncpy() functions return dst.
-    return dst;
-}
diff --git a/string/strlcat.c b/string/strlcat.c
deleted file mode 100644 (file)
index 4a79281..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2011 Apple, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <strings.h>
-
-size_t
-strlcat(char * restrict dst, const char * restrict src, size_t maxlen) {
-    const size_t srclen = strlen(src);
-    const size_t dstlen = strnlen(dst, maxlen);
-    if (dstlen == maxlen) return maxlen+srclen;
-    if (srclen < maxlen-dstlen) {
-        memcpy(dst+dstlen, src, srclen+1);
-    } else {
-        memcpy(dst+dstlen, src, maxlen-dstlen-1);
-        dst[maxlen-1] = '\0';
-    }
-    return dstlen + srclen;
-}
diff --git a/string/strlcpy.c b/string/strlcpy.c
deleted file mode 100644 (file)
index 763d309..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2011 Apple, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <strings.h>
-
-size_t
-strlcpy(char * restrict dst, const char * restrict src, size_t maxlen) {
-    const size_t srclen = strlen(src);
-    if (srclen < maxlen) {
-        memcpy(dst, src, srclen+1);
-    } else if (maxlen != 0) {
-        memcpy(dst, src, maxlen-1);
-        dst[maxlen-1] = '\0';
-    }
-    return srclen;
-}
diff --git a/string/strncpy.c b/string/strncpy.c
deleted file mode 100644 (file)
index 5db7554..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2011 Apple, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <string.h>
-
-char *
-strncpy(char * restrict dst, const char * restrict src, size_t maxlen) {
-    const size_t srclen = strnlen(src, maxlen);
-    if (srclen < maxlen) {
-        //  The stpncpy() and strncpy() functions copy at most maxlen
-        //  characters from src into dst.
-        memcpy(dst, src, srclen);
-        //  If src is less than maxlen characters long, the remainder
-        //  of dst is filled with '\0' characters.
-        memset(dst+srclen, 0, maxlen-srclen);
-    } else {
-        //  Otherwise, dst is not terminated.
-        memcpy(dst, src, maxlen);
-    }
-    //  The strcpy() and strncpy() functions return dst.
-    return dst;
-}
index 9311b0d9b5947e7f023b678f9fc9a508cfa70970..596fab33e7b955b3ea57e20007bf3cdd43daaf80 100644 (file)
@@ -26,6 +26,9 @@
 #include <TargetConditionals.h>
 #include <CrashReporterClient.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 extern void _arc4_fork_child();
 extern void _init_clock_port(void);
 extern void __environ_lock_fork_child();
@@ -40,3 +43,4 @@ _libc_fork_child(void)
        _init_clock_port();
        __environ_lock_fork_child();
 }
+#pragma clang diagnostic pop
index 72d181151f40df8feb123b950ecf6a986f7f53ee..a81d20c7e2b09c696c5d26817cd30639f64861e1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2017 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
-/*
- * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
- *
- *     @(#)sigaction.c 1.0
- */
 
 #include <CrashReporterClient.h>
 #include <stdlib.h>
 #include <sys/signal.h>
 #include <errno.h>
 
-/*
- *     Intercept the sigaction syscall and use our signal trampoline
- *     as the signal handler instead.  The code here is derived
- *     from sigvec in sys/kern_sig.c.
- */
-extern int __sigaction (int, struct __sigaction * __restrict, struct sigaction * __restrict);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
+extern int __platform_sigaction (int sig,
+               const struct sigaction * __restrict nsv,
+               struct sigaction * __restrict osv);
 
 int
-sigaction (int sig, const struct sigaction * __restrict nsv, struct sigaction * __restrict osv)
+sigaction (int sig, const struct sigaction * __restrict nsv,
+               struct sigaction * __restrict osv)
 {
-       extern void _sigtramp();
-       struct __sigaction sa;
-       struct __sigaction *sap;
-       int ret;
-
-       if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) {
-               errno = EINVAL;
-               return (-1);
-       }
-       sap = (struct __sigaction *)0;
-       if (nsv) {
-               sa.sa_handler = nsv->sa_handler;
-               sa.sa_tramp = _sigtramp;
-               sa.sa_mask = nsv->sa_mask;
-               sa.sa_flags = nsv->sa_flags;    
-               sap = &sa;
-       }
-       ret = __sigaction(sig, sap, osv);
+       int ret = __platform_sigaction(sig, nsv, osv);
 #ifdef FEATURE_SIGNAL_RESTRICTION
        // Note: The "sig != 0" here is to force the compiler to maintain that "sig"
        // is live, and in a register, after __sigaction so it is visible in the
@@ -87,3 +66,4 @@ _sigaction_nobind (sig, nsv, osv)
 }
 #endif
 
+#pragma clang diagnostic pop
index 772d4f957a349e3e1d3cb1b01e08397ccb37d342..91a234f62c622d3c5722c649fa7ed69a3555b00a 100644 (file)
@@ -16,7 +16,7 @@ void os_crash_function(const char *message) {
        }
 }
 
-T_DECL(os_crash_sanity, "sanity check for os_crash")
+T_DECL(os_crash_sanity_legacy, "sanity check for os_crash")
 {
        expected_message = "My AWESOME assertion message.";
        os_crash(expected_message);
diff --git a/tests/backtrace.c b/tests/backtrace.c
new file mode 100644 (file)
index 0000000..da91023
--- /dev/null
@@ -0,0 +1,151 @@
+#include <darwintest.h>
+#include <dlfcn.h>
+#include <execinfo.h>
+#include <mach-o/dyld_priv.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <uuid/uuid.h>
+
+
+#define MAX_FRAMES 32
+static const int expected_nframes = 20;
+
+static void *observed_bt[MAX_FRAMES] = {};
+static int observed_nframes = 0;
+static unsigned int save_fp_at_nframes = 0;
+static void *save_fp = NULL;
+
+static int __attribute__((noinline,not_tail_called,disable_tail_calls))
+recurse_a(unsigned int frames);
+static int __attribute__((noinline,not_tail_called,disable_tail_calls))
+recurse_b(unsigned int frames);
+
+static int __attribute__((noinline,not_tail_called,disable_tail_calls))
+recurse_a(unsigned int frames)
+{
+       if (frames == 1) {
+               if (save_fp_at_nframes > 0) {
+                       observed_nframes = backtrace_from_fp(save_fp, observed_bt,
+                                       MAX_FRAMES);
+               } else {
+                       observed_nframes = backtrace(observed_bt, MAX_FRAMES);
+               }
+               return 0;
+       } else if (frames == save_fp_at_nframes) {
+               save_fp = __builtin_frame_address(0);
+       }
+
+       return recurse_b(frames - 1);
+}
+
+static int __attribute__((noinline,not_tail_called,disable_tail_calls))
+recurse_b(unsigned int frames)
+{
+       if (frames == 1) {
+               if (save_fp_at_nframes > 0) {
+                       observed_nframes = backtrace_from_fp(save_fp, observed_bt,
+                                       MAX_FRAMES);
+               } else {
+                       observed_nframes = backtrace(observed_bt, MAX_FRAMES);
+               }
+               return 0;
+       } else if (frames == save_fp_at_nframes) {
+               save_fp = __builtin_frame_address(0);
+       }
+
+       return recurse_a(frames - 1);
+}
+
+static void __attribute__((noinline,not_tail_called,disable_tail_calls))
+setup_and_backtrace(unsigned int nframes, unsigned int skip_nframes)
+{
+       save_fp_at_nframes = skip_nframes ? skip_nframes - 1 : 0;
+       recurse_a(nframes - 1);
+}
+
+static bool
+check_for_setup(int i, struct dl_info *info)
+{
+       int ret = dladdr(observed_bt[i], info);
+       T_QUIET; T_ASSERT_POSIX_SUCCESS(ret, "dladdr(%p)", observed_bt[i]);
+       void *setup_fp = (void *)&setup_and_backtrace;
+       return info->dli_saddr == setup_fp;
+}
+
+static void __attribute__((noinline))
+expect_backtrace(void)
+{
+       void *recurse_a_fp = (void *)&recurse_a;
+       void *recurse_b_fp = (void *)&recurse_b;
+
+       void *tmp_backtrace[MAX_FRAMES];
+       const int observed_existing_nframes = backtrace(tmp_backtrace, MAX_FRAMES);
+
+       T_EXPECT_EQ(expected_nframes,
+                       observed_nframes - observed_existing_nframes,
+                       "number of frames traced matches");
+       bool expect_a = true;
+       bool found_setup = false;
+
+       for (int i = 0; i < observed_nframes; i++) {
+               struct dl_info info;
+               if (check_for_setup(i, &info)) {
+                       found_setup = true;
+                       break;
+               }
+
+               void *expected_saddr = expect_a ? recurse_a_fp : recurse_b_fp;
+               void *observed_saddr = info.dli_saddr;
+               T_EXPECT_GE(observed_saddr, expected_saddr,
+                               "frame %d (%p) matches", i, observed_bt[i]);
+               expect_a = !expect_a;
+       }
+
+       T_EXPECT_TRUE(found_setup, "should have found the setup frame");
+}
+
+T_DECL(backtrace, "ensure backtrace(3) gives the correct backtrace")
+{
+       setup_and_backtrace(expected_nframes, 0);
+       expect_backtrace();
+}
+
+T_DECL(backtrace_from_fp,
+               "ensure backtrace_from_fp(3) starts from the correct frame")
+{
+       const int skip_nframes = 5;
+       setup_and_backtrace(expected_nframes + skip_nframes, skip_nframes);
+       expect_backtrace();
+}
+
+T_DECL(backtrace_image_offsets,
+               "ensure backtrace_image_offsets(3) provides valid UUIDs and offsets")
+{
+       setup_and_backtrace(expected_nframes, 0);
+       struct image_offset imgoffs[observed_nframes];
+       backtrace_image_offsets(observed_bt, imgoffs, observed_nframes);
+
+       bool found_setup = false;
+
+       for (int i = 0; i < observed_nframes; i++) {
+               struct dl_info info;
+               if (check_for_setup(i, &info)) {
+                       found_setup = true;
+                       break;
+               }
+
+               const struct mach_header *mh =
+                               dyld_image_header_containing_address(observed_bt[i]);
+
+               uuid_t expected_uuid;
+               bool got_uuid = _dyld_get_image_uuid(mh, expected_uuid);
+               T_QUIET; T_ASSERT_TRUE(got_uuid, "got UUID for Mach-O header");
+
+               T_EXPECT_EQ(uuid_compare(expected_uuid, imgoffs[i].uuid), 0,
+                               "frame %d's UUID matches", i);
+               T_EXPECT_EQ((uintptr_t)observed_bt[i] - (uintptr_t)info.dli_fbase,
+                               (uintptr_t)imgoffs[i].offset, "frame %d's offset matches", i);
+       }
+
+       T_EXPECT_TRUE(found_setup, "should have found the setup frame");
+}
diff --git a/tests/envbuf.c b/tests/envbuf.c
new file mode 100644 (file)
index 0000000..1c6cd96
--- /dev/null
@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <darwintest.h>
+#include "darwintest_utils.h"
+
+#define IS_FLAG_SET(fp, flag) ((fp)->_flags & (flag))
+#define BUFFER_SIZE(fp) ((fp)->_bf._size)
+
+static FILE* test_setup(void)
+{
+       char* temp_dir;
+       temp_dir = dt_tmpdir();
+       T_LOG("Temp Dir: %s\n", temp_dir);
+
+       char temp_path[128];
+       snprintf(temp_path, sizeof(temp_path), "%s/%s", temp_dir, "test_file");
+       T_LOG("Using Temporary File: %s\n", temp_path);
+       FILE* fp = fopen(temp_path, "w");
+       T_LOG("File opened: %d\n", fileno(fp));
+       T_ASSERT_EQ(fileno(fp), 3, "file descriptor matches");
+       // Need to prime the buffer
+       fprintf(fp, "Test\n");
+
+       return fp;
+}
+
+T_DECL(envbuf_PR_38637477_unbuf_all, "Forcing unbuffered through environment variable", T_META_ENVVAR("STDBUF=U"))
+{
+       FILE* fp = test_setup();
+
+       T_EXPECT_TRUE(IS_FLAG_SET(fp, __SNBF), "unbuffered");
+       T_EXPECT_FALSE(IS_FLAG_SET(fp, __SLBF), "not line buffered");
+       T_EXPECT_EQ(BUFFER_SIZE(fp), 1, "buffer size 1");
+}
+
+
+T_DECL(envbuf_PR_38637477_line_all, "Forcing line buffering through environment variable", T_META_ENVVAR("STDBUF=L16"))
+{
+       FILE* fp = test_setup();
+
+       T_EXPECT_FALSE(IS_FLAG_SET(fp, __SNBF), "not unbuffered");
+       T_EXPECT_TRUE(IS_FLAG_SET(fp, __SLBF), "line buffered");
+       T_EXPECT_EQ(BUFFER_SIZE(fp), 16, "buffer size 16");
+}
+
+T_DECL(envbuf_PR_38637477_full_all, "Forcing full buffering through environment variable", T_META_ENVVAR("STDBUF=F16"))
+{
+       FILE* fp = test_setup();
+
+       T_EXPECT_FALSE(IS_FLAG_SET(fp, __SNBF), "not unbuffered");
+       T_EXPECT_FALSE(IS_FLAG_SET(fp, __SLBF), "not line buffered");
+       T_EXPECT_EQ(BUFFER_SIZE(fp), 16, "buffer size 16");
+}
+
+T_DECL(envbuf_PR_38637477_unbuf_stdout, "Forcing unbuffered through environment variable for stdout", T_META_ENVVAR("STDBUF1=U"))
+{
+
+       fprintf(stdout, "Test\n");
+
+       T_EXPECT_TRUE(IS_FLAG_SET(stdout, __SNBF), "unbuffered");
+       T_EXPECT_FALSE(IS_FLAG_SET(stdout, __SLBF), "not linebuffered");
+       T_EXPECT_EQ(BUFFER_SIZE(stdout), 1, "buffer size 1");
+}
+
+T_DECL(envbuf_PR_38637477_line_stdout, "Forcing line buffering through environment variable for stdout", T_META_ENVVAR("STDBUF1=L32"))
+{
+
+       fprintf(stdout, "Test\n");
+
+       T_EXPECT_FALSE(IS_FLAG_SET(stdout, __SNBF), "not unbuffered");
+       T_EXPECT_TRUE(IS_FLAG_SET(stdout, __SLBF), "line buffered");
+       T_EXPECT_EQ(BUFFER_SIZE(stdout), 32, "buffer size 32");
+}
+
+T_DECL(envbuf_PR_38637477_full_stdout, "Forcing full buffering through environment variable for stdout", T_META_ENVVAR("STDBUF1=F16"))
+{
+
+       fprintf(stdout, "Test\n");
+
+       T_EXPECT_FALSE(IS_FLAG_SET(stdout, __SNBF), "not unbuffered");
+       T_EXPECT_FALSE(IS_FLAG_SET(stdout, __SLBF), "not line buffered");
+       T_EXPECT_EQ(BUFFER_SIZE(stdout), 16, "buffer size 16");
+}
index 14c10cbdb47b20d77a2f1a0034bbec0bae6c2709..160e93549e156b8ce187013d87321e254aaa5da6 100644 (file)
@@ -2,6 +2,9 @@
 #include <unistd.h>
 #include <signal.h>
 #include <setjmp.h>
+#if __has_feature(ptrauth_calls) && !defined(__OPEN_SOURCE)
+#include <ptrauth.h>
+#endif
 
 #include <darwintest.h>
 
@@ -35,6 +38,9 @@ T_DECL(nxheap, "Non-executable heap", T_META_CHECK_LEAKS(false), T_META_ASROOT(t
        T_QUIET; T_ASSERT_NOTNULL((heap = malloc(1)), NULL);
 
        *heap = (char)0xc3; // retq
+#if __has_feature(ptrauth_calls) && !defined(__OPEN_SOURCE)
+       heap = ptrauth_sign_unauthenticated(heap, ptrauth_key_function_pointer, 0);
+#endif
        ((void (*)(void))heap)(); // call *%eax
 
        T_FAIL("SIGBUS");
diff --git a/tests/open_memstream.c b/tests/open_memstream.c
new file mode 100644 (file)
index 0000000..4123a04
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <darwintest.h>
+#include <darwintest_perf.h>
+
+static void
+perf_fixed_size(size_t size_per_write)
+{
+       dt_stat_time_t latency = dt_stat_time_create("write_latency",
+                       "adding %zu bytes to a memstream", size_per_write);
+       dt_stat_set_variable_d(latency, "bytes", (double)size_per_write);
+       char *src = calloc(1, size_per_write);
+       T_QUIET; T_ASSERT_NOTNULL(src, "allocated source buffer");
+
+       while (!dt_stat_stable(latency)) {
+               char *buf = NULL;
+               size_t size = 0;
+
+               FILE *victim = open_memstream(&buf, &size);
+               T_QUIET; T_WITH_ERRNO; T_ASSERT_NOTNULL(victim, "opened memstream");
+
+               T_STAT_MEASURE_BATCH(latency) {
+                       (void)fwrite(src, size_per_write, 1, victim);
+               }
+
+               fclose(victim);
+               T_QUIET; T_ASSERT_NOTNULL(buf, "buffer was set by open_memstream");
+               T_QUIET; T_ASSERT_GE(size, size_per_write,
+                               "memstream added non-zero bytes");
+
+               free(buf);
+       }
+
+       free(src);
+       dt_stat_finalize(latency);
+}
+
+T_DECL(perf_open_memstream, "measure the performance of open_memstream")
+{
+       size_t sizes[] = { 1, 8, 16, 64, 1024, 2048, 4096, 16 * 1024 };
+       for (size_t i = 0; i < sizeof(sizes) / sizeof(sizes[0]); i++) {
+               perf_fixed_size(sizes[i]);
+       }
+}
diff --git a/tests/os_simple_hash.c b/tests/os_simple_hash.c
new file mode 100644 (file)
index 0000000..ae1bc40
--- /dev/null
@@ -0,0 +1,17 @@
+#include <darwintest.h>
+#include <stdlib.h>
+#include <os/stdlib.h>
+
+T_DECL(os_simple_hash, "sanity check of os_simple_hash",
+               T_META_ALL_VALID_ARCHS(true))
+{
+       const char * string =
+                       "We made the buttons on the screen look so good you'll want to lick them.";
+       uint64_t hashval = os_simple_hash_string(string);
+       T_EXPECT_NE(hashval, 0ULL, "usually should get a non-0 hash value");
+
+       char buf[1024];
+       arc4random_buf(buf, sizeof(buf));
+       hashval = os_simple_hash(buf, sizeof(buf));
+       T_EXPECT_NE(hashval, 0ULL, "usually should get a non-0 hash value");
+}
index 8da0d671cf03b5f3f0b9c4597bbf2732b6a58d84..56e03721fcdcb411501ae4cfacaee816f1fcdfb6 100644 (file)
@@ -35,6 +35,9 @@
 #include <sys/param.h>
 #include <sys/ioctl.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wstrict-prototypes"
+
 int login_tty(fd)
        int fd;
 {
@@ -48,3 +51,4 @@ int login_tty(fd)
                (void) close(fd);
        return (0);
 }
+#pragma clang diagnostic pop
index 665fec991ea63faf7ed0ad93ceaa62631cf63ef3..428d41d01ec5ff535972fabecff39e9d7056b7cd 100644 (file)
@@ -64,6 +64,9 @@
 #include <unistd.h>
 #include <string.h>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconstant-conversion"
+
 int
 logout(char *line)
 {
@@ -103,3 +106,4 @@ logout(char *line)
        UTMPX_UNLOCK(def_utx);
        return 1;
 }
+#pragma clang diagnostic pop
diff --git a/x86_64/string/strcpy.s b/x86_64/string/strcpy.s
deleted file mode 100644 (file)
index 74cf9db..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2012 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the License
- * may not be used to create, or enable the creation or redistribution of,
- * unlawful or unlicensed copies of an Apple operating system, or to
- * circumvent, violate, or enable the circumvention or violation of, any
- * terms of an Apple operating system software license agreement.
- * 
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
- *
- * This file implements strcpy( ) for the x86_64 architecture.
- */
-
-.globl _strcpy
-
-/*****************************************************************************
- *  Macros                                                                   *
- *****************************************************************************/
-
-.macro EstablishFrame
-       push      %rbp
-       mov       %rsp,      %rbp
-.endm
-
-.macro ClearFrameAndReturn
-       pop       %rbp
-       ret
-.endm
-
-/*****************************************************************************
- *  Entrypoint                                                               *
- *****************************************************************************/
-
-.text
-.align 5
-_strcpy:
-//     char *strcpy(char * restrict d, const char * restrict s);
-//
-//     copies the string s to d, and returns d.  We look for NUL bytes using
-//     pcmpeqb on 16-byte aligned blocks.  Although this may read past the
-//     end of the string, because all access is aligned, it will never
-//     read past the end of the string across a page boundary, or even
-//     accross a cacheline.
-       EstablishFrame
-       mov       %rsi,      %rcx
-
-//     Load the 16-byte block containing the first byte of the string, and
-//     compare each byte to zero.  If any NUL bytes are present in this
-//     block, the corresponding *bit* in esi will be set to 1.
-       and       $-16,      %rsi
-       pxor      %xmm0,     %xmm0
-       pcmpeqb  (%rsi),     %xmm0
-       pmovmskb  %xmm0,     %eax
-
-//     The 16 bytes that we checked for NUL included some bytes preceeding
-//     the start of the string, if s is not 16-byte aligned.  We create a
-//     mask based on the alignment of s which covers only those bits
-//     corresponding to bytes that do not preceed s, and check for NULs
-//     only in those bits.  If we find one, the string is too small to use
-//  a vector copy, so jump to dedicated small-buffer implementation.
-       and       $0xf,      %rcx
-       or        $-1,       %rdx
-       shl       %cl,       %rdx
-       and       %edx,      %eax
-       jnz       L_strcpyGPR
-
-//     Check the next 16-byte block for NUL.  If none are found, that guarantees
-//     that the string is at least 16 bytes long, which means that we can use a
-//     single unaligned vector copy to handle any edging at the start of the
-//     string.  If instead a NUL is found, fall into the byte-by-byte copy loop.
-       movdqa 16(%rsi),     %xmm1
-       pxor      %xmm0,     %xmm0
-       pcmpeqb   %xmm1,     %xmm0
-       pmovmskb  %xmm0,     %edx
-       test      %edx,      %edx
-       jz        L_strcpySSE
-
-/*****************************************************************************
- *  GPR copy implementation                                                  *
- *****************************************************************************/
-
-//     There is at least one NUL in the 32 aligned bytes containing the start
-//     of the string being copied.  We assemble a bitmap for those 32 bytes from
-//     eax and edx, then shift it right by cl to throw out any bits preceeding
-//     the start of the string.  We can then identify the position of the
-//     first NUL byte using BSF.
-       shl       $16,       %edx
-       or        %edx,      %eax
-L_strcpyGPR:
-       shr       %cl,       %eax
-       bsf       %eax,      %edx
-//     Restore the original source pointer, and copy the destination pointer
-//     to rax so that it is returned on exit.
-       add       %rcx,      %rsi
-       mov       %rdi,      %rax
-       add       $1,        %rdx
-       call      _memcpy
-       ClearFrameAndReturn
-/*
-//     At this point we simply need to copy rdx + 1 bytes from rsi to rdi.  If
-//     the length is >= 8, start by doing a word-by-word copy; otherwise, use
-//     a byte-by-byte copy loop.
-       sub       $7,        %rdx // 7 instead of 8 to account for NUL
-       jb        1f
-0:     mov      (%rsi,%rdx),%rcx
-       mov       %rcx,     (%rdi,%rdx)
-       sub       $8,        %rdx
-       jae       0b
-1:     add       $8,        %rdx
-       jz        3f
-2:     movzb  -1(%rsi,%rdx),%rcx
-       movb      %cl,    -1(%rdi,%rdx)
-       sub       $1,        %rdx
-       jnz       2b
-3:     ClearFrameAndReturn
- */
-
-/*****************************************************************************
- *  SSE copy implementation                                                  *
- *****************************************************************************/
-
-L_strcpySSE:
-//     Begin by doing a single unaligned vector copy for edging.  We no longer
-//     have the original source pointer, but we can reconstruct it as rsi + rcx.
-       movdqu   (%rsi,%rcx),%xmm0
-       movdqu    %xmm0,    (%rdi)
-//     Next copy the original destination pointer to rax so that it is returned
-//     on exit, and adjust the destination pointer to correspond to rsi.
-       mov       %rdi,      %rax
-       sub       %rcx,      %rdi
-       xor       %rcx,      %rcx
-//     Main copy loop: store the 16 bytes loaded in the previous iteration of the
-//     loop, as they are already known to not contain a NUL.  The load the next
-//     16 bytes and check for NUL.
-0:     movdqu    %xmm1,  16(%rdi,%rcx)
-       add       $16,       %rcx
-       movdqa 16(%rsi,%rcx),%xmm1
-       pxor      %xmm0,     %xmm0
-       pcmpeqb   %xmm1,     %xmm0
-       pmovmskb  %xmm0,     %edx
-       test      %edx,      %edx
-       jz        0b
-
-//     Cleanup: at least one of the bytes in the last 16 that were loaded was
-//     NUL.  The corresponding bits of dx are set, and all other bits are zero.
-//     Thus, we can use BSF to find the position of the first NUL.  Once we have
-//     this information, we use an unaligned copy that runs precisely up to this
-//     position to handle edging.
-       bsf       %edx,      %edx
-       add       %rdx,      %rcx
-       movdqu  1(%rsi,%rcx),%xmm0      // offset is 1 so that we copy the trailing
-       movdqu    %xmm0,   1(%rdi,%rcx) // NUL byte as well.
-       ClearFrameAndReturn
-
diff --git a/x86_64/string/strlen.s b/x86_64/string/strlen.s
deleted file mode 100644 (file)
index 623f39e..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2005-2012 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the License
- * may not be used to create, or enable the creation or redistribution of,
- * unlawful or unlicensed copies of an Apple operating system, or to
- * circumvent, violate, or enable the circumvention or violation of, any
- * terms of an Apple operating system software license agreement.
- * 
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
- *
- * This file implements strlen( ) for the x86_64 architecture.
- */
-
-.globl _strlen
-
-/*****************************************************************************
- *  Macros                                                                   *
- *****************************************************************************/
-
-.macro EstablishFrame
-       push      %rbp
-       mov       %rsp,      %rbp
-.endm
-
-.macro ClearFrameAndReturn
-       pop       %rbp
-       ret
-.endm
-
-/*****************************************************************************
- *  Entrypoint                                                               *
- *****************************************************************************/
-
-.text
-.align 5
-_strlen:
-//     size_t strlen(const char *s);
-//
-//     returns the length of the string s (i.e. the distance in bytes from
-//     s to the first NUL byte following s).  We look for NUL bytes using
-//     pcmpeqb on 16-byte aligned blocks.  Although this may read past the
-//     end of the string, because all access is aligned, it will never
-//     read past the end of the string across a page boundary, or even
-//     accross a cacheline.
-       EstablishFrame
-       mov       %rdi,      %rcx
-       mov       %rdi,      %rdx
-
-//     Load the 16-byte block containing the first byte of the string, and
-//     compare each byte to zero.  If any NUL bytes are present in this
-//     block, the corresponding *bit* in esi will be set to 1.
-       and       $-16,      %rdi
-       pxor      %xmm0,     %xmm0
-       pcmpeqb  (%rdi),     %xmm0
-       pmovmskb  %xmm0,     %esi
-
-//     The 16 bytes that we checked for NUL included some bytes preceeding
-//     the start of the string, if s is not 16-byte aligned.  We create a
-//     mask based on the alignment of s which covers only those bits
-//     corresponding to bytes that do not preceed s, and check for NULs
-//     only in those bits.  If we do not find one, we jump to our main
-//     search loop.
-       and       $0xf,      %rcx
-       or        $-1,       %rax
-       shl       %cl,       %rax
-       and       %eax,      %esi
-       jz        L_loop
-
-L_foundNUL:
-//     The last 16-byte block that we searched contained at least one NUL.
-//     We use bsf to identify the first NUL, and compute the distance from
-//     that byte to the start of the string.
-       bsf       %esi,      %eax
-       sub       %rdx,      %rdi
-       add       %rdi,      %rax
-       ClearFrameAndReturn
-
-.align 4
-L_loop:
-//     Main search loop: check for NUL in a 16-byte block, continuing
-//     loop until one is found.
-       add       $16,       %rdi
-       pxor      %xmm0,     %xmm0
-       pcmpeqb  (%rdi),     %xmm0
-       pmovmskb  %xmm0,     %esi
-       test      %esi,      %esi
-       jz        L_loop
-       jmp       L_foundNUL
diff --git a/x86_64/string/strncpy.s b/x86_64/string/strncpy.s
deleted file mode 100644 (file)
index 72e2bf7..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_LICENSE_HEADER_END@
- */
-
-#include <machine/cpu_capabilities.h>
-
-
-// *****************
-// * S T R N C P Y *
-// *****************
-//
-// char  *strncpy(const char *dst, const char *src, size_t n);
-//
-// We optimize the move by doing it vector parallel.  This introduces
-// a complication: if we blindly did vector load/stores until finding
-// a 0, we might get a spurious page fault by touching bytes past it.
-// To avoid this, we never do a load that crosses a page boundary,
-// and never store a byte we don't have to.
-//
-// We align the destination, because unaligned vector stores are slow.
-//
-// Recall that strncpy() zero fills the remainder of the dest buffer,
-// and does not terminate the string if its length is greater than or
-// equal to n.
-
-#define        kShort  31                      // too short to bother with vector loop
-
-        .text
-        .globl _strncpy
-
-        .align         4
-_strncpy:                              // char  *strncpy(const char *dst, const char *src, size_t n);
-       movq    %rdi,%r8        // preserve destination pointer so we can return it
-       movl    %edi,%ecx               // copy low 4 bytes of dest ptr
-       negl    %ecx
-       andl    $15,%ecx                // how many bytes to align dest ptr?
-       jnz     LCheckShortCopy         // align destination first
-       
-       
-// In order to avoid spurious page faults, we loop until nearing the source page
-// end.  Then we revert to a byte-by-byte loop for 16 bytes until the page is crossed,
-// then resume the vector loop. 
-//     %rsi = source ptr (unaligned)
-//     %rdi = dest ptr (aligned)
-//     %rdx = buffer length remaining
-
-LNextChunk:                            // NB: can drop down to here
-       movl    %esi,%eax               // copy the low 4 bytes of the source ptr
-       movl    $4096,%ecx
-       andl    $4095,%eax              // get offset into source page
-       subl    %eax,%ecx               // get #bytes remaining in source page
-       cmpq    %rdx,%rcx               // will buffer run out before the page end?
-       cmova   %rdx,%rcx               // get min(length remaining, bytes to page end)
-       shrl    $4,%ecx                 // get #chunks till end of page
-       jnz     LLoopOverChunks         // enter vector loop
-       
-// We can't use the chunk loop yet.  Check for short and empty buffers, then use byte loop.
-
-LCrossPage:                            // if buffer is large enough, cross source page
-       movl    $16,%ecx                // move 16 bytes to cross page but keep dest aligned
-LCheckShortCopy:                       // we propose to copy %ecx bytes in byte loop
-       cmpq    $(kShort),%rdx          // much left?
-       ja      LLoopOverBytes          // yes, loop over bytes then more chunks
-       movl    %edx,%ecx               // no, use the byte loop for everything
-       testl   %edx,%edx               // have we filled buffer?
-       jnz     LLoopOverBytes          // no
-       jmp     LDone
-
-
-// Loop over bytes.
-//     %rsi = source ptr
-//     %rdi = dest ptr
-//     %rdx = buffer length remaining
-//     %rcx = count of bytes to loop over (<= buffer length)
-
-       .align  4,0x90                  // align inner loops to optimize I-fetch
-LLoopOverBytes:
-       movzb   (%rsi),%eax             // get source byte
-       addq    $1,%rsi
-       subq    $1,%rdx                 // decrement length
-       movb    %al,(%rdi)              // pack into dest
-       addq    $1,%rdi
-       testl   %eax,%eax               // 0?
-       jz      LZeroBuffer             // yes, we're done copying string
-       subq    $1,%rcx                 // more to go?
-       jnz     LLoopOverBytes
-       
-       testq   %rdx,%rdx               // at end of buffer?
-       jnz     LNextChunk              // no, xfer chunks
-       jmp     LDone                   // yes
-
-
-// Loop over 16-byte chunks.
-//     %rsi = source ptr (unaligned)
-//     %rdi = dest ptr (aligned)
-//     %rdx = buffer length remaining
-//     %ecx = chunk count
-
-       .align  4,0x90                  // align inner loops to optimize I-fetch
-LLoopOverChunks:
-       movdqu  (%rsi),%xmm1            // get source
-       pxor    %xmm0,%xmm0             // get some 0s
-       addq    $16,%rsi
-       pcmpeqb %xmm1,%xmm0             // compare source to 0s
-       pmovmskb %xmm0,%eax             // get result mask for 0 check
-       testl   %eax,%eax               // any 0s?
-       jnz     LFound0                 // yes, exit loop
-       movdqa  %xmm1,(%rdi)            // no 0s so do aligned store into destination
-       addq    $16,%rdi
-       subq    $16,%rdx                // decrement length remaining
-       subl    $1,%ecx                 // more to go?
-       jnz     LLoopOverChunks
-       
-       jmp     LCrossPage              // cross page but keep dest aligned
-       
-
-// Found a zero in the vector.  Figure out where it is, and store the bytes
-// up to it.  It is possible that we should check to be sure (%rdx >= 16), and
-// just do an aligned store of %xmm1 if so.  But if we did, we'd be doing byte
-// stores into the same double quadword in bzero(), which might hit a hazard.
-// Experimentation needed.
-//     %rdi = dest ptr (aligned)
-//     %eax = result mask
-//     %rdx = buffer length remaining
-//     %xmm1 = source vector
-
-LFound0:
-       bsf     %eax,%ecx               // find first 0
-       subq    %rcx,%rdx               // decrement remaining buffer length
-       test    $8,%cl                  // 8-byte store required?
-       jz      4f                      // no
-       movq    %xmm1,(%rdi)            // pack in 8 low bytes
-       psrldq  $8,%xmm1                // then shift vector down 8 bytes
-       addq    $8,%rdi
-4:
-       test    $4,%cl                  // 4-byte store required?
-       jz      3f                      // no
-       movd    %xmm1,(%rdi)            // pack in 4 low bytes
-       psrldq  $4,%xmm1                // then shift vector down 4 bytes
-       addq    $4,%rdi
-3:
-       andl    $3,%ecx                 // more to go?
-       jz      LZeroBuffer             // no
-       movd    %xmm1,%eax              // move remainders out of vector into %eax
-1:                                     // loop on up to three bytes
-       movb    %al,(%rdi)              // pack in next byte
-       shrl    $8,%eax                 // shift next byte into position
-       addq    $1,%rdi
-       subl    $1,%ecx
-       jnz     1b
-
-// We've copied the string.  Now zero the rest of the buffer, using commpage bzero().
-//     %rdi = dest ptr
-//     %rcx = buffer length remaining
-
-LZeroBuffer:
-       movq    %rdx,%rsi               // remaining buffer size (2nd argument)
-       pushq   %r8                             // save r8 and align stack to 16B
-       call    _bzero
-       popq    %r8
-
-LDone:
-       movq    %r8,%rax                // original dest ptr is return value
-       ret
diff --git a/x86_64/string/strnlen.s b/x86_64/string/strnlen.s
deleted file mode 100644 (file)
index 8b96003..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2012 Apple Computer, Inc. All rights reserved.
- *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. The rights granted to you under the License
- * may not be used to create, or enable the creation or redistribution of,
- * unlawful or unlicensed copies of an Apple operating system, or to
- * circumvent, violate, or enable the circumvention or violation of, any
- * terms of an Apple operating system software license agreement.
- * 
- * Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
- * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
- *
- * This file implements strnlen( ) for the x86_64 architecture.
- */
-
-.globl _strnlen
-
-/*****************************************************************************
- *  Macros                                                                   *
- *****************************************************************************/
-
-.macro EstablishFrame
-       push      %rbp
-       mov       %rsp,      %rbp
-.endm
-
-.macro ClearFrameAndReturn
-       pop       %rbp
-       ret
-.endm
-
-/*****************************************************************************
- *  Entrypoint                                                               *
- *****************************************************************************/
-
-.text
-.align 4
-_strnlen:
-//     size_t strnlen(char *s, size_t maxlen);
-
-//     If maxlen is larger than any object that can be allocated, we know a priori
-//     that it does not effect the operation of the function in any way; we can
-//     simply call strlen instead, which is more efficient and makes handling the
-//     edge cases here much cleaner.
-       test      %rsi,      %rsi
-       js        _strlen
-
-//     The strnlen() function attempts to compute the length of s, but never
-//     scans beyond the first maxlen bytes of s.
-//
-//     Thus, we need to early-out without doing any reads at all if maxlen == 0.
-       EstablishFrame
-       mov       %rsi,      %rax
-       jz        L_maxlenExhausted
-
-//     We are going to check the string in aligned 16-byte blocks.  The first such
-//     block may contain characters that preceed the start of the string, so we
-//     construct a mask based on the string's alignment to use in processing this
-//     initial block.  We also need to account for these characters in maxlen.
-       mov       %rdi,      %rcx
-       and       $0xf,      %rcx
-       or        $-1,       %rdx
-       shl       %cl,       %rdx // mask
-       add       %rcx,      %rsi // adjust maxlen
-
-//     Load the 16-byte block containing the start of the string.  If any NUL
-//     bytes are present in this block, the corresponding *bit* in ecx will be 1.
-//     We check only the bits that are set in the mask, to avoid detecting NULs
-//     that preceed the start of the string.
-       and       $-16,      %rdi
-       pxor      %xmm0,     %xmm0
-       pcmpeqb  (%rdi),     %xmm0
-       pmovmskb  %xmm0,     %ecx
-       and       %rdx,      %rcx
-       jnz       L_foundNUL
-
-//     Now subtract 16 from maxlen.  If this causes a borrow, then we exhausted
-//     maxlen somewhere in this 16-byte block (formally, we have read past maxlen
-//     bytes, but that is not a problem; because the accesses are all aligned, we
-//     cannot read accross a page--or even cacheline--boundary, so the observable
-//     behavior is not different from if we had stopped at maxlen).  If the result
-//     is exactly zero, we need to stop before reading the *next* 16 bytes.
-       sub       $16,       %rsi
-       jbe       L_maxlenExhausted
-
-L_loop:
-       add       $16,       %rdi
-       pxor      %xmm0,     %xmm0
-       pcmpeqb  (%rdi),     %xmm0
-       pmovmskb  %xmm0,     %ecx
-       test      %rcx,      %rcx
-       jnz       L_foundNUL
-       sub       $16,       %rsi
-       ja        L_loop
-
-L_maxlenExhausted:
-//     If we exhaust maxlen bytes without finding a NUL, we return maxlen.
-       ClearFrameAndReturn
-
-L_foundNUL:
-//     The last 16-byte block that we searched contained at least one NUL.
-//     We use bsf to identify the first NUL.
-       bsf       %rcx,      %rdx
-//     Handle the case where the NUL that we found is preceeded by the maxlen'th
-//     byte of the string, returning maxlen.
-       cmp       %rdx,      %rsi
-       jb        L_maxlenExhausted
-//     Otherwise, return the length of the string.
-       sub       %rsi,      %rax
-       add       %rdx,      %rax
-       ClearFrameAndReturn
index 651244eede0a79e9d0d4499687257249265b6674..c162edc4ef355614a234c96a6a1e006b834e67ec 100644 (file)
@@ -10,5 +10,13 @@ __platform_memset_pattern16 _memset_pattern16
 __platform_memset_pattern4 _memset_pattern4
 __platform_memset_pattern8 _memset_pattern8
 __platform_strchr _strchr
+__platform_strchr _index
 __platform_strcmp _strcmp
+__platform_strcpy _strcpy
+__platform_strlcat _strlcat
+__platform_strlcpy _strlcpy
+__platform_strlen _strlen
 __platform_strncmp _strncmp
+__platform_strncpy _strncpy
+__platform_strnlen _strnlen
+__platform_strstr _strstr
old mode 100644 (file)
new mode 100755 (executable)
index 0704fcd6b3f323ba34e56b7149adb891e41c4488..f275d28e4a21a557be54b38eeb1e7262bd14a318 100755 (executable)
@@ -20,13 +20,7 @@ for my $arch (split(/ /, $ENV{"ARCHS"}))
        # set ENV{"CURRENT_ARCH"} so we can predicate on it
        $ENV{"CURRENT_ARCH"} = $arch;
 
-       # BridgeOS shares the same platform name than the watch so
-       # we need to fix it and pick the right configuration.
-       my $platformName = $ENV{"PLATFORM_NAME"};
-       if ($ENV{"RC_BRIDGE"} eq "YES") {
-               $platformName = "bridgeos";
-       }
-
+       my $platformName = $ENV{"VARIANT_PLATFORM_NAME"};
        $platformName =~ s/simulator/os/;
 
        my $platformPath = $ENV{"SRCROOT"} . "/Platforms/" . $platformName . "/Makefile.inc";
@@ -125,7 +119,7 @@ for my $arch (split(/ /, $ENV{"ARCHS"}))
                $shortarch =~ s/armv\d+[a-z]?/arm/g;
 
                # map all arm64 subtypes to arm64
-               $shortarch =~ s/arm64[_a-z0-9]?/arm64/g;
+               $shortarch =~ s/arm64[_a-z0-9]*/arm64/g;
 
                printf HEADER "#if !defined(__".$shortarch."__)\n";
                printf HEADER "#error Mismatched libc-features.h architecture\n";
index d87641e010d4346335284f01bd91cf0ddcba3f13..5b9b9ed4a63e80303d7b5499fda3b535bb637da8 100755 (executable)
@@ -1,9 +1,6 @@
 #!/bin/bash
 set -x
 
-# Skip installing headers during Xcode build (buildit uses installhdrs+install)
-if [ "$ACTION" == build ]; then exit 0; fi
-
 # Installs Libc header files
 
 MKDIR="mkdir -p"
@@ -23,10 +20,16 @@ FGREP=fgrep
 eval $(${SRCROOT}/xcodescripts/generate_features.pl --bash)
 UNIFDEFARGS=$(${SRCROOT}/xcodescripts/generate_features.pl --unifdef)
 
-INCDIR=${DSTROOT}/${PUBLIC_HEADERS_FOLDER_PATH}
-LOCINCDIR=${DSTROOT}/${PRIVATE_HEADERS_FOLDER_PATH}
-SYSTEMFRAMEWORK=${DSTROOT}/System/Library/Frameworks/System.framework
-KERNELFRAMEWORK=${DSTROOT}/System/Library/Frameworks/Kernel.framework
+if [[ "${DEPLOYMENT_LOCATION}" == "NO" ]] ; then
+    HDRROOT=${BUILT_PRODUCTS_DIR}
+else
+    HDRROOT=${DSTROOT}
+fi
+
+INCDIR=${HDRROOT}/${PUBLIC_HEADERS_FOLDER_PATH}
+LOCINCDIR=${HDRROOT}/${PRIVATE_HEADERS_FOLDER_PATH}
+SYSTEMFRAMEWORK=${HDRROOT}/System/Library/Frameworks/System.framework
+KERNELFRAMEWORK=${HDRROOT}/System/Library/Frameworks/Kernel.framework
 
 PRIVHDRS=${SYSTEMFRAMEWORK}/Versions/B/PrivateHeaders
 PRIVKERNELHDRS=${KERNELFRAMEWORK}/Versions/A/PrivateHeaders
@@ -184,7 +187,8 @@ LOCALHDRS=(
        ${SRCROOT}/darwin/libc_private.h
        ${SRCROOT}/gen/utmpx_thread.h
        ${SRCROOT}/nls/FreeBSD/msgcat.h
-       ${SRCROOT}/libdarwin/dirstat.h
+       ${SRCROOT}/gen/thread_stack_pcs.h
+       ${SRCROOT}/libdarwin/h/dirstat.h
 )
 
 OS_LOCALHDRS=( ${SRCROOT}/os/assumes.h ${SRCROOT}/os/debug_private.h )
@@ -242,13 +246,13 @@ ${INSTALL} -m ${INSTALLMODE} ${SYS_INSTHDRS[@]} ${PRIVHDRS}/sys
 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVHDRS}/uuid
 ${INSTALL} -m ${INSTALLMODE} ${PRIVUUID_INSTHDRS[@]} ${PRIVKERNELHDRS}/uuid
 
-for i in `${FIND} "${DSTROOT}" -name \*.h -print0 | ${XARGS} -0 ${GREP} -l '^//Begin-Libc'`; do
+for i in `${FIND} "${HDRROOT}" -name \*.h -print0 | ${XARGS} -0 ${GREP} -l '^//Begin-Libc'`; do
        ${CHMOD} u+w $i &&
        ${ECHO} ${ED} - $i \< ${SRCROOT}/xcodescripts/strip-header.ed &&
        ${ED} - $i < ${SRCROOT}/xcodescripts/strip-header.ed &&
        ${CHMOD} u-w $i || exit 1;
 done
-for i in `${FIND} "${DSTROOT}" -name \*.h -print0 | ${XARGS} -0 ${FGREP} -l -e UNIFDEF -e OPEN_SOURCE`; do
+for i in `${FIND} "${HDRROOT}" -name \*.h -print0 | ${XARGS} -0 ${FGREP} -l -e UNIFDEF -e OPEN_SOURCE`; do
        ${CHMOD} u+w $i &&
        ${CP} $i $i.orig &&
        ${ECHO} ${UNIFDEF} ${UNIFDEFARGS} $i.orig \> $i &&
index e70e387a1cf88f12b4e5f6e1980999d9a3148b2e..f243d73cc104e6a53b3267b223c4ed0abed69a61 100644 (file)
@@ -29,10 +29,13 @@ WARNING_CFLAGS = -Wall -Werror -Wno-error=shorten-64-to-32 -Wno-error=incompatib
 COPY_PHASE_STRIP = NO
 SKIP_INSTALL = YES
 INSTALLHDRS_SCRIPT_PHASE = YES
+INSTALLHDRS_COPY_PHASE = YES
 VERSIONING_SYSTEM =
+VERSION_INFO_PREFIX = __attribute__((visibility("hidden")))
 COPY_PHASE_STRIP = NO
 STRIP_INSTALLED_PRODUCT = NO
 LD_DYLIB_INSTALL_NAME = /usr/lib/system/$(EXECUTABLE_NAME)
+IS_ZIPPERED = YES
 
 BUILD_VARIANTS = normal debug
 BUILD_ARCHIVES = Platform Base FreeBSD NetBSD TRE vCancelable vDarwinExtsn vDarwinExtsnCancelable vPre1050 vLegacy vInode32 FortifySource
@@ -87,29 +90,21 @@ ARCH_FAMILY_armv7s = arm
 ARCH_FAMILY_armv7f = arm
 ARCH_FAMILY_armv7k = arm
 ARCH_FAMILY_arm64 = arm64
-ARCH_FAMILY_arm64_32 = arm64
 
 // Platform target
-Platform_INCLUDED_SOURCE_FILE_NAMES = $(Platform_INCLUDED_SOURCE_FILE_NAMES_gen) $(Platform_INCLUDED_SOURCE_FILE_NAMES_stdlib) $(Platform_INCLUDED_SOURCE_FILE_NAMES_string)
+Platform_INCLUDED_SOURCE_FILE_NAMES = forceLibcToBuild.c $(Platform_INCLUDED_SOURCE_FILE_NAMES_gen)
 Platform_INCLUDED_SOURCE_FILE_NAMES_gen = $(ARCH_FAMILY)/gen/*.c $(ARCH_FAMILY)/gen/*.s $(ARCH_FAMILY)/gen/*.S
-Platform_INCLUDED_SOURCE_FILE_NAMES_stdlib = $(ARCH_FAMILY)/stdlib/*.c $(ARCH_FAMILY)/stdlib/*.s $(ARCH_FAMILY)/stdlib/*.S
-Platform_INCLUDED_SOURCE_FILE_NAMES_string = $(ARCH_FAMILY)/string/*.c $(ARCH_FAMILY)/string/*.s $(ARCH_FAMILY)/string/*.S
 
 // FreeBSD target
 FreeBSD_CFLAGS = -include $(SRCROOT)/fbsdcompat/_fbsd_compat_.h
 FreeBSD_SEARCH_PATHS = $(SRCROOT)/fbsdcompat $(SRCROOT)/gdtoa $(SRCROOT)/gdtoa/FreeBSD
 FreeBSD_EXCLUDED_SOURCE_GDTOA = gdtoa/FreeBSD/machdep* gdtoa-strtopx.c
 // Include the correct parts of gdtoa per-arch
+FreeBSD_INCLUDED_SOURCE_FILE_NAMES = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_$(ARCH_FAMILY))
 FreeBSD_INCLUDED_SOURCE_FILE_NAMES_x86_64 = gdtoa-strtopx.c machdep_ldisx.c
 FreeBSD_INCLUDED_SOURCE_FILE_NAMES_i386 = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_x86_64)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7 = machdep_ldisd.c
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7s = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7k = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7f = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv6 = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_arm64 = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_arm64_32 = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
-FreeBSD_INCLUDED_SOURCE_FILE_NAMES_arm64e = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_armv7)
+FreeBSD_INCLUDED_SOURCE_FILE_NAMES_arm = machdep_ldisd.c
+FreeBSD_INCLUDED_SOURCE_FILE_NAMES_arm64 = $(FreeBSD_INCLUDED_SOURCE_FILE_NAMES_arm)
 
 // NetBSD target
 NetBSD_CFLAGS = -include $(SRCROOT)/nbsdcompat/_nbsd_compat_.h
@@ -120,17 +115,10 @@ TRE_CFLAGS = -DHAVE_CONFIG_H
 TRE_SEARCH_PATHS = $(SRCROOT)/regex/TRE $(SRCROOT)/regex/FreeBSD
 
 // Files per architecture to exclude from the non-platform builds (because optimised versions exist in Platform)
-BASE_EXCLUDED_SOURCE_FILE_NAMES = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_$(CURRENT_ARCH)) $(BASE_EXCLUDED_SOURCE_FILE_NAMES_$(PLATFORM_NAME))
-BASE_EXCLUDED_SOURCE_FILE_NAMES_x86_64 = kvm.c nlist.c strcpy.c strlen.c strncpy.c strnlen.c
-BASE_EXCLUDED_SOURCE_FILE_NAMES_i386 = strcpy.c strlcat.c strlcpy.c strlen.c strncpy.c
-BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7 = strlen.c strnlen.c strstr.c
-BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7s = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7)
-BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7k = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7)
-BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7f = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7)
-BASE_EXCLUDED_SOURCE_FILE_NAMES_armv6 = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_armv7)
-BASE_EXCLUDED_SOURCE_FILE_NAMES_arm64 = strlen.c strnlen.c kvm.c nlist.c
-BASE_EXCLUDED_SOURCE_FILE_NAMES_arm64_32 = strlen.c strnlen.c kvm.c nlist.c
-BASE_EXCLUDED_SOURCE_FILE_NAMES_arm64e = strlen.c strnlen.c kvm.c nlist.c
+BASE_INCLUDED_SOURCE_FILE_NAMES = $(BASE_INCLUDED_SOURCE_FILE_NAMES_$(ARCH_FAMILY))
+BASE_EXCLUDED_SOURCE_FILE_NAMES = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_$(ARCH_FAMILY)) $(BASE_EXCLUDED_SOURCE_FILE_NAMES_$(VARIANT_PLATFORM_NAME))
+BASE_EXCLUDED_SOURCE_FILE_NAMES_x86_64 = kvm.c nlist.c
+BASE_EXCLUDED_SOURCE_FILE_NAMES_arm64 = kvm.c nlist.c
 
 // Rune support isn't included on iOS but there's no better way to exclude their complication
 BASE_EXCLUDED_SOURCE_FILE_NAMES_macosx = OSMemoryNotification.c
@@ -146,13 +134,19 @@ BASE_EXCLUDED_SOURCE_FILE_NAMES_bridgeos = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_iph
 BASE_EXCLUDED_SOURCE_FILE_NAMES_iphoneosnano = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_watchos)
 BASE_EXCLUDED_SOURCE_FILE_NAMES_iphonesimulatornano = $(BASE_EXCLUDED_SOURCE_FILE_NAMES_watchsimulator)
 
-// <rdar://problem/9513665> - collate.c crashes llvm-gcc on armv6 with -Os + -gdwarf-2
-COLLATE_C_CFLAGS_macosx_armv6 = -O1
-
-// ARMv6 thumb doesn't support all the instructions needed for OSAtomics
-OSATOMIC_C_CFLAGS_macosx_armv6 = -mno-thumb
-OSATOMIC_C_CFLAGS_iphoneos_armv6 = -mno-thumb
-
-// Make sure that OSAtomic isn't build unoptimised, otherwise the inlines
-// don't do what they are designed to do.
-OSATOMIC_C_CFLAGS = -Os -momit-leaf-frame-pointer $(OSATOMIC_C_CFLAGS_$(PLATFORM_NAME)_$(CURRENT_ARCH))
+// Enable installapi
+SUPPORTS_TEXT_BASED_API = YES
+TAPI_VERIFY_MODE = Pedantic
+OTHER_TAPI_FLAGS = --no-infer-include-paths -umbrella System -extra-public-header $(TAPI_PUBLIC_HEADER_PATH) -extra-private-header $(TAPI_PRIVATE_HEADER_PATH)
+TAPI_PUBLIC_HEADER_PATH = $(TAPI_PUBLIC_HEADER_PATH_$(DEPLOYMENT_LOCATION))
+TAPI_PUBLIC_HEADER_PATH_NO = $(BUILT_PRODUCTS_DIR)$(PUBLIC_HEADERS_FOLDER_PATH)
+TAPI_PUBLIC_HEADER_PATH_YES = $(DSTROOT)$(PUBLIC_HEADERS_FOLDER_PATH)
+TAPI_PRIVATE_HEADER_PATH = $(TAPI_PRIVATE_HEADER_PATH_$(DEPLOYMENT_LOCATION))
+TAPI_PRIVATE_HEADER_PATH_NO = $(BUILT_PRODUCTS_DIR)$(PRIVATE_HEADERS_FOLDER_PATH)
+TAPI_PRIVATE_HEADER_PATH_YES = $(DSTROOT)$(PRIVATE_HEADERS_FOLDER_PATH)
+TAPI_HEADER_SEARCH_PATHS =
+
+// TODO: Remove this hack once Marzipan bringup is done
+VARIANT_PLATFORM_NAME = $(VARIANT_PLATFORM_NAME_$(RC_MARZIPAN))
+VARIANT_PLATFORM_NAME_ = $(PLATFORM_NAME)
+VARIANT_PLATFORM_NAME_YES = macosx
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 9256418..f3bb0f7
@@ -4,4 +4,8 @@ if [[ "x${ACTION}" == "xinstallhdrs" ]]; then
        exit 0
 fi
 
+if [[ "x${ACTION}" == "xinstallapi" ]]; then
+       exit 0
+fi
+
 $@
index 415f81c354b8b0f98b4fd3f062d77893629c8d7d..f8118ea03a0630866b6bf34a515ca33ffa72e47c 100644 (file)
@@ -34,16 +34,16 @@ VARIANT_DARWINEXTSN_CANCELABLE_MACROS = -DVARIANT_CANCELABLE -DVARIANT_DARWINEXT
 
 // Pre-1050 symbols
 
-VARIANT_PRE1050_MACROS = $(VARIANT_PRE1050_MACROS_$(PLATFORM_NAME))
+VARIANT_PRE1050_MACROS = $(VARIANT_PRE1050_MACROS_$(VARIANT_PLATFORM_NAME))
 VARIANT_PRE1050_MACROS_macosx = -U__DARWIN_VERS_1050 -D__DARWIN_VERS_1050=0 -DVARIANT_PRE1050
-VARIANT_PRE1050_INCLUDE = $(VARIANT_PRE1050_INCLUDE_$(PLATFORM_NAME))
-VARIANT_PRE1050_INCLUDE_macosx = daemon.c $(VARIANT_PRE1050_INCLUDE_$(PLATFORM_NAME)_$(CURRENT_ARCH))
+VARIANT_PRE1050_INCLUDE = $(VARIANT_PRE1050_INCLUDE_$(VARIANT_PLATFORM_NAME))
+VARIANT_PRE1050_INCLUDE_macosx = daemon.c $(VARIANT_PRE1050_INCLUDE_$(VARIANT_PLATFORM_NAME)_$(CURRENT_ARCH))
 
 // Legacy symbols
 VARIANT_LEGACY_MACROS = -U__DARWIN_UNIX03 -D__DARWIN_UNIX03=0 -U__DARWIN_64_BIT_INO_T -D__DARWIN_64_BIT_INO_T=0 -DVARIANT_LEGACY
 
-VARIANT_LEGACY_INCLUDE = $(VARIANT_LEGACY_INCLUDE_$(PLATFORM_NAME))
-VARIANT_LEGACY_INCLUDE_macosx = $(VARIANT_LEGACY_INCLUDE_$(PLATFORM_NAME)_$(CURRENT_ARCH))
+VARIANT_LEGACY_INCLUDE = $(VARIANT_LEGACY_INCLUDE_$(VARIANT_PLATFORM_NAME))
+VARIANT_LEGACY_INCLUDE_macosx = $(VARIANT_LEGACY_INCLUDE_$(VARIANT_PLATFORM_NAME)_$(CURRENT_ARCH))
 VARIANT_LEGACY_INCLUDE_macosx_i386 = $(VARIANT_LEGACY_INCLUDE_compat) $(VARIANT_LEGACY_INCLUDE_gdtoa) $(VARIANT_LEGACY_INCLUDE_gen) $(VARIANT_LEGACY_INCLUDE_locale) $(VARIANT_LEGACY_INCLUDE_net) $(VARIANT_LEGACY_INCLUDE_regex) $(VARIANT_LEGACY_INCLUDE_stdio) $(VARIANT_LEGACY_INCLUDE_stdlib) $(VARIANT_LEGACY_INCLUDE_stdtime) $(VARIANT_LEGACY_INCLUDE_sys)
 
 VARIANT_LEGACY_INCLUDE_compat = creat.c setregid.c setreuid.c sigcompat.c killpg.c
@@ -61,8 +61,8 @@ VARIANT_LEGACY_INCLUDE_sys = msgctl.c semctl.c shmctl.c
 
 VARIANT_INODE32_MACROS = -U__DARWIN_64_BIT_INO_T -D__DARWIN_64_BIT_INO_T=0 -DVARIANT_INODE32
 
-VARIANT_INODE32_INCLUDE = $(VARIANT_INODE32_INCLUDE_$(PLATFORM_NAME))
-VARIANT_INODE32_INCLUDE_macosx = $(VARIANT_INODE32_INCLUDE_$(PLATFORM_NAME)_$(CURRENT_ARCH))
+VARIANT_INODE32_INCLUDE = $(VARIANT_INODE32_INCLUDE_$(VARIANT_PLATFORM_NAME))
+VARIANT_INODE32_INCLUDE_macosx = $(VARIANT_INODE32_INCLUDE_$(VARIANT_PLATFORM_NAME)_$(CURRENT_ARCH))
 VARIANT_INODE32_INCLUDE_macosx_i386 = $(VARIANT_INODE32_INCLUDE_gen) $(VARIANT_INODE32_INCLUDE_sys)
 VARIANT_INODE32_INCLUDE_macosx_x86_64 = $(VARIANT_INODE32_INCLUDE_gen) $(VARIANT_INODE32_INCLUDE_sys)
 
@@ -78,16 +78,5 @@ VARIANT_DYLD_INCLUDE = $(VARIANT_DYLD_INCLUDE_generic) $(VARIANT_DYLD_INCLUDE_$(
 VARIANT_DYLD_INCLUDE_generic = $(VARIANT_DYLD_INCLUDE_gen) $(VARIANT_DYLD_INCLUDE_stdlib) $(VARIANT_DYLD_INCLUDE_string) $(VARIANT_DYLD_INCLUDE_sys)
 VARIANT_DYLD_INCLUDE_gen = arc4random.c closedir.c dirfd.c getcwd.c getpagesize.c nanosleep.c opendir.c readdir.c scandir.c sysctl.c sysctlbyname.c telldir.c usleep.c
 VARIANT_DYLD_INCLUDE_stdlib = atexit.c exit.c gettimeofday.c heapsort.c merge.c qsort.c reallocf.c realpath.c
-VARIANT_DYLD_INCLUDE_string = bcopy.c libplatform.s strcat.c strchr.c strcpy.c strdup.c strlcat.c strlcpy.c strncmp.c strnlen.c strrchr.c strstr.c
+VARIANT_DYLD_INCLUDE_string = bcopy.c strcat.c strdup.c strrchr.c
 VARIANT_DYLD_INCLUDE_sys = _libc_init.c
-
-VARIANT_DYLD_INCLUDE_x86_64 = x86_64/string/strcpy.s x86_64/string/strlen.s x86_64/string/strncpy.s x86_64/string/strnlen.s            strstr.c
-VARIANT_DYLD_INCLUDE_i386 =     i386/string/strcpy.s   i386/string/strlen.s   i386/string/strncpy.s               strnlen.c            strstr.c
-VARIANT_DYLD_INCLUDE_armv7 =                strcpy.c    arm/string/strlen.s               strncpy.c    arm/string/strnlen.s arm/string/strstr.s
-VARIANT_DYLD_INCLUDE_arm64 =                strcpy.c                                      strncpy.c  arm64/string/strnlen.s            strstr.c
-VARIANT_DYLD_INCLUDE_arm64_32 =             strcpy.c                                      strncpy.c  arm64/string/strnlen.s            strstr.c
-
-VARIANT_DYLD_INCLUDE_armv7s = $(VARIANT_DYLD_INCLUDE_armv7)
-VARIANT_DYLD_INCLUDE_armv7k = $(VARIANT_DYLD_INCLUDE_armv7)
-VARIANT_DYLD_INCLUDE_armv7f = $(VARIANT_DYLD_INCLUDE_armv7)
-