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