#pragma ident "@(#)flag.c 1.11 08/05/31 SMI"
#include "libelf.h"
#include "decl.h"
#include "msg.h"
unsigned
elf_flagdata(Elf_Data * data, Elf_Cmd cmd, unsigned flags)
{
unsigned rc = 0;
Elf * elf;
Elf_Scn * scn;
Dnode * d;
if (data == 0)
return (0);
d = (Dnode *) data;
scn = d->db_scn;
elf = scn->s_elf;
READLOCKS(elf, scn)
if (cmd == ELF_C_SET) {
rc = d->db_uflags |= flags;
} else if (cmd == ELF_C_CLR) {
rc = d->db_uflags &= ~flags;
} else
_elf_seterr(EREQ_FLAG, 0);
READUNLOCKS(elf, scn)
return (rc);
}
unsigned int
elf_flagehdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
{
int rc;
if (elf == 0)
return (0);
if (cmd == ELF_C_SET) {
ELFWLOCK(elf)
rc = elf->ed_ehflags |= flags;
ELFUNLOCK(elf)
return (rc);
}
if (cmd == ELF_C_CLR) {
ELFWLOCK(elf)
rc = elf->ed_ehflags &= ~flags;
ELFUNLOCK(elf)
return (rc);
}
_elf_seterr(EREQ_FLAG, 0);
return (0);
}
unsigned
elf_flagelf(Elf * elf, Elf_Cmd cmd, unsigned flags)
{
int rc;
if (elf == 0)
return (0);
if (cmd == ELF_C_SET) {
ELFWLOCK(elf)
rc = elf->ed_uflags |= flags;
ELFUNLOCK(elf)
return (rc);
}
if (cmd == ELF_C_CLR) {
ELFWLOCK(elf)
rc = elf->ed_uflags &= ~flags;
ELFUNLOCK(elf)
return (rc);
}
_elf_seterr(EREQ_FLAG, 0);
return (0);
}
unsigned
elf_flagphdr(Elf * elf, Elf_Cmd cmd, unsigned flags)
{
int rc;
if (elf == 0)
return (0);
if (cmd == ELF_C_SET) {
ELFWLOCK(elf);
rc = elf->ed_phflags |= flags;
ELFUNLOCK(elf);
return (rc);
}
if (cmd == ELF_C_CLR) {
ELFWLOCK(elf);
rc = elf->ed_phflags &= ~flags;
ELFUNLOCK(elf);
return (rc);
}
_elf_seterr(EREQ_FLAG, 0);
return (0);
}
unsigned
elf_flagscn(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
{
unsigned rc;
Elf * elf;
if (scn == 0)
return (0);
elf = scn->s_elf;
if (cmd == ELF_C_SET) {
READLOCKS(elf, scn)
rc = scn->s_uflags |= flags;
READUNLOCKS(elf, scn)
return (rc);
}
if (cmd == ELF_C_CLR) {
READLOCKS(elf, scn)
rc = scn->s_uflags &= ~flags;
READUNLOCKS(elf, scn)
return (rc);
}
_elf_seterr(EREQ_FLAG, 0);
return (0);
}
unsigned
elf_flagshdr(Elf_Scn * scn, Elf_Cmd cmd, unsigned flags)
{
unsigned rc;
Elf * elf;
if (scn == 0)
return (0);
elf = scn->s_elf;
if (cmd == ELF_C_SET) {
READLOCKS(elf, scn)
rc = scn->s_shflags |= flags;
READUNLOCKS(elf, scn)
return (rc);
}
if (cmd == ELF_C_CLR) {
READLOCKS(elf, scn)
rc = scn->s_shflags &= ~flags;
READUNLOCKS(elf, scn)
return (rc);
}
_elf_seterr(EREQ_FLAG, 0);
return (0);
}