aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2020-12-30 07:18:30 -0500
committerRuss Cox <rsc@swtch.com>2020-12-30 07:53:28 -0500
commit18571208068d5fe2f0bf7b4e980525a7f577c503 (patch)
treebaf2061164df38258cc6127a102ab76d9089fb31
parente68f07d46f5f168dc2076286627279540bf1f99e (diff)
downloadplan9port-18571208068d5fe2f0bf7b4e980525a7f577c503.tar.gz
plan9port-18571208068d5fe2f0bf7b4e980525a7f577c503.tar.bz2
plan9port-18571208068d5fe2f0bf7b4e980525a7f577c503.zip
libthread: simplify
Now that everything uses pthreads and pthreadperthread, can delete various conditionals, all the custom context code, and so on. Also update documents. Fixes #355.
-rw-r--r--include/libc.h2
-rw-r--r--include/u.h7
-rw-r--r--src/libthread/386-ucontext.c22
-rw-r--r--src/libthread/386-ucontext.h119
-rw-r--r--src/libthread/COPYING.SPARC64-CONTEXT458
-rw-r--r--src/libthread/COPYRIGHT9
-rw-r--r--src/libthread/Linux-arm-asm.s41
-rw-r--r--src/libthread/Linux-sparc64-context.S135
-rw-r--r--src/libthread/OpenBSD-386-asm.s45
-rw-r--r--src/libthread/OpenBSD-power-asm.S73
-rw-r--r--src/libthread/OpenBSD-x86_64-asm.S44
-rw-r--r--src/libthread/arm-ucontext.c24
-rw-r--r--src/libthread/mkfile3
-rw-r--r--src/libthread/power-ucontext.c26
-rw-r--r--src/libthread/power-ucontext.h36
-rw-r--r--src/libthread/sparc64-ucontext.c49
-rw-r--r--src/libthread/stkmalloc.c13
-rw-r--r--src/libthread/stkmmap.c25
-rw-r--r--src/libthread/sysofiles.sh27
-rw-r--r--src/libthread/thread.c217
-rw-r--r--src/libthread/threadimpl.h44
-rw-r--r--src/libthread/x86_64-ucontext.c28
-rw-r--r--src/libthread/x86_64-ucontext.h42
23 files changed, 12 insertions, 1477 deletions
diff --git a/include/libc.h b/include/libc.h
index 4bb537d6..1e24f0bb 100644
--- a/include/libc.h
+++ b/include/libc.h
@@ -473,10 +473,8 @@ extern _Thread *(*threadnow)(void);
typedef struct Lock Lock;
struct Lock
{
-#ifdef PLAN9PORT_USING_PTHREADS
int init;
pthread_mutex_t mutex;
-#endif
int held;
};
diff --git a/include/u.h b/include/u.h
index f84e348a..856e10f4 100644
--- a/include/u.h
+++ b/include/u.h
@@ -67,7 +67,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
#if defined(__linux__)
# include <sys/types.h>
# include <pthread.h>
-# define PLAN9PORT_USING_PTHREADS 1
# if defined(__USE_MISC)
# undef _NEEDUSHORT
# undef _NEEDUINT
@@ -76,7 +75,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
#elif defined(__sun__)
# include <sys/types.h>
# include <pthread.h>
-# define PLAN9PORT_USING_PTHREADS 1
# undef _NEEDUSHORT
# undef _NEEDUINT
# undef _NEEDULONG
@@ -84,7 +82,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
#elif defined(__FreeBSD__)
# include <sys/types.h>
# include <osreldate.h>
-# define PLAN9PORT_USING_PTHREADS 1
# include <pthread.h>
# if !defined(_POSIX_SOURCE)
# undef _NEEDUSHORT
@@ -93,7 +90,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
#elif defined(__APPLE__)
# include <sys/types.h>
# include <pthread.h>
-# define PLAN9PORT_USING_PTHREADS 1
# if __GNUC__ < 4
# undef _NEEDUSHORT
# undef _NEEDUINT
@@ -108,20 +104,19 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
#elif defined(__NetBSD__)
# include <sched.h>
# include <sys/types.h>
+# include <pthread.h>
# undef _NEEDUSHORT
# undef _NEEDUINT
# undef _NEEDULONG
#elif defined(__OpenBSD__)
# include <sys/types.h>
# include <pthread.h>
-# define PLAN9PORT_USING_PTHREADS 1
# undef _NEEDUSHORT
# undef _NEEDUINT
# undef _NEEDULONG
#else
/* No idea what system this is -- try some defaults */
# include <pthread.h>
-# define PLAN9PORT_USING_PTHREADS 1
#endif
#ifndef O_DIRECT
diff --git a/src/libthread/386-ucontext.c b/src/libthread/386-ucontext.c
deleted file mode 100644
index 3afa9513..00000000
--- a/src/libthread/386-ucontext.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "threadimpl.h"
-
-void
-makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
-{
- int *sp;
-
- sp = USPALIGN(ucp, 4);
- sp -= argc;
- memmove(sp, &argc+1, argc*sizeof(int));
- *--sp = 0; /* return address */
- ucp->uc_mcontext.mc_eip = (long)func;
- ucp->uc_mcontext.mc_esp = (int)sp;
-}
-
-int
-swapcontext(ucontext_t *oucp, ucontext_t *ucp)
-{
- if(getcontext(oucp) == 0)
- setcontext(ucp);
- return 0;
-}
diff --git a/src/libthread/386-ucontext.h b/src/libthread/386-ucontext.h
deleted file mode 100644
index b1ee81b3..00000000
--- a/src/libthread/386-ucontext.h
+++ /dev/null
@@ -1,119 +0,0 @@
-#define setcontext(u) setmcontext(&(u)->uc_mcontext)
-#define getcontext(u) getmcontext(&(u)->uc_mcontext)
-typedef struct mcontext mcontext_t;
-typedef struct ucontext ucontext_t;
-
-extern int swapcontext(ucontext_t*, ucontext_t*);
-extern void makecontext(ucontext_t*, void(*)(), int, ...);
-extern int getmcontext(mcontext_t*);
-extern void setmcontext(mcontext_t*);
-
-/*-
- * Copyright (c) 1999 Marcel Moolenaar
- * 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
- * in this position and unchanged.
- * 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.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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: src/sys/sys/ucontext.h,v 1.4 1999/10/11 20:33:17 luoqi Exp $
- */
-
-/* #include <machine/ucontext.h> */
-
-/*-
- * Copyright (c) 1999 Marcel Moolenaar
- * 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
- * in this position and unchanged.
- * 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.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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: src/sys/i386/include/ucontext.h,v 1.4 1999/10/11 20:33:09 luoqi Exp $
- */
-
-struct mcontext {
- /*
- * The first 20 fields must match the definition of
- * sigcontext. So that we can support sigcontext
- * and ucontext_t at the same time.
- */
- int mc_onstack; /* XXX - sigcontext compat. */
- int mc_gs;
- int mc_fs;
- int mc_es;
- int mc_ds;
- int mc_edi;
- int mc_esi;
- int mc_ebp;
- int mc_isp;
- int mc_ebx;
- int mc_edx;
- int mc_ecx;
- int mc_eax;
- int mc_trapno;
- int mc_err;
- int mc_eip;
- int mc_cs;
- int mc_eflags;
- int mc_esp; /* machine state */
- int mc_ss;
-
- int mc_fpregs[28]; /* env87 + fpacc87 + u_long */
- int __spare__[17];
-};
-
-struct ucontext {
- /*
- * Keep the order of the first two fields. Also,
- * keep them the first two fields in the structure.
- * This way we can have a union with struct
- * sigcontext and ucontext_t. This allows us to
- * support them both at the same time.
- * note: the union is not defined, though.
- */
- sigset_t uc_sigmask;
- mcontext_t uc_mcontext;
-
- struct __ucontext *uc_link;
- stack_t uc_stack;
- int __spare__[8];
-};
diff --git a/src/libthread/COPYING.SPARC64-CONTEXT b/src/libthread/COPYING.SPARC64-CONTEXT
deleted file mode 100644
index 3b204400..00000000
--- a/src/libthread/COPYING.SPARC64-CONTEXT
+++ /dev/null
@@ -1,458 +0,0 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
diff --git a/src/libthread/COPYRIGHT b/src/libthread/COPYRIGHT
index d0820965..212b96bc 100644
--- a/src/libthread/COPYRIGHT
+++ b/src/libthread/COPYRIGHT
@@ -42,12 +42,3 @@ Contains parts of an earlier library that has:
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
-
-===
-
-The above notices do *NOT* apply to Linux-sparc64-context.S
-or to sparc64-ucontext.c. Those are functions from
-the GNU C library and are provided for systems that use the GNU C
-library but somehow are missing those functions. They are
-distributed under the Lesser GPL; see COPYING.SPARC64-CONTEXT.
-
diff --git a/src/libthread/Linux-arm-asm.s b/src/libthread/Linux-arm-asm.s
deleted file mode 100644
index 9bd54f8a..00000000
--- a/src/libthread/Linux-arm-asm.s
+++ /dev/null
@@ -1,41 +0,0 @@
-.globl mygetmcontext
-mygetmcontext:
- str r1, [r0,#4]
- str r2, [r0,#8]
- str r3, [r0,#12]
- str r4, [r0,#16]
- str r5, [r0,#20]
- str r6, [r0,#24]
- str r7, [r0,#28]
- str r8, [r0,#32]
- str r9, [r0,#36]
- str r10, [r0,#40]
- str r11, [r0,#44]
- str r12, [r0,#48]
- str r13, [r0,#52]
- str r14, [r0,#56]
- /* store 1 as r0-to-restore */
- mov r1, #1
- str r1, [r0]
- /* return 0 */
- mov r0, #0
- mov pc, lr
-
-.globl mysetmcontext
-mysetmcontext:
- ldr r1, [r0,#4]
- ldr r2, [r0,#8]
- ldr r3, [r0,#12]
- ldr r4, [r0,#16]
- ldr r5, [r0,#20]
- ldr r6, [r0,#24]
- ldr r7, [r0,#28]
- ldr r8, [r0,#32]
- ldr r9, [r0,#36]
- ldr r10, [r0,#40]
- ldr r11, [r0,#44]
- ldr r12, [r0,#48]
- ldr r13, [r0,#52]
- ldr r14, [r0,#56]
- ldr r0, [r0]
- mov pc, lr
diff --git a/src/libthread/Linux-sparc64-context.S b/src/libthread/Linux-sparc64-context.S
deleted file mode 100644
index 1cc38391..00000000
--- a/src/libthread/Linux-sparc64-context.S
+++ /dev/null
@@ -1,135 +0,0 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Jakub Jelinek <jakub@redhat.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-/* Constants shared between setcontext() and getcontext(). Don't
- install this header file. */
-
-
-#define UC_LINK 0
-#define __UC_SIGMASK 16
-#define UC_M_PC 40
-#define UC_M_NPC 48
-#define UC_SIGMASK 536
-#define SIGMASK_WORDS 16
-
-/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Richard Henderson (rth@tamu.edu).
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#define ENTRY(x) x:
-#define END(x)
-
-/*#include "ucontext_i.h" (up above) */
-
-/* int getcontext(ucontext_t *); */
-
-ENTRY(getcontext)
-
- ldx [%o0 + UC_LINK], %o1 /* Preserve uc_link field, the
- trap clears it. */
- ta 0x6e
-1:
- ldx [%o0 + UC_M_PC], %o2
- ldx [%o0 + UC_M_NPC], %o3
- ldx [%o0 + __UC_SIGMASK], %o4
- stx %o1, [%o0 + UC_LINK]
- add %o2, 2f - 1b, %o2
- stx %o2, [%o0 + UC_M_PC]
- add %o3, 2f - 1b, %o3
- stx %o3, [%o0 + UC_M_NPC]
-#if SIGMASK_WORDS == 16
- stx %o4, [%o0 + UC_SIGMASK]
- stx %g0, [%o0 + UC_SIGMASK + 8]
- stx %g0, [%o0 + UC_SIGMASK + 16]
- stx %g0, [%o0 + UC_SIGMASK + 24]
- stx %g0, [%o0 + UC_SIGMASK + 32]
- stx %g0, [%o0 + UC_SIGMASK + 40]
- stx %g0, [%o0 + UC_SIGMASK + 48]
- stx %g0, [%o0 + UC_SIGMASK + 56]
- stx %g0, [%o0 + UC_SIGMASK + 64]
- stx %g0, [%o0 + UC_SIGMASK + 72]
- stx %g0, [%o0 + UC_SIGMASK + 80]
- stx %g0, [%o0 + UC_SIGMASK + 88]
- stx %g0, [%o0 + UC_SIGMASK + 96]
- stx %g0, [%o0 + UC_SIGMASK + 104]
- stx %g0, [%o0 + UC_SIGMASK + 112]
- stx %g0, [%o0 + UC_SIGMASK + 120]
-#else
-# error Adjust getcontext
-#endif
-2:
- retl
- clr %o0
-
-END(getcontext)
-
-/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Richard Henderson (rth@tamu.edu).
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-/*
-#include <sysdep.h>
-#include "ucontext_i.h"
-*/
-
-/* int setcontext(ucontext_t *ctx); */
-.weak setcontext
-ENTRY(setcontext)
-
- mov 1, %o1
-
-/* int __setcontext(ucontext_t *ctx, int restoremask); */
-ENTRY(__setcontext)
-
- ldx [%o0 + UC_SIGMASK], %o2
- stx %o2, [%o0 + __UC_SIGMASK]
- ta 0x6f
-
-END(__setcontext)
-
diff --git a/src/libthread/OpenBSD-386-asm.s b/src/libthread/OpenBSD-386-asm.s
deleted file mode 100644
index ed18d2f0..00000000
--- a/src/libthread/OpenBSD-386-asm.s
+++ /dev/null
@@ -1,45 +0,0 @@
-.globl getmcontext
-getmcontext:
- movl 4(%esp), %eax
-
- movl %fs, 8(%eax)
- movl %es, 12(%eax)
- movl %ds, 16(%eax)
- movl %ss, 76(%eax)
- movl %edi, 20(%eax)
- movl %esi, 24(%eax)
- movl %ebp, 28(%eax)
- movl %ebx, 36(%eax)
- movl %edx, 40(%eax)
- movl %ecx, 44(%eax)
-
- movl $1, 48(%eax) /* %eax */
- movl (%esp), %ecx /* %eip */
- movl %ecx, 60(%eax)
- leal 4(%esp), %ecx /* %esp */
- movl %ecx, 72(%eax)
-
- movl 44(%eax), %ecx /* restore %ecx */
- movl $0, %eax
- ret
-
-.globl setmcontext
-setmcontext:
- movl 4(%esp), %eax
-
- movl 8(%eax), %fs
- movl 12(%eax), %es
- movl 16(%eax), %ds
- movl 76(%eax), %ss
- movl 20(%eax), %edi
- movl 24(%eax), %esi
- movl 28(%eax), %ebp
- movl 36(%eax), %ebx
- movl 40(%eax), %edx
- movl 44(%eax), %ecx
-
- movl 72(%eax), %esp
- pushl 60(%eax) /* new %eip */
- movl 48(%eax), %eax
- ret
-
diff --git a/src/libthread/OpenBSD-power-asm.S b/src/libthread/OpenBSD-power-asm.S
deleted file mode 100644
index 36035eb5..00000000
--- a/src/libthread/OpenBSD-power-asm.S
+++ /dev/null
@@ -1,73 +0,0 @@
-ENTRY(_getmcontext) /* xxx: instruction scheduling */
- mflr %r0
- mfcr %r5
- mfctr %r6
- mfxer %r7
- stw %r0, 0*4(%r3)
- stw %r5, 1*4(%r3)
- stw %r6, 2*4(%r3)
- stw %r7, 3*4(%r3)
-
- stw %r1, 4*4(%r3)
- stw %r2, 5*4(%r3)
- li %r5, 1 /* return value for setmcontext */
- stw %r5, 6*4(%r3)
-
- stw %r13, (0+7)*4(%r3) /* callee-save GPRs */
- stw %r14, (1+7)*4(%r3) /* xxx: block move */
- stw %r15, (2+7)*4(%r3)
- stw %r16, (3+7)*4(%r3)
- stw %r17, (4+7)*4(%r3)
- stw %r18, (5+7)*4(%r3)
- stw %r19, (6+7)*4(%r3)
- stw %r20, (7+7)*4(%r3)
- stw %r21, (8+7)*4(%r3)
- stw %r22, (9+7)*4(%r3)
- stw %r23, (10+7)*4(%r3)
- stw %r24, (11+7)*4(%r3)
- stw %r25, (12+7)*4(%r3)
- stw %r26, (13+7)*4(%r3)
- stw %r27, (14+7)*4(%r3)
- stw %r28, (15+7)*4(%r3)
- stw %r29, (16+7)*4(%r3)
- stw %r30, (17+7)*4(%r3)
- stw %r31, (18+7)*4(%r3)
-
- li %r3, 0 /* return */
- blr
-
-ENTRY(_setmcontext)
- lwz %r13, (0+7)*4(%r3) /* callee-save GPRs */
- lwz %r14, (1+7)*4(%r3) /* xxx: block move */
- lwz %r15, (2+7)*4(%r3)
- lwz %r16, (3+7)*4(%r3)
- lwz %r17, (4+7)*4(%r3)
- lwz %r18, (5+7)*4(%r3)
- lwz %r19, (6+7)*4(%r3)
- lwz %r20, (7+7)*4(%r3)
- lwz %r21, (8+7)*4(%r3)
- lwz %r22, (9+7)*4(%r3)
- lwz %r23, (10+7)*4(%r3)
- lwz %r24, (11+7)*4(%r3)
- lwz %r25, (12+7)*4(%r3)
- lwz %r26, (13+7)*4(%r3)
- lwz %r27, (14+7)*4(%r3)
- lwz %r28, (15+7)*4(%r3)
- lwz %r29, (16+7)*4(%r3)
- lwz %r30, (17+7)*4(%r3)
- lwz %r31, (18+7)*4(%r3)
-
- lwz %r1, 4*4(%r3)
- lwz %r2, 5*4(%r3)
-
- lwz %r0, 0*4(%r3)
- mtlr %r0
- lwz %r0, 1*4(%r3)
- mtcr %r0 /* mtcrf 0xFF, %r0 */
- lwz %r0, 2*4(%r3)
- mtctr %r0
- lwz %r0, 3*4(%r3)
- mtxer %r0
-
- lwz %r3, 6*4(%r3)
- blr
diff --git a/src/libthread/OpenBSD-x86_64-asm.S b/src/libthread/OpenBSD-x86_64-asm.S
deleted file mode 100644
index e982cdef..00000000
--- a/src/libthread/OpenBSD-x86_64-asm.S
+++ /dev/null
@@ -1,44 +0,0 @@
-.text
-.align 8
-
-.globl libthread_getmcontext
-libthread_getmcontext:
- movq $1, 0*8(%rdi) // rax
- movq %rbx, 1*8(%rdi)
- movq %rcx, 2*8(%rdi)
- movq %rdx, 3*8(%rdi)
- movq %rsi, 4*8(%rdi)
- movq %rdi, 5*8(%rdi)
- movq %rbp, 6*8(%rdi)
- movq %rsp, 7*8(%rdi)
- movq %r8, 8*8(%rdi)
- movq %r9, 9*8(%rdi)
- movq %r10, 10*8(%rdi)
- movq %r11, 11*8(%rdi)
- movq %r12, 12*8(%rdi)
- movq %r13, 13*8(%rdi)
- movq %r14, 14*8(%rdi)
- movq %r15, 15*8(%rdi)
- movq $0, %rax
- ret
-
-.globl libthread_setmcontext
-libthread_setmcontext:
- movq 0*8(%rdi), %rax
- movq 1*8(%rdi), %rbx
- movq 2*8(%rdi), %rcx
- movq 3*8(%rdi), %rdx
- movq 4*8(%rdi), %rsi
- // %rdi later
- movq 6*8(%rdi), %rbp
- movq 7*8(%rdi), %rsp
- movq 8*8(%rdi), %r8
- movq 9*8(%rdi), %r9
- movq 10*8(%rdi), %r10
- movq 11*8(%rdi), %r11
- movq 12*8(%rdi), %r12
- movq 13*8(%rdi), %r13
- movq 14*8(%rdi), %r14
- movq 15*8(%rdi), %r15
- movq 5*8(%rdi), %rdi
- ret
diff --git a/src/libthread/arm-ucontext.c b/src/libthread/arm-ucontext.c
deleted file mode 100644
index 512ca973..00000000
--- a/src/libthread/arm-ucontext.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "threadimpl.h"
-
-void
-makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
-{
- int i, *sp;
- va_list arg;
-
- sp = USPALIGN(uc, 4);
- va_start(arg, argc);
- for(i=0; i<4 && i<argc; i++)
- (&uc->uc_mcontext.arm_r0)[i] = va_arg(arg, uint);
- va_end(arg);
- uc->uc_mcontext.arm_sp = (uint)sp;
- uc->uc_mcontext.arm_lr = (uint)fn;
-}
-
-int
-swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
-{
- if(getcontext(oucp) == 0)
- setcontext(ucp);
- return 0;
-}
diff --git a/src/libthread/mkfile b/src/libthread/mkfile
index eca4f4df..40941f43 100644
--- a/src/libthread/mkfile
+++ b/src/libthread/mkfile
@@ -1,15 +1,14 @@
<$PLAN9/src/mkhdr
-SYSOFILES=`{sh ./sysofiles.sh}
LIB=libthread.a
OFILES=\
- $SYSOFILES\
bg.$O\
channel.$O\
daemonize.$O\
exec.$O\
ioproc.$O\
iorw.$O\
+ pthread.$O\
ref.$O\
thread.$O\
wait.$O\
diff --git a/src/libthread/power-ucontext.c b/src/libthread/power-ucontext.c
deleted file mode 100644
index 32a8e931..00000000
--- a/src/libthread/power-ucontext.c
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "threadimpl.h"
-
-void
-makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
-{
- ulong *sp, *tos;
- va_list arg;
-
- if(argc != 2)
- sysfatal("libthread: makecontext misused");
- sp = USPALIGN(ucp, 16);
- ucp->mc.pc = (long)func;
- ucp->mc.sp = (long)sp;
- va_start(arg, argc);
- ucp->mc.r3 = va_arg(arg, long);
- ucp->mc.r4 = va_arg(arg, long);
- va_end(arg);
-}
-
-int
-swapcontext(ucontext_t *oucp, ucontext_t *ucp)
-{
- if(getcontext(oucp) == 0)
- setcontext(ucp);
- return 0;
-}
diff --git a/src/libthread/power-ucontext.h b/src/libthread/power-ucontext.h
deleted file mode 100644
index 1985d98d..00000000
--- a/src/libthread/power-ucontext.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#define setcontext(u) _setmcontext(&(u)->mc)
-#define getcontext(u) _getmcontext(&(u)->mc)
-typedef struct mcontext mcontext_t;
-typedef struct ucontext ucontext_t;
-struct mcontext
-{
- ulong pc; /* lr */
- ulong cr; /* mfcr */
- ulong ctr; /* mfcr */
- ulong xer; /* mfcr */
- ulong sp; /* callee saved: r1 */
- ulong toc; /* callee saved: r2 */
- ulong r3; /* first arg to function, return register: r3 */
- ulong gpr[19]; /* callee saved: r13-r31 */
-/*
-// XXX: currently do not save vector registers or floating-point state
-// ulong pad;
-// uvlong fpr[18]; / * callee saved: f14-f31 * /
-// ulong vr[4*12]; / * callee saved: v20-v31, 256-bits each * /
-*/
-};
-
-struct ucontext
-{
- struct {
- void *ss_sp;
- uint ss_size;
- } uc_stack;
- sigset_t uc_sigmask;
- mcontext_t mc;
-};
-
-void makecontext(ucontext_t*, void(*)(void), int, ...);
-int swapcontext(ucontext_t*, ucontext_t*);
-int _getmcontext(mcontext_t*);
-void _setmcontext(mcontext_t*);
diff --git a/src/libthread/sparc64-ucontext.c b/src/libthread/sparc64-ucontext.c
deleted file mode 100644
index e4800c19..00000000
--- a/src/libthread/sparc64-ucontext.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Jakub Jelinek <jakub@redhat.com>.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <ucontext.h>
-
-#define UC_M_PC 40
-#define UC_M_NPC 48
-
-extern int __getcontext (ucontext_t *ucp);
-extern int __setcontext (const ucontext_t *ucp, int restoremask);
-
-int
-swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
-{
- extern void __swapcontext_ret (void);
- /* Save the current machine context to oucp. */
- __getcontext (oucp);
- /* Modify oucp to skip the __setcontext call on reactivation. */
- *(long*)((char*)oucp+UC_M_PC) = (long)__swapcontext_ret;
- *(long*)((char*)oucp+UC_M_NPC) = (long)__swapcontext_ret + 4;
- /* Restore the machine context in ucp. */
- __setcontext (ucp, 1);
- return 0;
-}
-
-asm (" \n\
- .text \n\
- .type __swapcontext_ret, #function \n\
-__swapcontext_ret: \n\
- return %i7 + 8 \n\
- clr %o0 \n\
- .size __swapcontext_ret, .-__swapcontext_ret \n\
- ");
diff --git a/src/libthread/stkmalloc.c b/src/libthread/stkmalloc.c
deleted file mode 100644
index 083aea1b..00000000
--- a/src/libthread/stkmalloc.c
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "threadimpl.h"
-
-void*
-_threadstkalloc(int n)
-{
- return malloc(n);
-}
-
-void
-_threadstkfree(void *v, int n)
-{
- free(v);
-}
diff --git a/src/libthread/stkmmap.c b/src/libthread/stkmmap.c
deleted file mode 100644
index f4a24630..00000000
--- a/src/libthread/stkmmap.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <u.h>
-#include <sys/mman.h>
-#include "threadimpl.h"
-
-#ifndef MAP_STACK
-#define MAP_STACK 0
-#endif
-
-void*
-_threadstkalloc(int n)
-{
- void *p;
-
- p = mmap(nil, n, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON|MAP_STACK, -1, 0);
- if(p == (void*)-1)
- return nil;
- return p;
-}
-
-void
-_threadstkfree(void *v, int n)
-{
- if(n > 0)
- munmap(v, n);
-}
diff --git a/src/libthread/sysofiles.sh b/src/libthread/sysofiles.sh
deleted file mode 100644
index cf9e0234..00000000
--- a/src/libthread/sysofiles.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-test -f $PLAN9/config && . $PLAN9/config
-
-echo pthread.o
-
-case "$SYSNAME" in
-OpenBSD)
- echo stkmmap.o
- ;;
-*)
- echo stkmalloc.o
-esac
-
-# Various libc don't supply swapcontext, makecontext, so we do.
-case "$SYSNAME-$OBJTYPE" in
-Linux-arm | Linux-sparc64 | NetBSD-arm | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64)
- echo $OBJTYPE-ucontext.o
- ;;
-esac
-
-# A few libc don't supply setcontext, getcontext, so we do.
-case "$SYSNAME-$OBJTYPE" in
-Linux-arm | Linux-sparc64 | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64)
- echo $SYSNAME-$OBJTYPE-asm.o
- ;;
-esac
diff --git a/src/libthread/thread.c b/src/libthread/thread.c
index 0c764000..d72bf896 100644
--- a/src/libthread/thread.c
+++ b/src/libthread/thread.c
@@ -7,7 +7,6 @@ static uint threadnsysproc;
static Lock threadnproclock;
static Ref threadidref;
static Proc *threadmainproc;
-static int pthreadperthread = 1;
static void addproc(Proc*);
static void delproc(Proc*);
@@ -16,9 +15,7 @@ static void delthread(_Threadlist*, _Thread*);
static int onlist(_Threadlist*, _Thread*);
static void addthreadinproc(Proc*, _Thread*);
static void delthreadinproc(Proc*, _Thread*);
-static void contextswitch(Context *from, Context *to);
static void procmain(Proc*);
-static void procscheduler(Proc*);
static int threadinfo(void*, char*);
static void pthreadscheduler(Proc *p);
static void pthreadsleepschedlocked(Proc *p, _Thread *t);
@@ -86,114 +83,24 @@ procalloc(void)
return p;
}
-static void
-threadstart(uint y, uint x)
-{
- _Thread *t;
- ulong z;
-
-//print("threadstart\n");
- z = (ulong)x << 16; /* hide undefined 32-bit shift from 32-bit compilers */
- z <<= 16;
- z |= y;
- t = (_Thread*)z;
-
-//print("threadstart sp=%p arg=%p startfn=%p t=%p\n", &t, t, t->startfn, t->startarg);
- t->startfn(t->startarg);
-/*print("threadexits %p\n", v); */
- threadexits(nil);
-/*print("not reacehd\n"); */
-}
-
-static _Thread*
-threadalloc(void (*fn)(void*), void *arg, uint stack)
+_Thread*
+_threadcreate(Proc *p, void (*fn)(void*), void *arg, uint stack)
{
_Thread *t;
- sigset_t zero;
- uint x, y;
- ulong z;
- /* allocate the task and stack together */
+ USED(stack);
t = malloc(sizeof *t);
if(t == nil)
- sysfatal("threadalloc malloc: %r");
+ sysfatal("threadcreate malloc: %r");
memset(t, 0, sizeof *t);
t->id = incref(&threadidref);
-//print("fn=%p arg=%p\n", fn, arg);
t->startfn = fn;
t->startarg = arg;
-//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn);
-
- /* do a reasonable initialization */
- if(stack == 0)
- return t;
- t->stk = _threadstkalloc(stack);
- if(t->stk == nil)
- sysfatal("threadalloc malloc stack: %r");
- t->stksize = stack;
- memset(&t->context.uc, 0, sizeof t->context.uc);
- sigemptyset(&zero);
- sigprocmask(SIG_BLOCK, &zero, &t->context.uc.uc_sigmask);
-//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn);
-
- /* must initialize with current context */
- if(getcontext(&t->context.uc) < 0)
- sysfatal("threadalloc getcontext: %r");
-//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn);
-
- /*
- * Call makecontext to do the real work.
- * To avoid various mistakes on other system software,
- * debuggers, and so on, don't get too close to both
- * ends of the stack. Just staying away is much easier
- * than debugging everything (outside our control)
- * that has off-by-one errors.
- */
- t->context.uc.uc_stack.ss_sp = (void*)(t->stk+64);
- t->context.uc.uc_stack.ss_size = t->stksize-2*64;
-#if defined(__sun__) && !defined(__MAKECONTEXT_V2_SOURCE) /* sigh */
- /* can avoid this with __MAKECONTEXT_V2_SOURCE but only on SunOS 5.9 */
- t->context.uc.uc_stack.ss_sp =
- (char*)t->context.uc.uc_stack.ss_sp
- +t->context.uc.uc_stack.ss_size;
-#endif
- /*
- * All this magic is because you have to pass makecontext a
- * function that takes some number of word-sized variables,
- * and on 64-bit machines pointers are bigger than words.
- */
-//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn);
- z = (ulong)t;
- y = z;
- z >>= 16; /* hide undefined 32-bit shift from 32-bit compilers */
- x = z>>16;
- makecontext(&t->context.uc, (void(*)(void))threadstart, 2, y, x);
-
- return t;
-}
-
-_Thread*
-_threadcreate(Proc *p, void (*fn)(void*), void *arg, uint stack)
-{
- _Thread *t;
-
- /* defend against bad C libraries */
- if(stack < (256<<10))
- stack = 256<<10;
-
- if(p->nthread == 0 || pthreadperthread)
- stack = 0; // not using it
- t = threadalloc(fn, arg, stack);
t->proc = p;
- if(pthreadperthread) {
- if(p->nthread != 0)
- _threadpthreadstart(p, t);
- else
- t->mainthread = 1;
- } else {
- if(p->nthread == 0)
- p->thread0 = t;
- }
+ if(p->nthread != 0)
+ _threadpthreadstart(p, t);
+ else
+ t->mainthread = 1;
p->nthread++;
addthreadinproc(p, t);
_threadready(t);
@@ -232,15 +139,8 @@ _threadswitch(void)
needstack(0);
p = proc();
-
/*print("threadswtch %p\n", p); */
-
- if(pthreadperthread)
- pthreadscheduler(p);
- else if(p->thread == p->thread0)
- procscheduler(p);
- else
- contextswitch(&p->thread->context, &p->schedcontext);
+ pthreadscheduler(p);
}
void
@@ -339,15 +239,6 @@ threadsysfatal(char *fmt, va_list arg)
}
static void
-contextswitch(Context *from, Context *to)
-{
- if(swapcontext(&from->uc, &to->uc) < 0){
- fprint(2, "swapcontext failed: %r\n");
- assert(0);
- }
-}
-
-static void
procmain(Proc *p)
{
_Thread *t;
@@ -357,7 +248,6 @@ procmain(Proc *p)
/* take out first thread to run on system stack */
t = p->runqueue.head;
delthread(&p->runqueue, t);
- memset(&t->context.uc, 0, sizeof t->context.uc);
/* run it */
p->thread = t;
@@ -379,84 +269,6 @@ _threadpthreadmain(Proc *p, _Thread *t)
}
static void
-procscheduler(Proc *p)
-{
- _Thread *t;
-
- _threaddebug(nil, "scheduler enter");
-//print("s %p\n", p);
- for(;;) {
- /* Finish running current thread. */
- lock(&p->lock);
- t = p->thread;
- p->thread = nil;
- if(t->exiting){
- delthreadinproc(p, t);
- p->nthread--;
- /*print("nthread %d\n", p->nthread); */
- _threadstkfree(t->stk, t->stksize);
- /*
- * Cannot free p->thread0 yet: it is used for the
- * context switches back to the scheduler.
- * Instead, we will free it at the end of this function.
- * But all the other threads can be freed now.
- */
- if(t != p->thread0)
- free(t);
- }
-
- /* Pick next thread. */
- t = procnext(p, nil);
- if(t == nil)
- break;
- _threaddebug(nil, "run %d (%s)", t->id, t->name);
- //print("run %p %p %p %p\n", t, *(uintptr*)(t->context.uc.mc.sp), t->context.uc.mc.di, t->context.uc.mc.si);
- unlock(&p->lock);
-
- /* Switch to next thread. */
- if(t == p->thread0)
- return;
- contextswitch(&p->schedcontext, &t->context);
-
- _threaddebug(nil, "back in scheduler");
- /*print("back in scheduler\n"); */
- }
-
- /* No more threads in proc. Clean up. */
- _threaddebug(nil, "scheduler exit");
- if(p->mainproc){
- /*
- * Stupid bug - on Linux 2.6 and maybe elsewhere,
- * if the main thread exits then the others keep running
- * but the process shows up as a zombie in ps and is not
- * attachable with ptrace. We'll just sit around pretending
- * to be a system proc instead of exiting.
- */
- _threaddaemonize();
- lock(&threadnproclock);
- if(++threadnsysproc == threadnproc)
- threadexitsall(p->msg);
- p->sysproc = 1;
- unlock(&threadnproclock);
- for(;;)
- sleep(1000);
- }
-
- delproc(p);
- lock(&threadnproclock);
- if(p->sysproc)
- --threadnsysproc;
- if(--threadnproc == threadnsysproc)
- threadexitsall(p->msg);
- unlock(&threadnproclock);
- unlock(&p->lock);
- _threadsetproc(nil);
- free(p->thread0);
- free(p);
- _threadpexit();
-}
-
-static void
pthreadsleepschedlocked(Proc *p, _Thread *t)
{
_threaddebug(t, "pthreadsleepsched %p %d", p, t->id);;
@@ -913,15 +725,6 @@ main(int argc, char **argv)
if(opts == nil)
opts = "";
- pthreadperthread = (strstr(opts, "pthreadperthread") != nil);
-#ifdef PLAN9PORT_ASAN
- // ASAN can't deal with the coroutine stack switches.
- // In theory it has support for informing it about stack switches,
- // but even with those calls added it can't deal with things
- // like fork or exit from a coroutine stack.
- // Easier to just run in pthread-per-thread mode.
- pthreadperthread = 1;
-#endif
if(threadmaybackground() && strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil)
_threadsetupdaemonize();
@@ -956,7 +759,7 @@ main(int argc, char **argv)
t = _threadcreate(p, threadmainstart, nil, mainstacksize);
t->mainthread = 1;
procmain(p);
- sysfatal("procscheduler returned in threadmain!");
+ sysfatal("procmain returned in libthread");
/* does not return */
return 0;
}
diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h
index 14646031..9eddba21 100644
--- a/src/libthread/threadimpl.h
+++ b/src/libthread/threadimpl.h
@@ -9,36 +9,11 @@
# if defined(__APPLE__)
# define _XOPEN_SOURCE /* for Snow Leopard */
# endif
-# include <ucontext.h>
#endif
#include <sys/utsname.h>
#include "libc.h"
#include "thread.h"
-#if defined(__OpenBSD__)
-# define mcontext libthread_mcontext
-# define mcontext_t libthread_mcontext_t
-# define ucontext libthread_ucontext
-# define ucontext_t libthread_ucontext_t
-# if defined __i386__
-# include "386-ucontext.h"
-# elif defined __amd64__
-# include "x86_64-ucontext.h"
-# else
-# include "power-ucontext.h"
-# endif
-extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
-#endif
-
-#if defined(__arm__)
-int mygetmcontext(ulong*);
-void mysetmcontext(const ulong*);
-#define setcontext(u) mysetmcontext(&(u)->uc_mcontext.arm_r0)
-#define getcontext(u) mygetmcontext(&(u)->uc_mcontext.arm_r0)
-#endif
-
-
-typedef struct Context Context;
typedef struct Execjob Execjob;
typedef struct Proc Proc;
typedef struct _Procrendez _Procrendez;
@@ -54,11 +29,6 @@ enum
STACK = 8192
};
-struct Context
-{
- ucontext_t uc;
-};
-
struct Execjob
{
int *fd;
@@ -72,11 +42,7 @@ struct _Procrendez
{
Lock *l;
int asleep;
-#ifdef PLAN9PORT_USING_PTHREADS
pthread_cond_t cond;
-#else
- int pid;
-#endif
};
struct _Thread
@@ -85,15 +51,10 @@ struct _Thread
_Thread *prev;
_Thread *allnext;
_Thread *allprev;
- Context context;
void (*startfn)(void*);
void *startarg;
uint id;
-#ifdef PLAN9PORT_USING_PTHREADS
pthread_t osprocid;
-#else
- int osprocid;
-#endif
uchar *stk;
uint stksize;
int exiting;
@@ -115,11 +76,7 @@ struct Proc
Proc *next;
Proc *prev;
char msg[128];
-#ifdef PLAN9PORT_USING_PTHREADS
pthread_t osprocid;
-#else
- int osprocid;
-#endif
Lock lock;
int nswitch;
_Thread *thread0;
@@ -133,7 +90,6 @@ struct Proc
_Procrendez runrend;
Lock schedlock;
_Thread *schedthread;
- Context schedcontext;
void *udata;
Jmp sigjmp;
int mainproc;
diff --git a/src/libthread/x86_64-ucontext.c b/src/libthread/x86_64-ucontext.c
deleted file mode 100644
index 5d1aaefc..00000000
--- a/src/libthread/x86_64-ucontext.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "threadimpl.h"
-
-void
-makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
-{
- uintptr *sp;
- va_list arg;
-
- if(argc != 2)
- sysfatal("libthread: makecontext misused");
- va_start(arg, argc);
- uc->mc.di = va_arg(arg, uint);
- uc->mc.si = va_arg(arg, uint);
- va_end(arg);
-
- sp = USPALIGN(uc, 16);
- *--sp = 0; // fn's return address
- *--sp = (uintptr)fn; // return address of setcontext
- uc->mc.sp = (uintptr)sp;
-}
-
-int
-swapcontext(ucontext_t *oucp, ucontext_t *ucp)
-{
- if(getcontext(oucp) == 0)
- setcontext(ucp);
- return 0;
-}
diff --git a/src/libthread/x86_64-ucontext.h b/src/libthread/x86_64-ucontext.h
deleted file mode 100644
index e0640761..00000000
--- a/src/libthread/x86_64-ucontext.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#define setcontext(u) libthread_setmcontext(&(u)->mc)
-#define getcontext(u) libthread_getmcontext(&(u)->mc)
-typedef struct mcontext mcontext_t;
-typedef struct ucontext ucontext_t;
-
-struct mcontext
-{
- uintptr ax;
- uintptr bx;
- uintptr cx;
- uintptr dx;
- uintptr si;
- uintptr di;
- uintptr bp;
- uintptr sp;
- uintptr r8;
- uintptr r9;
- uintptr r10;
- uintptr r11;
- uintptr r12;
- uintptr r13;
- uintptr r14;
- uintptr r15;
-/*
-// XXX: currently do not save vector registers or floating-point state
-*/
-};
-
-struct ucontext
-{
- struct {
- void *ss_sp;
- uint ss_size;
- } uc_stack;
- sigset_t uc_sigmask;
- mcontext_t mc;
-};
-
-void makecontext(ucontext_t*, void(*)(void), int, ...);
-int swapcontext(ucontext_t*, ucontext_t*);
-int libthread_getmcontext(mcontext_t*);
-void libthread_setmcontext(mcontext_t*);