From a5cd208c3ffb9df58796661133982cf99f63ef19 Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 28 Apr 2006 23:07:02 +0000 Subject: [PATCH] Libc-391.2.6.tar.gz --- db/hash/FreeBSD/hash_page.c.patch | 40 ++++++++- gdtoa/FreeBSD/_hdtoa.c | 145 ++++-------------------------- gdtoa/FreeBSD/_hdtoa.c.patch | 97 +++----------------- pthreads/pthread_tsd.c | 14 ++- stdlib/FreeBSD/grantpt.c.patch | 96 +++++++++++++++++++- 5 files changed, 171 insertions(+), 221 deletions(-) diff --git a/db/hash/FreeBSD/hash_page.c.patch b/db/hash/FreeBSD/hash_page.c.patch index 807837c..64d1390 100644 --- a/db/hash/FreeBSD/hash_page.c.patch +++ b/db/hash/FreeBSD/hash_page.c.patch @@ -1,5 +1,5 @@ ---- hash_page.c.orig Thu Mar 21 14:46:26 2002 -+++ hash_page.c Sat Oct 18 18:31:10 2003 +--- hash_page.c.orig 2006-04-22 23:04:55.000000000 -0700 ++++ hash_page.c 2006-04-23 00:23:46.000000000 -0700 @@ -74,7 +74,7 @@ #include #include "hash.h" @@ -9,3 +9,39 @@ static u_int32_t *fetch_bitmap(HTAB *, int); static u_int32_t first_free(u_int32_t); +@@ -586,7 +586,7 @@ + int is_bucket, is_bitmap; + { + int fd, page, size; +- int wsize; ++ int wsize, max; + + size = hashp->BSIZE; + if ((hashp->fp == -1) && open_temp(hashp)) +@@ -595,7 +595,6 @@ + + if (hashp->LORDER != BYTE_ORDER) { + int i; +- int max; + + if (is_bitmap) { + max = hashp->BSIZE >> 2; /* divide by 4 */ +@@ -619,6 +618,18 @@ + errno = EFTYPE; + return (-1); + } ++ /* 4485533 - reswap the in-memory copy */ ++ if (hashp->LORDER != BYTE_ORDER) { ++ int i; ++ ++ if (is_bitmap) { ++ for (i = 0; i < max; i++) ++ M_32_SWAP(((int *)p)[i]); ++ } else { ++ for (i = 0; i <= max; i++) ++ M_16_SWAP(((u_int16_t *)p)[i]); ++ } ++ } + return (0); + } + diff --git a/gdtoa/FreeBSD/_hdtoa.c b/gdtoa/FreeBSD/_hdtoa.c index 1a85986..77e99ac 100644 --- a/gdtoa/FreeBSD/_hdtoa.c +++ b/gdtoa/FreeBSD/_hdtoa.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2004 David Schultz + * Copyright (c) 2004, 2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,13 +25,11 @@ */ #include -__FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.2 2004/01/21 04:51:50 grehan Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.3 2005/01/18 18:44:07 das Exp $"); #include -#include #include #include -#include #include "fpmath.h" #include "gdtoaimp.h" @@ -39,51 +37,8 @@ __FBSDID("$FreeBSD: src/lib/libc/gdtoa/_hdtoa.c,v 1.2 2004/01/21 04:51:50 grehan #define INFSTR "Infinity" #define NANSTR "NaN" -#define DBL_BIAS (DBL_MAX_EXP - 1) -#define LDBL_BIAS (LDBL_MAX_EXP - 1) - -#ifdef LDBL_IMPLICIT_NBIT -#define LDBL_NBIT_ADJ 0 -#else -#define LDBL_NBIT_ADJ 1 -#endif - -/* - * Efficiently compute the log2 of an integer. Uses a combination of - * arcane tricks found in fortune and arcane tricks not (yet) in - * fortune. This routine behaves similarly to fls(9). - */ -static int -log2_32(uint32_t n) -{ - - n |= (n >> 1); - n |= (n >> 2); - n |= (n >> 4); - n |= (n >> 8); - n |= (n >> 16); - - n = (n & 0x55555555) + ((n & 0xaaaaaaaa) >> 1); - n = (n & 0x33333333) + ((n & 0xcccccccc) >> 2); - n = (n & 0x0f0f0f0f) + ((n & 0xf0f0f0f0) >> 4); - n = (n & 0x00ff00ff) + ((n & 0xff00ff00) >> 8); - n = (n & 0x0000ffff) + ((n & 0xffff0000) >> 16); - return (n - 1); -} - -#if (LDBL_MANH_SIZE > 32 || LDBL_MANL_SIZE > 32) - -static int -log2_64(uint64_t n) -{ - - if (n >> 32 != 0) - return (log2_32((uint32_t)(n >> 32)) + 32); - else - return (log2_32((uint32_t)n)); -} - -#endif /* (LDBL_MANH_SIZE > 32 || LDBL_MANL_SIZE > 32) */ +#define DBL_ADJ (DBL_MAX_EXP - 2 + ((DBL_MANT_DIG - 1) % 4)) +#define LDBL_ADJ (LDBL_MAX_EXP - 2 + ((LDBL_MANT_DIG - 1) % 4)) /* * Round up the given digit string. If the digit string is fff...f, @@ -168,46 +123,24 @@ char * __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve) { + static const int sigfigs = (DBL_MANT_DIG + 3) / 4; union IEEEd2bits u; char *s, *s0; int bufsize; - int impnbit; /* implicit normalization bit */ - int pos; - int shift; /* for subnormals, # of shifts required to normalize */ - int sigfigs; /* number of significant hex figures in result */ u.d = d; *sign = u.bits.sign; switch (fpclassify(d)) { case FP_NORMAL: - sigfigs = (DBL_MANT_DIG + 3) / 4; - impnbit = 1 << ((DBL_MANT_DIG - 1) % 4); - *decpt = u.bits.exp - DBL_BIAS + 1 - - ((DBL_MANT_DIG - 1) % 4); + *decpt = u.bits.exp - DBL_ADJ; break; case FP_ZERO: *decpt = 1; return (nrv_alloc("0", rve, 1)); case FP_SUBNORMAL: - /* - * The position of the highest-order bit tells us by - * how much to adjust the exponent (decpt). The - * adjustment is raised to the next nibble boundary - * since we will later choose the leftmost hexadecimal - * digit so that all subsequent digits align on nibble - * boundaries. - */ - if (u.bits.manh != 0) { - pos = log2_32(u.bits.manh); - shift = DBL_MANH_SIZE - pos; - } else { - pos = log2_32(u.bits.manl); - shift = DBL_MANH_SIZE + DBL_MANL_SIZE - pos; - } - sigfigs = (3 + DBL_MANT_DIG - shift) / 4; - impnbit = 0; - *decpt = DBL_MIN_EXP - ((shift + 3) & ~(4 - 1)); + u.d *= 0x1p514; + *decpt = u.bits.exp - (514 + DBL_ADJ); break; case FP_INFINITE: *decpt = INT_MAX; @@ -254,11 +187,9 @@ __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, * At this point, we have snarfed all the bits in the * mantissa, with the possible exception of the highest-order * (partial) nibble, which is dealt with by the next - * statement. That nibble is usually in manh, but it could be - * in manl instead for small subnormals. We also tack on the - * implicit normalization bit if appropriate. + * statement. We also tack on the implicit normalization bit. */ - *s = u.bits.manh | u.bits.manl | impnbit; + *s = u.bits.manh | (1U << ((DBL_MANT_DIG - 1) % 4)); /* If ndigits < 0, we are expected to auto-size the precision. */ if (ndigits < 0) { @@ -283,71 +214,29 @@ __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, /* * This is the long double version of __hdtoa(). - * - * On architectures that have an explicit integer bit, unnormals and - * pseudo-denormals cause problems in the conversion routine, so they - * are ``fixed'' by effectively toggling the integer bit. Although - * this is not correct behavior, the hardware will not produce these - * formats externally. */ char * __hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve) { + static const int sigfigs = (LDBL_MANT_DIG + 3) / 4; union IEEEl2bits u; char *s, *s0; int bufsize; - int impnbit; /* implicit normalization bit */ - int pos; - int shift; /* for subnormals, # of shifts required to normalize */ - int sigfigs; /* number of significant hex figures in result */ u.e = e; *sign = u.bits.sign; switch (fpclassify(e)) { case FP_NORMAL: - sigfigs = (LDBL_MANT_DIG + 3) / 4; - impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4); - *decpt = u.bits.exp - LDBL_BIAS + 1 - - ((LDBL_MANT_DIG - 1) % 4); + *decpt = u.bits.exp - LDBL_ADJ; break; case FP_ZERO: *decpt = 1; return (nrv_alloc("0", rve, 1)); case FP_SUBNORMAL: - /* - * The position of the highest-order bit tells us by - * how much to adjust the exponent (decpt). The - * adjustment is raised to the next nibble boundary - * since we will later choose the leftmost hexadecimal - * digit so that all subsequent digits align on nibble - * boundaries. - */ -#ifdef LDBL_IMPLICIT_NBIT - /* Don't trust the normalization bit to be off. */ - u.bits.manh &= ~(~0ULL << (LDBL_MANH_SIZE - 1)); -#endif - if (u.bits.manh != 0) { -#if LDBL_MANH_SIZE > 32 - pos = log2_64(u.bits.manh); -#else - pos = log2_32(u.bits.manh); -#endif - shift = LDBL_MANH_SIZE - LDBL_NBIT_ADJ - pos; - } else { -#if LDBL_MANL_SIZE > 32 - pos = log2_64(u.bits.manl); -#else - pos = log2_32(u.bits.manl); -#endif - shift = LDBL_MANH_SIZE + LDBL_MANL_SIZE - - LDBL_NBIT_ADJ - pos; - } - sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4; - *decpt = LDBL_MIN_EXP + LDBL_NBIT_ADJ - - ((shift + 3) & ~(4 - 1)); - impnbit = 0; + u.e *= 0x1p514L; + *decpt = u.bits.exp - (514 + LDBL_ADJ); break; case FP_INFINITE: *decpt = INT_MAX; @@ -394,11 +283,9 @@ __hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign, * At this point, we have snarfed all the bits in the * mantissa, with the possible exception of the highest-order * (partial) nibble, which is dealt with by the next - * statement. That nibble is usually in manh, but it could be - * in manl instead for small subnormals. We also tack on the - * implicit normalization bit if appropriate. + * statement. We also tack on the implicit normalization bit. */ - *s = u.bits.manh | u.bits.manl | impnbit; + *s = u.bits.manh | (1U << ((LDBL_MANT_DIG - 1) % 4)); /* If ndigits < 0, we are expected to auto-size the precision. */ if (ndigits < 0) { diff --git a/gdtoa/FreeBSD/_hdtoa.c.patch b/gdtoa/FreeBSD/_hdtoa.c.patch index 5b4d7cf..de6da95 100644 --- a/gdtoa/FreeBSD/_hdtoa.c.patch +++ b/gdtoa/FreeBSD/_hdtoa.c.patch @@ -1,86 +1,17 @@ ---- _hdtoa.c.orig 2004-06-03 15:22:08.000000000 -0700 -+++ _hdtoa.c 2004-08-28 17:10:21.000000000 -0700 -@@ -32,6 +32,9 @@ - #include - #include - #include -+#ifdef LDBL_HEAD_TAIL_PAIR -+#include -+#endif /* LDBL_HEAD_TAIL_PAIR */ - #include "fpmath.h" - #include "gdtoaimp.h" - -@@ -301,16 +304,31 @@ - int pos; - int shift; /* for subnormals, # of shifts required to normalize */ - int sigfigs; /* number of significant hex figures in result */ +--- _hdtoa.c.orig 2006-01-31 15:21:41.000000000 -0800 ++++ _hdtoa.c 2006-01-31 23:37:12.000000000 -0800 +@@ -223,6 +223,10 @@ + union IEEEl2bits u; + char *s, *s0; + int bufsize; +#ifdef LDBL_HEAD_TAIL_PAIR + uint32_t bits[4]; -+ int i; ++ int i, pos; +#endif /* LDBL_HEAD_TAIL_PAIR */ u.e = e; *sign = u.bits.sign; - -+#ifdef LDBL_HEAD_TAIL_PAIR -+ switch (__fpclassifyd(u.d[0])) { -+#else /* LDBL_HEAD_TAIL_PAIR */ - switch (fpclassify(e)) { -+#endif /* LDBL_HEAD_TAIL_PAIR */ - case FP_NORMAL: -+#ifdef LDBL_HEAD_TAIL_PAIR - sigfigs = (LDBL_MANT_DIG + 3) / 4; - impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4); - *decpt = u.bits.exp - LDBL_BIAS + 1 - - ((LDBL_MANT_DIG - 1) % 4); -+#else /* LDBL_HEAD_TAIL_PAIR */ -+ sigfigs = (LDBL_MANT_DIG + 3) / 4; -+ impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4); -+ *decpt = u.bits.exp - LDBL_BIAS + 1 - -+ ((LDBL_MANT_DIG - 1) % 4); -+#endif /* LDBL_HEAD_TAIL_PAIR */ - break; - case FP_ZERO: - *decpt = 1; -@@ -328,13 +346,26 @@ - /* Don't trust the normalization bit to be off. */ - u.bits.manh &= ~(~0ULL << (LDBL_MANH_SIZE - 1)); - #endif -+#ifndef LDBL_HEAD_TAIL_PAIR - if (u.bits.manh != 0) { -+#endif /* LDBL_HEAD_TAIL_PAIR */ - #if LDBL_MANH_SIZE > 32 - pos = log2_64(u.bits.manh); - #else - pos = log2_32(u.bits.manh); - #endif - shift = LDBL_MANH_SIZE - LDBL_NBIT_ADJ - pos; -+#ifdef LDBL_HEAD_TAIL_PAIR -+ sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4; -+ // we use DBL_MIN_EXP below because the head double is -+ // subnormal (and the tail double is zero) -+ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ; -+ pos = (LDBL_MANT_DIG + 3) % 4; -+ if (pos < shift) -+ *decpt -= pos + ((shift - pos + 3) & ~(4 - 1)); -+ else -+ *decpt -= shift; -+#else /* LDBL_HEAD_TAIL_PAIR */ - } else { - #if LDBL_MANL_SIZE > 32 - pos = log2_64(u.bits.manl); -@@ -345,8 +376,9 @@ - LDBL_NBIT_ADJ - pos; - } - sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4; -- *decpt = LDBL_MIN_EXP + LDBL_NBIT_ADJ - -+ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ - - ((shift + 3) & ~(4 - 1)); -+#endif /* LDBL_HEAD_TAIL_PAIR */ - impnbit = 0; - break; - case FP_INFINITE: -@@ -381,6 +413,19 @@ +@@ -270,6 +274,19 @@ */ for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--) *s = 0; @@ -100,7 +31,7 @@ for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) { *s = u.bits.manl & 0xf; u.bits.manl >>= 4; -@@ -389,6 +434,7 @@ +@@ -278,6 +295,7 @@ *s = u.bits.manh & 0xf; u.bits.manh >>= 4; } @@ -108,14 +39,14 @@ /* * At this point, we have snarfed all the bits in the -@@ -398,7 +444,11 @@ - * in manl instead for small subnormals. We also tack on the - * implicit normalization bit if appropriate. +@@ -285,7 +303,11 @@ + * (partial) nibble, which is dealt with by the next + * statement. We also tack on the implicit normalization bit. */ +#ifdef LDBL_HEAD_TAIL_PAIR -+ *s = bits[i] | impnbit; ++ *s = bits[i]; +#else /* LDBL_HEAD_TAIL_PAIR */ - *s = u.bits.manh | u.bits.manl | impnbit; + *s = u.bits.manh | (1U << ((LDBL_MANT_DIG - 1) % 4)); +#endif /* LDBL_HEAD_TAIL_PAIR */ /* If ndigits < 0, we are expected to auto-size the precision. */ diff --git a/pthreads/pthread_tsd.c b/pthreads/pthread_tsd.c index df1ee6f..91cdf3c 100644 --- a/pthreads/pthread_tsd.c +++ b/pthreads/pthread_tsd.c @@ -59,6 +59,12 @@ static struct void (*destructor)(void *); } _pthread_keys[_POSIX_THREAD_KEYS_MAX]; static pthread_lock_t tds_lock = LOCK_INITIALIZER; +/* + * Partition _pthread_keys in a lower part that dyld can use, and an upper + * part for libSystem. The libSystem part starts at __pthread_tsd_first = 4. + * dyld will set this value to 1. + */ +__private_extern__ int __pthread_tsd_first = 4; /* * Create a new key for thread specific data @@ -71,7 +77,7 @@ pthread_key_create(pthread_key_t *key, LOCK(tds_lock); res = ENOMEM; /* No 'free' keys */ /* The first slot is reserved for pthread_self() */ - for (i = 1; i < _POSIX_THREAD_KEYS_MAX; i++) + for (i = __pthread_tsd_first; i < _POSIX_THREAD_KEYS_MAX; i++) { if (_pthread_keys[i].created == FALSE) { @@ -95,7 +101,7 @@ pthread_key_delete(pthread_key_t key) int res; LOCK(tds_lock); /* The first slot is reserved for pthread_self() */ - if ((key > 0) && (key < _POSIX_THREAD_KEYS_MAX)) + if ((key >= __pthread_tsd_first) && (key < _POSIX_THREAD_KEYS_MAX)) { if (_pthread_keys[key].created) { @@ -137,7 +143,7 @@ pthread_setspecific(pthread_key_t key, int res; pthread_t self; /* The first slot is reserved for pthread_self() */ - if ((key > 0) && (key < _POSIX_THREAD_KEYS_MAX)) + if ((key >= __pthread_tsd_first) && (key < _POSIX_THREAD_KEYS_MAX)) { if (_pthread_keys[key].created) { @@ -166,7 +172,7 @@ _pthread_tsd_cleanup(pthread_t self) for (j = 0; j < PTHREAD_DESTRUCTOR_ITERATIONS; j++) { /* The first slot is reserved for pthread_self() */ - for (i = 1; i < _POSIX_THREAD_KEYS_MAX; i++) + for (i = __pthread_tsd_first; i < _POSIX_THREAD_KEYS_MAX; i++) { if (_pthread_keys[i].created && (param = self->tsd[i])) { diff --git a/stdlib/FreeBSD/grantpt.c.patch b/stdlib/FreeBSD/grantpt.c.patch index a41355b..2e73b70 100644 --- a/stdlib/FreeBSD/grantpt.c.patch +++ b/stdlib/FreeBSD/grantpt.c.patch @@ -1,5 +1,5 @@ ---- grantpt.c.orig 2004-09-14 19:06:46.000000000 -0700 -+++ grantpt.c 2004-09-14 19:11:31.000000000 -0700 +--- grantpt.c.orig 2006-04-21 22:41:31.000000000 -0700 ++++ grantpt.c 2006-04-21 22:43:03.000000000 -0700 @@ -54,18 +54,16 @@ #include #include "un-namespace.h" @@ -58,7 +58,97 @@ minor((x).st_rdev) >= 0 && \ minor((x).st_rdev) < PT_MAX) -@@ -227,8 +246,8 @@ +@@ -100,50 +119,53 @@ + serrno = errno; + + if ((slave = ptsname(fildes)) != NULL) { +- /* +- * Block SIGCHLD. +- */ +- (void)sigemptyset(&nblock); +- (void)sigaddset(&nblock, SIGCHLD); +- (void)_sigprocmask(SIG_BLOCK, &nblock, &oblock); +- +- switch (pid = fork()) { +- case -1: +- break; +- case 0: /* child */ ++ /* 4430299: if we are root, we don't need to fork/exec */ ++ if (geteuid() != 0) { + /* +- * pt_chown expects the master pseudo TTY to be its +- * standard input. ++ * Block SIGCHLD. + */ +- (void)_dup2(fildes, STDIN_FILENO); +- (void)_sigprocmask(SIG_SETMASK, &oblock, NULL); +- execl(_PATH_PTCHOWN, _PATH_PTCHOWN, (char *)NULL); +- _exit(EX_UNAVAILABLE); +- /* NOTREACHED */ +- default: /* parent */ ++ (void)sigemptyset(&nblock); ++ (void)sigaddset(&nblock, SIGCHLD); ++ (void)_sigprocmask(SIG_BLOCK, &nblock, &oblock); ++ ++ switch (pid = fork()) { ++ case -1: ++ break; ++ case 0: /* child */ ++ /* ++ * pt_chown expects the master pseudo TTY to be its ++ * standard input. ++ */ ++ (void)_dup2(fildes, STDIN_FILENO); ++ (void)_sigprocmask(SIG_SETMASK, &oblock, NULL); ++ execl(_PATH_PTCHOWN, _PATH_PTCHOWN, (char *)NULL); ++ _exit(EX_UNAVAILABLE); ++ /* NOTREACHED */ ++ default: /* parent */ ++ /* ++ * Just wait for the process. Error checking is ++ * done below. ++ */ ++ while ((spid = _waitpid(pid, &status, 0)) == -1 && ++ (errno == EINTR)) ++ ; ++ if (spid != -1 && WIFEXITED(status) && ++ WEXITSTATUS(status) == EX_OK) ++ retval = 0; ++ else ++ errno = EACCES; ++ break; ++ } ++ + /* +- * Just wait for the process. Error checking is +- * done below. ++ * Restore process's signal mask. + */ +- while ((spid = _waitpid(pid, &status, 0)) == -1 && +- (errno == EINTR)) +- ; +- if (spid != -1 && WIFEXITED(status) && +- WEXITSTATUS(status) == EX_OK) +- retval = 0; +- else +- errno = EACCES; +- break; ++ (void)_sigprocmask(SIG_SETMASK, &oblock, NULL); + } + +- /* +- * Restore process's signal mask. +- */ +- (void)_sigprocmask(SIG_SETMASK, &oblock, NULL); +- + if (retval) { + /* +- * pt_chown failed. Try to manually change the ++ * pt_chown failed (or we're root). Try to manually change the + * permissions for the slave. + */ + gid = (grp = getgrnam("tty")) ? grp->gr_gid : -1; +@@ -227,8 +249,8 @@ errno = EINVAL; else { (void)sprintf(slave, _PATH_DEV PTS_PREFIX "%c%c", -- 2.45.2