xref: /titanic_51/usr/src/cmd/sgs/libelf/common/flag.c (revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include "libelf.h"
33 #include "decl.h"
34 #include "msg.h"
35 
36 
37 unsigned
38 elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned flags)
39 {
40 	unsigned	rc = 0;
41 	Elf *		elf;
42 	Elf_Scn *	scn;
43 	Dnode *		d;
44 
45 	if (data == 0)
46 		return (0);
47 	d = (Dnode *) data;
48 	scn = d->db_scn;
49 	elf = scn->s_elf;
50 
51 	READLOCKS(elf, scn)
52 
53 	if (cmd == ELF_C_SET) {
54 		rc = d->db_uflags |= flags;
55 	} else if (cmd == ELF_C_CLR) {
56 		rc = d->db_uflags &= ~flags;
57 	} else
58 		_elf_seterr(EREQ_FLAG, 0);
59 	READUNLOCKS(elf, scn)
60 	return (rc);
61 }
62 
63 
64 unsigned int
65 elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
66 {
67 	int	rc;
68 	if (elf == 0)
69 		return (0);
70 	if (cmd == ELF_C_SET) {
71 		ELFWLOCK(elf)
72 		rc = elf->ed_ehflags |= flags;
73 		ELFUNLOCK(elf)
74 		return (rc);
75 	}
76 	if (cmd == ELF_C_CLR) {
77 		ELFWLOCK(elf)
78 		rc = elf->ed_ehflags &= ~flags;
79 		ELFUNLOCK(elf)
80 		return (rc);
81 	}
82 	_elf_seterr(EREQ_FLAG, 0);
83 	return (0);
84 }
85 
86 
87 unsigned
88 elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned flags)
89 {
90 	int	rc;
91 	if (elf == 0)
92 		return (0);
93 	if (cmd == ELF_C_SET) {
94 		ELFWLOCK(elf)
95 		rc = elf->ed_uflags |= flags;
96 		ELFUNLOCK(elf)
97 		return (rc);
98 	}
99 	if (cmd == ELF_C_CLR) {
100 		ELFWLOCK(elf)
101 		rc = elf->ed_uflags &= ~flags;
102 		ELFUNLOCK(elf)
103 		return (rc);
104 	}
105 	_elf_seterr(EREQ_FLAG, 0);
106 	return (0);
107 }
108 
109 
110 unsigned
111 elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
112 {
113 	int	rc;
114 	if (elf == 0)
115 		return (0);
116 	if (cmd == ELF_C_SET) {
117 		ELFWLOCK(elf);
118 		rc = elf->ed_phflags |= flags;
119 		ELFUNLOCK(elf);
120 		return (rc);
121 	}
122 	if (cmd == ELF_C_CLR) {
123 		ELFWLOCK(elf);
124 		rc = elf->ed_phflags &= ~flags;
125 		ELFUNLOCK(elf);
126 		return (rc);
127 	}
128 	_elf_seterr(EREQ_FLAG, 0);
129 	return (0);
130 }
131 
132 
133 unsigned
134 elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
135 {
136 	unsigned	rc;
137 	Elf *		elf;
138 
139 	if (scn == 0)
140 		return (0);
141 
142 	elf = scn->s_elf;
143 	if (cmd == ELF_C_SET) {
144 		READLOCKS(elf, scn)
145 		rc = scn->s_uflags |= flags;
146 		READUNLOCKS(elf, scn)
147 		return (rc);
148 	}
149 	if (cmd == ELF_C_CLR) {
150 		READLOCKS(elf, scn)
151 		rc = scn->s_uflags &= ~flags;
152 		READUNLOCKS(elf, scn)
153 		return (rc);
154 	}
155 	_elf_seterr(EREQ_FLAG, 0);
156 	return (0);
157 }
158 
159 
160 unsigned
161 elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
162 {
163 	unsigned	rc;
164 	Elf *		elf;
165 	if (scn == 0)
166 		return (0);
167 
168 	elf = scn->s_elf;
169 	if (cmd == ELF_C_SET) {
170 		READLOCKS(elf, scn)
171 		rc = scn->s_shflags |= flags;
172 		READUNLOCKS(elf, scn)
173 		return (rc);
174 	}
175 	if (cmd == ELF_C_CLR) {
176 		READLOCKS(elf, scn)
177 		rc = scn->s_shflags &= ~flags;
178 		READUNLOCKS(elf, scn)
179 		return (rc);
180 	}
181 	_elf_seterr(EREQ_FLAG, 0);
182 	return (0);
183 }
184