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 #include "libelf.h" 31 #include "decl.h" 32 #include "msg.h" 33 34 35 unsigned 36 elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned flags) 37 { 38 unsigned rc = 0; 39 Elf * elf; 40 Elf_Scn * scn; 41 Dnode * d; 42 43 if (data == 0) 44 return (0); 45 d = (Dnode *) data; 46 scn = d->db_scn; 47 elf = scn->s_elf; 48 49 READLOCKS(elf, scn) 50 51 if (cmd == ELF_C_SET) { 52 rc = d->db_uflags |= flags; 53 } else if (cmd == ELF_C_CLR) { 54 rc = d->db_uflags &= ~flags; 55 } else 56 _elf_seterr(EREQ_FLAG, 0); 57 READUNLOCKS(elf, scn) 58 return (rc); 59 } 60 61 62 unsigned int 63 elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned flags) 64 { 65 int rc; 66 if (elf == 0) 67 return (0); 68 if (cmd == ELF_C_SET) { 69 ELFWLOCK(elf) 70 rc = elf->ed_ehflags |= flags; 71 ELFUNLOCK(elf) 72 return (rc); 73 } 74 if (cmd == ELF_C_CLR) { 75 ELFWLOCK(elf) 76 rc = elf->ed_ehflags &= ~flags; 77 ELFUNLOCK(elf) 78 return (rc); 79 } 80 _elf_seterr(EREQ_FLAG, 0); 81 return (0); 82 } 83 84 85 unsigned 86 elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned flags) 87 { 88 int rc; 89 if (elf == 0) 90 return (0); 91 if (cmd == ELF_C_SET) { 92 ELFWLOCK(elf) 93 rc = elf->ed_uflags |= flags; 94 ELFUNLOCK(elf) 95 return (rc); 96 } 97 if (cmd == ELF_C_CLR) { 98 ELFWLOCK(elf) 99 rc = elf->ed_uflags &= ~flags; 100 ELFUNLOCK(elf) 101 return (rc); 102 } 103 _elf_seterr(EREQ_FLAG, 0); 104 return (0); 105 } 106 107 108 unsigned 109 elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned flags) 110 { 111 int rc; 112 if (elf == 0) 113 return (0); 114 if (cmd == ELF_C_SET) { 115 ELFWLOCK(elf); 116 rc = elf->ed_phflags |= flags; 117 ELFUNLOCK(elf); 118 return (rc); 119 } 120 if (cmd == ELF_C_CLR) { 121 ELFWLOCK(elf); 122 rc = elf->ed_phflags &= ~flags; 123 ELFUNLOCK(elf); 124 return (rc); 125 } 126 _elf_seterr(EREQ_FLAG, 0); 127 return (0); 128 } 129 130 131 unsigned 132 elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags) 133 { 134 unsigned rc; 135 Elf * elf; 136 137 if (scn == 0) 138 return (0); 139 140 elf = scn->s_elf; 141 if (cmd == ELF_C_SET) { 142 READLOCKS(elf, scn) 143 rc = scn->s_uflags |= flags; 144 READUNLOCKS(elf, scn) 145 return (rc); 146 } 147 if (cmd == ELF_C_CLR) { 148 READLOCKS(elf, scn) 149 rc = scn->s_uflags &= ~flags; 150 READUNLOCKS(elf, scn) 151 return (rc); 152 } 153 _elf_seterr(EREQ_FLAG, 0); 154 return (0); 155 } 156 157 158 unsigned 159 elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags) 160 { 161 unsigned rc; 162 Elf * elf; 163 if (scn == 0) 164 return (0); 165 166 elf = scn->s_elf; 167 if (cmd == ELF_C_SET) { 168 READLOCKS(elf, scn) 169 rc = scn->s_shflags |= flags; 170 READUNLOCKS(elf, scn) 171 return (rc); 172 } 173 if (cmd == ELF_C_CLR) { 174 READLOCKS(elf, scn) 175 rc = scn->s_shflags &= ~flags; 176 READUNLOCKS(elf, scn) 177 return (rc); 178 } 179 _elf_seterr(EREQ_FLAG, 0); 180 return (0); 181 } 182