xref: /titanic_51/usr/src/cmd/sgs/libelf/common/getident.c (revision 10db1377dafab8ba3feedef26db9c5d8539a5cd1)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 /*
26  * Copyright (c) 1998 by Sun Microsystems, Inc.
27  * All rights reserved.
28  */
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI" 	/* SVr4.0 1.8	*/
31 
32 #pragma weak	elf_getident = _elf_getident
33 
34 
35 #include "syn.h"
36 #include "libelf.h"
37 #include "decl.h"
38 
39 
40 char *
41 elf_getident(Elf * elf, size_t * ptr)
42 {
43 	size_t	sz = 0;
44 	char *	id = 0;
45 
46 	if (elf != 0) {
47 		ELFRLOCK(elf)
48 		if (elf->ed_identsz != 0) {
49 			if ((elf->ed_vm == 0) || (elf->ed_status !=
50 			    ES_COOKED)) {
51 				/*
52 				 * We need to upgrade to a Writers
53 				 * lock
54 				 */
55 				ELFUNLOCK(elf)
56 				ELFWLOCK(elf)
57 				if ((_elf_cook(elf) == OK_YES) &&
58 				    (_elf_vm(elf, (size_t)0,
59 				    elf->ed_identsz) == OK_YES)) {
60 					id = elf->ed_ident;
61 					sz = elf->ed_identsz;
62 				}
63 			} else {
64 				id = elf->ed_ident;
65 				sz = elf->ed_identsz;
66 			}
67 		}
68 		ELFUNLOCK(elf)
69 	}
70 	if (ptr != 0)
71 		*ptr = sz;
72 	return (id);
73 }
74