From 581533b6f7a8280eca7970dad02233f4afde7c27 Mon Sep 17 00:00:00 2001 From: Eirik Nygaard Date: Mon, 8 Dec 2003 13:56:36 +0000 Subject: [PATCH] * Merge fixes from libc to libcr. --- lib/libcr/gen/initgroups.c | 11 +- lib/libcr/gen/psignal.3 | 19 +- lib/libcr/gen/siglist.c | 73 +++- lib/libcr/i386/string/strcat.S | 4 +- lib/libcr/i386/string/strcmp.S | 4 +- lib/libcr/i386/string/strcpy.S | 4 +- lib/libcr/locale/Makefile.inc | 6 +- lib/libcr/locale/gb18030.5 | 79 +++++ lib/libcr/locale/gb18030.c | 167 ++++++++++ lib/libcr/locale/gbk.5 | 64 ++++ lib/libcr/{stdlib/atexit.c => locale/gbk.c} | 115 ++++--- lib/libcr/locale/mskanji.c | 4 +- lib/libcr/locale/setrunelocale.c | 8 +- lib/libcr/locale/utf8.c | 2 +- lib/libcr/rpc/pmap_getport.c | 14 +- lib/libcr/stdio/local.h | 8 +- lib/libcr/stdlib/atexit.c | 4 +- lib/libcr/stdlib/bsearch.c | 16 +- lib/libcr/stdlib/calloc.c | 6 +- lib/libcr/stdlib/exit.c | 6 +- lib/libcr/stdlib/getenv.3 | 9 +- lib/libcr/stdlib/getenv.c | 10 +- lib/libcr/stdlib/getsubopt.c | 10 +- lib/libcr/stdlib/heapsort.c | 6 +- lib/libcr/stdlib/malloc.c | 4 +- lib/libcr/stdlib/merge.c | 8 +- lib/libcr/stdlib/qsort.c | 8 +- lib/libcr/stdlib/radixsort.c | 16 +- lib/libcr/stdlib/random.c | 73 ++-- lib/libcr/stdlib/setenv.c | 14 +- lib/libcr/stdlib/strhash.c | 14 +- lib/libcr/stdlib/strtod.c | 14 +- lib/libcr/stdlib/strtol.c | 14 +- lib/libcr/stdlib/strtoll.c | 14 +- lib/libcr/stdlib/strtoul.c | 14 +- lib/libcr/stdlib/strtoull.c | 14 +- lib/libcr/string/memccpy.c | 4 +- lib/libcr/sys/Makefile.inc | 7 +- lib/libcr/sys/send.2 | 6 +- lib/libcr/sys/upc_register.2 | 352 ++++++++++++++++++++ 40 files changed, 1017 insertions(+), 208 deletions(-) create mode 100644 lib/libcr/locale/gb18030.5 create mode 100644 lib/libcr/locale/gb18030.c create mode 100644 lib/libcr/locale/gbk.5 copy lib/libcr/{stdlib/atexit.c => locale/gbk.c} (59%) create mode 100644 lib/libcr/sys/upc_register.2 diff --git a/lib/libcr/gen/initgroups.c b/lib/libcr/gen/initgroups.c index 0cb7b72191..3678f9594d 100644 --- a/lib/libcr/gen/initgroups.c +++ b/lib/libcr/gen/initgroups.c @@ -32,7 +32,7 @@ * * @(#)initgroups.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/gen/initgroups.c,v 1.3.8.1 2001/12/19 15:49:35 tobez Exp $ - * $DragonFly: src/lib/libcr/gen/Attic/initgroups.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libcr/gen/Attic/initgroups.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -46,9 +46,14 @@ initgroups(uname, agroup) const char *uname; int agroup; { - int groups[NGROUPS], ngroups; + int ngroups; + /* + * Provide space for one group more than NGROUPS to allow + * setgroups to fail and set errno. + */ + gid_t groups[NGROUPS + 1]; - ngroups = NGROUPS; + ngroups = NGROUPS + 1; getgrouplist(uname, agroup, groups, &ngroups); return (setgroups(ngroups, groups)); } diff --git a/lib/libcr/gen/psignal.3 b/lib/libcr/gen/psignal.3 index 9e55f53bd1..3afecd08fe 100644 --- a/lib/libcr/gen/psignal.3 +++ b/lib/libcr/gen/psignal.3 @@ -31,7 +31,7 @@ .\" .\" @(#)psignal.3 8.2 (Berkeley) 2/27/95 .\" $FreeBSD: src/lib/libc/gen/psignal.3,v 1.10.2.5 2003/03/15 15:11:05 trhodes Exp $ -.\" $DragonFly: src/lib/libcr/gen/Attic/psignal.3,v 1.2 2003/06/17 04:26:42 dillon Exp $ +.\" $DragonFly: src/lib/libcr/gen/Attic/psignal.3,v 1.3 2003/12/08 13:56:35 eirikn Exp $ .\" .Dd February 27, 1995 .Dt PSIGNAL 3 @@ -41,6 +41,7 @@ .Nm strsignal , .Nm sys_siglist , .Nm sys_signame +.Nm sys_nsig .Nd system signal messages .Sh LIBRARY .Lb libc @@ -50,6 +51,7 @@ .Fn psignal "unsigned sig" "const char *s" .Vt extern const char * const sys_siglist[] ; .Vt extern const char * const sys_signame[] ; +.Vt extern const int sys_nsig ; .In string.h .Ft "char *" .Fn strsignal "int sig" @@ -97,12 +99,23 @@ is used similarly and contains short, lower-case abbreviations for signals which are useful for recognizing signal names in user input. -The defined variable -.Dv NSIG +The external variable +.Va sys_nsig contains a count of the strings in .Va sys_siglist and .Va sys_signame . +Note that the defined variable +.Dv NSIG +will typically be the same as +.Va sys_nsig , +but might be different due to newer or older kernels and newer or +older libc libraries. For maximum portability you must use +.Va sys_nsig +to limit-check the above arrays. Additionally, you should check +for +.Dv NULL +array entries and generate a generic signal name in those cases. .Sh SEE ALSO .Xr sigaction 2 , .Xr perror 3 , diff --git a/lib/libcr/gen/siglist.c b/lib/libcr/gen/siglist.c index 29d05ebb24..6df3555b18 100644 --- a/lib/libcr/gen/siglist.c +++ b/lib/libcr/gen/siglist.c @@ -31,6 +31,7 @@ * SUCH DAMAGE. * * @(#)siglist.c 8.1 (Berkeley) 6/4/93 + * $DragonFly: src/lib/libcr/gen/Attic/siglist.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -69,6 +70,41 @@ const char *const sys_signame[NSIG] = { "info", /* SIGINFO */ "usr1", /* SIGUSR1 */ "usr2", /* SIGUSR2 */ + + /* 32-63 */ + + "thrd", /* 32 */ + "ckpt", /* 33 */ + "ckptx", /* 34 */ + "Signal35", /* 35 */ + "Signal36", /* 36 */ + "Signal37", /* 37 */ + "Signal38", /* 38 */ + "Signal39", /* 39 */ + "Signal40", /* 40 */ + "Signal41", /* 41 */ + "Signal42", /* 42 */ + "Signal43", /* 43 */ + "Signal44", /* 44 */ + "Signal45", /* 45 */ + "Signal46", /* 46 */ + "Signal47", /* 47 */ + "Signal48", /* 48 */ + "Signal49", /* 49 */ + "Signal50", /* 50 */ + "Signal51", /* 51 */ + "Signal52", /* 52 */ + "Signal53", /* 53 */ + "Signal54", /* 54 */ + "Signal55", /* 55 */ + "Signal56", /* 56 */ + "Signal57", /* 57 */ + "Signal58", /* 58 */ + "Signal59", /* 59 */ + "Signal60", /* 60 */ + "Signal61", /* 61 */ + "Signal62", /* 62 */ + "Signal63" /* 63 */ }; const char *const sys_siglist[NSIG] = { @@ -103,6 +139,41 @@ const char *const sys_siglist[NSIG] = { "Window size changes", /* SIGWINCH */ "Information request", /* SIGINFO */ "User defined signal 1", /* SIGUSR1 */ - "User defined signal 2" /* SIGUSR2 */ + "User defined signal 2", /* SIGUSR2 */ + + /* 32-63 */ + + "Thread Scheduler", /* SIGTHR */ + "CheckPoint", /* SIGCKPT */ + "CheckPointExit", /* SIGCKPTEXIT */ + "Signal35", /* 35 */ + "Signal36", /* 36 */ + "Signal37", /* 37 */ + "Signal38", /* 38 */ + "Signal39", /* 39 */ + "Signal40", /* 40 */ + "Signal41", /* 41 */ + "Signal42", /* 42 */ + "Signal43", /* 43 */ + "Signal44", /* 44 */ + "Signal45", /* 45 */ + "Signal46", /* 46 */ + "Signal47", /* 47 */ + "Signal48", /* 48 */ + "Signal49", /* 49 */ + "Signal50", /* 50 */ + "Signal51", /* 51 */ + "Signal52", /* 52 */ + "Signal53", /* 53 */ + "Signal54", /* 54 */ + "Signal55", /* 55 */ + "Signal56", /* 56 */ + "Signal57", /* 57 */ + "Signal58", /* 58 */ + "Signal59", /* 59 */ + "Signal60", /* 60 */ + "Signal61", /* 61 */ + "Signal62", /* 62 */ + "Signal63" /* 63 */ }; const int sys_nsig = sizeof(sys_siglist) / sizeof(sys_siglist[0]); diff --git a/lib/libcr/i386/string/strcat.S b/lib/libcr/i386/string/strcat.S index 1c4fdea529..29d4bcf481 100644 --- a/lib/libcr/i386/string/strcat.S +++ b/lib/libcr/i386/string/strcat.S @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/string/strcat.S,v 1.5 1999/08/27 23:59:33 peter Exp $ - * $DragonFly: src/lib/libcr/i386/string/Attic/strcat.S,v 1.2 2003/06/17 04:26:43 dillon Exp $ + * $DragonFly: src/lib/libcr/i386/string/Attic/strcat.S,v 1.3 2003/12/08 13:56:35 eirikn Exp $ * * $FreeBSD: src/lib/libc/i386/string/strcat.S,v 1.5 1999/08/27 23:59:33 peter Exp $ */ @@ -47,7 +47,7 @@ /* * I've unrolled the loop eight times: large enough to make a * significant difference, and small enough not to totally trash the - * cashe. + * cache. */ ENTRY(strcat) diff --git a/lib/libcr/i386/string/strcmp.S b/lib/libcr/i386/string/strcmp.S index 3d54cda169..2df5ab27cf 100644 --- a/lib/libcr/i386/string/strcmp.S +++ b/lib/libcr/i386/string/strcmp.S @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/string/strcmp.S,v 1.5 1999/08/27 23:59:33 peter Exp $ - * $DragonFly: src/lib/libcr/i386/string/Attic/strcmp.S,v 1.2 2003/06/17 04:26:43 dillon Exp $ + * $DragonFly: src/lib/libcr/i386/string/Attic/strcmp.S,v 1.3 2003/12/08 13:56:35 eirikn Exp $ * * $FreeBSD: src/lib/libc/i386/string/strcmp.S,v 1.5 1999/08/27 23:59:33 peter Exp $ */ @@ -51,7 +51,7 @@ /* * I've unrolled the loop eight times: large enough to make a * significant difference, and small enough not to totally trash the - * cashe. + * cache. */ ENTRY(strcmp) diff --git a/lib/libcr/i386/string/strcpy.S b/lib/libcr/i386/string/strcpy.S index 0c662374c4..96222b1dcc 100644 --- a/lib/libcr/i386/string/strcpy.S +++ b/lib/libcr/i386/string/strcpy.S @@ -28,7 +28,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/string/strcpy.S,v 1.5 1999/08/27 23:59:34 peter Exp $ - * $DragonFly: src/lib/libcr/i386/string/Attic/strcpy.S,v 1.2 2003/06/17 04:26:43 dillon Exp $ + * $DragonFly: src/lib/libcr/i386/string/Attic/strcpy.S,v 1.3 2003/12/08 13:56:35 eirikn Exp $ * * $FreeBSD: src/lib/libc/i386/string/strcpy.S,v 1.5 1999/08/27 23:59:34 peter Exp $ */ @@ -46,7 +46,7 @@ /* * I've unrolled the loop eight times: large enough to make a * significant difference, and small enough not to totally trash the - * cashe. + * cache. */ ENTRY(strcpy) diff --git a/lib/libcr/locale/Makefile.inc b/lib/libcr/locale/Makefile.inc index aea0ff3bc5..ef998ed866 100644 --- a/lib/libcr/locale/Makefile.inc +++ b/lib/libcr/locale/Makefile.inc @@ -1,12 +1,12 @@ # from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 # $FreeBSD: src/lib/libc/locale/Makefile.inc,v 1.16.2.5 2002/10/24 11:00:52 tjr Exp $ -# $DragonFly: src/lib/libcr/locale/Attic/Makefile.inc,v 1.3 2003/07/24 21:41:49 dillon Exp $ +# $DragonFly: src/lib/libcr/locale/Attic/Makefile.inc,v 1.4 2003/12/08 13:56:35 eirikn Exp $ # locale sources .PATH: ${.CURDIR}/../libcr/${MACHINE_ARCH}/locale ${.CURDIR}/../libcr/locale SRCS+= ansi.c big5.c collate.c collcmp.c euc.c fix_grouping.c frune.c \ - isctype.c \ + gbk.c gb18030.c isctype.c \ ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \ mskanji.c nl_langinfo.c nomacros.c none.c rune.c \ runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \ @@ -17,7 +17,7 @@ MAN+= ctype.3 isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 \ isdigit.3 isgraph.3 islower.3 isprint.3 ispunct.3 isspace.3 \ isupper.3 isxdigit.3 mbrune.3 multibyte.3 nl_langinfo.3 rune.3 \ setlocale.3 toascii.3 tolower.3 toupper.3 -MAN+= euc.4 utf2.4 +MAN+= euc.4 utf2.4 gb18030.5 gbk.5 MAN+= utf8.5 MLINKS+=mbrune.3 mbmb.3 mbrune.3 mbrrune.3 diff --git a/lib/libcr/locale/gb18030.5 b/lib/libcr/locale/gb18030.5 new file mode 100644 index 0000000000..394c069d06 --- /dev/null +++ b/lib/libcr/locale/gb18030.5 @@ -0,0 +1,79 @@ +.\" Copyright (c) 2002, 2003 Tim J. Robbins +.\" 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. +.\" +.\" 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: src/lib/libc/locale/gb18030.5,v 1.3.2.1 2003/11/04 05:12:21 murray Exp $ +.\" $DragonFly: src/lib/libcr/locale/Attic/gb18030.5,v 1.1 2003/12/08 13:56:35 eirikn Exp $ +.Dd August 10, 2003 +.Dt GB18030 5 +.Os +.Sh NAME +.Nm gb18030 +.Nd "GB 18030 encoding method for Chinese text" +.Sh SYNOPSIS +.Nm ENCODING +.Qq GB18030 +.Sh DESCRIPTION +The +.Nm GB18030 +encoding implements GB 18030-2000, a PRC national standard for the encoding of +Chinese characters. +It is a superset of the older GB\ 2312-1980 and GBK encodings, +and incorporates Unicode's Unihan Extension A completely. +It also provides code space for all Unicode 3.0 code points. +.Pp +Multibyte characters in the +.Nm GB18030 +encoding can be one byte, two bytes, or +four bytes long. +There are a total of over 1.5 million code positions. +.Pp +.No GB\ 11383-1981 ( Ns +.Tn ASCII ) +characters are represented by single bytes in the range 0x00 to 0x7F. +.Pp +Chinese characters are represented as either two bytes or four bytes. +Characters that are represented by two bytes begin with a byte in the range +0x81-0xFE and end with a byte either in the range 0x40-0x7E or 0x80-0xFE. +.Pp +Characters that are represented by four bytes begin with a byte in the range +0x81-0xFE, have a second byte in the range 0x30-0x39, a third byte in the range +0x81-0xFE and a fourth byte in the range 0x30-0x39. +.Sh SEE ALSO +.Xr euc 4 , +.Xr gbk 5 , +.Xr utf8 5 +.Rs +.%T "Chinese National Standard GB 18030-2000: Information Technology -- Chinese ideograms coded character set for information interchange -- Extension for the basic set" +.%D "March 2000" +.Re +.Rs +.%Q "The Unicode Consortium" +.%T "The Unicode Standard, Version 3.0" +.%D "2000" +.Re +.Sh STANDARDS +The +.Nm GB18030 +encoding is believed to be compatible with GB 18030-2000. + diff --git a/lib/libcr/locale/gb18030.c b/lib/libcr/locale/gb18030.c new file mode 100644 index 0000000000..92c5a20f68 --- /dev/null +++ b/lib/libcr/locale/gb18030.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2003 + * The Regents of the University of California. All rights reserved. + * + * This code is contributed to Robin Hu + * + * 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 the University of + * California, Berkeley and its contributors. + * 4. 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. + * $DragonFly: src/lib/libcr/locale/Attic/gb18030.c,v 1.1 2003/12/08 13:56:35 eirikn Exp $ + */ + +#include + +#include +#include +#include +#include +#include + +rune_t _GB18030_sgetrune(const char *, size_t, char const **); +int _GB18030_sputrune(rune_t, char *, size_t, char **); + +int +_GB18030_init(rl) + _RuneLocale *rl; +{ + rl->sgetrune = _GB18030_sgetrune; + rl->sputrune = _GB18030_sputrune; + _CurrentRuneLocale = rl; + __mb_cur_max = 4; + return (0); +} + +static inline int +_gb18030_check_string(s_, n) + const char* s_; + int n; +{ + const unsigned char* s = s_; + if ((s[0]>=0x81&&s[0]<=0xfe)) { + if (n<2) goto bad_string; + if ((s[1]>=0x40&&s[1]<=0x7e)||(s[1]>=0x80&&s[1]<=0xfe)) + return 2; + if ((s[1]>=0x30&&s[1]<=0x39)) { + if (n<4) goto bad_string; + if ((s[2]>=0x81&&s[2]<=0xfe) && (s[3]>=0x30&&s[3]<=0x39)) + return 4; + else + goto bad_string; + } + } else { + return 1; + } + bad_string: + return -1; +} + +static inline int +_gb18030_check_rune(r) + rune_t r; +{ + if (r&0xff000000) { + return 4; + } + if (r&0xff00) { + return 2; + } + return 1; +} + +rune_t +_GB18030_sgetrune(string, n, result) + const char *string; + size_t n; + char const **result; +{ + rune_t rune = 0; + int len; + + len = _gb18030_check_string(string, n); + + if (len == -1) { + if (result) + *result = string; + return (_INVALID_RUNE); + } + + while (--len >= 0) + rune = (rune << 8) | ((u_int)(*string++) & 0xff); + + rune &= 0x7fffffff; + if (result) + *result = string; + return rune; +} + +int +_GB18030_sputrune(c, string, n, result) + rune_t c; + char *string, **result; + size_t n; +{ + int len; + len = _gb18030_check_rune(c); + + switch (len) { + case 1: + if (n >= 1) { + *string = c & 0xff; + if (result) + *result = string + 1; + return (1); + } + break; + case 2: + if (n >= 2) { + string[0] = (c >> 8) & 0xff; + string[1] = c & 0xff; + if (result) + *result = string + 2; + return (2); + } + break; + case 4: + if (n >= 4) { + string[0] = ((c >>24) & 0xff) | 0x80; + string[1] = (c >>16) & 0xff; + string[2] = (c >>8) & 0xff; + string[3] = c & 0xff; + if (result) + *result = string + 4; + return (4); + } + break; + default: + break; + } + if (result) + *result = string; + return (0); +} + diff --git a/lib/libcr/locale/gbk.5 b/lib/libcr/locale/gbk.5 new file mode 100644 index 0000000000..27f19ec3f0 --- /dev/null +++ b/lib/libcr/locale/gbk.5 @@ -0,0 +1,64 @@ +.\" Copyright (c) 2003 Tim J. Robbins +.\" 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. +.\" +.\" 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: src/lib/libc/locale/gbk.5,v 1.1.2.1 2003/11/04 19:38:29 murray Exp $ +.\" $DragonFly: src/lib/libcr/locale/Attic/gbk.5,v 1.1 2003/12/08 13:56:35 eirikn Exp $ +.Dd August 10, 2003 +.Dt GBK 5 +.Os +.Sh NAME +.Nm gbk +.Nd "Guojia biaozhun kuozhan (GBK) encoding method for Chinese text" +.Sh SYNOPSIS +.Nm ENCODING +.Qq GBK +.Sh DESCRIPTION +GBK is a backwards-compatible extension of the GB\ 2312-1980 encoding +method for Chinese text, which adds the characters defined in the +Unified Han portion of the Unicode 2.1 standard. +.Pp +Multibyte characters in the GBK +encoding can be one byte or two bytes long. +.No GB\ 11383-1981 ( Ns +.Tn ASCII ) +characters are represented by single bytes in the range 0x00 to 0x7F. +Chinese characters are represented by two bytes, beginning with a byte in +the range 0x80-0xFE and ending with a byte in the range 0x40-0xFE. +.Sh SEE ALSO +.Xr euc 4 , +.Xr gb18030 5 , +.Xr utf8 5 +.Rs +.%Q "The Unicode Consortium" +.%T "The Unicode Standard, Version 2.1" +.%D "1999" +.Re +.Rs +.%T "Chinese National Standard GB 18030-2000: Information Technology -- Chinese ideograms coded character set for information interchange -- Extension for the basic set" +.%D "March 2000" +.Re +.Sh STANDARDS +GBK is not a standard, but has been superceded by +GB\ 18030-2000. + diff --git a/lib/libcr/stdlib/atexit.c b/lib/libcr/locale/gbk.c similarity index 59% copy from lib/libcr/stdlib/atexit.c copy to lib/libcr/locale/gbk.c index be495d960d..128acc78fe 100644 --- a/lib/libcr/stdlib/atexit.c +++ b/lib/libcr/locale/gbk.c @@ -1,9 +1,9 @@ /*- - * Copyright (c) 1990, 1993 + * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by - * Chris Torek. + * Paul Borman at Krystal Technologies. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,61 +32,84 @@ * 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/lib/libc/stdlib/atexit.c,v 1.3.6.1 2002/03/10 20:28:40 tegge Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/atexit.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ - * - * @(#)atexit.c 8.2 (Berkeley) 7/3/94 + * $DragonFly: src/lib/libcr/locale/Attic/gbk.c,v 1.1 2003/12/08 13:56:35 eirikn Exp $ */ -#include +#include + +#include #include -#include -#include "atexit.h" +#include -#include "libc_private.h" -#include "spinlock.h" +rune_t _GBK_sgetrune(const char *, size_t, char const **); +int _GBK_sputrune(rune_t, char *, size_t, char **); -static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; +int +_GBK_init(rl) + _RuneLocale *rl; +{ + rl->sgetrune = _GBK_sgetrune; + rl->sputrune = _GBK_sputrune; + _CurrentRuneLocale = rl; + __mb_cur_max = 2; + return (0); +} + +static inline int +_gbk_check(c) + u_int c; +{ + c &= 0xff; + return ((c >= 0x80 && c <= 0xfe) ? 2 : 1); +} -#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock); -#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock); +rune_t +_GBK_sgetrune(string, n, result) + const char *string; + size_t n; + char const **result; +{ + rune_t rune = 0; + int len; -struct atexit *__atexit; /* points to head of LIFO stack */ + if (n < 1 || (len = _gbk_check(*string)) > n) { + if (result) + *result = string; + return (_INVALID_RUNE); + } + while (--len >= 0) + rune = (rune << 8) | ((u_int)(*string++) & 0xff); + if (result) + *result = string; + return rune; +} -/* - * Register a function to be performed at exit. - */ int -atexit(fn) - void (*fn)(); +_GBK_sputrune(c, string, n, result) + rune_t c; + char *string, **result; + size_t n; { - static struct atexit __atexit0; /* one guaranteed table */ - register struct atexit *p; - - THREAD_LOCK(); - if ((p = __atexit) == NULL) - __atexit = p = &__atexit0; - else while (p->ind >= ATEXIT_SIZE) { - struct atexit *old__atexit; - old__atexit = __atexit; - THREAD_UNLOCK(); - if ((p = (struct atexit *)malloc(sizeof(*p))) == NULL) - return (-1); - THREAD_LOCK(); - if (old__atexit != __atexit) { - /* Lost race, retry operation */ - THREAD_UNLOCK(); - free(p); - THREAD_LOCK(); - p = __atexit; - continue; + if (c & 0x8000) { + if (n >= 2) { + string[0] = (c >> 8) & 0xff; + string[1] = c & 0xff; + if (result) + *result = string + 2; + return (2); + } + } + else { + if (n >= 1) { + *string = c & 0xff; + if (result) + *result = string + 1; + return (1); } - p->ind = 0; - p->next = __atexit; - __atexit = p; } - p->fns[p->ind++] = fn; - THREAD_UNLOCK(); + if (result) + *result = string; return (0); + } + diff --git a/lib/libcr/locale/mskanji.c b/lib/libcr/locale/mskanji.c index d95a9851c2..6cfdfe842d 100644 --- a/lib/libcr/locale/mskanji.c +++ b/lib/libcr/locale/mskanji.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/locale/mskanji.c,v 1.2.8.2 2001/03/05 10:22:45 obrien Exp $ - * $DragonFly: src/lib/libcr/locale/Attic/mskanji.c,v 1.3 2003/11/12 20:21:27 eirikn Exp $ + * $DragonFly: src/lib/libcr/locale/Attic/mskanji.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ * * @(#)mskanji.c 1.0 (Phase One) 5/5/95 */ @@ -39,8 +39,6 @@ #include #include -#include -#include #include rune_t _MSKanji_sgetrune (const char *, size_t, char const **); diff --git a/lib/libcr/locale/setrunelocale.c b/lib/libcr/locale/setrunelocale.c index f561d93a31..f2a47c12c2 100644 --- a/lib/libcr/locale/setrunelocale.c +++ b/lib/libcr/locale/setrunelocale.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/locale/setrunelocale.c,v 1.14.6.4 2002/10/24 11:00:52 tjr Exp $ - * $DragonFly: src/lib/libcr/locale/Attic/setrunelocale.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libcr/locale/Attic/setrunelocale.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -50,6 +50,8 @@ extern int _none_init(_RuneLocale *); extern int _UTF2_init(_RuneLocale *); extern int _UTF8_init(_RuneLocale *); extern int _EUC_init(_RuneLocale *); +extern int _GB18030_init(_RuneLocale *); +extern int _GBK_init(_RuneLocale *); extern int _BIG5_init(_RuneLocale *); extern int _MSKanji_init(_RuneLocale *); extern _RuneLocale *_Read_RuneMagi(FILE *); @@ -135,6 +137,10 @@ setrunelocale(char *encoding) ret = _UTF8_init(rl); else if (strcmp(rl->encoding, "EUC") == 0) ret = _EUC_init(rl); + else if (strcmp(rl->encoding, "GB18030") == 0) + ret = _GB18030_init(rl); + else if (strcmp(rl->encoding, "GBK") == 0) + ret = _GBK_init(rl); else if (strcmp(rl->encoding, "BIG5") == 0) ret = _BIG5_init(rl); else if (strcmp(rl->encoding, "MSKanji") == 0) diff --git a/lib/libcr/locale/utf8.c b/lib/libcr/locale/utf8.c index 7aa41dd593..d6d27a52d4 100644 --- a/lib/libcr/locale/utf8.c +++ b/lib/libcr/locale/utf8.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/locale/utf8.c,v 1.1.2.1 2002/10/24 11:00:52 tjr Exp $ - * $DragonFly: src/lib/libcr/locale/Attic/utf8.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libcr/locale/Attic/utf8.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include diff --git a/lib/libcr/rpc/pmap_getport.c b/lib/libcr/rpc/pmap_getport.c index 318e4d3795..5d7740aae6 100644 --- a/lib/libcr/rpc/pmap_getport.c +++ b/lib/libcr/rpc/pmap_getport.c @@ -29,7 +29,7 @@ * @(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro * @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/pmap_getport.c,v 1.10 2000/01/27 23:06:40 jasone Exp $ - * $DragonFly: src/lib/libcr/rpc/Attic/pmap_getport.c,v 1.2 2003/06/17 04:26:45 dillon Exp $ + * $DragonFly: src/lib/libcr/rpc/Attic/pmap_getport.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ /* @@ -49,6 +49,18 @@ static struct timeval timeout = { 5, 0 }; static struct timeval tottimeout = { 60, 0 }; +/* + * Change the primary pmap_getport() timeout + */ +void +pmap_getport_timeout(struct timeval *otv, struct timeval *ntv) +{ + if (otv) + *otv = tottimeout; + if (ntv) + tottimeout = *ntv; +} + /* * Find the mapped port for program,version. * Calls the pmap service remotely to do the lookup. diff --git a/lib/libcr/stdio/local.h b/lib/libcr/stdio/local.h index 5e58acce01..db5d243b41 100644 --- a/lib/libcr/stdio/local.h +++ b/lib/libcr/stdio/local.h @@ -36,9 +36,13 @@ * @(#)local.h 8.3 (Berkeley) 7/3/94 * * $FreeBSD: src/lib/libc/stdio/local.h,v 1.1.1.2.6.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libcr/stdio/Attic/local.h,v 1.3 2003/11/12 20:21:28 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdio/Attic/local.h,v 1.4 2003/12/08 13:56:35 eirikn Exp $ */ +#ifndef _MACHINE_STDINT_H_ +#include /* __size_t */ +#endif + /* * Information local to this implementation of stdio, * in particular, macros and private variables. @@ -55,7 +59,7 @@ extern void __sinit (void); extern void _cleanup (void); extern void (*__cleanup) (void); extern void __smakebuf (FILE *); -extern int __swhatbuf (FILE *, size_t *, int *); +extern int __swhatbuf (FILE *, __size_t *, int *); extern int _fwalk (int (*)(FILE *)); extern int __swsetup (FILE *); extern int __sflags (const char *, int *); diff --git a/lib/libcr/stdlib/atexit.c b/lib/libcr/stdlib/atexit.c index be495d960d..d87f512217 100644 --- a/lib/libcr/stdlib/atexit.c +++ b/lib/libcr/stdlib/atexit.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/atexit.c,v 1.3.6.1 2002/03/10 20:28:40 tegge Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/atexit.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/atexit.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ * * @(#)atexit.c 8.2 (Berkeley) 7/3/94 */ @@ -62,7 +62,7 @@ atexit(fn) void (*fn)(); { static struct atexit __atexit0; /* one guaranteed table */ - register struct atexit *p; + struct atexit *p; THREAD_LOCK(); if ((p = __atexit) == NULL) diff --git a/lib/libcr/stdlib/bsearch.c b/lib/libcr/stdlib/bsearch.c index e685bb62c2..3daaf12108 100644 --- a/lib/libcr/stdlib/bsearch.c +++ b/lib/libcr/stdlib/bsearch.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)bsearch.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcr/stdlib/Attic/bsearch.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/bsearch.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -55,16 +55,16 @@ */ void * bsearch(key, base0, nmemb, size, compar) - register const void *key; + const void *key; const void *base0; size_t nmemb; - register size_t size; - register int (*compar) (const void *, const void *); + size_t size; + int (*compar) (const void *, const void *); { - register const char *base = base0; - register size_t lim; - register int cmp; - register const void *p; + const char *base = base0; + size_t lim; + int cmp; + const void *p; for (lim = nmemb; lim != 0; lim >>= 1) { p = base + (lim >> 1) * size; diff --git a/lib/libcr/stdlib/calloc.c b/lib/libcr/stdlib/calloc.c index ddc033e900..f833fc1165 100644 --- a/lib/libcr/stdlib/calloc.c +++ b/lib/libcr/stdlib/calloc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)calloc.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcr/stdlib/Attic/calloc.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/calloc.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -40,9 +40,9 @@ void * calloc(num, size) size_t num; - register size_t size; + size_t size; { - register void *p; + void *p; size *= num; if ( (p = malloc(size)) ) diff --git a/lib/libcr/stdlib/exit.c b/lib/libcr/stdlib/exit.c index b289e738cb..73eeea7f59 100644 --- a/lib/libcr/stdlib/exit.c +++ b/lib/libcr/stdlib/exit.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/exit.c,v 1.3.6.1 2001/03/05 11:33:57 obrien Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/exit.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/exit.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ * * @(#)exit.c 8.1 (Berkeley) 6/4/93 */ @@ -58,8 +58,8 @@ void exit(status) int status; { - register struct atexit *p; - register int n; + struct atexit *p; + int n; #ifdef _THREAD_SAFE extern int _thread_autoinit_dummy_decl; diff --git a/lib/libcr/stdlib/getenv.3 b/lib/libcr/stdlib/getenv.3 index 153ca87b95..c310197e19 100644 --- a/lib/libcr/stdlib/getenv.3 +++ b/lib/libcr/stdlib/getenv.3 @@ -35,7 +35,7 @@ .\" .\" @(#)getenv.3 8.2 (Berkeley) 12/11/93 .\" $FreeBSD: src/lib/libc/stdlib/getenv.3,v 1.4.2.7 2001/12/14 18:33:58 ru Exp $ -.\" $DragonFly: src/lib/libcr/stdlib/Attic/getenv.3,v 1.2 2003/06/17 04:26:46 dillon Exp $ +.\" $DragonFly: src/lib/libcr/stdlib/Attic/getenv.3,v 1.3 2003/12/08 13:56:35 eirikn Exp $ .\" .Dd December 11, 1993 .Dt GETENV 3 @@ -116,6 +116,13 @@ deletes all instances of the variable name pointed to by from the list. .Sh RETURN VALUES .Rv -std setenv putenv +.Pp +The +.Fn getenv +function returns NULL if the environment variable was not found. +If the variable was found, +it returns the value of the variable as a NULL terminated string. +This string should not be modified or freed. .Sh ERRORS .Bl -tag -width Er .It Bq Er ENOMEM diff --git a/lib/libcr/stdlib/getenv.c b/lib/libcr/stdlib/getenv.c index 7856fc2465..f929749a45 100644 --- a/lib/libcr/stdlib/getenv.c +++ b/lib/libcr/stdlib/getenv.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)getenv.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcr/stdlib/Attic/getenv.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/getenv.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -51,13 +51,13 @@ inline char *__findenv (const char *, int *); */ inline char * __findenv(name, offset) - register const char *name; + const char *name; int *offset; { extern char **environ; - register int len, i; - register const char *np; - register char **p, *cp; + int len, i; + const char *np; + char **p, *cp; if (name == NULL || environ == NULL) return (NULL); diff --git a/lib/libcr/stdlib/getsubopt.c b/lib/libcr/stdlib/getsubopt.c index ad6f160d22..c74bd9a29a 100644 --- a/lib/libcr/stdlib/getsubopt.c +++ b/lib/libcr/stdlib/getsubopt.c @@ -30,6 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * + * $DragonFly: src/lib/libcr/stdlib/Attic/getsubopt.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ + * * @(#)getsubopt.c 8.1 (Berkeley) 6/4/93 */ @@ -46,11 +48,11 @@ char *suboptarg; int getsubopt(optionp, tokens, valuep) - register char **optionp, **valuep; - register char * const *tokens; + char **optionp, **valuep; + char * const *tokens; { - register int cnt; - register char *p; + int cnt; + char *p; suboptarg = *valuep = NULL; diff --git a/lib/libcr/stdlib/heapsort.c b/lib/libcr/stdlib/heapsort.c index 07c8e5ddf6..ec8eafefe6 100644 --- a/lib/libcr/stdlib/heapsort.c +++ b/lib/libcr/stdlib/heapsort.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)heapsort.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcr/stdlib/Attic/heapsort.c,v 1.4 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/heapsort.c,v 1.5 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -142,8 +142,8 @@ heapsort(vbase, nmemb, size, compar) size_t nmemb, size; int (*compar) (const void *, const void *); { - register int cnt, i, j, l; - register char tmp, *tmp1, *tmp2; + int cnt, i, j, l; + char tmp, *tmp1, *tmp2; char *base, *k, *p, *t; if (nmemb <= 1) diff --git a/lib/libcr/stdlib/malloc.c b/lib/libcr/stdlib/malloc.c index 71b72f4975..2b985af11f 100644 --- a/lib/libcr/stdlib/malloc.c +++ b/lib/libcr/stdlib/malloc.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.49.2.4 2001/12/29 08:10:14 knu Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/malloc.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/malloc.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ * */ @@ -1059,7 +1059,7 @@ ifree(void *ptr) void * malloc(size_t size) { - register void *r; + void *r; THREAD_LOCK(); malloc_func = " in malloc():"; diff --git a/lib/libcr/stdlib/merge.c b/lib/libcr/stdlib/merge.c index 3aeba47213..67df9034dd 100644 --- a/lib/libcr/stdlib/merge.c +++ b/lib/libcr/stdlib/merge.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)merge.c 8.2 (Berkeley) 2/14/94 - * $DragonFly: src/lib/libcr/stdlib/Attic/merge.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/merge.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ */ /* @@ -97,12 +97,12 @@ int mergesort(base, nmemb, size, cmp) void *base; size_t nmemb; - register size_t size; + size_t size; int (*cmp) (const void *, const void *); { - register int i, sense; + int i, sense; int big, iflag; - register u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; + u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2; u_char *list2, *list1, *p2, *p, *last, **p1; if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */ diff --git a/lib/libcr/stdlib/qsort.c b/lib/libcr/stdlib/qsort.c index ae77b51f4d..e8a186085f 100644 --- a/lib/libcr/stdlib/qsort.c +++ b/lib/libcr/stdlib/qsort.c @@ -32,7 +32,7 @@ * * @(#)qsort.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdlib/qsort.c,v 1.8 1999/08/28 00:01:35 peter Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/qsort.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/qsort.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -48,10 +48,10 @@ static inline void swapfunc (char *, char *, int, int); */ #define swapcode(TYPE, parmi, parmj, n) { \ long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ + TYPE *pi = (TYPE *) (parmi); \ + TYPE *pj = (TYPE *) (parmj); \ do { \ - register TYPE t = *pi; \ + TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ } while (--i > 0); \ diff --git a/lib/libcr/stdlib/radixsort.c b/lib/libcr/stdlib/radixsort.c index fc7d6d8618..a5395de9dc 100644 --- a/lib/libcr/stdlib/radixsort.c +++ b/lib/libcr/stdlib/radixsort.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)radixsort.c 8.2 (Berkeley) 4/28/95 - * $DragonFly: src/lib/libcr/stdlib/Attic/radixsort.c,v 1.4 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/radixsort.c,v 1.5 2003/12/08 13:56:35 eirikn Exp $ */ /* @@ -139,8 +139,8 @@ r_sort_a(a, n, i, tr, endch) u_int endch; { static int count[256], nc, bmin; - register int c; - register const u_char **ak, *r; + int c; + const u_char **ak, *r; stack s[SIZE], *sp, *sp0, *sp1, temp; int *cp, bigc; const u_char **an, *t, **aj, **top[256]; @@ -230,8 +230,8 @@ r_sort_b(a, ta, n, i, tr, endch) u_int endch; { static int count[256], nc, bmin; - register int c; - register const u_char **ak, **ai; + int c; + const u_char **ak, **ai; stack s[512], *sp, *sp0, *sp1, temp; const u_char **top[256]; int *cp, bigc; @@ -296,12 +296,12 @@ r_sort_b(a, ta, n, i, tr, endch) static inline void simplesort(a, n, b, tr, endch) /* insertion sort */ - register const u_char **a; + const u_char **a; int n, b; - register const u_char *tr; + const u_char *tr; u_int endch; { - register u_char ch; + u_char ch; const u_char **ak, **ai, *s, *t; for (ak = a+1; --n >= 1; ak++) diff --git a/lib/libcr/stdlib/random.c b/lib/libcr/stdlib/random.c index 6570f09337..f032aab52d 100644 --- a/lib/libcr/stdlib/random.c +++ b/lib/libcr/stdlib/random.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/random.c,v 1.13 2000/01/27 23:06:49 jasone Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/random.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/random.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ * * @(#)random.c 8.2 (Berkeley) 5/19/95 */ @@ -58,10 +58,10 @@ * congruential generator. If the amount of state information is less than * 32 bytes, a simple linear congruential R.N.G. is used. * - * Internally, the state information is treated as an array of longs; the + * Internally, the state information is treated as an array of ints; the * zeroeth element of the array is the type of R.N.G. being used (small * integer); the remainder of the array is the state information for the - * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of + * R.N.G. Thus, 32 bytes of state information will give 7 ints worth of * state information, which will allow a degree seven polynomial. (Note: * the zeroeth word of state information also has some other information * stored in it -- see setstate() for details). @@ -139,8 +139,8 @@ */ #define MAX_TYPES 5 /* max number of types above */ -static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; -static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; +static const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; +static const int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; /* * Initially, everything is set up as if from: @@ -156,7 +156,7 @@ static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3. */ -static long randtbl[DEG_3 + 1] = { +static uint32_t randtbl[DEG_3 + 1] = { TYPE_3, #ifdef USE_WEAK_SEEDING /* Historic implementation compatibility */ @@ -191,8 +191,8 @@ static long randtbl[DEG_3 + 1] = { * in the initialization of randtbl) because the state table pointer is set * to point to randtbl[1] (as explained below). */ -static long *fptr = &randtbl[SEP_3 + 1]; -static long *rptr = &randtbl[1]; +static uint32_t *fptr = &randtbl[SEP_3 + 1]; +static uint32_t *rptr = &randtbl[1]; /* * The following things are the pointer to the state information table, the @@ -204,16 +204,16 @@ static long *rptr = &randtbl[1]; * this is more efficient than indexing every time to find the address of * the last element to see if the front and rear pointers have wrapped. */ -static long *state = &randtbl[1]; -static long rand_type = TYPE_3; -static long rand_deg = DEG_3; -static long rand_sep = SEP_3; -static long *end_ptr = &randtbl[DEG_3 + 1]; +static uint32_t *state = &randtbl[1]; +static int rand_type = TYPE_3; +static int rand_deg = DEG_3; +static int rand_sep = SEP_3; +static uint32_t *end_ptr = &randtbl[DEG_3 + 1]; static inline long good_rand (long); static inline long good_rand (x) - register long x; + long x; { #ifdef USE_WEAK_SEEDING /* @@ -231,7 +231,7 @@ static inline long good_rand (x) * Park and Miller, Communications of the ACM, vol. 31, no. 10, * October 1988, p. 1195. */ - register long hi, lo; + long hi, lo; hi = x / 127773; lo = x % 127773; @@ -258,14 +258,14 @@ void srandom(x) unsigned long x; { - register long i; + int i; if (rand_type == TYPE_0) - state[0] = x; + state[0] = (uint32_t)x; else { - state[0] = x; + state[0] = (uint32_t)x; for (i = 1; i < rand_deg; i++) - state[i] = good_rand(state[i - 1]); + state[i] = (uint32_t)good_rand(state[i - 1]); fptr = &state[rand_sep]; rptr = &state[0]; for (i = 0; i < 10 * rand_deg; i++) @@ -337,7 +337,7 @@ srandomdev() * * Returns a pointer to the old state. * - * Note: The Sparc platform requires that arg_state begin on a long + * Note: The Sparc platform requires that arg_state begin on an int * word boundary; otherwise a bus error will occur. Even so, lint will * complain about mis-alignment, but you should disregard these messages. */ @@ -347,13 +347,13 @@ initstate(seed, arg_state, n) char *arg_state; /* pointer to state array */ long n; /* # bytes of state info */ { - register char *ostate = (char *)(&state[-1]); - register long *long_arg_state = (long *) arg_state; + char *ostate = (char *)(&state[-1]); + uint32_t *int_arg_state = (uint32_t *)(void *)arg_state; if (rand_type == TYPE_0) state[-1] = rand_type; else - state[-1] = MAX_TYPES * (rptr - state) + rand_type; + state[-1] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type; if (n < BREAK_0) { (void)fprintf(stderr, "random: not enough state (%ld bytes); ignored.\n", n); @@ -380,13 +380,13 @@ initstate(seed, arg_state, n) rand_deg = DEG_4; rand_sep = SEP_4; } - state = (long *) (long_arg_state + 1); /* first location */ + state = (uint32_t *) (int_arg_state + 1); /* first location */ end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */ - srandom(seed); + srandom((uint32_t)seed); if (rand_type == TYPE_0) - long_arg_state[0] = rand_type; + int_arg_state[0] = rand_type; else - long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type; + int_arg_state[0] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type; return(ostate); } @@ -413,15 +413,15 @@ char * setstate(arg_state) char *arg_state; /* pointer to state array */ { - register long *new_state = (long *) arg_state; - register long type = new_state[0] % MAX_TYPES; - register long rear = new_state[0] / MAX_TYPES; + uint32_t *new_state = (uint32_t *)(void *)arg_state; + uint32_t type = new_state[0] % MAX_TYPES; + uint32_t rear = new_state[0] / MAX_TYPES; char *ostate = (char *)(&state[-1]); if (rand_type == TYPE_0) state[-1] = rand_type; else - state[-1] = MAX_TYPES * (rptr - state) + rand_type; + state[-1] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type; switch(type) { case TYPE_0: case TYPE_1: @@ -436,7 +436,7 @@ setstate(arg_state) (void)fprintf(stderr, "random: state info corrupted; not changed.\n"); } - state = (long *) (new_state + 1); + state = (uint32_t *) (new_state + 1); if (rand_type != TYPE_0) { rptr = &state[rear]; fptr = &state[(rear + rand_sep) % rand_deg]; @@ -465,8 +465,8 @@ setstate(arg_state) long random() { - register long i; - register long *f, *r; + uint32_t i; + uint32_t *f, *r; if (rand_type == TYPE_0) { i = state[0]; @@ -477,7 +477,8 @@ random() */ f = fptr; r = rptr; *f += *r; - i = (*f >> 1) & 0x7fffffff; /* chucking least random bit */ + /* chucking least random bit */ + i = (*f >> 1) & 0x7fffffff; if (++f >= end_ptr) { f = state; ++r; @@ -488,5 +489,5 @@ random() fptr = f; rptr = r; } - return(i); + return((long)i); } diff --git a/lib/libcr/stdlib/setenv.c b/lib/libcr/stdlib/setenv.c index 61445b482e..9d88b9571a 100644 --- a/lib/libcr/stdlib/setenv.c +++ b/lib/libcr/stdlib/setenv.c @@ -32,7 +32,7 @@ * * @(#)setenv.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdlib/setenv.c,v 1.5.2.1 2000/09/20 19:46:03 brian Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/setenv.c,v 1.3 2003/11/12 20:21:29 eirikn Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/setenv.c,v 1.4 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -48,13 +48,13 @@ char *__findenv (const char *, int *); */ int setenv(name, value, rewrite) - register const char *name; - register const char *value; + const char *name; + const char *value; int rewrite; { extern char **environ; static char **alloced; /* if allocated space before */ - register char *c; + char *c; int l_value, offset; if (*value == '=') /* no `=' in value */ @@ -68,8 +68,8 @@ setenv(name, value, rewrite) return (0); } } else { /* create new slot */ - register int cnt; - register char **p; + int cnt; + char **p; for (p = environ, cnt = 0; *p; ++p, ++cnt); if (alloced == environ) { /* just increase size */ @@ -108,7 +108,7 @@ unsetenv(name) const char *name; { extern char **environ; - register char **p; + char **p; int offset; while (__findenv(name, &offset)) /* if set multiple times */ diff --git a/lib/libcr/stdlib/strhash.c b/lib/libcr/stdlib/strhash.c index a91245c52f..852767ee03 100644 --- a/lib/libcr/stdlib/strhash.c +++ b/lib/libcr/stdlib/strhash.c @@ -23,7 +23,7 @@ * without specific, written prior permission. * * $FreeBSD: src/lib/libc/stdlib/strhash.c,v 1.8 1999/09/05 17:42:45 peter Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/strhash.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/strhash.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ /* @@ -97,7 +97,7 @@ static hash_node *list_find(caddr_t key, hash_node *head); hash_table * hash_create(int size) { - register int i; + int i; hash_table *new = (hash_table *)malloc(sizeof(hash_table)); if (!new || size < 0){ @@ -290,8 +290,8 @@ assign_key(char *key, hash_node *node) void hash_traverse(hash_table *table, int (*func)(), void *arg) { - register int i; - register int size = table->size; + int i; + int size = table->size; if (!func) return; @@ -317,8 +317,8 @@ hash_traverse(hash_table *table, int (*func)(), void *arg) void hash_purge(hash_table *table, void (*purge_func)(char *p1, void *p2)) { - register int i; - register int size = table->size; + int i; + int size = table->size; for (i = 0; i < size; i++) { hash_node *n = table->buckets[i]; @@ -347,7 +347,7 @@ hash_purge(hash_table *table, void (*purge_func)(char *p1, void *p2)) void hash_stats(hash_table *table, int verbose) { - register int i; + int i; int total_elements = 0; int non_empty_buckets = 0; int max_count = 0; diff --git a/lib/libcr/stdlib/strtod.c b/lib/libcr/stdlib/strtod.c index 9595a4416b..3fb138fa3a 100644 --- a/lib/libcr/stdlib/strtod.c +++ b/lib/libcr/stdlib/strtod.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/strtod.c,v 1.3.8.4 2002/08/31 22:26:35 dwmalone Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/strtod.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/strtod.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ * * @(#)strtod.c 8.1 (Berkeley) 6/4/93 */ @@ -493,12 +493,12 @@ s2b static int hi0bits #ifdef KR_headers - (x) register unsigned long x; + (x) unsigned long x; #else - (register unsigned long x) + (unsigned long x) #endif { - register int k = 0; + int k = 0; if (!(x & 0xffff0000)) { k = 16; @@ -532,8 +532,8 @@ lo0bits (unsigned long *y) #endif { - register int k; - register unsigned long x = *y; + int k; + unsigned long x = *y; if (x & 7) { if (x & 1) @@ -894,7 +894,7 @@ ulp (double x) #endif { - register long L; + long L; double a; L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; diff --git a/lib/libcr/stdlib/strtol.c b/lib/libcr/stdlib/strtol.c index 1f31cd807f..241d61f7e0 100644 --- a/lib/libcr/stdlib/strtol.c +++ b/lib/libcr/stdlib/strtol.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)strtol.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcr/stdlib/Attic/strtol.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/strtol.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -50,13 +50,13 @@ long strtol(nptr, endptr, base) const char *nptr; char **endptr; - register int base; + int base; { - register const char *s = nptr; - register unsigned long acc; - register unsigned char c; - register unsigned long cutoff; - register int neg = 0, any, cutlim; + const char *s = nptr; + unsigned long acc; + unsigned char c; + unsigned long cutoff; + int neg = 0, any, cutlim; /* * Skip white space and pick up leading +/- sign if any. diff --git a/lib/libcr/stdlib/strtoll.c b/lib/libcr/stdlib/strtoll.c index b84ca25c1c..9ddb84b6ca 100644 --- a/lib/libcr/stdlib/strtoll.c +++ b/lib/libcr/stdlib/strtoll.c @@ -32,7 +32,7 @@ * * @(#)strtoq.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdlib/strtoll.c,v 1.5.2.1 2001/03/02 09:45:20 obrien Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/strtoll.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/strtoll.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -52,13 +52,13 @@ long long strtoll(nptr, endptr, base) const char *nptr; char **endptr; - register int base; + int base; { - register const char *s; - register unsigned long long acc; - register unsigned char c; - register unsigned long long qbase, cutoff; - register int neg, any, cutlim; + const char *s; + unsigned long long acc; + unsigned char c; + unsigned long long qbase, cutoff; + int neg, any, cutlim; /* * Skip white space and pick up leading +/- sign if any. diff --git a/lib/libcr/stdlib/strtoul.c b/lib/libcr/stdlib/strtoul.c index fb8d9946c5..a7b4cd9130 100644 --- a/lib/libcr/stdlib/strtoul.c +++ b/lib/libcr/stdlib/strtoul.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)strtoul.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libcr/stdlib/Attic/strtoul.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/strtoul.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -49,13 +49,13 @@ unsigned long strtoul(nptr, endptr, base) const char *nptr; char **endptr; - register int base; + int base; { - register const char *s = nptr; - register unsigned long acc; - register unsigned char c; - register unsigned long cutoff; - register int neg = 0, any, cutlim; + const char *s = nptr; + unsigned long acc; + unsigned char c; + unsigned long cutoff; + int neg = 0, any, cutlim; /* * See strtol for comments as to the logic used. diff --git a/lib/libcr/stdlib/strtoull.c b/lib/libcr/stdlib/strtoull.c index 344ee78572..0307027b7c 100644 --- a/lib/libcr/stdlib/strtoull.c +++ b/lib/libcr/stdlib/strtoull.c @@ -32,7 +32,7 @@ * * @(#)strtouq.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdlib/strtoull.c,v 1.5.2.1 2001/03/02 09:45:20 obrien Exp $ - * $DragonFly: src/lib/libcr/stdlib/Attic/strtoull.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/stdlib/Attic/strtoull.c,v 1.3 2003/12/08 13:56:35 eirikn Exp $ */ #include @@ -52,13 +52,13 @@ unsigned long long strtoull(nptr, endptr, base) const char *nptr; char **endptr; - register int base; + int base; { - register const char *s = nptr; - register unsigned long long acc; - register unsigned char c; - register unsigned long long qbase, cutoff; - register int neg, any, cutlim; + const char *s = nptr; + unsigned long long acc; + unsigned char c; + unsigned long long qbase, cutoff; + int neg, any, cutlim; /* * See strtoq for comments as to the logic used. diff --git a/lib/libcr/string/memccpy.c b/lib/libcr/string/memccpy.c index 2b6bf6a3c4..607250db60 100644 --- a/lib/libcr/string/memccpy.c +++ b/lib/libcr/string/memccpy.c @@ -32,7 +32,7 @@ * * @(#)memccpy.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/string/memccpy.c,v 1.2.12.1 2001/07/09 23:30:03 obrien Exp $ - * $DragonFly: src/lib/libcr/string/Attic/memccpy.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libcr/string/Attic/memccpy.c,v 1.3 2003/12/08 13:56:36 eirikn Exp $ */ #include @@ -43,7 +43,7 @@ memccpy(t, f, c, n) void *t; const void *f; int c; - register size_t n; + size_t n; { if (n) { diff --git a/lib/libcr/sys/Makefile.inc b/lib/libcr/sys/Makefile.inc index 2145703d64..03a2221a31 100644 --- a/lib/libcr/sys/Makefile.inc +++ b/lib/libcr/sys/Makefile.inc @@ -1,6 +1,6 @@ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # $FreeBSD: src/lib/libc/sys/Makefile.inc,v 1.75.2.7 2003/04/22 17:31:18 trhodes Exp $ -# $DragonFly: src/lib/libcr/sys/Attic/Makefile.inc,v 1.3 2003/07/24 21:41:56 dillon Exp $ +# $DragonFly: src/lib/libcr/sys/Attic/Makefile.inc,v 1.4 2003/12/08 13:56:36 eirikn Exp $ # sys sources .PATH: ${.CURDIR}/../libcr/${MACHINE_ARCH}/sys ${.CURDIR}/../libcr/sys @@ -27,7 +27,7 @@ SRCS+= __error.c # Add machine dependent asm sources: SRCS+=${MDASM} -# Look though the complete list of syscalls (MIASM) for names that are +# Look through the complete list of syscalls (MIASM) for names that are # not defined with machine dependent implementations (MDASM) and are # not declared for no generation of default code (NOASM). If the # syscall is not hidden, add it to the ASM list, otherwise add it @@ -59,6 +59,7 @@ SRCS+= ${SASM} ${SASMR} ${SPSEUDO} ${SPSEUDOR} # Generated files CLEANFILES+= ${SASM} ${SASMR} ${SPSEUDO} ${SPSEUDOR} +# Generate the syscalls source-files ${SASM}: printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' > ${.TARGET} @@ -102,7 +103,7 @@ MAN+= _exit.2 accept.2 access.2 acct.2 adjtime.2 \ sigstack.2 sigsuspend.2 socket.2 socketpair.2 stat.2 statfs.2 \ swapon.2 symlink.2 sync.2 sysarch.2 syscall.2 \ truncate.2 umask.2 undelete.2 \ - unlink.2 utimes.2 vfork.2 wait.2 write.2 + unlink.2 utimes.2 upc_register.2 vfork.2 wait.2 write.2 .if !defined(NO_P1003_1B) MAN+= sched_get_priority_max.2 sched_setparam.2 \ sched_setscheduler.2 sched_yield.2 diff --git a/lib/libcr/sys/send.2 b/lib/libcr/sys/send.2 index b2e714c2f5..f5756d7226 100644 --- a/lib/libcr/sys/send.2 +++ b/lib/libcr/sys/send.2 @@ -31,7 +31,7 @@ .\" .\" From: @(#)send.2 8.2 (Berkeley) 2/21/94 .\" $FreeBSD: src/lib/libc/sys/send.2,v 1.10.2.6 2001/12/14 18:34:01 ru Exp $ -.\" $DragonFly: src/lib/libcr/sys/Attic/send.2,v 1.2 2003/06/17 04:26:47 dillon Exp $ +.\" $DragonFly: src/lib/libcr/sys/Attic/send.2,v 1.3 2003/12/08 13:56:36 eirikn Exp $ .\" .Dd February 15, 1995 .Dt SEND 2 @@ -179,6 +179,10 @@ from the last message sent. This typically means that the receiver is not listening on the remote port. .It Bq Er EHOSTDOWN The remote host was down. +.It Bq Er EPIPE +The socket is unable to send anymore data (SS_CANTSENDMORE has +been set on the socket). This typically means that the socket +is not connected. .El .Sh BUGS Because diff --git a/lib/libcr/sys/upc_register.2 b/lib/libcr/sys/upc_register.2 new file mode 100644 index 0000000000..4348a55cc9 --- /dev/null +++ b/lib/libcr/sys/upc_register.2 @@ -0,0 +1,352 @@ +.\" Copyright (c) 2003 Matthew Dillon +.\" 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. +.\" +.\" 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. +.\" +.\" $DragonFly: src/lib/libcr/sys/Attic/upc_register.2,v 1.1 2003/12/08 13:56:36 eirikn Exp $ +.\" +.Dd November 20, 2003 +.Dt UPC_REGISTER 2 +.Os +.Sh NAME +.Nm upc_register , +.Nm upc_control +.Nd configure and control upcalls +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/upcall.h +.Ft int +.Fn upc_register "struct upcall *upc" "upcall_func_t ctxfunc" "upcall_func_t cfunc" "void *data" +.Ft int +.Fn upc_control "int command" "int upcall_id" "void *data" +.Sh DESCRIPTION +.Fn Upc_register +registers an upcall. Note that the specified upcall structural pointer +is per-process, not per-upcall. It points to a structure in user memory +that both the user and kernel manipulate to deal with upcall/critical-section +interlocks. +.Fa ctxfunc +is a pointer to context save and restore code. The native upcall interface +does not necessarily save and restore call-used registers. This function +is typically written in assembly and supplied by +.Lb libc . +.Fa cfunc +is a pointer to a C style function and +.Fa data +is the data passed to it as an argument. A positive upcall identifier +will be returned or -1 if an error occured. +.Pp +When an upcall is executed the +kernel will add LWKT_CRITPRI to the critical section count in the upcall +structure, push a minimal context (not even call-used), and pass the C +function and data pointers to +.Fa ctxfunc +in registers. +.Fa ctxfunc +will then proceed to save appropriate state, call the C function, and +deal with cleanup. Cleanup typically involves an interlocking operation +and a call to +.Fn Upc_control +in order to undo the critical section count and process any additional +pending upcalls atomically. +.Fa ctxfunc +will typically pop most of its state, set upcall->pending to 1, +subtract LWKT_CRITPRI from upcall->crit_count, and call +.Fn upc_control "UPC_CONTROL_NEXT" "-1" "stack_pointer" +which atomically handles any further pending upcalls and/or pops the +original stack context supplied to +.Fn upc_control +and resumes the originally interrupted code. This is all very complex +which is why +.Lb libc +typically supplies +.Fa ctxfunc . +.Pp +Note that upcalls can only occur if the target process is not in a critical +section. If an upcall cannot be dispatched it will instead be made pending +and the pending field in the user-supplied upcall structure will be set to +non-zero. Userland critical-section-exiting code must check the pending +bit and call the appropriate +.Fn upc_control +function to handle any pending upcalls. +.Pp +The upcall identifier space is shared amoungst all processes sharing the +same VM space. That is, all the processes created through clone() or +rfork(RFMEM). Through appropriate +.Fn upc_control +calls any process within this domain can generate an upcall on any other +process within this domain, including itself. Each process typically +installs a different (per-process) upcall data structure. +.Pp +.Fn Upc_control +is a multi-function system call capable of dispatching upcalls, handling +the context assembly function's interlocks, deleting upcalls, and polling +for upcalls. +.Pp +.Ft int +.Fn upc_control "UPC_CONTROL_DISPATCH" "upcid" "(int)priority" +.Pp +.Bd -offset indent +Dispatch a particular upcall. 0 is returned on success, ENOENT if +.Fa upcid +does not exist. You can dispatch upcalls belonging to your process or +to another process. You may specify a +.Fa upcid +of -1 to re-dispatch the first upcall owned by your own process that is +pending from a previous operation. Note that that critical section and +pending rules apply, and an actual dispatch will pushdown the stack. +.Pp +The priority will be compared against the current crit_count to determine +whether the upcall dispatches or is made pending. +.Pp +This command is most often used to alert a target process to a change in +a shared structure, queue, etc. +.Ed +.Pp +.Ft int +.Fn upc_control "UPC_CONTROL_NEXT" "-1" "stack_pointer" +.Pp +.Bd -offset indent +Do interlocking and stack munging to process additional upcalls. This +system call should never be made directly by C code because it expects +all registers not saved by the operating system in entering a context +function to have been popped and a pointer to the base of the OS-supplied +stack context on entry to the context routine to be supplied. This routine +does not return to the caller but instead either regenerates the stack +context for the next pending upcall or it restores the original context, +resuming whomever was interrupted by the original upcall that entered the +context routine. +.Ed +.Pp +.Ft int +.Fn upc_control "UPC_CONTROL_DELETE" "upcid" "NULL" +.Pp +.Bd -offset indent +Delete the specified +.Fa upcid +or, if -1 is specified, delete all upcall registered by the current process. +If -1 is specified, the upcalls registered by another process will not be +deleted. If a particular +.Fa upcid +is specified, it will be deleted regardless of which process registered it. +The upcall structural pointer registered with this or any other process is +not effected. +.Ed +.Pp +.Ft int +.Fn upc_control "UPC_CONTROL_POLL" "upcid" "NULL" +.Pp +.Ft int +.Fn upc_control "UPC_CONTROL_POLLANDCLEAR" "upcid" "(int)priority" +.Pp +.Bd -offset indent +Poll or poll-and-clear the pending status for a particular upcall. 0 or 1 +is returned, or -1 if an error occured (e.g. ENOENT). +If a +.Fa upcid +of -1 is specified, locate a pending upcall for the current process and return +it's +.Fa upcid , +or 0 if no upcalls for the current process are pending. +.Pp +The priority will be compared against the upcall's pending priority. Only +upcalls with greater or equal pending priorities are returned. You must +specify a minimum priority of 1 or this call will simply return a random +registered upcall that may or may not be pending. +.Ed +.Pp +.Bd -literal -offset indent -compact +struct upcall { + int magic; /* must be UPCALL_MAGIC */ + int crit_count; /* critical section count */ + int pending; /* additional upcalls are pending */ +}; +.Ed +.Pp +This is a user space structure a pointer to which is registered with the +kernel via +.Fn upc_register +\. +The +.Fa crit_count +field prevents new upcalls from being dispatched. When an upcall is +dispatched the kernel automatically adds +.Va UPC_CRITADD +to +.Fa crit_count +and sets +.Fa pending +to indicate whether any additional upcalls are pending. A non-zero +.Fa pending +OR +.Fa crit_count +will prevent new upcalls from the being dispatched. The context function +code is expected to make appropriate checks to dispatch any remaining upcalls +when the current upcall has completed. In particular, the context function +must subtract +.Va UPC_CRITADD +from +.Fa crit_count +before restoring the original context or calling +.Fn upc_control "UPC_CONTROL_NEXT" "..." +\. +Note that +.Fa pending +may be set as a side effect to various +.Fn upc_control +system calls as well as as a side effect to upcall dispatches. +.Pp +Userland threading code typically uses +.Fa crit_count +to control critical sections within a virtual cpu (aka cloned process). +Entering a critical section is as simply as add UPC_CRITADD to +.Fa crit_count . +No atomic or locked instructions are required as this field is accessed +only by the current process and any upcalls or interrupts will restore it +to the condition they found it before returning. Exiting a critical section +is almost as simple as subtracting UPC_CRITADD from +.Fa crit_count . +The routine which performs this function must also check the +.Fa pending +field once the critical section count has reached 0. If the pending field +is non-zero, the routine will generally call +.Fn upc_control "UPC_CONTROL_DISPATCH" "-1" "NULL" +to dispatch upcalls which were made pending while you were in the critical +section. +.Sh CONTEXT FUNCTION - IA32 +The context function is called with the stack pointer pointing at a +kernel-constructed stack frame. Only a minimal number of registers are +saved by the kernel. +.Pp +.Bd -literal -offset indent -compact +frame { + int32_t eax; + int32_t ecx; + int32_t edx; + int32_t eflags; + int32_t origip; +} +.Ed +.Pp +On entry, %eax will hold the C function pointer, %ecx will hold the +C data pointer, and %edx will hold a pointer to the user-supplied upcall +structure. The context code does not need to push %eax, %ecx, or %edx +because these registers have already been pushed on the stack for it, but +it must generally push any remaining registers that it might use and be +careful in regards to others, such as floating point registers, which +the OS has not saved. The operating system has already adjusted the +.Fa crit_count +and +.Fa pending +fields in the user-supplied +.Fa upcall +structure, so the context code will generally next push the data pointer +(%ecx) and call the C function through %eax. Upon return the context code +is responsible for interlocking the upcall return which it does by first +setting +.Fa pending +to 1, then subtracting +.Va UPC_CRITADD +from +.Fa crit_count , +then restoring its part of the context but leaving the OS context intact, +then calling +.Fn upc_control "UPC_CONTROL_NEXT" "-1" "stack_pointer_to_OS_context" +\. +The control function will not return. It will either restart the context +at the next upcall, if more are pending, or it will restore the original +context. +.Pp +The context code does not have to follow this regimn. There is nothing +preventing the context code from restoring the original frame itself and +returning directly to the originally interrupted user code without having +to make another kernel transition. It is possible to optimize this by +having the context code subtract down +.Va UPC_CRITADD +as per normal but not pre-set the +.Fa pending +field. If it does this and +.Fa pending +is 0, it is possible for the kernel to initiate another upcall before +the context code has had a chance to pop its stack and restore the original +user context. This is ok under controlled circumstances. On the otherhand, +if +.Fa pending +is 1 +the context code knows there is another upcall pending and can call +.Fn upc_control +as appropriate. +.Pp +.Bd -literal -offset indent -compact + /* + * upc is a global pointing to this process's upcall structure + * (just as an example). The Os-supplied stack frame is: + * + * [%eax %ecx %edx,%eflags %original_ip] + */ +callused_wrapper: + pushl %edx /* save %edx (upcall pointer) */ + pushl %ecx /* func=%eax(data=%ecx) */ + call *%eax /* call the C function */ + addl $4,%esp + popl %edx /* restore the upcall pointer */ + incl PENDING(%edx) /* setting pending stops upcalls */ + subl $32,CRIT_COUNT(%edx) /* cleanup crit section count */ + pushl %esp /* sp pointing to os user frame */ + pushl $-1 /* upcid */ + pushl $2 /* FETCH next */ + call upc_control + /* not reached */ + /* just for show, restore Os supplied user context */ + popl %eax /* code just for show */ + popl %ecx /* code just for show */ + popl %edx /* code just for show */ + popfl /* code just for show */ + ret /* code just for show */ +.Ed + +.Sh ERRORS +.Fn Upc_register +returns +.It Bq Er EFBIG +if the kernel has reached its upcall registration limit. The limit is on a +per-shared-vmspace basis and is no less then 32. Otherwise this function +returns a non-zero, positive number indicating the upcall identifier that +was registered. +.Pp +.Fh Upc_control +returns +.It Bq Er ENOENT +if a particular requested +.Fa upcid +cannot be found. +.Sh SEE ALSO +.Xr clone 3 +.Sh HISTORY +The +.Fn upc_register +and +.Fn upc_control +function calls +appeared in +DragonFly 1.0 . -- 2.41.0