diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/db/hash/ndbm.c | 2 | ||||
-rw-r--r-- | lib/libc/db/man/dbm.3 | 6 | ||||
-rw-r--r-- | lib/libc/gen/psignal.3 | 4 | ||||
-rw-r--r-- | lib/libc/gen/psignal.c | 4 | ||||
-rw-r--r-- | lib/libc/iconv/citrus_esdb.c | 18 | ||||
-rw-r--r-- | lib/libc/locale/ascii.c | 2 | ||||
-rw-r--r-- | lib/libc/locale/none.c | 1 | ||||
-rw-r--r-- | lib/libc/stdlib/div.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/imaxdiv.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/ldiv.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/lldiv.c | 2 | ||||
-rw-r--r-- | lib/libc/stdlib/rand.c | 52 | ||||
-rw-r--r-- | lib/libc/stdlib/random.c | 62 | ||||
-rw-r--r-- | lib/libc/sys/_umtx_op.2 | 95 | ||||
-rw-r--r-- | lib/libc/sys/jail.2 | 2 | ||||
-rw-r--r-- | lib/libc/sys/thr_exit.2 | 26 | ||||
-rw-r--r-- | lib/libc/sys/thr_kill.2 | 10 | ||||
-rw-r--r-- | lib/libc/sys/thr_new.2 | 38 | ||||
-rw-r--r-- | lib/libc/sys/thr_self.2 | 10 | ||||
-rw-r--r-- | lib/libc/sys/thr_set_name.2 | 7 | ||||
-rw-r--r-- | lib/libc/sys/wait.2 | 10 |
21 files changed, 178 insertions, 179 deletions
diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c index 37adaf6..1a02d00 100644 --- a/lib/libc/db/hash/ndbm.c +++ b/lib/libc/db/hash/ndbm.c @@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$"); * NULL on failure */ extern DBM * -dbm_open(const char *file, int flags, int mode) +dbm_open(const char *file, int flags, mode_t mode) { HASHINFO info; char path[MAXPATHLEN]; diff --git a/lib/libc/db/man/dbm.3 b/lib/libc/db/man/dbm.3 index eedf804..4fe5d82 100644 --- a/lib/libc/db/man/dbm.3 +++ b/lib/libc/db/man/dbm.3 @@ -15,7 +15,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 19, 2015 +.Dd May 30, 2016 .Dt DBM 3 .Os .Sh NAME @@ -34,7 +34,7 @@ .In fcntl.h .In ndbm.h .Ft DBM * -.Fn dbm_open "const char *base" "int flags" "int mode" +.Fn dbm_open "const char *base" "int flags" "mode_t mode" .Ft void .Fn dbm_close "DBM *db" .Ft int @@ -66,7 +66,7 @@ is declared in .In ndbm.h : .Bd -literal typedef struct { - char *dptr; + void *dptr; int dsize; } datum; .Ed diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3 index 231acfa..ed7023b 100644 --- a/lib/libc/gen/psignal.3 +++ b/lib/libc/gen/psignal.3 @@ -28,7 +28,7 @@ .\" @(#)psignal.3 8.2 (Berkeley) 2/27/95 .\" $FreeBSD$ .\" -.Dd February 4, 2011 +.Dd May 30, 2016 .Dt PSIGNAL 3 .Os .Sh NAME @@ -42,7 +42,7 @@ .Sh SYNOPSIS .In signal.h .Ft void -.Fn psignal "unsigned sig" "const char *s" +.Fn psignal "int sig" "const char *s" .Vt extern const char * const sys_siglist[] ; .Vt extern const char * const sys_signame[] ; .In string.h diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index 5c5aada..d1c70c6 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -44,11 +44,11 @@ __FBSDID("$FreeBSD$"); #include "un-namespace.h" void -psignal(unsigned int sig, const char *s) +psignal(int sig, const char *s) { const char *c; - if (sig < NSIG) + if (sig >= 0 && sig < NSIG) c = sys_siglist[sig]; else c = "Unknown signal"; diff --git a/lib/libc/iconv/citrus_esdb.c b/lib/libc/iconv/citrus_esdb.c index ed404a6..299dd5f 100644 --- a/lib/libc/iconv/citrus_esdb.c +++ b/lib/libc/iconv/citrus_esdb.c @@ -291,18 +291,12 @@ _citrus_esdb_get_list(char ***rlist, size_t *rnum, bool sorted) /* get alias entries */ while ((ret = _lookup_seq_next(cla, &key, &data)) == 0) { - if (sorted) - snprintf(buf, sizeof(buf), "%.*s/%.*s", - (int)_region_size(&data), - (const char *)_region_head(&data), - (int)_region_size(&key), - (const char *)_region_head(&key)); - else - snprintf(buf, sizeof(buf), "%.*s/%.*s", - (int)_region_size(&data), - (const char *)_region_head(&data), - (int)_region_size(&key), - (const char *)_region_head(&key)); + /* XXX: sorted? */ + snprintf(buf, sizeof(buf), "%.*s/%.*s", + (int)_region_size(&data), + (const char *)_region_head(&data), + (int)_region_size(&key), + (const char *)_region_head(&key)); _bcs_convert_to_upper(buf); list[num] = strdup(buf); if (list[num] == NULL) { diff --git a/lib/libc/locale/ascii.c b/lib/libc/locale/ascii.c index 784814d..a70d71a 100644 --- a/lib/libc/locale/ascii.c +++ b/lib/libc/locale/ascii.c @@ -143,6 +143,7 @@ _ascii_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src, nchr = 0; while (len-- > 0 && nms-- > 0) { if (*s & 0x80) { + *src = s; errno = EILSEQ; return ((size_t)-1); } @@ -177,6 +178,7 @@ _ascii_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, nchr = 0; while (len-- > 0 && nwc-- > 0) { if (*s < 0 || *s > 127) { + *src = s; errno = EILSEQ; return ((size_t)-1); } diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c index c4695fd..4e5a61d 100644 --- a/lib/libc/locale/none.c +++ b/lib/libc/locale/none.c @@ -174,6 +174,7 @@ _none_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, nchr = 0; while (len-- > 0 && nwc-- > 0) { if (*s < 0 || *s > UCHAR_MAX) { + *src = s; errno = EILSEQ; return ((size_t)-1); } diff --git a/lib/libc/stdlib/div.c b/lib/libc/stdlib/div.c index 7dfe553..0bafbe6 100644 --- a/lib/libc/stdlib/div.c +++ b/lib/libc/stdlib/div.c @@ -46,6 +46,7 @@ div(num, denom) r.quot = num / denom; r.rem = num % denom; +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) /* * The ANSI standard says that |r.quot| <= |n/d|, where * n/d is to be computed in infinite precision. In other @@ -73,5 +74,6 @@ div(num, denom) r.quot++; r.rem -= denom; } +#endif return (r); } diff --git a/lib/libc/stdlib/imaxdiv.c b/lib/libc/stdlib/imaxdiv.c index 7dae467..adcab0b 100644 --- a/lib/libc/stdlib/imaxdiv.c +++ b/lib/libc/stdlib/imaxdiv.c @@ -37,9 +37,11 @@ imaxdiv(intmax_t numer, intmax_t denom) retval.quot = numer / denom; retval.rem = numer % denom; +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) if (numer >= 0 && retval.rem < 0) { retval.quot++; retval.rem -= denom; } +#endif return (retval); } diff --git a/lib/libc/stdlib/ldiv.c b/lib/libc/stdlib/ldiv.c index 0ec98e6..745c566 100644 --- a/lib/libc/stdlib/ldiv.c +++ b/lib/libc/stdlib/ldiv.c @@ -48,9 +48,11 @@ ldiv(num, denom) r.quot = num / denom; r.rem = num % denom; +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) if (num >= 0 && r.rem < 0) { r.quot++; r.rem -= denom; } +#endif return (r); } diff --git a/lib/libc/stdlib/lldiv.c b/lib/libc/stdlib/lldiv.c index b34b65e..197b48f 100644 --- a/lib/libc/stdlib/lldiv.c +++ b/lib/libc/stdlib/lldiv.c @@ -37,9 +37,11 @@ lldiv(long long numer, long long denom) retval.quot = numer / denom; retval.rem = numer % denom; +#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) if (numer >= 0 && retval.rem < 0) { retval.quot++; retval.rem -= denom; } +#endif return (retval); } diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index eb3c10a..2e0456a 100644 --- a/lib/libc/stdlib/rand.c +++ b/lib/libc/stdlib/rand.c @@ -48,14 +48,6 @@ __FBSDID("$FreeBSD$"); static int do_rand(unsigned long *ctx) { -#ifdef USE_WEAK_SEEDING -/* - * Historic implementation compatibility. - * The random sequences do not vary much with the seed, - * even with overflowing. - */ - return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); -#else /* !USE_WEAK_SEEDING */ /* * Compute x = (7^5 * x) mod (2^31 - 1) * without overflowing 31 bits: @@ -66,48 +58,34 @@ do_rand(unsigned long *ctx) */ long hi, lo, x; - /* Must be in [1, 0x7ffffffe] range at this point. */ - hi = *ctx / 127773; - lo = *ctx % 127773; + /* Transform to [1, 0x7ffffffe] range. */ + x = (*ctx % 0x7ffffffe) + 1; + hi = x / 127773; + lo = x % 127773; x = 16807 * lo - 2836 * hi; if (x < 0) x += 0x7fffffff; - *ctx = x; /* Transform to [0, 0x7ffffffd] range. */ - return (x - 1); -#endif /* !USE_WEAK_SEEDING */ + x--; + *ctx = x; + return (x); } int -rand_r(unsigned int *ctx) +rand_r(unsigned *ctx) { u_long val; int r; -#ifdef USE_WEAK_SEEDING val = *ctx; -#else - /* Transform to [1, 0x7ffffffe] range. */ - val = (*ctx % 0x7ffffffe) + 1; -#endif r = do_rand(&val); - -#ifdef USE_WEAK_SEEDING - *ctx = (unsigned int)val; -#else - *ctx = (unsigned int)(val - 1); -#endif + *ctx = (unsigned)val; return (r); } -static u_long next = -#ifdef USE_WEAK_SEEDING - 1; -#else - 2; -#endif +static u_long next = 1; int rand(void) @@ -116,13 +94,9 @@ rand(void) } void -srand(u_int seed) +srand(unsigned seed) { next = seed; -#ifndef USE_WEAK_SEEDING - /* Transform to [1, 0x7ffffffe] range. */ - next = (next % 0x7ffffffe) + 1; -#endif } @@ -144,10 +118,6 @@ sranddev(void) mib[0] = CTL_KERN; mib[1] = KERN_ARND; sysctl(mib, 2, (void *)&next, &len, NULL, 0); -#ifndef USE_WEAK_SEEDING - /* Transform to [1, 0x7ffffffe] range. */ - next = (next % 0x7ffffffe) + 1; -#endif } diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index f7b745e..fe8fc86 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -137,11 +137,7 @@ __FBSDID("$FreeBSD$"); */ #define MAX_TYPES 5 /* max number of types above */ -#ifdef USE_WEAK_SEEDING -#define NSHUFF 0 -#else /* !USE_WEAK_SEEDING */ #define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */ -#endif /* !USE_WEAK_SEEDING */ static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; static const int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; @@ -162,23 +158,12 @@ static const int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; static uint32_t randtbl[DEG_3 + 1] = { TYPE_3, -#ifdef USE_WEAK_SEEDING -/* Historic implementation compatibility */ -/* The random sequences do not vary much with the seed */ - 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, - 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, - 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, - 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, - 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, - 0x27fb47b9, -#else /* !USE_WEAK_SEEDING */ - 0x991539b1, 0x16a5bce3, 0x6774a4cd, 0x3e01511e, 0x4e508aaa, 0x61048c05, - 0xf5500617, 0x846b7115, 0x6a19892c, 0x896a97af, 0xdb48f936, 0x14898454, - 0x37ffd106, 0xb58bff9c, 0x59e17104, 0xcf918a49, 0x09378c83, 0x52c7a471, - 0x8d293ea9, 0x1f4fc301, 0xc3db71be, 0x39b44e1c, 0xf8a44ef9, 0x4c8b80b1, - 0x19edc328, 0x87bf4bdd, 0xc9b240e5, 0xe9ee4b1b, 0x4382aee7, 0x535b6b41, - 0xf3bec5da -#endif /* !USE_WEAK_SEEDING */ + 0x2cf41758, 0x27bb3711, 0x4916d4d1, 0x7b02f59f, 0x9b8e28eb, 0xc0e80269, + 0x696f5c16, 0x878f1ff5, 0x52d9c07f, 0x916a06cd, 0xb50b3a20, 0x2776970a, + 0xee4eb2a6, 0xe94640ec, 0xb1d65612, 0x9d1ed968, 0x1043f6b7, 0xa3432a76, + 0x17eacbb9, 0x3c09e2eb, 0x4f8c2b3, 0x708a1f57, 0xee341814, 0x95d0e4d2, + 0xb06f216c, 0x8bd2e72e, 0x8f7c38d7, 0xcfc6a8fc, 0x2a59495, 0xa20d2a69, + 0xe29d12d1 }; /* @@ -215,16 +200,8 @@ static int rand_sep = SEP_3; static uint32_t *end_ptr = &randtbl[DEG_3 + 1]; static inline uint32_t -good_rand(int32_t x) +good_rand(uint32_t ctx) { -#ifdef USE_WEAK_SEEDING -/* - * Historic implementation compatibility. - * The random sequences do not vary much with the seed, - * even with overflowing. - */ - return (1103515245 * x + 12345); -#else /* !USE_WEAK_SEEDING */ /* * Compute x = (7^5 * x) mod (2^31 - 1) * wihout overflowing 31 bits: @@ -233,18 +210,17 @@ good_rand(int32_t x) * Park and Miller, Communications of the ACM, vol. 31, no. 10, * October 1988, p. 1195. */ - int32_t hi, lo; + int32_t hi, lo, x; - /* Can't be initialized with 0, so use another value. */ - if (x == 0) - x = 123459876; + /* Transform to [1, 0x7ffffffe] range. */ + x = (ctx % 0x7ffffffe) + 1; hi = x / 127773; lo = x % 127773; x = 16807 * lo - 2836 * hi; if (x < 0) x += 0x7fffffff; - return (x); -#endif /* !USE_WEAK_SEEDING */ + /* Transform to [0, 0x7ffffffd] range. */ + return (x - 1); } /* @@ -404,16 +380,8 @@ setstate(char *arg_state) uint32_t rear = new_state[0] / MAX_TYPES; char *ostate = (char *)(&state[-1]); - switch(type) { - case TYPE_0: - case TYPE_1: - case TYPE_2: - case TYPE_3: - case TYPE_4: - break; - default: + if (type != TYPE_0 && rear >= degrees[type]) return (NULL); - } if (rand_type == TYPE_0) state[-1] = rand_type; else @@ -455,14 +423,14 @@ random(void) if (rand_type == TYPE_0) { i = state[0]; - state[0] = i = (good_rand(i)) & 0x7fffffff; + state[0] = i = good_rand(i); } else { /* * Use local variables rather than static variables for speed. */ f = fptr; r = rptr; *f += *r; - i = (*f >> 1) & 0x7fffffff; /* chucking least random bit */ + i = *f >> 1; /* chucking least random bit */ if (++f >= end_ptr) { f = state; ++r; diff --git a/lib/libc/sys/_umtx_op.2 b/lib/libc/sys/_umtx_op.2 index e2ce109..bd4ad3b 100644 --- a/lib/libc/sys/_umtx_op.2 +++ b/lib/libc/sys/_umtx_op.2 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 17, 2016 +.Dd May 29, 2016 .Dt _UMTX_OP 2 .Os .Sh NAME @@ -257,7 +257,7 @@ are defined, in addition to the common flags: .It Dv URWLOCK_PREFER_READER If specified, immediately grant read lock requests when .Dv urwlock -is already read-locked, even in presence of the unsatisfied write +is already read-locked, even in presence of unsatisfied write lock requests. By default, if there is a write lock waiter, further read requests are not granted, to prevent unfair write lock waiter starvation. @@ -387,7 +387,7 @@ variant which returns an error rather than sleeping if the lock cannot be obtained. Also, .Fn _umtx_op -provides requests which explicitely put the thread to sleep. +provides requests which explicitly put the thread to sleep. .Pp Wakes need to know which threads to make runnable, so sleeping threads are grouped into containers called @@ -399,12 +399,12 @@ Note that the .Em physical address is used, which means that same variable mapped multiple times will give one key value. -This mechanism enables the construction of the +This mechanism enables the construction of .Em process-shared locks. .Pp A related attribute of the key is shareability. -Some requests always interpet keys as private for the current process, +Some requests always interpret keys as private for the current process, creating sleep queues with the scope of the current process even if the memory is shared. Others either select the shareability automatically from the @@ -435,7 +435,8 @@ the queue are selected. The .Em robust umutexes are provided as a substrate for a userspace library to implement -POSIX robust mutexes. +.Tn POSIX +robust mutexes. A robust umutex must have the .Dv UMUTEX_ROBUST flag set. @@ -524,13 +525,13 @@ argument is compared with the If they are equal, the requesting thread is put to interruptible sleep until woken up or the optionally specified timeout expires. .Pp -The comparision and sleep are atomic. +The comparison and sleep are atomic. In other words, if another thread writes a new value to .Dv *obj and then issues .Dv UMTX_OP_WAKE , the request is guaranteed to not miss the wakeup, -which might otherwise happen between comparision and blocking. +which might otherwise happen between comparison and blocking. .Pp The physical address of memory where the .Fa *obj @@ -599,7 +600,7 @@ contention indicator, and provides the acquire barrier for lock entrance semantic. .Pp If the lock cannot be obtained immediately because another thread owns -the lock, the current thread is put into sleep, with +the lock, the current thread is put to sleep, with .Dv UMUTEX_CONTESTED bit set before. Upon wake up, the lock conditions are re-tested. @@ -668,7 +669,9 @@ New ceiling value. .It Fa uaddr Address of a variable of type .Vt uint32_t . -If not NULL, after the successful update the previous ceiling value is +If not +.Dv NULL +and the update was successful, the previous ceiling value is written to the location pointed to by .Fa uaddr . .El @@ -685,7 +688,9 @@ member of the after which the umutex is unlocked. .Pp The locking does not adhere to the priority protect protocol, -to confirm with the POSIX requirements for the +to conform to the +.Tn POSIX +requirements for the .Xr pthread_mutex_setprioceiling 3 interface. .It Dv UMTX_OP_CV_WAIT @@ -769,7 +774,8 @@ If the flag is supplied, the timeout specifies absolute time value, otherwise it denotes a relative time interval. .Pp -The request is not restartable. An unblocked signal delivered during +The request is not restartable. +An unblocked signal delivered during the wait always results in sleep interruption and .Er EINTR error. @@ -845,7 +851,7 @@ If the .Dv URWLOCK_WRITE_OWNER bit is set in the word .Dv rw_state , -the lock was granted to a writer which has not yet relinguished +the lock was granted to a writer which has not yet relinquished its ownership. In this case the current thread is put to sleep until it makes sense to retry. @@ -959,7 +965,7 @@ Same as .Dv UMTX_OP_WAKE , but unconditionally select the process-private sleep queue. .It Dv UMTX_OP_MUTEX_WAIT -Wait for the mutex availability. +Wait for mutex availability. The arguments to the request are: .Bl -tag -width "It Fa obj" .It Fa obj @@ -986,12 +992,12 @@ priority inherited protocol mutexes. Optionally, a timeout for the request may be specified. .Pp .Pp -The request with a timeout specified is not restartable. +A request with a timeout specified is not restartable. An unblocked signal delivered during the wait always results in sleep interruption and .Er EINTR error. -The request without a timeout automatically restarts if the signal disposition +A request without a timeout automatically restarts if the signal disposition requested restart via the .Dv SA_RESTART flag in @@ -999,7 +1005,7 @@ flag in member .Dv sa_flags . .It Dv UMTX_OP_NWAKE_PRIVATE -Wake up a batch of sleeping thread. +Wake up a batch of sleeping threads. The arguments to the request are: .Bl -tag -width "It Fa obj" .It Fa obj @@ -1016,7 +1022,7 @@ wakes up all threads waiting on the sleep queue with the key being the byte addressed by the array element. .It Dv UMTX_OP_MUTEX_WAKE -Check if the normal umutex is unlocked and wake up a waiter. +Check if a normal umutex is unlocked and wake up a waiter. The arguments for the request are: .Bl -tag -width "It Fa obj" .It Fa obj @@ -1035,8 +1041,22 @@ with the byte addressed by the if any. Only normal mutexes are supported by the request. The sleep queue is always one for a normal mutex type. +.Pp +This request is deprecated in favor of +.Dv UMTX_OP_MUTEX_WAKE2 +since mutexes using it cannot synchronize their own destruction. +That is, the +.Dv m_owner +word has already been set to +.Dv UMUTEX_UNOWNED +when this request is made, +so that another thread can lock, unlock and destroy the mutex +(if no other thread uses the mutex afterwards). +Clearing the +.Dv UMUTEX_CONTESTED +bit may then modify freed memory. .It Dv UMTX_OP_MUTEX_WAKE2 -Check if the umutex is unlocked and wake up a waiter. +Check if a umutex is unlocked and wake up a waiter. The arguments for the request are: .Bl -tag -width "It Fa obj" .It Fa obj @@ -1048,7 +1068,7 @@ The umutex flags. The request does not read the .Dv m_flags member of the -.Vt struct umutex , +.Vt struct umutex ; instead, the .Fa val argument supplies flag information, in particular, to determine the @@ -1064,8 +1084,7 @@ one waiter but the mutex is owned by a thread, the bit is set in the .Dv m_owner word of the -.Vt struct umutex -the request operates upon. +.Vt struct umutex . .It Dv UMTX_OP_SEM2_WAIT Wait until semaphore is available. The arguments to the request are: @@ -1076,12 +1095,12 @@ Pointer to the semaphore (of type .El Put the requesting thread onto a sleep queue if the semaphore counter is zero. -If thread is put to sleep, the +If the thread is put to sleep, the .Dv USEM_HAS_WAITERS bit is set in the .Dv _count word to indicate waiters. -Function returns either due to +The function returns either due to .Dv _count indicating the semaphore is available (non-zero count due to post), or due to a wakeup. @@ -1096,7 +1115,7 @@ interruption and .Er EINTR error. .It Dv UMTX_OP_SEM2_WAKE -Wake up waiters on the semaphore lock. +Wake up waiters on semaphore lock. The arguments to the request are: .Bl -tag -width "It Fa obj" .It Fa obj @@ -1112,7 +1131,9 @@ bit was set in the .Dv _count word, and the last sleeping thread was woken up, the bit is cleared. .It Dv UMTX_OP_SHM -Manage the anonymous POSIX shared objects (see +Manage anonymous +.Tn POSIX +shared memory objects (see .Xr shm_open 2 ) , which can be attached to a byte of physical memory, mapped into the process address space. @@ -1126,7 +1147,7 @@ argument specifies the sub-request of the request: .Bl -tag -width "Dv UMTX_SHM_DESTROY" .It Dv UMTX_SHM_CREAT -Creates the POSIX anonymous memory shared object, which can be looked up +Creates the anonymous shared memory object, which can be looked up with the specified key .Fa uaddr. If the object associated with the @@ -1143,7 +1164,7 @@ Same as request, but if there is no shared memory object associated with the specified key .Fa uaddr , -an error is returned, and new object is not created. +an error is returned, and no new object is created. .It Dv UMTX_SHM_DESTROY De-associate the shared object with the specified key .Fa uaddr. @@ -1158,7 +1179,7 @@ This request is an optimization of the .Dv UMTX_SHM_LOOKUP request. It is cheaper when only the liveness of the associated object is asked -for, since the file descriptor is not installed in the process fd table +for, since no file descriptor is installed in the process fd table on success. .El .Pp @@ -1212,7 +1233,7 @@ The kernel inspects the in addition to walking the shared and private lists. Also, the mutex pointed to by .Dv robust_inact_offset -is handled more loosly at the thread termination time, +is handled more loosely at the thread termination time, than other mutexes on the list. That mutex is allowed to be not owned by the current thread, in which case list processing is continued. @@ -1233,7 +1254,7 @@ The .Dv UMTX_SHM_CREAT and .Dv UMTX_SHM_LOOKUP -return a POSIX shared memory file descriptor on success. +return a shared memory file descriptor on success. On error \-1 is returned, and the .Va errno variable is set to indicate the error. @@ -1326,15 +1347,15 @@ and .Dv UMTX_SHM_ALIVE sub-requests of the .Dv UMTX_OP_SHM -request, there is no shared object associated with the provided key. +request, there is no shared memory object associated with the provided key. .It Bq Er ENOMEM The .Dv UMTX_SHM_CREAT sub-request of the .Dv UMTX_OP_SHM -request cannot be satisfied, because allocation of the shared object +request cannot be satisfied, because allocation of the shared memory object would exceed the -.Dv RLIMIT_UMXP +.Dv RLIMIT_UMTXP resource limit, see .Xr setrlimit 2 . .It Bq Er EAGAIN @@ -1358,7 +1379,7 @@ specified in absolute time may be restartable. .It Bq Er ERESTART A signal was delivered during wait, for a restartable operation. Mutex lock requests without timeout specified are restartable. -The error is typically not returned to userspace code, restart +The error is not returned to userspace code since restart is handled by usual adjustment of the instruction counter. .El .Sh BUGS @@ -1374,7 +1395,7 @@ implementation is only vulnerable to this race when operating on a shared mutex. A possible fix for the current implementation is to strengthen the checks for shared mutexes before terminating them, in particular, verifying -that the mutex memory is mapped from the POSIX shared object, allocated +that the mutex memory is mapped from a shared memory object allocated by the .Dv UMTX_OP_SHM request. @@ -1402,5 +1423,5 @@ system call is non-standard and is used by the .Lb libthr to implement .St -p1003.1-2001 -.Xr pthread(3) +.Xr pthread 3 functionality. diff --git a/lib/libc/sys/jail.2 b/lib/libc/sys/jail.2 index 8b6add9..2e13a6c 100644 --- a/lib/libc/sys/jail.2 +++ b/lib/libc/sys/jail.2 @@ -106,7 +106,7 @@ pointers can be set to an arrays of IPv4 and IPv6 addresses to be assigned to the prison, or NULL if none. IPv4 addresses must be in network byte order. .Pp -This is equivalent to the +This is equivalent to, and deprecated in favor of, the .Fn jail_set system call (see below), with the parameters .Va path , diff --git a/lib/libc/sys/thr_exit.2 b/lib/libc/sys/thr_exit.2 index 0804219..781b07f 100644 --- a/lib/libc/sys/thr_exit.2 +++ b/lib/libc/sys/thr_exit.2 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_EXIT 2 .Os .Sh NAME @@ -41,24 +41,33 @@ .Ft void .Fn thr_exit "long *state" .Sh DESCRIPTION +.Bf -symbolic +This function is intended for implementing threading. +Normal applications should call +.Xr pthread_exit 3 +instead. +.Ef +.Pp The .Fn thr_exit system call terminates the current kernel-scheduled thread. .Pp If the .Fa state -argument is not NULL, the location pointed to by the argument is -updated with an arbitrary non-zero value, and +argument is not +.Dv NULL , +the location pointed to by the argument is +updated with an arbitrary non-zero value, and an .Xr _umtx_op 2 .Dv UMTX_OP_WAKE operation is consequently performed on the location. .Pp -Attempts to terminate last thread in the process are silently ignored. +Attempts to terminate the last thread in the process are silently ignored. Use .Xr _exit 2 syscall to terminate the process. .Sh RETURN VALUES -The function does not return any values. +The function does not return a value. A return from the function indicates that the calling thread was the last one in the process. .Sh SEE ALSO @@ -68,13 +77,14 @@ last one in the process. .Xr thr_new 2 , .Xr thr_self 2 , .Xr thr_set_name 2 , -.Xr _umtx_op 2 +.Xr _umtx_op 2 , +.Xr pthread_exit 3 .Sh STANDARDS The .Fn thr_exit -system call is non-standard and is used by the +system call is non-standard and is used by .Lb libthr to implement .St -p1003.1-2001 -.Xr pthread(3) +.Xr pthread 3 functionality. diff --git a/lib/libc/sys/thr_kill.2 b/lib/libc/sys/thr_kill.2 index 8c12ef7..04293aa 100644 --- a/lib/libc/sys/thr_kill.2 +++ b/lib/libc/sys/thr_kill.2 @@ -28,12 +28,12 @@ .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_kill 2 .Os .Sh NAME .Nm thr_kill -.Nd send signal to the thread +.Nd send signal to thread .Sh LIBRARY .Lb libc .Sh SYNOPSIS @@ -72,7 +72,7 @@ The .Fa sig argument defines the delivered signal. It must be a valid signal number or zero. -In the later case no signal is actually send, and the call is used to +In the latter case no signal is actually sent, and the call is used to verify the liveness of the thread. .Pp The signal is delivered with @@ -112,11 +112,13 @@ The current process does not have sufficient privilege to check existence or send a signal to the specified process. .El .Sh SEE ALSO +.Xr kill 2 , .Xr thr_exit 2 , .Xr thr_new 2 , .Xr thr_self 2 , .Xr thr_set_name 2 , .Xr _umtx_op 2 , +.Xr pthread_kill 3 , .Xr signal 3 .Sh STANDARDS The @@ -127,5 +129,5 @@ system calls are non-standard and are used by the .Lb libthr to implement .St -p1003.1-2001 -.Xr pthread(3) +.Xr pthread 3 functionality. diff --git a/lib/libc/sys/thr_new.2 b/lib/libc/sys/thr_new.2 index 44c468d..1de5f92 100644 --- a/lib/libc/sys/thr_new.2 +++ b/lib/libc/sys/thr_new.2 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_NEW 2 .Os .Sh NAME @@ -41,6 +41,13 @@ .Ft int .Fn thr_new "struct thr_param *param" "int param_size" .Sh DESCRIPTION +.Bf -symbolic +This function is intended for implementing threading. +Normal applications should call +.Xr pthread_create 3 +instead. +.Ef +.Pp The .Fn thr_new system call creates a new kernel-scheduled thread of execution in the context @@ -52,7 +59,7 @@ The machine context for the new thread is copied from the creating thread's context, including coprocessor state. FPU state and specific machine registers are excluded from the copy. These are set according to ABI requirements and syscall parameters. -The FPU state for new thread is reinitialized to clean. +The FPU state for the new thread is reinitialized to clean. .Pp The .Fa param @@ -77,22 +84,22 @@ struct thr_param { and contains the following fields: .Bl -tag -width ".Va parent_tid" .It Va start_func -The pointer to the thread entry function. -Kernel arranges for the new thread to start executing the function +Pointer to the thread entry function. +The kernel arranges for the new thread to start executing the function upon the first return to userspace. .It Va arg Opaque argument supplied to the entry function. .It Va stack_base Stack base address. The stack must be allocated by the caller. -On some architectures, the ABI might require that system put information +On some architectures, the ABI might require that the system put information on the stack to ensure the execution environment for .Va start_func . .It Va stack_size Stack size. .It Va tls_base TLS base address. -The value of TLS base is loaded to the ABI-defined machine register +The value of TLS base is loaded into the ABI-defined machine register in the new thread context. .It Va tls_size TLS size. @@ -113,9 +120,9 @@ issuing the syscall, while .Va parent_tid is used by the thread creator. -The later is separate from the +The latter is separate from .Va child_tid -because new thread might exit and free its thread data before parent +because the new thread might exit and free its thread data before the parent has a chance to execute far enough to access it. .It Va flags Thread creation flags. @@ -132,7 +139,9 @@ The flag is not currently implemented. .El .It Va rtp Real-time scheduling priority for the new thread. -May be NULL if thread should inherit the priority from the +May be +.Dv NULL +to inherit the priority from the creating thread. .El .Pp @@ -184,14 +193,16 @@ initial data on the stack. .It Bq Er EINVAL The .Fa param_size -argument specifies negative value, or its value is greater than the +argument specifies a negative value, or the value is greater than the largest .Fa struct param size the kernel can interpret. .It Bq Er EINVAL The .Fa rtp -member is not NULL, but specifies invalid scheduling parameters. +member is not +.Dv NULL +and specifies invalid scheduling parameters. .It Bq Er EINVAL The specified TLS base is invalid. .It Bq Er EPROCLIM @@ -216,7 +227,8 @@ No kernel memory to allocate for the new thread structures. .Xr thr_kill2 2 , .Xr thr_self 2 , .Xr thr_set_name 2 , -.Xr _umtx_op 2 +.Xr _umtx_op 2 , +.Xr pthread_create 3 .Sh STANDARDS The .Fn thr_new @@ -224,5 +236,5 @@ system call is non-standard and is used by the .Lb libthr to implement .St -p1003.1-2001 -.Xr pthread(3) +.Xr pthread 3 functionality. diff --git a/lib/libc/sys/thr_self.2 b/lib/libc/sys/thr_self.2 index d90b863..949b600 100644 --- a/lib/libc/sys/thr_self.2 +++ b/lib/libc/sys/thr_self.2 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_SELF 2 .Os .Sh NAME @@ -76,13 +76,15 @@ argument is not valid. .Xr thr_kill2 2 , .Xr thr_new 2 , .Xr thr_set_name 2 , -.Xr _umtx_op 2 +.Xr _umtx_op 2 , +.Xr pthread_getthreadid_np 3 , +.Xr pthread_self 3 .Sh STANDARDS The .Fn thr_self -system call is non-standard and is used by the +system call is non-standard and is used by .Lb libthr to implement .St -p1003.1-2001 -.Xr pthread(3) +.Xr pthread 3 functionality. diff --git a/lib/libc/sys/thr_set_name.2 b/lib/libc/sys/thr_set_name.2 index 681e94b..d2549e4 100644 --- a/lib/libc/sys/thr_set_name.2 +++ b/lib/libc/sys/thr_set_name.2 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_SET_NAME 2 .Os .Sh NAME @@ -45,7 +45,7 @@ The .Fn thr_set_name sets the user-visible name for the kernel thread with the identifier .Va id -in the current process, to the NULL-terminated string +in the current process, to the NUL-terminated string .Va name . The thread name can be seen in the output of the .Xr ps 1 @@ -87,10 +87,11 @@ does not exist in the current process. .Xr thr_new 2 , .Xr thr_self 2 , .Xr _umtx_op 2 , +.Xr pthread_set_name_np 3 , .Xr ddb 4 , .Xr ktr 9 .Sh STANDARDS The .Fn thr_new -system call is non-standard and is used by the +system call is non-standard and is used by .Lb libthr . diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2 index 687bc18..38b7bb7 100644 --- a/lib/libc/sys/wait.2 +++ b/lib/libc/sys/wait.2 @@ -28,7 +28,7 @@ .\" @(#)wait.2 8.2 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd December 3, 2013 +.Dd June 1, 2016 .Dt WAIT 2 .Os .Sh NAME @@ -596,6 +596,14 @@ and fields of .Fa infop must be checked against zero to determine if a process reported status. +.Pp +.Fn wait +called with -1 to wait for any child process will ignore a child that is +referenced by a process descriptor (see +.Xr pdfork 2 ) . +Specific processes can still be waited on by specifying the process ID +or descriptor (see +.Xr pdwait 4 ) . .Sh ERRORS The .Fn wait |