xref: /titanic_41/usr/src/cmd/sgs/libelf/common/getshdr.c (revision 6185db853e024a486ff8837e6784dd290d866112)
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.4	*/
31 
32 #pragma weak	elf32_getshdr = _elf32_getshdr
33 
34 #include "syn.h"
35 #include "libelf.h"
36 #include "decl.h"
37 #include "msg.h"
38 
39 
40 static void *
41 getshdr(Elf_Scn * scn, int class)
42 {
43 	void *	rc;
44 	Elf *	elf;
45 	if (scn == 0)
46 		return (0);
47 	elf = scn->s_elf;
48 	READLOCKS(elf, scn)
49 	if (elf->ed_class != class) {
50 		READUNLOCKS(elf, scn)
51 		_elf_seterr(EREQ_CLASS, 0);
52 		return (0);
53 	}
54 
55 	rc = scn->s_shdr;
56 	READUNLOCKS(elf, scn)
57 	return (rc);
58 }
59 
60 Elf32_Shdr *
61 elf32_getshdr(Elf_Scn * scn)
62 {
63 	return ((Elf32_Shdr*) getshdr(scn, ELFCLASS32));
64 }
65 
66 Elf64_Shdr *
67 elf64_getshdr(Elf_Scn * scn)
68 {
69 	return ((Elf64_Shdr*) getshdr(scn, ELFCLASS64));
70 }
71