xref: /titanic_52/usr/src/cmd/sgs/libelf/common/flag.c (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
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 /*
27  * Copyright (c) 1998 by Sun Microsystems, Inc.
28  * All rights reserved.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI" 	/* SVr4.0 1.6	*/
32 
33 #pragma weak	elf_flagdata = _elf_flagdata
34 #pragma weak	elf_flagehdr = _elf_flagehdr
35 #pragma weak	elf_flagelf = _elf_flagelf
36 #pragma weak	elf_flagphdr = _elf_flagphdr
37 #pragma weak	elf_flagscn = _elf_flagscn
38 #pragma weak	elf_flagshdr = _elf_flagshdr
39 
40 
41 #include "syn.h"
42 #include "libelf.h"
43 #include "decl.h"
44 #include "msg.h"
45 
46 
47 unsigned
48 elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned flags)
49 {
50 	unsigned	rc = 0;
51 	Elf *		elf;
52 	Elf_Scn *	scn;
53 	Dnode *		d;
54 
55 	if (data == 0)
56 		return (0);
57 	d = (Dnode *) data;
58 	scn = d->db_scn;
59 	elf = scn->s_elf;
60 
61 	READLOCKS(elf, scn)
62 
63 	if (cmd == ELF_C_SET) {
64 		rc = d->db_uflags |= flags;
65 	} else if (cmd == ELF_C_CLR) {
66 		rc = d->db_uflags &= ~flags;
67 	} else
68 		_elf_seterr(EREQ_FLAG, 0);
69 	READUNLOCKS(elf, scn)
70 	return (rc);
71 }
72 
73 
74 unsigned int
75 elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
76 {
77 	int	rc;
78 	if (elf == 0)
79 		return (0);
80 	if (cmd == ELF_C_SET) {
81 		ELFWLOCK(elf)
82 		rc = elf->ed_ehflags |= flags;
83 		ELFUNLOCK(elf)
84 		return (rc);
85 	}
86 	if (cmd == ELF_C_CLR) {
87 		ELFWLOCK(elf)
88 		rc = elf->ed_ehflags &= ~flags;
89 		ELFUNLOCK(elf)
90 		return (rc);
91 	}
92 	_elf_seterr(EREQ_FLAG, 0);
93 	return (0);
94 }
95 
96 
97 unsigned
98 elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned flags)
99 {
100 	int	rc;
101 	if (elf == 0)
102 		return (0);
103 	if (cmd == ELF_C_SET) {
104 		ELFWLOCK(elf)
105 		rc = elf->ed_uflags |= flags;
106 		ELFUNLOCK(elf)
107 		return (rc);
108 	}
109 	if (cmd == ELF_C_CLR) {
110 		ELFWLOCK(elf)
111 		rc = elf->ed_uflags &= ~flags;
112 		ELFUNLOCK(elf)
113 		return (rc);
114 	}
115 	_elf_seterr(EREQ_FLAG, 0);
116 	return (0);
117 }
118 
119 
120 unsigned
121 elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
122 {
123 	int	rc;
124 	if (elf == 0)
125 		return (0);
126 	if (cmd == ELF_C_SET) {
127 		ELFWLOCK(elf);
128 		rc = elf->ed_phflags |= flags;
129 		ELFUNLOCK(elf);
130 		return (rc);
131 	}
132 	if (cmd == ELF_C_CLR) {
133 		ELFWLOCK(elf);
134 		rc = elf->ed_phflags &= ~flags;
135 		ELFUNLOCK(elf);
136 		return (rc);
137 	}
138 	_elf_seterr(EREQ_FLAG, 0);
139 	return (0);
140 }
141 
142 
143 unsigned
144 elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
145 {
146 	unsigned	rc;
147 	Elf *		elf;
148 
149 	if (scn == 0)
150 		return (0);
151 
152 	elf = scn->s_elf;
153 	if (cmd == ELF_C_SET) {
154 		READLOCKS(elf, scn)
155 		rc = scn->s_uflags |= flags;
156 		READUNLOCKS(elf, scn)
157 		return (rc);
158 	}
159 	if (cmd == ELF_C_CLR) {
160 		READLOCKS(elf, scn)
161 		rc = scn->s_uflags &= ~flags;
162 		READUNLOCKS(elf, scn)
163 		return (rc);
164 	}
165 	_elf_seterr(EREQ_FLAG, 0);
166 	return (0);
167 }
168 
169 
170 unsigned
171 elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
172 {
173 	unsigned	rc;
174 	Elf *		elf;
175 	if (scn == 0)
176 		return (0);
177 
178 	elf = scn->s_elf;
179 	if (cmd == ELF_C_SET) {
180 		READLOCKS(elf, scn)
181 		rc = scn->s_shflags |= flags;
182 		READUNLOCKS(elf, scn)
183 		return (rc);
184 	}
185 	if (cmd == ELF_C_CLR) {
186 		READLOCKS(elf, scn)
187 		rc = scn->s_shflags &= ~flags;
188 		READUNLOCKS(elf, scn)
189 		return (rc);
190 	}
191 	_elf_seterr(EREQ_FLAG, 0);
192 	return (0);
193 }
194