Index: head/lib/libc/sys/thr_exit.2 =================================================================== --- head/lib/libc/sys/thr_exit.2 (revision 301170) +++ head/lib/libc/sys/thr_exit.2 (revision 301171) @@ -1,82 +1,90 @@ .\" Copyright (c) 2016 The FreeBSD Foundation, Inc. .\" All rights reserved. .\" .\" This documentation was written by .\" Konstantin Belousov under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHORS 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 AUTHORS 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. .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_EXIT 2 .Os .Sh NAME .Nm thr_exit .Nd terminate current thread .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/thr.h .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 .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 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 a value. A return from the function indicates that the calling thread was the last one in the process. .Sh SEE ALSO .Xr _exit 2 , .Xr thr_kill 2 , .Xr thr_kill2 2 , .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 .Lb libthr to implement .St -p1003.1-2001 .Xr pthread 3 functionality. Index: head/lib/libc/sys/thr_kill.2 =================================================================== --- head/lib/libc/sys/thr_kill.2 (revision 301170) +++ head/lib/libc/sys/thr_kill.2 (revision 301171) @@ -1,131 +1,133 @@ .\" Copyright (c) 2016 The FreeBSD Foundation, Inc. .\" All rights reserved. .\" .\" This documentation was written by .\" Konstantin Belousov under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHORS 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 AUTHORS 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. .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_kill 2 .Os .Sh NAME .Nm thr_kill .Nd send signal to thread .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/thr.h .Ft int .Fn thr_kill "long id" "int sig" .Ft int .Fn thr_kill2 "pid_t pid" "long id" "int sig" .Sh DESCRIPTION The .Fn thr_kill and .Fn thr_kill2 system calls allow sending a signal, specified by the .Fa sig argument, to some threads in a process. For the .Fn thr_kill function, signalled threads are always limited to the current process. For the .Fn thr_kill2 function, the .Fa pid argument specifies the process with threads to be signalled. .Pp The .Fa id argument specifies which threads get the signal. If .Fa id is equal to \-1, all threads in the specified process are signalled. Otherwise, only the thread with the thread identifier equal to the argument is signalled. .Pp The .Fa sig argument defines the delivered signal. It must be a valid signal number or zero. 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 .Dv siginfo .Dv si_code set to .Dv SI_LWP . .Sh RETURN VALUES If successful, .Fn thr_kill and .Fn thr_kill2 will return zero, otherwise \-1 is returned, and .Va errno is set to indicate the error. .Sh ERRORS The .Fn thr_kill and .Fn thr_kill2 operations return the following errors: .Bl -tag -width Er .It Bq Er EINVAL The .Fa sig argument is not zero and does not specify valid signal. .It Bq Er ESRCH The specified process or thread was not found. .El .Pp Additionally, the .Fn thr_kill2 may return the following errors: .Bl -tag -width Er .It Bq Er EPERM 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 .Fn thr_kill and .Fn thr_kill2 system calls are non-standard and are used by the .Lb libthr to implement .St -p1003.1-2001 .Xr pthread 3 functionality. Index: head/lib/libc/sys/thr_new.2 =================================================================== --- head/lib/libc/sys/thr_new.2 (revision 301170) +++ head/lib/libc/sys/thr_new.2 (revision 301171) @@ -1,232 +1,240 @@ .\" Copyright (c) 2016 The FreeBSD Foundation, Inc. .\" All rights reserved. .\" .\" This documentation was written by .\" Konstantin Belousov under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHORS 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 AUTHORS 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. .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_NEW 2 .Os .Sh NAME .Nm thr_new .Nd create new thread of execution .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/thr.h .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 of the current process. The newly created thread shares all attributes of the process with the existing kernel-scheduled threads in the process, but has private processor execution state. 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 the new thread is reinitialized to clean. .Pp The .Fa param structure supplies parameters affecting the thread creation. The structure is defined in the .In sys/thr.h header as follows .Bd -literal struct thr_param { void (*start_func)(void *); void *arg; char *stack_base; size_t stack_size; char *tls_base; size_t tls_size; long *child_tid; long *parent_tid; int flags; struct rtprio *rtp; }; .Ed and contains the following fields: .Bl -tag -width ".Va parent_tid" .It Va start_func 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 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 into the ABI-defined machine register in the new thread context. .It Va tls_size TLS size. .It Va child_tid Address to store the new thread identifier, for the child's use. .It Va parent_tid Address to store the new thread identifier, for the parent's use. .Pp Both .Va child_tid and .Va parent_tid are provided, with the intent that .Va child_tid is used by the new thread to get its thread identifier without issuing the .Xr thr_self 2 syscall, while .Va parent_tid is used by the thread creator. The latter is separate from .Va child_tid 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. The .Va flags member may specify the following flags: .Bl -tag -width ".Dv THR_SYSTEM_SCOPE" .It Dv THR_SUSPENDED Create the new thread in the suspended state. The flag is not currently implemented. .It Dv THR_SYSTEM_SCOPE Create the system scope thread. The flag is not currently implemented. .El .It Va rtp Real-time scheduling priority for the new thread. May be .Dv NULL to inherit the priority from the creating thread. .El .Pp The .Fa param_size argument should be set to the size of the .Fa param structure. .Pp After the first successful creation of an additional thread, the process is marked by the kernel as multi-threaded. In particular, the .Dv P_HADTHREADS flag is set in the process' .Dv p_flag (visible in the .Xr ps 1 output), and several operations are executed in multi-threaded mode. For instance, the .Xr execve 2 system call terminates all threads but the calling one on successful execution. .Sh RETURN VALUES If successful, .Fn thr_new will return zero, otherwise \-1 is returned, and .Va errno is set to indicate the error. .Sh ERRORS The .Fn thr_new operation returns the following errors: .Bl -tag -width Er .It Bq Er EFAULT The memory pointed to by the .Fa param argument is not valid. .It Bq Er EFAULT The memory pointed to by the .Fa param structure .Fa child_tid , parent_tid or .Fa rtp arguments is not valid. .It Bq Er EFAULT Specified stack base is invalid, or the kernel was unable to put required initial data on the stack. .It Bq Er EINVAL The .Fa param_size 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 .Dv NULL and specifies invalid scheduling parameters. .It Bq Er EINVAL The specified TLS base is invalid. .It Bq Er EPROCLIM Creation of the new thread would exceed the .Dv RACCT_NTHR limit, see .Xr racct 2 . .It Bq Er EPROCLIM Creation of the new thread would exceed the .Dv kern.threads.max_threads_per_proc .Xr sysctl 2 limit. .It Bq Er ENOMEM No kernel memory to allocate for the new thread structures. .El .Sh SEE ALSO .Xr ps 1 , .Xr execve 2 , .Xr racct 2 , .Xr thr_exit 2 , .Xr thr_kill 2 , .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 system call is non-standard and is used by the .Lb libthr to implement .St -p1003.1-2001 .Xr pthread 3 functionality. Index: head/lib/libc/sys/thr_self.2 =================================================================== --- head/lib/libc/sys/thr_self.2 (revision 301170) +++ head/lib/libc/sys/thr_self.2 (revision 301171) @@ -1,88 +1,90 @@ .\" Copyright (c) 2016 The FreeBSD Foundation, Inc. .\" All rights reserved. .\" .\" This documentation was written by .\" Konstantin Belousov under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHORS 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 AUTHORS 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. .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_SELF 2 .Os .Sh NAME .Nm thr_self .Nd return thread identifier for the calling thread .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/thr.h .Ft int .Fn thr_self "long *id" .Sh DESCRIPTION The .Fn thr_self system call stores the system-wide thread identifier for the current kernel-scheduled thread in the variable pointed by the argument .Va id . .Pp The thread identifier is an integer in the range from .Dv PID_MAX + 2 (10002) to .Dv INT_MAX . The thread identifier is guaranteed to be unique at any given time, for each running thread in the system. After the thread exits, the identifier may be reused. .Sh RETURN VALUES If successful, .Fn thr_self will return zero, otherwise \-1 is returned, and .Va errno is set to indicate the error. .Sh ERRORS The .Fn thr_self operation may return the following errors: .Bl -tag -width Er .It Bq Er EFAULT The memory pointed to by the .Fa id argument is not valid. .El .Sh SEE ALSO .Xr thr_exit 2 , .Xr thr_kill 2 , .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 .Lb libthr to implement .St -p1003.1-2001 .Xr pthread 3 functionality. Index: head/lib/libc/sys/thr_set_name.2 =================================================================== --- head/lib/libc/sys/thr_set_name.2 (revision 301170) +++ head/lib/libc/sys/thr_set_name.2 (revision 301171) @@ -1,96 +1,97 @@ .\" Copyright (c) 2016 The FreeBSD Foundation, Inc. .\" All rights reserved. .\" .\" This documentation was written by .\" Konstantin Belousov under sponsorship .\" from the FreeBSD Foundation. .\" .\" 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 AUTHORS 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 AUTHORS 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. .\" .\" $FreeBSD$ .\" -.Dd May 5, 2016 +.Dd June 1, 2016 .Dt THR_SET_NAME 2 .Os .Sh NAME .Nm thr_set_name .Nd set user-visible thread name .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/thr.h .Ft int .Fn thr_set_name "long id" "const char *name" .Sh DESCRIPTION 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 NUL-terminated string .Va name . The thread name can be seen in the output of the .Xr ps 1 and .Xr top 1 commands, in the kernel debuggers and kernel tracing facility outputs, also in userland debuggers and program core files, as notes. .Sh RETURN VALUES If successful, .Fn thr_set_name will return zero, otherwise \-1 is returned, and .Va errno is set to indicate the error. .Sh ERRORS The .Fn thr_set_name operation may return the following errors: .Bl -tag -width Er .It Bq Er EFAULT The memory pointed to by the .Fa name argument is not valid. .It Bq Er ENAMETOOLONG The string pointed to by the .Fa name argument exceeds .Dv MAXCOMLEN + 1 bytes in length. .It Bq Er ESRCH The thread with the identifier .Fa id does not exist in the current process. .El .Sh SEE ALSO .Xr ps 1 , .Xr thr_exit 2 , .Xr thr_kill 2 , .Xr thr_kill2 2 , .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 .Lb libthr .