From b1ddde874c215cc8891531ed92876f091b7eb83e Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Mon, 14 Apr 2025 17:32:06 +0000 Subject: This commit was manufactured by cvs2git to create tag 'tb_20250414'. --- src/lib/libc/include/DETAILS | 133 ----------- src/lib/libc/include/README | 110 --------- src/lib/libc/include/atfork.h | 45 ---- src/lib/libc/include/cancel.h | 78 ------- src/lib/libc/include/ctype_private.h | 9 - src/lib/libc/include/localedef.h | 106 --------- src/lib/libc/include/mpool.h | 122 ---------- src/lib/libc/include/namespace.h | 98 -------- src/lib/libc/include/thread_private.h | 427 ---------------------------------- 9 files changed, 1128 deletions(-) delete mode 100644 src/lib/libc/include/DETAILS delete mode 100644 src/lib/libc/include/README delete mode 100644 src/lib/libc/include/atfork.h delete mode 100644 src/lib/libc/include/cancel.h delete mode 100644 src/lib/libc/include/ctype_private.h delete mode 100644 src/lib/libc/include/localedef.h delete mode 100644 src/lib/libc/include/mpool.h delete mode 100644 src/lib/libc/include/namespace.h delete mode 100644 src/lib/libc/include/thread_private.h (limited to 'src/lib/libc/include') diff --git a/src/lib/libc/include/DETAILS b/src/lib/libc/include/DETAILS deleted file mode 100644 index 6382cc1c0d..0000000000 --- a/src/lib/libc/include/DETAILS +++ /dev/null @@ -1,133 +0,0 @@ -The goal: calls from inside libc to other libc functions should - * not be overridable (except for the malloc family), and - * not have pointless inefficiencies. - -To achieve this, we arrange that all these internal call be via -identifiers that are of hidden visibility and--to avoid confusion -and work correctly in static executables--are in the reserved -namespace. - -This document describes the details of the naming scheme and how -it is implemented. - -I've chosen a prefix of underbar-libc-underbar ("_libc_") for this. -These are not declared directly; instead, the gcc "asm labels" -extension is used to rename the function. - -We need many of the symbols to be weak in *static* builds, but they -can be strong in the dynamic library, as there's a natural precedence -from the search order there. When the descriptions below say a -name is "weak", that is only necessary for the static library and -not for the shared library. Note: use defined(PIC) to recognize -when compiling the shared objects: some archs define __PIC__ *all* -the time. - ---------- - -For syscalls which are not cancellation points, such as getpid(), -the identifiers are just: - _libc_getpid hidden alias, for use internal to libc only - _thread_sys_getpid global name, for use outside libc only - getpid weak alias, for use outside libc only - -For syscalls which are cancellation points, such as wait4(), there -are identifiers that do not provide cancellation: - _libc_wait4 hidden alias, for use internal to libc only - _thread_sys_wait4 global name, for use outside libc only -...and identifiers that do provide cancellation: - wait4 weak alias, for general use - _libc_wait4_cancel hidden name, for use internal to libc only -Inside libc, the bare name ("wait4") binds to the version *with* -cancellation. If it's necessary to use the syscall without doing -cancellation it can be obtained by calling HIDDEN(x) instead of -just x. - -Some other calls need to be wrapped for reasons other than cancellation, -such as to provide functionality beyond the underlying syscall (e.g., -ptrace). For these, there are identifiers for the raw call, without -the wrapping: - _libc_ptrace hidden alias, for use internal to libc only - _thread_sys_ptrace global name, for use outside libc only -...and identifiers that do provide the libc wrapping: - ptrace weak alias, for general use - _libc_ptrace_wrap hidden name, for use internal to libc only -Inside libc, the bare name ("ptrace") binds to the wrapper; if -the raw version is necessary it can be obtained by calling HIDDEN(x) -instead of just x. - -For syscalls implemented in ASM, the aliases of the raw syscall stub -are provided by the ASM macros. Of the macros used by sys/Makefile.inc: -RSYSCALL(), PSEUDO(), and PSEUDO_NOERROR() generate all three names -(ala getpid() above), while RSYSCALL_HIDDEN() generates just the -_thread_sys_x and _libc_x names. - - - -By using gcc's "asm label" extension, we can usually avoid having -to type those prefixes in the .h and .c files. However, for those -cases where a non-default binding is necessary we can use these macros -to get the desired identifier: - - CANCEL(x) - This expands to the internal, hidden name of a cancellation - wrapper: _libc_x_cancel. ex: CANCEL(fsync)(fd) - - WRAP(x) - This expands to the internal, hidden name of a non-cancellation - wrapper: _libc_x_wrap. ex: WRAP(sigprocmask)(set) - - -In order to actually set up the desired asm labels, we use these in -the internal .h files: - PROTO_NORMAL(x) Symbols used both internally and externally - This makes gcc convert use of x to use _libc_x instead - ex: PROTO_NORMAL(getpid) - - PROTO_STD_DEPRECATED(x) Standard C symbols that we don't want to use - This just marks the symbol as deprecated, with no renaming. - ex: PROTO_STD_DEPRECATED(strcpy) - - PROTO_DEPRECATED(x) Symbols not in ISO C that we don't want to use - This marks the symbol as both weak and deprecated, with no renaming - ex: PROTO_DEPRECATED(creat) - - PROTO_CANCEL(x) Functions that have cancellation wrappers - Like PROTO_NORMAL(x), but also declares _libc_x_cancel - ex: PROTO_CANCEL(wait4) - - PROTO_WRAP(x) Functions that have wrappers for other reasons - Like PROTO_NORMAL(x), but also declares _libc_x_wrap. Internal - calls that want the wrapper's processing should invoke WRAP(x)(...) - ex: PROTO_WRAP(sigaction) - - -Finally, to create the expected aliases, we use these in the .c files -where the definitions are: - DEF_STRONG(x) Symbols reserved to or specified by ISO C - This defines x as a strong alias for _libc_x; this must only - be used for symbols that are reserved by the C standard - (or reserved in the external identifier namespace). - Matches with PROTO_NORMAL() - ex: DEF_STRONG(fopen) - - DEF_WEAK(x) Symbols used internally and not in ISO C - This defines x as a weak alias for _libc_x - Matches with PROTO_NORMAL() - ex: DEF_WEAK(lseek) - - DEF_CANCEL(x) Symbols that have a cancellation wrapper - This defines x as a weak alias for _libc_x_cancel. - Matches with PROTO_CANCEL() - ex: DEF_CANCEL(read) - - DEF_WRAP(x) - This defines x as a weak alias for _libc_x_wrap. - Matches with PROTO_WRAP() - ex: DEF_WRAP(ptrace) - - MAKE_CLONE(dst, src) Symbols that are exact clones of other symbols - This declares _libc_dst as being the same type as dst, and makes - _libc_dst a strong, hidden alias for _libc_src. You still need to - DEF_STRONG(dst) or DEF_WEAK(dst) to alias dst itself - ex: MAKE_CLONE(SHA224Pad, SHA256Pad) - diff --git a/src/lib/libc/include/README b/src/lib/libc/include/README deleted file mode 100644 index 89acee491e..0000000000 --- a/src/lib/libc/include/README +++ /dev/null @@ -1,110 +0,0 @@ -So you want to add an interface to libc... - -CASE I: internal symbols - - A) used in a single file - Duh: use whatever name you want and make it static - - B) used in multiple files - Give it a name in the implementation namespace (leading underbar) - and declare it in a __{BEGIN,END}_HIDDEN_DECLS block in a .h - file inside libc. If it's used in just a single subdir of - libc *and* that subdir has an appropriate .h file in it, then - declare it there. - Example: stdio/local.h. - Otherwise, declare it in one of the hidden/* files. - Example: _mktemp() in hidden/stdio.h - -CASE II: external symbols - - First of all, add your symbol to Symbols.list. MD symbols go in - arch/*/Symbols.list (shock, I know) - - Declare your function in the appropriate header. It almost certainly - should be in a public header installed under /usr/include/. Exceptions - are symbols that are just shared between libc and libpthread/csu/ld.so - which are only declared in libc/include/* or just in each .c file. - - A) objects (variables) - That's it, you're done. - - - B) plain C functions (not syscalls) - 1) functions that are *not* called from inside libc - - If this function is specified in the ISO C standard or its - name begins with an underbar, then in the hidden/* version - of the header where you declared the function, add this line: - PROTO_STD_DEPRECATED(your_function_name); - - Otherwise, this is *not* a function specified in the ISO C - standard and its name begins with a letter. In the hidden/* - version of the header where you declared the function, add - this line: - PROTO_DEPRECATED(your_function_name); - - Note: the "DEPRECATED" suffix is about a detail of - how the macros work and has nothing to do with whether the - function itself is a Good Thing vs deprecated. - - 2) functions that are called from inside libc - - In the hidden/* version of the header where you declared - the function, add this line: - PROTO_NORMAL(your_function_name); - - Then, in the .c file(s) where the function is defined: - - if the function is specified in the ISO C standard or - its name begins with an underbar, add - DEF_STRONG(your_function_name); - - - otherwise, add: - DEF_WEAK(your_function_name); - - - C) syscalls that don't require any wrapping - - In the hidden/* version of the header where you declared the - function, add this line: - PROTO_NORMAL(your_function_name); - - Generate the stub by adding it to the ASM variable in - libc/sys/Makefile.inc - - - D) syscalls that require cancellation or similar wrappers that don't - change the function signature - - Generate the stub by adding it to the HIDDEN (*not* ASM!) - variable in libc/sys/Makefile.inc - - In the hidden/* version of the header where you declared the - function, add this line: - PROTO_WRAP(your_function_name); - - The wrapper function should be defined in - libc/sys/w_your_function_name.c - which should define WRAP(your_function_name) and follow it - with DEF_WRAP(your_function_name). Look at libc/sys/w_sigaction.c - for an example. - - By default, libc code that calls your_function_name() will get - the real syscall and *not* the wrapper. libc calls that need - to go through the wrapper should invoke WRAP(your_function_name) - - - E) syscalls that require libc wrappers for other reasons - First of all, make sure this really is the Right Thing. Talk - with kettenis, deraadt, millert, and guenther. - - If the actual syscall doesn't have the same calling convention - as the C interface, then maybe it shouldn't be exported at all - and you should just have an ASM stub, like SYS___tfork --> - __tfork_thread() or SYS_break --> brk() and sbrk(). If it - _could_ be called from C, then give the syscall a name different - from the C API. Syscalls that fail this for historical reasons - (e.g., exit == _exit(2)) are generated with PSEUDO/PSEUDO_NOERR - in libc/sys/Makefile.inc, so the ASM stub has a leading underbar. - Go read gen/getlogin.c rev 1.13 for an example of how to do - this, but don't pick this option, really. - diff --git a/src/lib/libc/include/atfork.h b/src/lib/libc/include/atfork.h deleted file mode 100644 index f09de4892a..0000000000 --- a/src/lib/libc/include/atfork.h +++ /dev/null @@ -1,45 +0,0 @@ -/* $OpenBSD: atfork.h,v 1.2 2015/08/27 04:37:09 guenther Exp $ */ - -/* - * Copyright (c) 2008 Kurt Miller - * Copyright (c) 2008 Philip Guenther - * Copyright (c) 2003 Daniel Eischen - * 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. - * 2. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $ - */ - -#include - -struct atfork_fn { - TAILQ_ENTRY(atfork_fn) fn_next; - void (*fn_prepare)(void); - void (*fn_parent)(void); - void (*fn_child)(void); - void *fn_dso; -}; - -__BEGIN_HIDDEN_DECLS -extern TAILQ_HEAD(atfork_listhead, atfork_fn) _atfork_list; -__END_HIDDEN_DECLS diff --git a/src/lib/libc/include/cancel.h b/src/lib/libc/include/cancel.h deleted file mode 100644 index c452bf3d4c..0000000000 --- a/src/lib/libc/include/cancel.h +++ /dev/null @@ -1,78 +0,0 @@ -/* $OpenBSD: cancel.h,v 1.5 2017/09/05 02:40:54 guenther Exp $ */ -/* - * Copyright (c) 2015 Philip Guenther - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _CANCEL_H_ -#define _CANCEL_H_ - -#include -#include "thread_private.h" - -/* process a cancel request at a cancel point */ -__dead void _thread_canceled(void); - -#ifdef __LIBC__ -PROTO_NORMAL(_thread_canceled); -#endif - -#if defined(__LIBC__) && !defined(TCB_HAVE_MD_GET) -/* - * Override TIB_GET macro to use the caching callback - */ -#undef TIB_GET -#define TIB_GET() TCB_TO_TIB(_thread_cb.tc_tcb()) -#endif - -#define PREP_CANCEL_POINT(tib) \ - int _cantcancel = (tib)->tib_cantcancel - -#define ENTER_CANCEL_POINT_INNER(tib, can_cancel, delay) \ - if (_cantcancel == 0) { \ - (tib)->tib_cancel_point = (delay) ? \ - CANCEL_POINT_DELAYED : CANCEL_POINT; \ - if (can_cancel) { \ - __asm volatile("":::"memory"); \ - if (__predict_false((tib)->tib_canceled)) \ - _thread_canceled(); \ - } \ - } - -#define LEAVE_CANCEL_POINT_INNER(tib, can_cancel) \ - if (_cantcancel == 0) { \ - (tib)->tib_cancel_point = 0; \ - if (can_cancel) { \ - __asm volatile("":::"memory"); \ - if (__predict_false((tib)->tib_canceled)) \ - _thread_canceled(); \ - } \ - } - -/* - * Enter or leave a cancelation point, optionally processing pending - * cancelation requests. Note that ENTER_CANCEL_POINT opens a block - * and LEAVE_CANCEL_POINT must close that same block. - */ -#define ENTER_CANCEL_POINT(can_cancel) \ - { \ - struct tib *_tib = TIB_GET(); \ - PREP_CANCEL_POINT(_tib); \ - ENTER_CANCEL_POINT_INNER(_tib, can_cancel, 0) - -#define LEAVE_CANCEL_POINT(can_cancel) \ - LEAVE_CANCEL_POINT_INNER(_tib, can_cancel); \ - } - -#endif /* _CANCEL_H_ */ diff --git a/src/lib/libc/include/ctype_private.h b/src/lib/libc/include/ctype_private.h deleted file mode 100644 index cbe1b20475..0000000000 --- a/src/lib/libc/include/ctype_private.h +++ /dev/null @@ -1,9 +0,0 @@ -/* $OpenBSD: ctype_private.h,v 1.2 2015/08/27 04:37:09 guenther Exp $ */ -/* Written by Marc Espie, public domain */ -#define CTYPE_NUM_CHARS 256 - -__BEGIN_HIDDEN_DECLS -extern const char _C_ctype_[]; -extern const short _C_toupper_[]; -extern const short _C_tolower_[]; -__END_HIDDEN_DECLS diff --git a/src/lib/libc/include/localedef.h b/src/lib/libc/include/localedef.h deleted file mode 100644 index 12dd47fffa..0000000000 --- a/src/lib/libc/include/localedef.h +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: localedef.h,v 1.1 2016/05/23 00:05:15 guenther Exp $ */ -/* $NetBSD: localedef.h,v 1.4 1996/04/09 20:55:31 cgd Exp $ */ - -/* - * Copyright (c) 1994 Winning Strategies, Inc. - * 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. - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Winning Strategies, Inc. - * 4. 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. - */ - -#ifndef _LOCALEDEF_H_ -#define _LOCALEDEF_H_ - -#include - -typedef struct -{ - char *yesexpr; - char *noexpr; - char *yesstr; - char *nostr; -} _MessagesLocale; - - -typedef struct -{ - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; -} _MonetaryLocale; - - -typedef struct -{ - const char *decimal_point; - const char *thousands_sep; - const char *grouping; -} _NumericLocale; - - -typedef struct { - const char *abday[7]; - const char *day[7]; - const char *abmon[12]; - const char *mon[12]; - const char *am_pm[2]; - const char *d_t_fmt; - const char *d_fmt; - const char *t_fmt; - const char *t_fmt_ampm; -} _TimeLocale; - - -__BEGIN_HIDDEN_DECLS -extern const _MessagesLocale *_CurrentMessagesLocale; -extern const _MessagesLocale _DefaultMessagesLocale; -extern const _MonetaryLocale *_CurrentMonetaryLocale; -extern const _MonetaryLocale _DefaultMonetaryLocale; -extern const _NumericLocale *_CurrentNumericLocale; -extern const _NumericLocale _DefaultNumericLocale; -extern const _TimeLocale *_CurrentTimeLocale; -extern const _TimeLocale _DefaultTimeLocale; -__END_HIDDEN_DECLS - -#endif /* !_LOCALEDEF_H_ */ diff --git a/src/lib/libc/include/mpool.h b/src/lib/libc/include/mpool.h deleted file mode 100644 index 005b006d17..0000000000 --- a/src/lib/libc/include/mpool.h +++ /dev/null @@ -1,122 +0,0 @@ -/* $OpenBSD: mpool.h,v 1.1 2015/09/09 15:35:24 guenther Exp $ */ -/* $NetBSD: mpool.h,v 1.7 1996/05/03 21:13:41 cgd Exp $ */ - -/*- - * Copyright (c) 1991, 1993, 1994 - * The Regents of the University of California. 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. - * 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. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - * - * @(#)mpool.h 8.4 (Berkeley) 11/2/95 - */ - -#ifndef _MPOOL_H_ -#define _MPOOL_H_ - -#include - -/* - * The memory pool scheme is a simple one. Each in-memory page is referenced - * by a bucket which is threaded in up to two of three ways. All active pages - * are threaded on a hash chain (hashed by page number) and an lru chain. - * Inactive pages are threaded on a free chain. Each reference to a memory - * pool is handed an opaque MPOOL cookie which stores all of this information. - */ -#define HASHSIZE 128 -#define HASHKEY(pgno) ((pgno - 1 + HASHSIZE) % HASHSIZE) - -/* The BKT structures are the elements of the queues. */ -typedef struct _bkt { - TAILQ_ENTRY(_bkt) hq; /* hash queue */ - TAILQ_ENTRY(_bkt) q; /* lru queue */ - void *page; /* page */ - pgno_t pgno; /* page number */ - -#define MPOOL_DIRTY 0x01 /* page needs to be written */ -#define MPOOL_PINNED 0x02 /* page is pinned into memory */ -#define MPOOL_INUSE 0x04 /* page address is valid */ - u_int8_t flags; /* flags */ -} BKT; - -typedef struct MPOOL { - TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ - /* hash queue array */ - TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; - pgno_t curcache; /* current number of cached pages */ - pgno_t maxcache; /* max number of cached pages */ - pgno_t npages; /* number of pages in the file */ - unsigned long pagesize; /* file page size */ - int fd; /* file descriptor */ - /* page in conversion routine */ - void (*pgin)(void *, pgno_t, void *); - /* page out conversion routine */ - void (*pgout)(void *, pgno_t, void *); - void *pgcookie; /* cookie for page in/out routines */ -#ifdef STATISTICS - unsigned long cachehit; - unsigned long cachemiss; - unsigned long pagealloc; - unsigned long pageflush; - unsigned long pageget; - unsigned long pagenew; - unsigned long pageput; - unsigned long pageread; - unsigned long pagewrite; -#endif -} MPOOL; - -#define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ -#define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a - specific page number. */ -#define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next - page number. */ - -__BEGIN_HIDDEN_DECLS -MPOOL *mpool_open(void *, int, pgno_t, pgno_t); -void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), - void (*)(void *, pgno_t, void *), void *); -void *mpool_new(MPOOL *, pgno_t *, unsigned int); -void *mpool_get(MPOOL *, pgno_t, unsigned int); -int mpool_delete(MPOOL *, void *); -int mpool_put(MPOOL *, void *, unsigned int); -int mpool_sync(MPOOL *); -int mpool_close(MPOOL *); - -PROTO_NORMAL(mpool_open); -PROTO_NORMAL(mpool_filter); -PROTO_NORMAL(mpool_new); -PROTO_NORMAL(mpool_get); -PROTO_NORMAL(mpool_delete); -PROTO_NORMAL(mpool_put); -PROTO_NORMAL(mpool_sync); -PROTO_NORMAL(mpool_close); - -#ifdef STATISTICS -void mpool_stat(MPOOL *); -PROTO_NORMAL(mpool_stat); -#endif -__END_HIDDEN_DECLS - -#endif diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h deleted file mode 100644 index 8503de47be..0000000000 --- a/src/lib/libc/include/namespace.h +++ /dev/null @@ -1,98 +0,0 @@ -/* $OpenBSD: namespace.h,v 1.16 2023/10/29 14:26:13 millert Exp $ */ - -#ifndef _LIBC_NAMESPACE_H_ -#define _LIBC_NAMESPACE_H_ - -/* - * Copyright (c) 2015 Philip Guenther - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * ISO C11 or higher is required to build libc. - * This must come _before_ sys/cdefs.h is included. - */ -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112 -#define _ISOC11_SOURCE 1 -#endif - -/* - * For explanations of how to use these, see README - * For explanations of why we use them and how they work, see DETAILS - */ - -#include /* for __dso_hidden and __{weak,strong}_alias */ - -#define __dso_protected __attribute__((__visibility__("protected"))) - -#define HIDDEN(x) _libc_##x -#define CANCEL(x) _libc_##x##_cancel -#define WRAP(x) _libc_##x##_wrap -#define HIDDEN_STRING(x) "_libc_" __STRING(x) -#define CANCEL_STRING(x) "_libc_" __STRING(x) "_cancel" -#define WRAP_STRING(x) "_libc_" __STRING(x) "_wrap" - -#define PROTO_NORMAL(x) __dso_hidden typeof(x) x asm(HIDDEN_STRING(x)) -#define PROTO_STD_DEPRECATED(x) typeof(x) x __attribute__((deprecated)) -#define PROTO_DEPRECATED(x) typeof(x) x __attribute__((deprecated, weak)) -#define PROTO_CANCEL(x) __dso_hidden typeof(x) HIDDEN(x), \ - x asm(CANCEL_STRING(x)) -#define PROTO_WRAP(x) PROTO_NORMAL(x), WRAP(x) -#define PROTO_PROTECTED(x) __dso_protected typeof(x) x - -#define DEF_STRONG(x) __strong_alias(x, HIDDEN(x)) -#define DEF_WEAK(x) __weak_alias(x, HIDDEN(x)) -#define DEF_CANCEL(x) __weak_alias(x, CANCEL(x)) -#define DEF_WRAP(x) __weak_alias(x, WRAP(x)) -#define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) - -#if !defined(__clang__) && __GNUC__ != 3 -/* our gcc 4.2 handles redirecting builtins via PROTO_NORMAL()'s asm() label */ -#define DEF_BUILTIN(x) DEF_STRONG(x) -#define BUILTIN -#else -/* - * clang and gcc can't redirect builtins via asm() labels, so mark - * them protected instead. - */ -#define DEF_BUILTIN(x) __asm("") -#define BUILTIN __dso_protected -#endif - -#define MAKE_CLONE(dst, src) __dso_hidden typeof(dst) HIDDEN(dst) \ - __attribute__((alias (HIDDEN_STRING(src)))) - -#define __relro __attribute__((section(".data.rel.ro"))) - - -/* - * gcc and clang will generate calls to the functions below. - * Declare and redirect them here so we always go - * directly to our hidden aliases. - */ -#include -BUILTIN void *memmove(void *, const void *, __size_t); -BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); -BUILTIN void *memset(void *, int, __size_t); -BUILTIN void __stack_smash_handler(const char [], int __unused); -#if !defined(__clang__) && __GNUC__ != 3 -PROTO_NORMAL(memmove); -PROTO_NORMAL(memcpy); -PROTO_NORMAL(memset); -PROTO_NORMAL(__stack_smash_handler); -#endif -#undef BUILTIN - -#endif /* _LIBC_NAMESPACE_H_ */ - diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h deleted file mode 100644 index 1ec1071161..0000000000 --- a/src/lib/libc/include/thread_private.h +++ /dev/null @@ -1,427 +0,0 @@ -/* $OpenBSD: thread_private.h,v 1.37 2024/08/18 02:25:51 guenther Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ - -#ifndef _THREAD_PRIVATE_H_ -#define _THREAD_PRIVATE_H_ - -extern int __isthreaded; - -#define _MALLOC_MUTEXES 32 -void _malloc_init(int); -#ifdef __LIBC__ -PROTO_NORMAL(_malloc_init); -#endif /* __LIBC__ */ - -/* - * The callbacks needed by libc to handle the threaded case. - * NOTE: Bump the version when you change the struct contents! - * - * tc_canceled: - * If not NULL, what to do when canceled (otherwise _exit(0)) - * - * tc_flockfile, tc_ftrylockfile, and tc_funlockfile: - * If not NULL, these implement the flockfile() family. - * XXX In theory, you should be able to lock a FILE before - * XXX loading libpthread and have that be a real lock on it, - * XXX but that doesn't work without the libc base version - * XXX tracking the recursion count. - * - * tc_malloc_lock and tc_malloc_unlock: - * tc_atexit_lock and tc_atexit_unlock: - * tc_atfork_lock and tc_atfork_unlock: - * tc_arc4_lock and tc_arc4_unlock: - * The locks used by the malloc, atexit, atfork, and arc4 subsystems. - * These have to be ordered specially in the fork/vfork wrappers - * and may be implemented differently than the general mutexes - * in the callbacks below. - * - * tc_mutex_lock and tc_mutex_unlock: - * Lock and unlock the given mutex. If the given mutex is NULL - * a mutex is allocated and initialized automatically. - * - * tc_mutex_destroy: - * Destroy/deallocate the given mutex. - * - * tc_tag_lock and tc_tag_unlock: - * Lock and unlock the mutex associated with the given tag. - * If the given tag is NULL a tag is allocated and initialized - * automatically. - * - * tc_tag_storage: - * Returns a pointer to per-thread instance of data associated - * with the given tag. If the given tag is NULL a tag is - * allocated and initialized automatically. - * - * tc_fork, tc_vfork: - * If not NULL, they are called instead of the syscall stub, so that - * the thread library can do necessary locking and reinitialization. - * - * tc_thread_release: - * Handles the release of a thread's TIB and struct pthread and the - * notification of other threads...when there are other threads. - * - * tc_thread_key_zero: - * For each thread, zero out the key data associated with the given key. - - * If doesn't define TCB_GET(), then locating the TCB in a - * threaded process requires a syscall (__get_tcb(2)) which is too much - * overhead for single-threaded processes. For those archs, there are two - * additional callbacks, though they are placed first in the struct for - * convenience in ASM: - * - * tc_errnoptr: - * Returns the address of the thread's errno. - * - * tc_tcb: - * Returns the address of the thread's TCB. - */ - -struct __sFILE; -struct pthread; -struct thread_callbacks { - int *(*tc_errnoptr)(void); /* MUST BE FIRST */ - void *(*tc_tcb)(void); - __dead void (*tc_canceled)(void); - void (*tc_flockfile)(struct __sFILE *); - int (*tc_ftrylockfile)(struct __sFILE *); - void (*tc_funlockfile)(struct __sFILE *); - void (*tc_malloc_lock)(int); - void (*tc_malloc_unlock)(int); - void (*tc_atexit_lock)(void); - void (*tc_atexit_unlock)(void); - void (*tc_atfork_lock)(void); - void (*tc_atfork_unlock)(void); - void (*tc_arc4_lock)(void); - void (*tc_arc4_unlock)(void); - void (*tc_mutex_lock)(void **); - void (*tc_mutex_unlock)(void **); - void (*tc_mutex_destroy)(void **); - void (*tc_tag_lock)(void **); - void (*tc_tag_unlock)(void **); - void *(*tc_tag_storage)(void **, void *, size_t, void (*)(void *), - void *); - __pid_t (*tc_fork)(void); - __pid_t (*tc_vfork)(void); - void (*tc_thread_release)(struct pthread *); - void (*tc_thread_key_zero)(int); -}; - -__BEGIN_PUBLIC_DECLS -/* - * Set the callbacks used by libc - */ -void _thread_set_callbacks(const struct thread_callbacks *_cb, size_t _len); -__END_PUBLIC_DECLS - -#ifdef __LIBC__ -__BEGIN_HIDDEN_DECLS -/* the current set */ -extern struct thread_callbacks _thread_cb; -__END_HIDDEN_DECLS -#endif /* __LIBC__ */ - -/* - * helper macro to make unique names in the thread namespace - */ -#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) - -/* - * Macros used in libc to access thread mutex, keys, and per thread storage. - * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for - * historical reasons. They do the same thing, define a static variable - * keyed by 'name' that identifies a mutex and a key to identify per thread - * data. - */ -#define _THREAD_PRIVATE_KEY(name) \ - static void *__THREAD_NAME(name) -#define _THREAD_PRIVATE_MUTEX(name) \ - static void *__THREAD_NAME(name) - - -#ifndef __LIBC__ /* building some sort of reach around */ - -#define _THREAD_PRIVATE_MUTEX_LOCK(name) do {} while (0) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) do {} while (0) -#define _THREAD_PRIVATE(keyname, storage, error) &(storage) -#define _THREAD_PRIVATE_DT(keyname, storage, dt, error) &(storage) -#define _MUTEX_LOCK(mutex) do {} while (0) -#define _MUTEX_UNLOCK(mutex) do {} while (0) -#define _MUTEX_DESTROY(mutex) do {} while (0) -#define _MALLOC_LOCK(n) do {} while (0) -#define _MALLOC_UNLOCK(n) do {} while (0) -#define _ATEXIT_LOCK() do {} while (0) -#define _ATEXIT_UNLOCK() do {} while (0) -#define _ATFORK_LOCK() do {} while (0) -#define _ATFORK_UNLOCK() do {} while (0) -#define _ARC4_LOCK() do {} while (0) -#define _ARC4_UNLOCK() do {} while (0) - -#else /* building libc */ -#define _THREAD_PRIVATE_MUTEX_LOCK(name) \ - do { \ - if (_thread_cb.tc_tag_lock != NULL) \ - _thread_cb.tc_tag_lock(&(__THREAD_NAME(name))); \ - } while (0) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ - do { \ - if (_thread_cb.tc_tag_unlock != NULL) \ - _thread_cb.tc_tag_unlock(&(__THREAD_NAME(name))); \ - } while (0) -#define _THREAD_PRIVATE(keyname, storage, error) \ - (_thread_cb.tc_tag_storage == NULL ? &(storage) : \ - _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \ - &(storage), sizeof(storage), NULL, (error))) - -#define _THREAD_PRIVATE_DT(keyname, storage, dt, error) \ - (_thread_cb.tc_tag_storage == NULL ? &(storage) : \ - _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \ - &(storage), sizeof(storage), (dt), (error))) - -/* - * Macros used in libc to access mutexes. - */ -#define _MUTEX_LOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_mutex_lock(mutex); \ - } while (0) -#define _MUTEX_UNLOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_mutex_unlock(mutex); \ - } while (0) -#define _MUTEX_DESTROY(mutex) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_mutex_destroy(mutex); \ - } while (0) - -/* - * malloc lock/unlock prototypes and definitions - */ -#define _MALLOC_LOCK(n) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_malloc_lock(n); \ - } while (0) -#define _MALLOC_UNLOCK(n) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_malloc_unlock(n); \ - } while (0) - -#define _ATEXIT_LOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atexit_lock(); \ - } while (0) -#define _ATEXIT_UNLOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atexit_unlock(); \ - } while (0) - -#define _ATFORK_LOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atfork_lock(); \ - } while (0) -#define _ATFORK_UNLOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atfork_unlock(); \ - } while (0) - -#define _ARC4_LOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_arc4_lock(); \ - } while (0) -#define _ARC4_UNLOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_arc4_unlock(); \ - } while (0) -#endif /* __LIBC__ */ - - -/* - * Copyright (c) 2004,2005 Ted Unangst - * All Rights Reserved. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Private data structures that back up the typedefs in pthread.h. - * Since only the thread library cares about their size or arrangement, - * it should be possible to switch libraries without relinking. - * - * Do not reorder _atomic_lock_t and sem_t variables in the structs. - * This is due to alignment requirements of certain arches like hppa. - * The current requirement is 16 bytes. - * - * THE MACHINE DEPENDENT CERROR CODE HAS HARD CODED OFFSETS INTO PTHREAD_T! - */ - -#include -#include -#include -#include - -#define _SPINLOCK_UNLOCKED _ATOMIC_LOCK_UNLOCKED - -struct __sem { - _atomic_lock_t lock; - volatile int waitcount; - volatile int value; - int shared; -}; - -TAILQ_HEAD(pthread_queue, pthread); - -#ifdef FUTEX - -struct pthread_mutex { - volatile unsigned int lock; - int type; - pthread_t owner; - int count; - int prioceiling; -}; - -struct pthread_cond { - volatile unsigned int seq; - clockid_t clock; - struct pthread_mutex *mutex; -}; - -struct pthread_rwlock { - volatile unsigned int value; -}; - -#else - -struct pthread_mutex { - _atomic_lock_t lock; - struct pthread_queue lockers; - int type; - pthread_t owner; - int count; - int prioceiling; -}; - -struct pthread_cond { - _atomic_lock_t lock; - struct pthread_queue waiters; - struct pthread_mutex *mutex; - clockid_t clock; -}; - -struct pthread_rwlock { - _atomic_lock_t lock; - pthread_t owner; - struct pthread_queue writers; - int readers; -}; -#endif /* FUTEX */ - -struct pthread_mutex_attr { - int ma_type; - int ma_protocol; - int ma_prioceiling; -}; - -struct pthread_cond_attr { - clockid_t ca_clock; -}; - -struct pthread_attr { - void *stack_addr; - size_t stack_size; - size_t guard_size; - int detach_state; - int contention_scope; - int sched_policy; - struct sched_param sched_param; - int sched_inherit; -}; - -struct rthread_storage { - int keyid; - struct rthread_storage *next; - void *data; -}; - -struct rthread_cleanup_fn { - void (*fn)(void *); - void *arg; - struct rthread_cleanup_fn *next; -}; - -struct tib; -struct stack; -struct pthread { - struct __sem donesem; - unsigned int flags; - _atomic_lock_t flags_lock; - struct tib *tib; - void *retval; - void *(*fn)(void *); - void *arg; - char name[32]; - struct stack *stack; - LIST_ENTRY(pthread) threads; - TAILQ_ENTRY(pthread) waiting; - pthread_cond_t blocking_cond; - struct pthread_attr attr; - struct rthread_storage *local_storage; - struct rthread_cleanup_fn *cleanup_fns; - - /* cancel received in a delayed cancel block? */ - int delayed_cancel; -}; -/* flags in pthread->flags */ -#define THREAD_DONE 0x001 -#define THREAD_DETACHED 0x002 - -/* flags in tib->tib_thread_flags */ -#define TIB_THREAD_ASYNC_CANCEL 0x001 -#define TIB_THREAD_INITIAL_STACK 0x002 /* has stack from exec */ - -#define ENTER_DELAYED_CANCEL_POINT(tib, self) \ - (self)->delayed_cancel = 0; \ - ENTER_CANCEL_POINT_INNER(tib, 1, 1) - -/* - * Internal functions exported from libc's thread bits for use by libpthread - */ -void _spinlock(volatile _atomic_lock_t *); -int _spinlocktry(volatile _atomic_lock_t *); -void _spinunlock(volatile _atomic_lock_t *); - -void _rthread_debug(int, const char *, ...) - __attribute__((__format__ (printf, 2, 3))); -pid_t _thread_dofork(pid_t (*_sys_fork)(void)); -void _thread_finalize(void); - -/* - * Threading syscalls not declared in system headers - */ -__dead void __threxit(pid_t *); -int __thrsleep(const volatile void *, clockid_t, - const struct timespec *, volatile void *, const int *); -int __thrwakeup(const volatile void *, int n); -int __thrsigdivert(sigset_t, siginfo_t *, const struct timespec *); - -#endif /* _THREAD_PRIVATE_H_ */ -- cgit v1.2.3-55-g6feb