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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <sys/types.h>
42 static mutex_t auxlock
= DEFAULTMUTEX
;
45 * Get auxiliary entry.
46 * Returns pointer to entry, or 0 if entry does not exist.
51 static auxv_t
*auxb
= NULL
;
52 static size_t nauxv
= 0;
56 * The first time through, read the initial aux vector that was
57 * passed to the process at exec(2). Only do this once.
60 lmutex_lock(&auxlock
);
66 if ((fd
= open("/proc/self/auxv", O_RDONLY
)) != -1 &&
67 fstat(fd
, &statb
) != -1)
69 statb
.st_size
+ sizeof (auxv_t
));
72 i
= read(fd
, buf
, statb
.st_size
);
74 nauxv
= i
/ sizeof (auxv_t
);
75 buf
[nauxv
].a_type
= AT_NULL
;
88 lmutex_unlock(&auxlock
);
93 * Scan the auxiliary entries looking for the required type.
95 for (i
= 0; i
< nauxv
; i
++)
96 if (auxb
[i
].a_type
== type
)
100 * No auxiliary array (static executable) or entry not found.
102 return ((auxv_t
*)0);
106 * These two routines are utilities exported to the rest of libc.
110 ___getauxval(int type
)
114 if ((auxp
= _getaux(type
)) != (auxv_t
*)0)
115 return (auxp
->a_un
.a_val
);
120 ___getauxptr(int type
)
124 if ((auxp
= _getaux(type
)) != (auxv_t
*)0)
125 return (auxp
->a_un
.a_ptr
);