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