10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
22*6812Sraf /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*6812Sraf * Use is subject to license terms.
25*6812Sraf */
26*6812Sraf
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include "libelf.h"
330Sstevel@tonic-gate #include "decl.h"
340Sstevel@tonic-gate #include "msg.h"
350Sstevel@tonic-gate
360Sstevel@tonic-gate
370Sstevel@tonic-gate unsigned
elf_flagdata(Elf_Data * data,Elf_Cmd cmd,unsigned flags)380Sstevel@tonic-gate elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned flags)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate unsigned rc = 0;
410Sstevel@tonic-gate Elf * elf;
420Sstevel@tonic-gate Elf_Scn * scn;
430Sstevel@tonic-gate Dnode * d;
440Sstevel@tonic-gate
450Sstevel@tonic-gate if (data == 0)
460Sstevel@tonic-gate return (0);
470Sstevel@tonic-gate d = (Dnode *) data;
480Sstevel@tonic-gate scn = d->db_scn;
490Sstevel@tonic-gate elf = scn->s_elf;
500Sstevel@tonic-gate
510Sstevel@tonic-gate READLOCKS(elf, scn)
520Sstevel@tonic-gate
530Sstevel@tonic-gate if (cmd == ELF_C_SET) {
540Sstevel@tonic-gate rc = d->db_uflags |= flags;
550Sstevel@tonic-gate } else if (cmd == ELF_C_CLR) {
560Sstevel@tonic-gate rc = d->db_uflags &= ~flags;
570Sstevel@tonic-gate } else
580Sstevel@tonic-gate _elf_seterr(EREQ_FLAG, 0);
590Sstevel@tonic-gate READUNLOCKS(elf, scn)
600Sstevel@tonic-gate return (rc);
610Sstevel@tonic-gate }
620Sstevel@tonic-gate
630Sstevel@tonic-gate
640Sstevel@tonic-gate unsigned int
elf_flagehdr(Elf * elf,Elf_Cmd cmd,unsigned flags)650Sstevel@tonic-gate elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
660Sstevel@tonic-gate {
670Sstevel@tonic-gate int rc;
680Sstevel@tonic-gate if (elf == 0)
690Sstevel@tonic-gate return (0);
700Sstevel@tonic-gate if (cmd == ELF_C_SET) {
710Sstevel@tonic-gate ELFWLOCK(elf)
720Sstevel@tonic-gate rc = elf->ed_ehflags |= flags;
730Sstevel@tonic-gate ELFUNLOCK(elf)
740Sstevel@tonic-gate return (rc);
750Sstevel@tonic-gate }
760Sstevel@tonic-gate if (cmd == ELF_C_CLR) {
770Sstevel@tonic-gate ELFWLOCK(elf)
780Sstevel@tonic-gate rc = elf->ed_ehflags &= ~flags;
790Sstevel@tonic-gate ELFUNLOCK(elf)
800Sstevel@tonic-gate return (rc);
810Sstevel@tonic-gate }
820Sstevel@tonic-gate _elf_seterr(EREQ_FLAG, 0);
830Sstevel@tonic-gate return (0);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate
860Sstevel@tonic-gate
870Sstevel@tonic-gate unsigned
elf_flagelf(Elf * elf,Elf_Cmd cmd,unsigned flags)880Sstevel@tonic-gate elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned flags)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate int rc;
910Sstevel@tonic-gate if (elf == 0)
920Sstevel@tonic-gate return (0);
930Sstevel@tonic-gate if (cmd == ELF_C_SET) {
940Sstevel@tonic-gate ELFWLOCK(elf)
950Sstevel@tonic-gate rc = elf->ed_uflags |= flags;
960Sstevel@tonic-gate ELFUNLOCK(elf)
970Sstevel@tonic-gate return (rc);
980Sstevel@tonic-gate }
990Sstevel@tonic-gate if (cmd == ELF_C_CLR) {
1000Sstevel@tonic-gate ELFWLOCK(elf)
1010Sstevel@tonic-gate rc = elf->ed_uflags &= ~flags;
1020Sstevel@tonic-gate ELFUNLOCK(elf)
1030Sstevel@tonic-gate return (rc);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate _elf_seterr(EREQ_FLAG, 0);
1060Sstevel@tonic-gate return (0);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate unsigned
elf_flagphdr(Elf * elf,Elf_Cmd cmd,unsigned flags)1110Sstevel@tonic-gate elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
1120Sstevel@tonic-gate {
1130Sstevel@tonic-gate int rc;
1140Sstevel@tonic-gate if (elf == 0)
1150Sstevel@tonic-gate return (0);
1160Sstevel@tonic-gate if (cmd == ELF_C_SET) {
1170Sstevel@tonic-gate ELFWLOCK(elf);
1180Sstevel@tonic-gate rc = elf->ed_phflags |= flags;
1190Sstevel@tonic-gate ELFUNLOCK(elf);
1200Sstevel@tonic-gate return (rc);
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate if (cmd == ELF_C_CLR) {
1230Sstevel@tonic-gate ELFWLOCK(elf);
1240Sstevel@tonic-gate rc = elf->ed_phflags &= ~flags;
1250Sstevel@tonic-gate ELFUNLOCK(elf);
1260Sstevel@tonic-gate return (rc);
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate _elf_seterr(EREQ_FLAG, 0);
1290Sstevel@tonic-gate return (0);
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate unsigned
elf_flagscn(Elf_Scn * scn,Elf_Cmd cmd,unsigned flags)1340Sstevel@tonic-gate elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate unsigned rc;
1370Sstevel@tonic-gate Elf * elf;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate if (scn == 0)
1400Sstevel@tonic-gate return (0);
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate elf = scn->s_elf;
1430Sstevel@tonic-gate if (cmd == ELF_C_SET) {
1440Sstevel@tonic-gate READLOCKS(elf, scn)
1450Sstevel@tonic-gate rc = scn->s_uflags |= flags;
1460Sstevel@tonic-gate READUNLOCKS(elf, scn)
1470Sstevel@tonic-gate return (rc);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate if (cmd == ELF_C_CLR) {
1500Sstevel@tonic-gate READLOCKS(elf, scn)
1510Sstevel@tonic-gate rc = scn->s_uflags &= ~flags;
1520Sstevel@tonic-gate READUNLOCKS(elf, scn)
1530Sstevel@tonic-gate return (rc);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate _elf_seterr(EREQ_FLAG, 0);
1560Sstevel@tonic-gate return (0);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate unsigned
elf_flagshdr(Elf_Scn * scn,Elf_Cmd cmd,unsigned flags)1610Sstevel@tonic-gate elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate unsigned rc;
1640Sstevel@tonic-gate Elf * elf;
1650Sstevel@tonic-gate if (scn == 0)
1660Sstevel@tonic-gate return (0);
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate elf = scn->s_elf;
1690Sstevel@tonic-gate if (cmd == ELF_C_SET) {
1700Sstevel@tonic-gate READLOCKS(elf, scn)
1710Sstevel@tonic-gate rc = scn->s_shflags |= flags;
1720Sstevel@tonic-gate READUNLOCKS(elf, scn)
1730Sstevel@tonic-gate return (rc);
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate if (cmd == ELF_C_CLR) {
1760Sstevel@tonic-gate READLOCKS(elf, scn)
1770Sstevel@tonic-gate rc = scn->s_shflags &= ~flags;
1780Sstevel@tonic-gate READUNLOCKS(elf, scn)
1790Sstevel@tonic-gate return (rc);
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate _elf_seterr(EREQ_FLAG, 0);
1820Sstevel@tonic-gate return (0);
1830Sstevel@tonic-gate }
184