diff options
Diffstat (limited to 'cddl/contrib/opensolaris/head')
-rw-r--r-- | cddl/contrib/opensolaris/head/atomic.h | 34 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/libintl.h | 97 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/nlist.h | 51 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/note.h | 55 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/stdio_ext.h | 32 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/storclass.h | 79 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/syms.h | 230 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/synch.h | 218 | ||||
-rw-r--r-- | cddl/contrib/opensolaris/head/thread.h | 104 |
9 files changed, 900 insertions, 0 deletions
diff --git a/cddl/contrib/opensolaris/head/atomic.h b/cddl/contrib/opensolaris/head/atomic.h new file mode 100644 index 000000000000..00c947604eb8 --- /dev/null +++ b/cddl/contrib/opensolaris/head/atomic.h @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _ATOMIC_H +#define _ATOMIC_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/atomic.h> + +#endif /* _ATOMIC_H */ diff --git a/cddl/contrib/opensolaris/head/libintl.h b/cddl/contrib/opensolaris/head/libintl.h new file mode 100644 index 000000000000..262fa89a1722 --- /dev/null +++ b/cddl/contrib/opensolaris/head/libintl.h @@ -0,0 +1,97 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2014 Garrett D'Amore <garrett@damore.org> + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#ifndef _LIBINTL_H +#define _LIBINTL_H + +#include <sys/isa_defs.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * wchar_t is a built-in type in standard C++ and as such is not + * defined here when using standard C++. However, the GNU compiler + * fixincludes utility nonetheless creates its own version of this + * header for use by gcc and g++. In that version it adds a redundant + * guard for __cplusplus. To avoid the creation of a gcc/g++ specific + * header we need to include the following magic comment: + * + * we must use the C++ compiler's type + * + * The above comment should not be removed or changed until GNU + * gcc/fixinc/inclhack.def is updated to bypass this header. + */ +#if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__)) +#ifndef _WCHAR_T +#define _WCHAR_T +#if defined(_LP64) +typedef int wchar_t; +#else +typedef long wchar_t; +#endif +#endif /* !_WCHAR_T */ +#endif /* !defined(__cplusplus) ... */ + +#define TEXTDOMAINMAX 256 + +#define __GNU_GETTEXT_SUPPORTED_REVISION(m) \ + ((((m) == 0) || ((m) == 1)) ? 1 : -1) + +extern char *dcgettext(const char *, const char *, const int); +extern char *dgettext(const char *, const char *); +extern char *gettext(const char *); +extern char *textdomain(const char *); +extern char *bindtextdomain(const char *, const char *); + +/* + * LI18NUX 2000 Globalization Specification Version 1.0 + * with Amendment 2 + */ +extern char *dcngettext(const char *, const char *, + const char *, unsigned long int, int); +extern char *dngettext(const char *, const char *, + const char *, unsigned long int); +extern char *ngettext(const char *, const char *, unsigned long int); +extern char *bind_textdomain_codeset(const char *, const char *); + +/* Word handling functions --- requires dynamic linking */ +/* Warning: these are experimental and subject to change. */ +extern int wdinit(void); +extern int wdchkind(wchar_t); +extern int wdbindf(wchar_t, wchar_t, int); +extern wchar_t *wddelim(wchar_t, wchar_t, int); +extern wchar_t mcfiller(void); +extern int mcwrap(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBINTL_H */ diff --git a/cddl/contrib/opensolaris/head/nlist.h b/cddl/contrib/opensolaris/head/nlist.h new file mode 100644 index 000000000000..de6be5e18444 --- /dev/null +++ b/cddl/contrib/opensolaris/head/nlist.h @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2014 Garrett D'Amore <garrett@damore.org> + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#ifndef _NLIST_H +#define _NLIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct nlist { + char *n_name; /* symbol name */ + long n_value; /* value of symbol */ + short n_scnum; /* section number */ + unsigned short n_type; /* type and derived type */ + char n_sclass; /* storage class */ + char n_numaux; /* number of aux. entries */ +}; + +extern int nlist(const char *, struct nlist *); + +#ifdef __cplusplus +} +#endif + +#endif /* _NLIST_H */ diff --git a/cddl/contrib/opensolaris/head/note.h b/cddl/contrib/opensolaris/head/note.h new file mode 100644 index 000000000000..6c73867a0275 --- /dev/null +++ b/cddl/contrib/opensolaris/head/note.h @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1994 by Sun Microsystems, Inc. + */ + +/* + * note.h: interface for annotating source with info for tools + * + * NOTE is the default interface, but if the identifier NOTE is in use for + * some other purpose, you may prepare a similar header file using your own + * identifier, mapping that identifier to _NOTE. Also, exported header + * files should *not* use NOTE, since the name may already be in use in + * a program's namespace. Rather, exported header files should include + * sys/note.h directly and use _NOTE. For consistency, all kernel source + * should use _NOTE. + */ + +#ifndef _NOTE_H +#define _NOTE_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/note.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define NOTE _NOTE + +#ifdef __cplusplus +} +#endif + +#endif /* _NOTE_H */ diff --git a/cddl/contrib/opensolaris/head/stdio_ext.h b/cddl/contrib/opensolaris/head/stdio_ext.h new file mode 100644 index 000000000000..839e05f7eebd --- /dev/null +++ b/cddl/contrib/opensolaris/head/stdio_ext.h @@ -0,0 +1,32 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _STDIO_EXT_H +#define _STDIO_EXT_H + +#define enable_extended_FILE_stdio(x,y) (0) + +#endif diff --git a/cddl/contrib/opensolaris/head/storclass.h b/cddl/contrib/opensolaris/head/storclass.h new file mode 100644 index 000000000000..3cbfb8e48fbf --- /dev/null +++ b/cddl/contrib/opensolaris/head/storclass.h @@ -0,0 +1,79 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#ifndef _STORCLASS_H +#define _STORCLASS_H + +#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * STORAGE CLASSES + */ + +#define C_EFCN -1 /* physical end of function */ +#define C_NULL 0 +#define C_AUTO 1 /* automatic variable */ +#define C_EXT 2 /* external symbol */ +#define C_STAT 3 /* static */ +#define C_REG 4 /* register variable */ +#define C_EXTDEF 5 /* external definition */ +#define C_LABEL 6 /* label */ +#define C_ULABEL 7 /* undefined label */ +#define C_MOS 8 /* member of structure */ +#define C_ARG 9 /* function argument */ +#define C_STRTAG 10 /* structure tag */ +#define C_MOU 11 /* member of union */ +#define C_UNTAG 12 /* union tag */ +#define C_TPDEF 13 /* type definition */ +#define C_USTATIC 14 /* undefined static */ +#define C_ENTAG 15 /* enumeration tag */ +#define C_MOE 16 /* member of enumeration */ +#define C_REGPARM 17 /* register parameter */ +#define C_FIELD 18 /* bit field */ +#define C_BLOCK 100 /* ".bb" or ".eb" */ +#define C_FCN 101 /* ".bf" or ".ef" */ +#define C_EOS 102 /* end of structure */ +#define C_FILE 103 /* file name */ + +/* + * The following storage class is a "dummy" used only by STS + * for line number entries reformatted as symbol table entries + */ + +#define C_LINE 104 +#define C_ALIAS 105 /* duplicate tag */ +#define C_HIDDEN 106 /* special storage class for external */ + /* symbols in dmert public libraries */ +#define C_SHADOW 107 /* shadow symbol */ + +#ifdef __cplusplus +} +#endif + +#endif /* _STORCLASS_H */ diff --git a/cddl/contrib/opensolaris/head/syms.h b/cddl/contrib/opensolaris/head/syms.h new file mode 100644 index 000000000000..d18dda2ff4a5 --- /dev/null +++ b/cddl/contrib/opensolaris/head/syms.h @@ -0,0 +1,230 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#ifndef _SYMS_H +#define _SYMS_H + +#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 2.8 */ + +/* Storage Classes are defined in storclass.h */ +#include <storclass.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Number of characters in a symbol name */ +#define SYMNMLEN 8 +/* Number of characters in a file name */ +#define FILNMLEN 14 +/* Number of array dimensions in auxiliary entry */ +#define DIMNUM 4 + +struct syment +{ + union + { + char _n_name[SYMNMLEN]; /* old COFF version */ + struct + { + long _n_zeroes; /* new == 0 */ + long _n_offset; /* offset into string table */ + } _n_n; + char *_n_nptr[2]; /* allows for overlaying */ + } _n; + unsigned long n_value; /* value of symbol */ + short n_scnum; /* section number */ + unsigned short n_type; /* type and derived type */ + char n_sclass; /* storage class */ + char n_numaux; /* number of aux. entries */ +}; + +#define n_name _n._n_name +#define n_nptr _n._n_nptr[1] +#define n_zeroes _n._n_n._n_zeroes +#define n_offset _n._n_n._n_offset + +/* + * Relocatable symbols have a section number of the + * section in which they are defined. Otherwise, section + * numbers have the following meanings: + */ + /* undefined symbol */ +#define N_UNDEF 0 + /* value of symbol is absolute */ +#define N_ABS -1 + /* special debugging symbol -- value of symbol is meaningless */ +#define N_DEBUG -2 + /* indicates symbol needs transfer vector (preload) */ +#define N_TV (unsigned short)-3 + + /* indicates symbol needs transfer vector (postload) */ + +#define P_TV (unsigned short)-4 + +/* + * The fundamental type of a symbol packed into the low + * 4 bits of the word. + */ + +#define _EF ".ef" + +#define T_NULL 0 +#define T_ARG 1 /* function argument (only used by compiler) */ +#define T_CHAR 2 /* character */ +#define T_SHORT 3 /* short integer */ +#define T_INT 4 /* integer */ +#define T_LONG 5 /* long integer */ +#define T_FLOAT 6 /* floating point */ +#define T_DOUBLE 7 /* double word */ +#define T_STRUCT 8 /* structure */ +#define T_UNION 9 /* union */ +#define T_ENUM 10 /* enumeration */ +#define T_MOE 11 /* member of enumeration */ +#define T_UCHAR 12 /* unsigned character */ +#define T_USHORT 13 /* unsigned short */ +#define T_UINT 14 /* unsigned integer */ +#define T_ULONG 15 /* unsigned long */ + +/* + * derived types are: + */ + +#define DT_NON 0 /* no derived type */ +#define DT_PTR 1 /* pointer */ +#define DT_FCN 2 /* function */ +#define DT_ARY 3 /* array */ + +/* + * type packing constants + */ + +#define N_BTMASK 017 +#define N_TMASK 060 +#define N_TMASK1 0300 +#define N_TMASK2 0360 +#define N_BTSHFT 4 +#define N_TSHIFT 2 + +/* + * MACROS + */ + + /* Basic Type of x */ + +#define BTYPE(x) ((x) & N_BTMASK) + + /* Is x a pointer ? */ + +#define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT)) + + /* Is x a function ? */ + +#define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT)) + + /* Is x an array ? */ + +#define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT)) + + /* Is x a structure, union, or enumeration TAG? */ + +#define ISTAG(x) ((x) == C_STRTAG || (x) == C_UNTAG || (x) == C_ENTAG) + +#define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(DT_PTR<<N_BTSHFT)|(x&N_BTMASK)) + +#define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK)) + +/* + * AUXILIARY ENTRY FORMAT + */ + +union auxent +{ + struct + { + long x_tagndx; /* str, un, or enum tag indx */ + union + { + struct + { + unsigned short x_lnno; /* declaration line */ + /* number */ + unsigned short x_size; /* str, union, array */ + /* size */ + } x_lnsz; + long x_fsize; /* size of function */ + } x_misc; + union + { + struct /* if ISFCN, tag, or .bb */ + { + long x_lnnoptr; /* ptr to fcn line # */ + long x_endndx; /* entry ndx past */ + /* block end */ + } x_fcn; + struct /* if ISARY, up to 4 dimen. */ + { + unsigned short x_dimen[DIMNUM]; + } x_ary; + } x_fcnary; + unsigned short x_tvndx; /* tv index */ + } x_sym; + struct + { + char x_fname[FILNMLEN]; + } x_file; + struct + { + long x_scnlen; /* section length */ + unsigned short x_nreloc; /* number of reloc entries */ + unsigned short x_nlinno; /* number of line numbers */ + } x_scn; + + struct + { + long x_tvfill; /* tv fill value */ + unsigned short x_tvlen; /* length of .tv */ + unsigned short x_tvran[2]; /* tv range */ + } x_tv; /* info about .tv section (in auxent of symbol .tv)) */ +}; + +#define SYMENT struct syment +#define SYMESZ 18 /* sizeof(SYMENT) */ + +#define AUXENT union auxent +#define AUXESZ 18 /* sizeof(AUXENT) */ + +/* Defines for "special" symbols */ + +#define _ETEXT "etext" +#define _EDATA "edata" +#define _END "end" +#define _START "_start" + +#ifdef __cplusplus +} +#endif + +#endif /* _SYMS_H */ diff --git a/cddl/contrib/opensolaris/head/synch.h b/cddl/contrib/opensolaris/head/synch.h new file mode 100644 index 000000000000..c0f68f12f008 --- /dev/null +++ b/cddl/contrib/opensolaris/head/synch.h @@ -0,0 +1,218 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2014 Garrett D'Amore <garrett@damore.org> + * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. + */ + +#ifndef _SYNCH_H +#define _SYNCH_H + +/* + * synch.h: + * definitions needed to use the thread synchronization interface + */ + +#ifndef _ASM +#include <sys/machlock.h> +#include <sys/time_impl.h> +#include <sys/synch.h> +#endif /* _ASM */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ASM + +/* + * Semaphores + */ +typedef struct _sema { + /* this structure must be the same as sem_t in <semaphore.h> */ + uint32_t count; /* semaphore count */ + uint16_t type; + uint16_t magic; + upad64_t pad1[3]; /* reserved for a mutex_t */ + upad64_t pad2[2]; /* reserved for a cond_t */ +} sema_t; + +/* + * POSIX.1c Note: + * POSIX.1c requires that <pthread.h> define the structures pthread_mutex_t + * and pthread_cond_t. These structures are identical to mutex_t (lwp_mutex_t) + * and cond_t (lwp_cond_t) which are defined in <synch.h>. A nested included + * of <synch.h> (to allow a "#typedef mutex_t pthread_mutex_t") would pull in + * non-posix symbols/constants violating the namespace restrictions. Hence, + * pthread_mutex_t/pthread_cond_t have been redefined in <pthread.h> (actually + * in <sys/types.h>). Any modifications done to mutex_t/lwp_mutex_t or + * cond_t/lwp_cond_t should also be done to pthread_mutex_t/pthread_cond_t. + */ +typedef lwp_mutex_t mutex_t; +typedef lwp_cond_t cond_t; + +/* + * Readers/writer locks + * + * NOTE: The layout of this structure should be kept in sync with the layout + * of the correponding structure of pthread_rwlock_t in sys/types.h. + * Also, there is an identical structure for lwp_rwlock_t in <sys/synch.h>. + * Because we have to deal with C++, we cannot redefine this one as that one. + */ +typedef struct _rwlock { + int32_t readers; /* rwstate word */ + uint16_t type; + uint16_t magic; + mutex_t mutex; /* used with process-shared rwlocks */ + cond_t readercv; /* used only to indicate ownership */ + cond_t writercv; /* used only to indicate ownership */ +} rwlock_t; + +int _lwp_mutex_lock(lwp_mutex_t *); +int _lwp_mutex_unlock(lwp_mutex_t *); +int _lwp_mutex_trylock(lwp_mutex_t *); +int _lwp_cond_wait(lwp_cond_t *, lwp_mutex_t *); +int _lwp_cond_timedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *); +int _lwp_cond_reltimedwait(lwp_cond_t *, lwp_mutex_t *, timespec_t *); +int _lwp_cond_signal(lwp_cond_t *); +int _lwp_cond_broadcast(lwp_cond_t *); +int _lwp_sema_init(lwp_sema_t *, int); +int _lwp_sema_wait(lwp_sema_t *); +int _lwp_sema_trywait(lwp_sema_t *); +int _lwp_sema_post(lwp_sema_t *); +int cond_init(cond_t *, int, void *); +int cond_destroy(cond_t *); +int cond_wait(cond_t *, mutex_t *); +int cond_timedwait(cond_t *, mutex_t *, const timespec_t *); +int cond_reltimedwait(cond_t *, mutex_t *, const timespec_t *); +int cond_signal(cond_t *); +int cond_broadcast(cond_t *); +int mutex_init(mutex_t *, int, void *); +int mutex_destroy(mutex_t *); +int mutex_consistent(mutex_t *); +int mutex_lock(mutex_t *); +int mutex_trylock(mutex_t *); +int mutex_unlock(mutex_t *); +int rwlock_init(rwlock_t *, int, void *); +int rwlock_destroy(rwlock_t *); +int rw_rdlock(rwlock_t *); +int rw_wrlock(rwlock_t *); +int rw_unlock(rwlock_t *); +int rw_tryrdlock(rwlock_t *); +int rw_trywrlock(rwlock_t *); +int sema_init(sema_t *, unsigned int, int, void *); +int sema_destroy(sema_t *); +int sema_wait(sema_t *); +int sema_timedwait(sema_t *, const timespec_t *); +int sema_reltimedwait(sema_t *, const timespec_t *); +int sema_post(sema_t *); +int sema_trywait(sema_t *); + +#endif /* _ASM */ + +/* "Magic numbers" tagging synchronization object types */ +#define MUTEX_MAGIC _MUTEX_MAGIC +#define SEMA_MAGIC _SEMA_MAGIC +#define COND_MAGIC _COND_MAGIC +#define RWL_MAGIC _RWL_MAGIC + +/* + * POSIX.1c Note: + * DEFAULTMUTEX is defined same as PTHREAD_MUTEX_INITIALIZER in <pthread.h>. + * DEFAULTCV is defined same as PTHREAD_COND_INITIALIZER in <pthread.h>. + * DEFAULTRWLOCK is defined same as PTHREAD_RWLOCK_INITIALIZER in <pthread.h>. + * Any changes to these macros should be reflected in <pthread.h> + */ +#define DEFAULTMUTEX \ + {{0, 0, 0, {USYNC_THREAD}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define SHAREDMUTEX \ + {{0, 0, 0, {USYNC_PROCESS}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define RECURSIVEMUTEX \ + {{0, 0, 0, {USYNC_THREAD|LOCK_RECURSIVE}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define ERRORCHECKMUTEX \ + {{0, 0, 0, {USYNC_THREAD|LOCK_ERRORCHECK}, MUTEX_MAGIC}, \ + {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define RECURSIVE_ERRORCHECKMUTEX \ + {{0, 0, 0, {USYNC_THREAD|LOCK_RECURSIVE|LOCK_ERRORCHECK}, \ + MUTEX_MAGIC}, {{{0, 0, 0, 0, 0, 0, 0, 0}}}, 0} +#define DEFAULTCV \ + {{{0, 0, 0, 0}, USYNC_THREAD, COND_MAGIC}, 0} +#define SHAREDCV \ + {{{0, 0, 0, 0}, USYNC_PROCESS, COND_MAGIC}, 0} +#define DEFAULTSEMA \ + {0, USYNC_THREAD, SEMA_MAGIC, {0, 0, 0}, {0, 0}} +#define SHAREDSEMA \ + {0, USYNC_PROCESS, SEMA_MAGIC, {0, 0, 0}, {0, 0}} +#define DEFAULTRWLOCK \ + {0, USYNC_THREAD, RWL_MAGIC, DEFAULTMUTEX, DEFAULTCV, DEFAULTCV} +#define SHAREDRWLOCK \ + {0, USYNC_PROCESS, RWL_MAGIC, SHAREDMUTEX, SHAREDCV, SHAREDCV} + +/* + * Tests on lock states. + */ +#define SEMA_HELD(x) _sema_held(x) +#define RW_READ_HELD(x) _rw_read_held(x) +#define RW_WRITE_HELD(x) _rw_write_held(x) +#define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x)) +#define MUTEX_HELD(x) _mutex_held(x) + +/* + * The following definitions are for assertions which can be checked + * statically by tools like lock_lint. You can also define your own + * run-time test for each. If you don't, we define them to 1 so that + * such assertions simply pass. + */ +#ifndef NO_LOCKS_HELD +#define NO_LOCKS_HELD 1 +#endif +#ifndef NO_COMPETING_THREADS +#define NO_COMPETING_THREADS 1 +#endif + +#ifndef _ASM + +/* + * The *_held() functions apply equally well to Solaris threads + * and to Posix threads synchronization objects, but the formal + * type declarations are different, so we just declare the argument + * to each *_held() function to be a void *, expecting that they will + * be called with the proper type of argument in each case. + */ +int _sema_held(void *); /* sema_t or sem_t */ +int _rw_read_held(void *); /* rwlock_t or pthread_rwlock_t */ +int _rw_write_held(void *); /* rwlock_t or pthread_rwlock_t */ +int _mutex_held(void *); /* mutex_t or pthread_mutex_t */ + +/* Pause API */ +void smt_pause(void); + +#endif /* _ASM */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYNCH_H */ diff --git a/cddl/contrib/opensolaris/head/thread.h b/cddl/contrib/opensolaris/head/thread.h new file mode 100644 index 000000000000..be58e1cf4183 --- /dev/null +++ b/cddl/contrib/opensolaris/head/thread.h @@ -0,0 +1,104 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2014 Garrett D'Amore <garrett@damore.org> + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _THREAD_H +#define _THREAD_H + +#include <pthread.h> +#include <pthread_np.h> +#include <assert.h> + +/* + * Compatibility thread stuff needed for Solaris -> Linux port + */ + +typedef pthread_t thread_t; +typedef pthread_mutex_t mutex_t; +typedef pthread_cond_t cond_t; +typedef pthread_rwlock_t rwlock_t; + +#define USYNC_THREAD 0 + +#define thr_self() (unsigned long)pthread_self() +#define thr_equal(a,b) pthread_equal(a,b) +#define thr_join(t,d,s) pthread_join(t,s) +#define thr_exit(r) pthread_exit(r) +#define _mutex_init(l,f,a) pthread_mutex_init(l,NULL) +#define _mutex_destroy(l) pthread_mutex_destroy(l) +#define mutex_lock(l) pthread_mutex_lock(l) +#define mutex_trylock(l) pthread_mutex_trylock(l) +#define mutex_unlock(l) pthread_mutex_unlock(l) +#define rwlock_init(l,f,a) pthread_rwlock_init(l,NULL) +#define rwlock_destroy(l) pthread_rwlock_destroy(l) +#define rw_rdlock(l) pthread_rwlock_rdlock(l) +#define rw_wrlock(l) pthread_rwlock_wrlock(l) +#define rw_tryrdlock(l) pthread_rwlock_tryrdlock(l) +#define rw_trywrlock(l) pthread_rwlock_trywrlock(l) +#define rw_unlock(l) pthread_rwlock_unlock(l) +#define cond_init(l,f,a) pthread_cond_init(l,NULL) +#define cond_destroy(l) pthread_cond_destroy(l) +#define cond_wait(l,m) pthread_cond_wait(l,m) +#define cond_signal(l) pthread_cond_signal(l) +#define cond_broadcast(l) pthread_cond_broadcast(l) + +#define THR_BOUND 0x00000001 /* = PTHREAD_SCOPE_SYSTEM */ +#define THR_NEW_LWP 0x00000002 +#define THR_DETACHED 0x00000040 /* = PTHREAD_CREATE_DETACHED */ +#define THR_SUSPENDED 0x00000080 +#define THR_DAEMON 0x00000100 + +static __inline int +thr_create(void *stack_base, size_t stack_size, void *(*start_func) (void*), + void *arg, long flags, thread_t *new_thread_ID) +{ + pthread_t dummy; + int ret; + + assert(stack_base == NULL); + assert(stack_size == 0); + assert((flags & ~THR_BOUND & ~THR_DETACHED) == 0); + + pthread_attr_t attr; + pthread_attr_init(&attr); + + if (flags & THR_DETACHED) + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + if (new_thread_ID == NULL) + new_thread_ID = &dummy; + + /* This function ignores the THR_BOUND flag, since NPTL doesn't seem to support PTHREAD_SCOPE_PROCESS */ + + ret = pthread_create(new_thread_ID, &attr, start_func, arg); + + pthread_attr_destroy(&attr); + + return (ret); +} + +#endif /* _THREAD_H */ |