5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  25  * Copyright 2015 Joyent, Inc.
  26  */
  27 
  28 /*
  29  * Implementation of all external interfaces between ld.so.1 and libc.
  30  *
  31  * This file started as a set of routines that provided synchronization and
  32  * locking operations using calls to libthread.  libthread has merged with libc
  33  * under the Unified Process Model (UPM), and things have gotten a lot simpler.
  34  * This file continues to establish and redirect various events within ld.so.1
  35  * to interfaces within libc.
  36  *
  37  * Until libc is loaded and relocated, any external interfaces are captured
  38  * locally.  Each link-map list maintains its own set of external vectors, as
  39  * each link-map list typically provides its own libc.  Although this per-link-
  40  * map list vectoring provides a degree of flexibility, there is a protocol
  41  * expected when calling various libc interfaces.
  42  *
  43  * i.   Any new alternative link-map list should call CI_THRINIT, and then call
  44  *      CI_TLS_MODADD to register any TLS for each object of that link-map list
  45  *      (this item is labeled i. as auditors can be the first objects loaded,
 
 
 704 
 705 int
 706 isxdigit(int c)
 707 {
 708         return ((isdigit(c) || (c >= 'A' && c <= 'F') ||
 709             (c >= 'a' && c <= 'f')) ? 1 : 0);
 710 }
 711 
 712 int
 713 isalpha(int c)
 714 {
 715         return ((isupper(c) || islower(c)) ? 1 : 0);
 716 }
 717 
 718 int
 719 isalnum(int c)
 720 {
 721         return ((isalpha(c) || isdigit(c)) ? 1 : 0);
 722 }
 723 
 724 /*
 725  * In a similar vein to the is* functions above, we also have to define our own
 726  * version of strerror, as it is implemented in terms of the locale aware
 727  * strerror_l, and we'd rather not have the full set of libc symbols used here.
 728  */
 729 extern const char _sys_errs[];
 730 extern const int _sys_index[];
 731 extern int _sys_num_err;
 732 
 733 char *
 734 strerror(int errnum)
 735 {
 736         if (errnum < _sys_num_err && errnum >= 0) {
 737                 return (dgettext("SUNW_OST_OSLIB",
 738                     (char *)&_sys_errs[_sys_index[errnum]]));
 739         }
 740 
 741         errno = EINVAL;
 742         return (dgettext("SUNW_OST_OSLIB", "Unknown error"));
 743 }
 | 
 
 
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  25  * Copyright 2016 Joyent, Inc.
  26  */
  27 
  28 /*
  29  * Implementation of all external interfaces between ld.so.1 and libc.
  30  *
  31  * This file started as a set of routines that provided synchronization and
  32  * locking operations using calls to libthread.  libthread has merged with libc
  33  * under the Unified Process Model (UPM), and things have gotten a lot simpler.
  34  * This file continues to establish and redirect various events within ld.so.1
  35  * to interfaces within libc.
  36  *
  37  * Until libc is loaded and relocated, any external interfaces are captured
  38  * locally.  Each link-map list maintains its own set of external vectors, as
  39  * each link-map list typically provides its own libc.  Although this per-link-
  40  * map list vectoring provides a degree of flexibility, there is a protocol
  41  * expected when calling various libc interfaces.
  42  *
  43  * i.   Any new alternative link-map list should call CI_THRINIT, and then call
  44  *      CI_TLS_MODADD to register any TLS for each object of that link-map list
  45  *      (this item is labeled i. as auditors can be the first objects loaded,
 
 
 704 
 705 int
 706 isxdigit(int c)
 707 {
 708         return ((isdigit(c) || (c >= 'A' && c <= 'F') ||
 709             (c >= 'a' && c <= 'f')) ? 1 : 0);
 710 }
 711 
 712 int
 713 isalpha(int c)
 714 {
 715         return ((isupper(c) || islower(c)) ? 1 : 0);
 716 }
 717 
 718 int
 719 isalnum(int c)
 720 {
 721         return ((isalpha(c) || isdigit(c)) ? 1 : 0);
 722 }
 723 
 724 #if defined(__i386) || defined(__amd64)
 725 /*
 726  * Instead of utilizing the comm page for clock_gettime, rtld uses the raw
 727  * syscall instead.  Doing so decreases the surface of symbols needed from libc
 728  * for a modest performance cost.
 729  */
 730 extern int __clock_gettime_sys(clockid_t, struct timespec *);
 731 
 732 int
 733 __clock_gettime(clockid_t clock_id, struct timespec *tp)
 734 {
 735         return (__clock_gettime_sys(clock_id, tp));
 736 }
 737 #endif /* defined(__i386) || defined(__amd64) */
 738 
 739 /*
 740  * In a similar vein to the is* functions above, we also have to define our own
 741  * version of strerror, as it is implemented in terms of the locale aware
 742  * strerror_l, and we'd rather not have the full set of libc symbols used here.
 743  */
 744 extern const char _sys_errs[];
 745 extern const int _sys_index[];
 746 extern int _sys_num_err;
 747 
 748 char *
 749 strerror(int errnum)
 750 {
 751         if (errnum < _sys_num_err && errnum >= 0) {
 752                 return (dgettext("SUNW_OST_OSLIB",
 753                     (char *)&_sys_errs[_sys_index[errnum]]));
 754         }
 755 
 756         errno = EINVAL;
 757         return (dgettext("SUNW_OST_OSLIB", "Unknown error"));
 758 }
 |