aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/sys
diff options
context:
space:
mode:
authorJulian Elischer <julian@FreeBSD.org>1996-01-22 00:02:33 +0000
committerJulian Elischer <julian@FreeBSD.org>1996-01-22 00:02:33 +0000
commitf70177e76e605ec6e6cd5b938fa77ade5d380e87 (patch)
treea89c7f50ec371cef4418259b9dccdd31ebb2f61f /lib/libc/sys
parent61de51cad66df0d565233915f856932159d33a4a (diff)
downloadsrc-f70177e76e605ec6e6cd5b938fa77ade5d380e87.tar.gz
src-f70177e76e605ec6e6cd5b938fa77ade5d380e87.zip
Reviewed by: julian and (hsu?)
Submitted by: John Birrel(L?) changes for threadsafe operations
Notes
Notes: svn path=/head/; revision=13545
Diffstat (limited to 'lib/libc/sys')
-rw-r--r--lib/libc/sys/accept.225
-rw-r--r--lib/libc/sys/bind.222
-rw-r--r--lib/libc/sys/close.222
-rw-r--r--lib/libc/sys/connect.228
-rw-r--r--lib/libc/sys/dup.247
-rw-r--r--lib/libc/sys/execve.217
-rw-r--r--lib/libc/sys/fcntl.223
-rw-r--r--lib/libc/sys/flock.222
-rw-r--r--lib/libc/sys/fsync.222
-rw-r--r--lib/libc/sys/ftruncate.c16
-rw-r--r--lib/libc/sys/getdirentries.222
-rw-r--r--lib/libc/sys/getpeername.222
-rw-r--r--lib/libc/sys/getsockname.222
-rw-r--r--lib/libc/sys/getsockopt.245
-rw-r--r--lib/libc/sys/intro.244
-rw-r--r--lib/libc/sys/ioctl.222
-rw-r--r--lib/libc/sys/listen.224
-rw-r--r--lib/libc/sys/lseek.c17
-rw-r--r--lib/libc/sys/open.220
-rw-r--r--lib/libc/sys/read.247
-rw-r--r--lib/libc/sys/write.247
21 files changed, 567 insertions, 9 deletions
diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2
index d475e3685b43..126000a2ecb6 100644
--- a/lib/libc/sys/accept.2
+++ b/lib/libc/sys/accept.2
@@ -129,6 +129,31 @@ by issuing a
call with providing only the control information,
or by calling
.Xr setsockopt 2 .
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn accept
+is implemented as the
+.Va accept
+syscall.
+.Pp
+In the threaded library, the
+.Va accept
+syscall is assembled to
+.Fn _thread_sys_accept
+and
+.Fn accept
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_accept .
+If the call to
+.Fn _thread_sys_accept
+would block, a context switch is performed. Before returning,
+.Fn accept
+unlocks
+.Va s .
+.Pp
.Sh RETURN VALUES
The call returns \-1 on error. If it succeeds, it returns a non-negative
integer that is a descriptor for the accepted socket.
diff --git a/lib/libc/sys/bind.2 b/lib/libc/sys/bind.2
index 18512e29e5c9..f98631d7939b 100644
--- a/lib/libc/sys/bind.2
+++ b/lib/libc/sys/bind.2
@@ -62,6 +62,28 @@ needed (using
.Pp
The rules used in name binding vary between communication domains.
Consult the manual entries in section 4 for detailed information.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn bind
+is implemented as the
+.Va bind
+syscall.
+.Pp
+In the threaded library, the
+.Va bind
+syscall is assembled to
+.Fn _thread_sys_bind
+and
+.Fn bind
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_bind .
+Before returning,
+.Fn bind
+unlocks
+.Va s .
.Sh RETURN VALUES
If the bind is successful, a 0 value is returned.
A return value of -1 indicates an error, which is
diff --git a/lib/libc/sys/close.2 b/lib/libc/sys/close.2
index 885ac807b693..3cb3d51d3b74 100644
--- a/lib/libc/sys/close.2
+++ b/lib/libc/sys/close.2
@@ -90,6 +90,28 @@ execve; the call
.Dq Li fcntl(d, F_SETFD, 0)
restores the default,
which is to not close the descriptor.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn close
+is implemented as the
+.Va close
+syscall.
+.Pp
+In the threaded library, the
+.Va close
+syscall is assembled to
+.Fn _thread_sys_close
+and
+.Fn close
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_close .
+Before returning,
+.Fn close
+unlocks
+.Va d .
.Sh RETURN VALUES
Upon successful completion, a value of 0 is returned.
Otherwise, a value of -1 is returned and the global integer variable
diff --git a/lib/libc/sys/connect.2 b/lib/libc/sys/connect.2
index eb38ab320b4b..a6d7c7133165 100644
--- a/lib/libc/sys/connect.2
+++ b/lib/libc/sys/connect.2
@@ -68,6 +68,30 @@ only once; datagram sockets may use
multiple times to change their association.
Datagram sockets may dissolve the association
by connecting to an invalid address, such as a null address.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn connect
+is implemented as the
+.Va connect
+syscall.
+.Pp
+In the threaded library, the
+.Va connect
+syscall is assembled to
+.Fn _thread_sys_connect
+and
+.Fn connect
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_connect .
+If the call to
+.Fn _thread_sys_connect
+would block, a context switch is performed. Before returning,
+.Fn connect
+unlocks
+.Va s .
.Sh RETURN VALUES
If the connection or binding succeeds, 0 is returned.
Otherwise a -1 is returned, and a more specific error
@@ -79,10 +103,10 @@ The
call fails if:
.Bl -tag -width EADDRNOTAVAILABB
.It Bq Er EBADF
-.Fa S
+.Fa s
is not a valid descriptor.
.It Bq Er ENOTSOCK
-.Fa S
+.Fa s
is a descriptor for a file, not a socket.
.It Bq Er EADDRNOTAVAIL
The specified address is not available on this machine.
diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2
index 898963923e8c..29d1ada27b77 100644
--- a/lib/libc/sys/dup.2
+++ b/lib/libc/sys/dup.2
@@ -95,6 +95,53 @@ is specified. If this descriptor is already
in use, the descriptor is first deallocated as if a
.Xr close 2
call had been done first.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn dup
+is implemented as the
+.Va dup
+syscall.
+.Pp
+In the threaded library, the
+.Va dup
+syscall is assembled to
+.Fn _thread_sys_dup
+and
+.Fn dup
+is implemented as a function which locks
+.Va oldd
+for read and write, then calls
+.Fn _thread_sys_dup .
+Before returning,
+.Fn dup
+unlocks
+.Va oldd .
+.Pp
+In the non-threaded library
+.Fn dup2
+is implemented as the
+.Va dup2
+syscall.
+.Pp
+In the threaded library, the
+.Va dup2
+syscall is assembled to
+.Fn _thread_sys_dup2
+and
+.Fn dup2
+is implemented as a function which locks both
+.Va oldd
+and
+.Va newd
+for read and write, then calls
+.Fn _thread_sys_dup2 .
+Before returning,
+.Fn dup2
+unlocks
+.Va oldd .
+and
+.Va newd .
.Sh RETURN VALUES
The value -1 is returned if an error occurs in either call.
The external variable
diff --git a/lib/libc/sys/execve.2 b/lib/libc/sys/execve.2
index ba47e6d1833c..2bfb0a2bc254 100644
--- a/lib/libc/sys/execve.2
+++ b/lib/libc/sys/execve.2
@@ -178,6 +178,23 @@ and
.Fa argv
points to the array of character pointers
to the arguments themselves.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn execve
+is implemented as the
+.Va execve
+syscall.
+.Pp
+In the threaded library, the
+.Va execve
+syscall is assembled to
+.Fn _thread_sys_execve
+and
+.Fn execve
+is implemented as a function which performs user-thread
+library re-initialization and then calls
+.Fn _thread_sys_execve .
.Sh RETURN VALUES
As the
.Fn execve
diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2
index f53c02f2403d..eb752fe2fe96 100644
--- a/lib/libc/sys/fcntl.2
+++ b/lib/libc/sys/fcntl.2
@@ -330,6 +330,29 @@ This implementation detects that sleeping until a locked region is unlocked
would cause a deadlock and fails with an
.Er EDEADLK
error.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn fcntl
+is implemented as the
+.Va fcntl
+syscall.
+.Pp
+In the threaded library, the
+.Va fcntl
+syscall is assembled to
+.Fn _thread_sys_fcntl
+and
+.Fn fcntl
+is implemented as a function which disables thread resheduling, locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_fcntl .
+Before returning,
+.Fn fcntl
+unlocks
+.Va fd
+and enables thread resheduling.
.Sh RETURN VALUES
Upon successful completion, the value returned depends on
.Fa cmd
diff --git a/lib/libc/sys/flock.2 b/lib/libc/sys/flock.2
index bb6abb75fc5b..5ec080c5f5d1 100644
--- a/lib/libc/sys/flock.2
+++ b/lib/libc/sys/flock.2
@@ -109,6 +109,28 @@ forks and the child explicitly unlocks the file, the parent will
lose its lock.
.Pp
Processes blocked awaiting a lock may be awakened by signals.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn flock
+is implemented as the
+.Va flock
+syscall.
+.Pp
+In the threaded library, the
+.Va flock
+syscall is assembled to
+.Fn _thread_sys_flock
+and
+.Fn flock
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_flock .
+Before returning,
+.Fn flock
+unlocks
+.Va fd .
.Sh RETURN VALUES
Zero is returned if the operation was successful;
on an error a -1 is returned and an error code is left in
diff --git a/lib/libc/sys/fsync.2 b/lib/libc/sys/fsync.2
index 234ea6e996ed..1116cf9b3605 100644
--- a/lib/libc/sys/fsync.2
+++ b/lib/libc/sys/fsync.2
@@ -53,6 +53,28 @@ of buffers for the associated file to be written to a disk.
should be used by programs that require a file to be
in a known state, for example, in building a simple transaction
facility.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn fsync
+is implemented as the
+.Va fsync
+syscall.
+.Pp
+In the threaded library, the
+.Va fsync
+syscall is assembled to
+.Fn _thread_sys_fsync
+and
+.Fn fsync
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_fsync .
+Before returning,
+.Fn fsync
+unlocks
+.Va fd .
.Sh RETURN VALUES
A 0 value is returned on success. A -1 value indicates
an error.
diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c
index 2f3ae6d5a024..72a6a9158153 100644
--- a/lib/libc/sys/ftruncate.c
+++ b/lib/libc/sys/ftruncate.c
@@ -37,6 +37,11 @@ static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93";
#include <sys/types.h>
#include <sys/syscall.h>
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* This function provides 64-bit offset padding that
@@ -48,5 +53,16 @@ ftruncate(fd, length)
off_t length;
{
+#ifdef _THREAD_SAFE
+ int retval;
+ if (_thread_fd_lock(fd, FD_RDWR, NULL,__FILE__,__LINE__) != 0) {
+ retval = -1;
+ } else {
+ retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length);
+ _thread_fd_unlock(fd, FD_RDWR);
+ }
+ return(retval);
+#else
return(__syscall((quad_t)SYS_ftruncate, fd, 0, length));
+#endif
}
diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2
index 6df944420db6..9e6dc508eb89 100644
--- a/lib/libc/sys/getdirentries.2
+++ b/lib/libc/sys/getdirentries.2
@@ -120,6 +120,28 @@ The current position pointer should only be set to a value returned by
a value returned in the location pointed to by
.Fa basep ,
or zero.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getdirentries
+is implemented as the
+.Va getdirentries
+syscall.
+.Pp
+In the threaded library, the
+.Va getdirentries
+syscall is assembled to
+.Fn _thread_sys_getdirentries
+and
+.Fn getdirentries
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_getdirentries .
+Before returning,
+.Fn getdirentries
+unlocks
+.Va fd .
.Sh RETURN VALUES
If successful, the number of bytes actually transferred is returned.
Otherwise, -1 is returned and the global variable
diff --git a/lib/libc/sys/getpeername.2 b/lib/libc/sys/getpeername.2
index d89488c3aaf9..5ca0a443c326 100644
--- a/lib/libc/sys/getpeername.2
+++ b/lib/libc/sys/getpeername.2
@@ -53,6 +53,28 @@ the amount of space pointed to by
On return it contains the actual size of the name
returned (in bytes).
The name is truncated if the buffer provided is too small.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getpeername
+is implemented as the
+.Va getpeername
+syscall.
+.Pp
+In the threaded library, the
+.Va getpeername
+syscall is assembled to
+.Fn _thread_sys_getpeername
+and
+.Fn getpeername
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_getpeername .
+Before returning,
+.Fn getpeername
+unlocks
+.Va s .
.Sh DIAGNOSTICS
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2
index d56e40486646..e053b4768e7b 100644
--- a/lib/libc/sys/getsockname.2
+++ b/lib/libc/sys/getsockname.2
@@ -51,6 +51,28 @@ the amount of space pointed to by
.Fa name .
On return it contains the actual size of the name
returned (in bytes).
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getsockname
+is implemented as the
+.Va getsockname
+syscall.
+.Pp
+In the threaded library, the
+.Va getsockname
+syscall is assembled to
+.Fn _thread_sys_getsockname
+and
+.Fn getsockname
+is implemented as a function which locks
+.Va fd
+for read and write, then calls
+.Fn _thread_sys_getsockname .
+Before returning,
+.Fn getsockname
+unlocks
+.Va fd .
.Sh DIAGNOSTICS
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2
index 24ae2b8b4660..e2ec25751e95 100644
--- a/lib/libc/sys/getsockopt.2
+++ b/lib/libc/sys/getsockopt.2
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94
-.\" $Id$
+.\" $Id: getsockopt.2,v 1.2 1995/11/03 18:34:36 wollman Exp $
.\"
.Dd November 3, 1995
.Dt GETSOCKOPT 2
@@ -313,6 +313,49 @@ returns any pending error on the socket and clears
the error status.
It may be used to check for asynchronous errors on connected
datagram sockets or for other asynchronous errors.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn getsockopt
+is implemented as the
+.Va getsockopt
+syscall.
+.Pp
+In the threaded library, the
+.Va getsockopt
+syscall is assembled to
+.Fn _thread_sys_getsockopt
+and
+.Fn getsockopt
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_getsockopt .
+Before returning,
+.Fn getsockopt
+unlocks
+.Va s .
+.Pp
+In the non-threaded library
+.Fn setsockopt
+is implemented as the
+.Va setsockopt
+syscall.
+.Pp
+In the threaded library, the
+.Va setsockopt
+syscall is assembled to
+.Fn _thread_sys_setsockopt
+and
+.Fn setsockopt
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_setsockopt .
+Before returning,
+.Fn setsockopt
+unlocks
+.Va s .
.Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails.
.Sh ERRORS
diff --git a/lib/libc/sys/intro.2 b/lib/libc/sys/intro.2
index bf4380917e39..a6e735155544 100644
--- a/lib/libc/sys/intro.2
+++ b/lib/libc/sys/intro.2
@@ -47,13 +47,49 @@ their error returns, and other common definitions and concepts.
.\".Pp
.\"<more later...>
.Sh DIAGNOSTICS
-Nearly all of the system calls provide an error number in the external
-variable
-.Va errno ,
-which is defined as:
+Nearly all of the system calls provide an error number referenced via
+the external identifier errno. This identifier is defined in
+.Aq Pa sys/errno.h
+for non-threaded programs as:
.Pp
.Dl extern int errno
.Pp
+and for threaded programs as:
+.Pp
+.Dl extern int * __error();
+.Dl #define errno (* __error())
+.Pp
+A threaded program must be compiled with
+.Va _THREAD_SAFE
+defined so that the preprocessor will output the appropriate errno
+definition to the compiler. Failure to do so will mean that error
+variables will not be thread specific.
+.Pp
+The threaded library implementation of
+.Va __error()
+returns a pointer to a field in the thread specific structure for
+threads other than the initial thread. For the initial thread,
+.Va __error()
+returns a pointer to a global
+.Va errno
+variable that is compatible with that used by non-threaded programs.
+This allows the initial thread to call functions in libraries which have
+not been compiled with
+.Va _THREAD_SAFE .
+Programmers should ensure that threads other than the initial thread only
+call functions in libraries that have been compiled with
+.Va _THREAD_SAFE .
+.Pp
+Programmers should include
+.Aq Pa sys/errno.h to obtain the definition of
+.Va errno
+rather than coding the definition as an external reference directly. It is
+planned that the
+.Va extern int errno
+definition will eventually be replaced by the threaded definition so that
+all libraries will have a thread-aware treatment of
+.Va errno .
+.Pp
When a system call detects an error,
it returns an integer value
indicating failure (usually -1)
diff --git a/lib/libc/sys/ioctl.2 b/lib/libc/sys/ioctl.2
index 36ce6ff47f65..38c58b9dcf59 100644
--- a/lib/libc/sys/ioctl.2
+++ b/lib/libc/sys/ioctl.2
@@ -68,6 +68,28 @@ Macros and defines used in specifying an ioctl
.Fa request
are located in the file
.Ao Pa sys/ioctl.h Ac .
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn ioctl
+is implemented as the
+.Va ioctl
+syscall.
+.Pp
+In the threaded library, the
+.Va ioctl
+syscall is assembled to
+.Fn _thread_sys_ioctl
+and
+.Fn ioctl
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_ioctl .
+Before returning,
+.Fn ioctl
+unlocks
+.Va d .
.Sh RETURN VALUES
If an error has occurred, a value of -1 is returned and
.Va errno
diff --git a/lib/libc/sys/listen.2 b/lib/libc/sys/listen.2
index eaa9522d5ee5..6d2a64f14522 100644
--- a/lib/libc/sys/listen.2
+++ b/lib/libc/sys/listen.2
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)listen.2 8.2 (Berkeley) 12/11/93
-.\" $Id$
+.\" $Id: listen.2,v 1.3 1995/11/03 18:34:38 wollman Exp $
.\"
.Dd November 3, 1995
.Dt LISTEN 2
@@ -82,6 +82,28 @@ or less than zero is specified,
.Fa backlog
is silently forced to
.Li kern.somaxconn .
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn listen
+is implemented as the
+.Va listen
+syscall.
+.Pp
+In the threaded library, the
+.Va listen
+syscall is assembled to
+.Fn _thread_sys_listen
+and
+.Fn listen
+is implemented as a function which locks
+.Va s
+for read and write, then calls
+.Fn _thread_sys_listen .
+Before returning,
+.Fn listen
+unlocks
+.Va s .
.Sh RETURN VALUES
A 0 return value indicates success; -1 indicates an error.
.Sh ERRORS
diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c
index 52208d137a93..8896ad8d3567 100644
--- a/lib/libc/sys/lseek.c
+++ b/lib/libc/sys/lseek.c
@@ -37,6 +37,11 @@ static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93";
#include <sys/types.h>
#include <sys/syscall.h>
+#include <unistd.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/*
* This function provides 64-bit offset padding that
@@ -48,7 +53,17 @@ lseek(fd, offset, whence)
off_t offset;
int whence;
{
- extern off_t __syscall();
+#ifdef _THREAD_SAFE
+ off_t offs;
+ if (_thread_fd_lock(fd, FD_RDWR, NULL,__FILE__,__LINE__) != 0) {
+ offs = -1;
+ } else {
+ offs = __syscall((quad_t) SYS_lseek,fd, 0, offset, whence);
+ _thread_fd_unlock(fd, FD_RDWR);
+ }
+ return(offs);
+#else
return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence));
+#endif
}
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index dea59fcce346..479a20944ac7 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -146,6 +146,26 @@ The system imposes a limit on the number of file descriptors
open simultaneously by one process.
.Xr Getdtablesize 2
returns the current system limit.
+.Pp
+.Sh IMPLEMENTATION NOTES
+In the non-threaded library
+.Fn open
+is implemented as the
+.Va open
+syscall.
+.Pp
+In the threaded library, the
+.Va open
+syscall is assembled to
+.Fn _thread_sys_open
+and
+.Fn open
+is implemented as a function which disables thread rescheduling
+and calls
+.Fn _thread_sys_open .
+Before returning,
+.Fn open
+enables thread rescheduling.
.Sh ERRORS
The named file is opened unless:
.Bl -tag -width Er
diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2
index b94341a043c0..ea428fd47a12 100644
--- a/lib/libc/sys/read.2
+++ b/lib/libc/sys/read.2
@@ -107,6 +107,53 @@ The system guarantees to read the number of bytes requested if
the descriptor references a normal file that has that many bytes left
before the end-of-file, but in no other case.
.Pp
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn read
+is implemented as the
+.Va read
+syscall.
+.Pp
+In the threaded library, the
+.Va read
+syscall is assembled to
+.Fn _thread_sys_read
+and
+.Fn read
+is implemented as a function which locks
+.Va d
+for read, then calls
+.Fn _thread_sys_read .
+If the call to
+.Fn _thread_sys_read
+would block, a context switch is performed. Before returning,
+.Fn read
+unlocks
+.Va d .
+.Pp
+In the non-threaded library
+.Fn readv
+is implemented as the
+.Va readv
+syscall.
+.Pp
+In the threaded library, the
+.Va readv
+syscall is assembled to
+.Fn _thread_sys_readv
+and
+.Fn readv
+is implemented as a function which locks
+.Va d
+for read, then calls
+.Fn _thread_sys_readv .
+If the call to
+.Fn _thread_sys_readv
+would block, a context switch is performed. Before returning,
+.Fn readv
+unlocks
+.Va d .
.Sh RETURN VALUES
If successful, the
number of bytes actually read is returned. Upon reading end-of-file,
diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2
index de2d3aef59ab..a1e4a517cbe2 100644
--- a/lib/libc/sys/write.2
+++ b/lib/libc/sys/write.2
@@ -115,6 +115,53 @@ and
may write fewer bytes than requested;
the return value must be noted,
and the remainder of the operation should be retried when possible.
+.Sh IMPLEMENTATION NOTES
+.Pp
+In the non-threaded library
+.Fn write
+is implemented as the
+.Va write
+syscall.
+.Pp
+In the threaded library, the
+.Va write
+syscall is assembled to
+.Fn _thread_sys_write
+and
+.Fn write
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_write .
+If the call to
+.Fn _thread_sys_write
+would block, a context switch is performed. Before returning,
+.Fn write
+unlocks
+.Va d .
+.Pp
+In the non-threaded library
+.Fn writev
+is implemented as the
+.Va writev
+syscall.
+.Pp
+In the threaded library, the
+.Va writev
+syscall is assembled to
+.Fn _thread_sys_writev
+and
+.Fn writev
+is implemented as a function which locks
+.Va d
+for read and write, then calls
+.Fn _thread_sys_writev .
+If the call to
+.Fn _thread_sys_writev
+would block, a context switch is performed. Before returning,
+.Fn writev
+unlocks
+.Va d .
.Sh RETURN VALUES
Upon successful completion the number of bytes which were written
is returned. Otherwise a -1 is returned and the global variable