1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
|
/*
* 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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Garrett D'Amore <garrett@damore.org>
* Copyright (c) 2017, Joyent, Inc.
*/
/*
* Implementation of all external interfaces between ld.so.1 and libc.
*
* This file started as a set of routines that provided synchronization and
* locking operations using calls to libthread. libthread has merged with libc
* under the Unified Process Model (UPM), and things have gotten a lot simpler.
* This file continues to establish and redirect various events within ld.so.1
* to interfaces within libc.
*
* Until libc is loaded and relocated, any external interfaces are captured
* locally. Each link-map list maintains its own set of external vectors, as
* each link-map list typically provides its own libc. Although this per-link-
* map list vectoring provides a degree of flexibility, there is a protocol
* expected when calling various libc interfaces.
*
* i. Any new alternative link-map list should call CI_THRINIT, and then call
* CI_TLS_MODADD to register any TLS for each object of that link-map list
* (this item is labeled i. as auditors can be the first objects loaded,
* and they exist on their own lik-map list).
*
* ii. For the primary link-map list, CI_TLS_STATMOD must be called first to
* register any static TLS. This routine is called regardless of there
* being any TLS, as this routine also establishes the link-map list as the
* primary list and fixes the association of uberdata). CI_THRINIT should
* then be called.
*
* iii. Any objects added to an existing link-map list (primary or alternative)
* should call CI_TLS_MODADD to register any additional TLS.
*
* These events are established by:
*
* i. Typically, libc is loaded as part of the primary dependencies of any
* link-map list (since the Unified Process Model (UPM), libc can't be
* lazily loaded). To minimize the possibility of loading and registering
* objects, and then tearing them down (because of a relocation error),
* external vectors are established as part of load_completion(). This
* routine is called on completion of any operation that can cause objects
* to be loaded. This point of control insures the objects have been fully
* analyzed and relocated, and moved to their controlling link-map list.
* The external vectors are established prior to any .inits being fired.
*
* ii. Calls to CI_THRINIT, and CI_TLS_MODADD also occur as part of
* load_completion(). CI_THRINIT is only called once for each link-map
* control list.
*
* iii. Calls to CI_TLS_STATMOD, and CI_THRINIT occur for the primary link-map
* list in the final stages of setup().
*
* The interfaces provide by libc can be divided into two families. The first
* family consists of those interfaces that should be called from the link-map
* list. It's possible that these interfaces convey state concerning the
* link-map list they are part of:
*
* CI_ATEXIT
* CI TLS_MODADD
* CI_TLS_MODREM
* CI_TLS_STATMOD
* CI_THRINIT
*
* The second family are global in nature, that is, the link-map list from
* which they are called provides no state information. In fact, for
* CI_BIND_GUARD, the calling link-map isn't even known. The link-map can only
* be deduced after ld.so.1's global lock has been obtained. Therefore, the
* following interfaces are also maintained as global:
*
* CI_LCMESSAGES
* CI_BIND_GUARD
* CI_BIND_CLEAR
* CI_THR_SELF
*
* Note, it is possible that these global interfaces are obtained from an
* alternative link-map list that gets torn down because of a processing
* failure (unlikely, because the link-map list components must be analyzed
* and relocated prior to load_completion(), but perhaps the tear down is still
* a possibility). Thus the global interfaces may have to be replaced. Once
* the interfaces have been obtained from the primary link-map, they can
* remain fixed, as the primary link-map isn't going to go anywhere.
*
* The last wrinkle in the puzzle is what happens if an alternative link-map
* is loaded with no libc dependency? In this case, the alternative objects
* can not call CI_THRINIT, can not be allowed to use TLS, and will not receive
* any atexit processing.
*
* The history of these external interfaces is defined by their version:
*
* TI_VERSION == 1
* Under this model libthread provided rw_rwlock/rw_unlock, through which
* all rt_mutex_lock/rt_mutex_unlock calls were vectored.
* Under libc/libthread these interfaces provided _sigon/_sigoff (unlike
* lwp/libthread that provided signal blocking via bind_guard/bind_clear).
*
* TI_VERSION == 2
* Under this model only libthreads bind_guard/bind_clear and thr_self
* interfaces were used. Both libthreads blocked signals under the
* bind_guard/bind_clear interfaces. Lower level locking is derived
* from internally bound _lwp_ interfaces. This removes recursive
* problems encountered when obtaining locking interfaces from libthread.
* The use of mutexes over reader/writer locks also enables the use of
* condition variables for controlling thread concurrency (allows access
* to objects only after their .init has completed).
*
* NOTE, the TI_VERSION indicated the ti_interface version number, where the
* ti_interface was a large vector of functions passed to both libc (to override
* the thread stub interfaces) and ld.so.1. ld.so.1 used only a small subset of
* these interfaces.
*
* CI_VERSION == 1
* Introduced with CI_VERSION & CI_ATEXIT
*
* CI_VERSION == 2 (Solaris 8 update 2).
* Added support for CI_LCMESSAGES
*
* CI_VERSION == 3 (Solaris 9).
* Added the following versions to the CI table:
*
* CI_BIND_GUARD, CI_BIND_CLEAR, CI_THR_SELF
* CI_TLS_MODADD, CI_TLS_MOD_REMOVE, CI_TLS_STATMOD
*
* This version introduced the DT_SUNW_RTLDINFO structure as a mechanism
* to handshake with ld.so.1.
*
* CI_VERSION == 4 (Solaris 10).
* Added the CI_THRINIT handshake as part of the libc/libthread unified
* process model. libc now initializes the current thread pointer from
* this interface (and no longer relies on the INITFIRST flag - which
* others have started to camp out on).
*
* CI_VERSION == 5 (Solaris 11).
* Use of "protected" references within libc, so that symbols are
* pre-bound, and don't require ld.so.1 binding. This implementation
* protects libc's critical regions from being vectored to auditors.
*
* CI_VERSION == 6 (Solaris 11).
* Added the CI_CRITICAL handshake, to allow "mem*" family to be reexposed
* as "global", and thus be redirected to auxiliary filters.
*
* Release summary:
*
* Solaris 8 CI_ATEXIT via _ld_libc()
* TI_* via _ld_concurrency()
*
* Solaris 9 CI_ATEXIT and CI_LCMESSAGES via _ld_libc()
* CI_* via RTLDINFO and _ld_libc() - new libthread
* TI_* via _ld_concurrency() - old libthread
*
* Solaris 10 CI_ATEXIT and CI_LCMESSAGES via _ld_libc()
* CI_* via RTLDINFO and _ld_libc() - new libthread
*/
#include <sys/debug.h>
#include <synch.h>
#include <signal.h>
#include <thread.h>
#include <synch.h>
#include <strings.h>
#include <stdio.h>
#include <libintl.h>
#include <debug.h>
#include <libc_int.h>
#include "_elf.h"
#include "_rtld.h"
/*
* This interface provides the unified process model communication between
* ld.so.1 and libc. This interface can be called a number of times:
*
* - Initially, this interface is called to process RTLDINFO. This data
* structure is typically provided by libc, and contains the address of
* libc interfaces that must be called to initialize threads information.
*
* - _ld_libc(), this interface can also be called by libc at process
* initialization, after libc has been loaded and relocated, but before
* control has been passed to any user code (.init's or main()). This
* call provides additional libc interface information that ld.so.1 must
* call during process execution.
*
* - _ld_libc() can also be called by libc during process execution to
* re-establish interfaces such as the locale.
*/
static void
get_lcinterface(Rt_map *lmp, Lc_interface *funcs)
{
int threaded = 0, entry = 0, tag;
Lm_list *lml;
Lc_desc *lcp;
if ((lmp == NULL) || (funcs == NULL))
return;
/*
* Once the process is active, ensure we grab a lock.
*/
if (rtld_flags & RT_FL_APPLIC)
entry = enter(0);
lml = LIST(lmp);
lcp = &lml->lm_lcs[0];
DBG_CALL(Dbg_util_nl(lml, DBG_NL_STD));
for (tag = funcs->ci_tag; tag; tag = (++funcs)->ci_tag) {
char *gptr;
char *lptr = funcs->ci_un.ci_ptr;
DBG_CALL(Dbg_util_lcinterface(lmp, tag, lptr));
if (tag >= CI_MAX)
continue;
/*
* Maintain all interfaces on a per-link-map basis. Note, for
* most interfaces, only the first interface is used for any
* link-map list. This prevents accidents with developers who
* manage to load two different versions of libc.
*/
if ((lcp[tag].lc_lmp) &&
(tag != CI_LCMESSAGES) && (tag != CI_VERSION)) {
DBG_CALL(Dbg_unused_lcinterface(lmp,
lcp[tag].lc_lmp, tag));
continue;
}
lcp[tag].lc_un.lc_ptr = lptr;
lcp[tag].lc_lmp = lmp;
gptr = glcs[tag].lc_un.lc_ptr;
/*
* Process any interfaces that must be maintained on a global
* basis.
*/
switch (tag) {
case CI_ATEXIT:
break;
case CI_LCMESSAGES:
/*
* At startup, ld.so.1 can establish a locale from one
* of the locale family of environment variables (see
* ld_str_env() and readenv_user()). During process
* execution the locale can also be changed by the user.
* This interface is called from libc should the locale
* be modified. Presently, only one global locale is
* maintained for all link-map lists, and only objects
* on the primrary link-map may change this locale.
*/
if ((lml->lm_flags & LML_FLG_BASELM) &&
((gptr == NULL) || (strcmp(gptr, lptr) != 0))) {
/*
* If we've obtained a message locale (typically
* supplied via libc's setlocale()), then
* register the locale for use in dgettext() so
* as to reestablish the locale for ld.so.1's
* messages.
*/
if (gptr) {
free((void *)gptr);
rtld_flags |= RT_FL_NEWLOCALE;
}
glcs[tag].lc_un.lc_ptr = strdup(lptr);
/*
* Clear any cached messages.
*/
bzero(err_strs, sizeof (err_strs));
nosym_str = NULL;
}
break;
case CI_BIND_GUARD:
case CI_BIND_CLEAR:
case CI_THR_SELF:
case CI_CRITICAL:
/*
* If the global vector is unset, or this is the primary
* link-map, set the global vector.
*/
if ((gptr == NULL) || (lml->lm_flags & LML_FLG_BASELM))
glcs[tag].lc_un.lc_ptr = lptr;
/* FALLTHROUGH */
case CI_TLS_MODADD:
case CI_TLS_MODREM:
case CI_TLS_STATMOD:
case CI_THRINIT:
threaded++;
break;
case CI_VERSION:
if ((rtld_flags2 & RT_FL2_RTLDSEEN) == 0) {
Aliste idx;
Lm_list *lml2;
int version;
rtld_flags2 |= RT_FL2_RTLDSEEN;
version = funcs->ci_un.ci_val;
#if defined(CI_V_FIVE)
if (version >= CI_V_FIVE) {
thr_flg_nolock = THR_FLG_NOLOCK;
thr_flg_reenter = THR_FLG_REENTER;
}
#endif
if (version < CI_V_FOUR)
break;
rtld_flags2 |= RT_FL2_UNIFPROC;
/*
* We might have seen an auditor which is not
* dependent on libc. Such an auditor's link
* map list has LML_FLG_HOLDLOCK set. This
* lock needs to be dropped. Refer to
* audit_setup() in audit.c.
*/
if ((rtld_flags2 & RT_FL2_HASAUDIT) == 0)
break;
/*
* Yes, we did. Take care of them.
*/
for (APLIST_TRAVERSE(dynlm_list, idx, lml2)) {
Rt_map *map = (Rt_map *)lml2->lm_head;
if (FLAGS(map) & FLG_RT_AUDIT) {
lml2->lm_flags &=
~LML_FLG_HOLDLOCK;
}
}
}
break;
default:
break;
}
}
if (threaded) {
/*
* If a version of libc gives us only a subset of the TLS
* interfaces, it's confused and we discard the whole lot.
*/
if (((lcp[CI_TLS_MODADD].lc_un.lc_func != NULL) &&
(lcp[CI_TLS_MODREM].lc_un.lc_func != NULL) &&
(lcp[CI_TLS_STATMOD].lc_un.lc_func != NULL)) == 0) {
lcp[CI_TLS_MODADD].lc_un.lc_func = NULL;
lcp[CI_TLS_MODREM].lc_un.lc_func = NULL;
lcp[CI_TLS_STATMOD].lc_un.lc_func = NULL;
}
/*
* Indicate that we're now thread capable.
*/
if ((lml->lm_flags & LML_FLG_RTLDLM) == 0)
rtld_flags |= RT_FL_THREADS;
}
if (entry)
leave(lml, 0);
}
/*
* At this point we know we have a set of objects that have been fully analyzed
* and relocated. Prior to the next major step of running .init sections (ie.
* running user code), retrieve any RTLDINFO interfaces.
*/
int
rt_get_extern(Lm_list *lml, Rt_map *lmp)
{
if (lml->lm_rti) {
Aliste idx;
Rti_desc *rti;
for (ALIST_TRAVERSE(lml->lm_rti, idx, rti))
get_lcinterface(rti->rti_lmp, rti->rti_info);
free(lml->lm_rti);
lml->lm_rti = 0;
}
/*
* Perform some sanity checks. If we have TLS requirements we better
* have the associated external interfaces.
*/
if (lml->lm_tls &&
(lml->lm_lcs[CI_TLS_STATMOD].lc_un.lc_func == NULL)) {
eprintf(lml, ERR_FATAL, MSG_INTL(MSG_TLS_NOSUPPORT),
NAME(lmp));
return (0);
}
return (1);
}
/*
* Provide an interface for libc to communicate additional interface
* information.
*/
void
_ld_libc(void *ptr)
{
get_lcinterface(_caller(caller(), CL_EXECDEF), (Lc_interface *)ptr);
}
static int bindmask = 0;
int
rt_bind_guard(int flags)
{
int (*fptr)(int);
int bindflag;
if ((fptr = glcs[CI_BIND_GUARD].lc_un.lc_func) != NULL) {
return ((*fptr)(flags));
} else {
bindflag = (flags & THR_FLG_RTLD);
if ((bindflag & bindmask) == 0) {
bindmask |= bindflag;
return (1);
}
return (0);
}
}
int
rt_bind_clear(int flags)
{
int (*fptr)(int);
int bindflag;
if ((fptr = glcs[CI_BIND_CLEAR].lc_un.lc_func) != NULL) {
return ((*fptr)(flags));
} else {
bindflag = (flags & THR_FLG_RTLD);
if (bindflag == 0)
return (bindmask);
else {
bindmask &= ~bindflag;
return (0);
}
}
}
/*
* Make sure threads have been initialized. This interface is called once for
* each link-map list.
*/
void
rt_thr_init(Lm_list *lml)
{
int (*fptr)(void);
if ((fptr = lml->lm_lcs[CI_THRINIT].lc_un.lc_func) != NULL) {
lml->lm_lcs[CI_THRINIT].lc_un.lc_func = NULL;
leave(lml, thr_flg_reenter);
(void) (*fptr)();
(void) enter(thr_flg_reenter);
/*
* If this is an alternative link-map list, and this is the
* first call to initialize threads, don't let the destination
* libc be deleted. It is possible that an auditors complete
* initialization fails, but there is presently no main link-map
* list. As this libc has established the thread pointer, don't
* delete this libc, otherwise the initialization of libc on the
* main link-map can be compromised during its threads
* initialization.
*/
if (((lml->lm_flags & LML_FLG_BASELM) == 0) &&
((rtld_flags2 & RT_FL2_PLMSETUP) == 0))
MODE(lml->lm_lcs[CI_THRINIT].lc_lmp) |= RTLD_NODELETE;
}
}
thread_t
rt_thr_self()
{
thread_t (*fptr)(void);
if ((fptr = (thread_t (*)())glcs[CI_THR_SELF].lc_un.lc_func) != NULL)
return ((*fptr)());
return (1);
}
int
rt_mutex_lock(Rt_lock *mp)
{
return (_lwp_mutex_lock((lwp_mutex_t *)mp));
}
int
rt_mutex_unlock(Rt_lock *mp)
{
return (_lwp_mutex_unlock((lwp_mutex_t *)mp));
}
/*
* Test whether we're in a libc critical region. Certain function references,
* like the "mem*" family, might require binding. Although these functions can
* safely bind to auxiliary filtees, they should not be captured by auditors.
*/
int
rt_critical()
{
int (*fptr)(void);
if ((fptr = glcs[CI_CRITICAL].lc_un.lc_func) != NULL)
return ((*fptr)());
return (0);
}
/*
* Mutex interfaces to resolve references from any objects extracted from
* libc_pic.a. Note, as ld.so.1 is essentially single threaded these can be
* noops.
*/
#pragma weak lmutex_lock = mutex_lock
/* ARGSUSED */
int
mutex_lock(mutex_t *mp)
{
return (0);
}
#pragma weak lmutex_unlock = mutex_unlock
/* ARGSUSED */
int
mutex_unlock(mutex_t *mp)
{
return (0);
}
/* ARGSUSED */
int
mutex_init(mutex_t *mp, int type, void *arg)
{
return (0);
}
/* ARGSUSED */
int
mutex_destroy(mutex_t *mp)
{
return (0);
}
/*
* This is needed to satisfy sysconf() (case _SC_THREAD_STACK_MIN)
*/
size_t
thr_min_stack()
{
return (sizeof (uintptr_t) * 1024);
}
/*
* Local str[n]casecmp() interfaces for the dynamic linker,
* to avoid problems when linking with libc_pic.a
*/
int
strcasecmp(const char *s1, const char *s2)
{
extern int ascii_strcasecmp(const char *, const char *);
return (ascii_strcasecmp(s1, s2));
}
int
strncasecmp(const char *s1, const char *s2, size_t n)
{
extern int ascii_strncasecmp(const char *, const char *, size_t);
return (ascii_strncasecmp(s1, s2, n));
}
/*
* The following functions are cancellation points in libc.
* They are called from other functions in libc that we extract
* and use directly. We don't do cancellation while we are in
* the dynamic linker, so we redefine these to call the primitive,
* non-cancellation interfaces.
*/
int
close(int fildes)
{
extern int __close(int);
return (__close(fildes));
}
int
fcntl(int fildes, int cmd, ...)
{
extern int __fcntl(int, int, ...);
intptr_t arg;
va_list ap;
va_start(ap, cmd);
arg = va_arg(ap, intptr_t);
va_end(ap);
return (__fcntl(fildes, cmd, arg));
}
int
open(const char *path, int oflag, ...)
{
extern int __open(const char *, int, mode_t);
mode_t mode;
va_list ap;
va_start(ap, oflag);
mode = va_arg(ap, mode_t);
va_end(ap);
return (__open(path, oflag, mode));
}
int
openat(int fd, const char *path, int oflag, ...)
{
extern int __openat(int, const char *, int, mode_t);
mode_t mode;
va_list ap;
va_start(ap, oflag);
mode = va_arg(ap, mode_t);
va_end(ap);
return (__openat(fd, path, oflag, mode));
}
ssize_t
read(int fd, void *buf, size_t size)
{
extern ssize_t __read(int, void *, size_t);
return (__read(fd, buf, size));
}
ssize_t
write(int fd, const void *buf, size_t size)
{
extern ssize_t __write(int, const void *, size_t);
return (__write(fd, buf, size));
}
/*
* ASCII versions of ctype character classification functions. This avoids
* pulling in the entire locale framework that is in libc.
*/
int
isdigit(int c)
{
return ((c >= '0' && c <= '9') ? 1 : 0);
}
int
isupper(int c)
{
return ((c >= 'A' && c <= 'Z') ? 1 : 0);
}
int
islower(int c)
{
return ((c >= 'a' && c <= 'z') ? 1 : 0);
}
int
isspace(int c)
{
return (((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n') ||
(c == '\v') || (c == '\f')) ? 1 : 0);
}
int
isxdigit(int c)
{
return ((isdigit(c) || (c >= 'A' && c <= 'F') ||
(c >= 'a' && c <= 'f')) ? 1 : 0);
}
int
isalpha(int c)
{
return ((isupper(c) || islower(c)) ? 1 : 0);
}
int
isalnum(int c)
{
return ((isalpha(c) || isdigit(c)) ? 1 : 0);
}
#if defined(__i386) || defined(__amd64)
/*
* Instead of utilizing the comm page for clock_gettime and gettimeofday, rtld
* uses the raw syscall instead. Doing so decreases the surface of symbols
* needed from libc for a modest performance cost.
*/
extern int __clock_gettime_sys(clockid_t, struct timespec *);
int
__clock_gettime(clockid_t clock_id, struct timespec *tp)
{
return (__clock_gettime_sys(clock_id, tp));
}
int
gettimeofday(struct timeval *tv, void *tz)
{
if (tv != NULL) {
/*
* Perform the same logic as the libc gettimeofday() when it
* lacks comm page support: Make the clock_gettime syscall and
* divide out the tv_usec field as required.
*/
__clock_gettime_sys(CLOCK_REALTIME, (timespec_t *)tv);
tv->tv_usec /= 1000;
}
return (0);
}
#endif /* defined(__i386) || defined(__amd64) */
/*
* In a similar vein to the is* functions above, we also have to define our own
* version of strerror, as it is implemented in terms of the locale aware
* strerror_l, and we'd rather not have the full set of libc symbols used here.
*/
extern const char _sys_errs[];
extern const int _sys_index[];
extern int _sys_num_err;
char *
strerror(int errnum)
{
if (errnum < _sys_num_err && errnum >= 0) {
return (dgettext("SUNW_OST_OSLIB",
(char *)&_sys_errs[_sys_index[errnum]]));
}
errno = EINVAL;
return (dgettext("SUNW_OST_OSLIB", "Unknown error"));
}
|