/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1988 AT&T
* All Rights Reserved
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <ar.h>
#include <stdlib.h>
#include <memory.h>
#include <errno.h>
#include <libelf.h>
#include "decl.h"
#include "member.h"
#include "msg.h"
/*
* Initialize archive member
*/
Elf *
{
return (0);
fd = -1;
_elf_seterr(EREQ_ARRDWR, 0);
return (0);
}
_elf_seterr(EREQ_ARMEMFD, 0);
return (0);
}
return (0);
_elf_seterr(EFMT_ARMEMSZ, 0);
return (0);
}
return (0);
}
/*
* If this member is the archive string table,
* we've already altered the bytes.
*/
return (elf);
}
Elf *
{
return (0);
}
return (0);
}
return (elf);
}
Elf *
{
char *base;
unsigned encode;
/*
* Determine if this is a ELF file.
*/
/*
* Allow writing only if originally specified read only.
* This is only necessary if the file must be translating
* from one encoding to another.
*/
return (0);
}
}
return (elf);
}
/*
* Determine if this is an Archive
*/
return (elf);
}
/*
* Return a few ident bytes, but not so many that
* getident() must read a large file. 512 is arbitrary.
*/
return (elf);
}
Elf *
{
unsigned work;
/*
* version() no called yet?
*/
_elf_seterr(ESEQ_VER, 0);
return (0);
}
return (0);
}
return (elf);
}
/*
* The following is a private interface between the linkers (ld & ld.so.1)
* and libelf.
*
* elf_begin(0, ELF_C_IMAGE, ref)
* Return a new elf_descriptor which uses the memory image from
* ref as the base image of the elf file. Before this elf_begin()
* is called an elf_update(ref, ELF_C_WRIMAGE) must have been
* done to the ref elf descriptor.
* The ELF_C_IMAGE is unique in that modificatino of the Elf structure
* is illegal (no elf_new*()) but you can modify the actual
* data image of the file in question.
*
* When you are done processing this file you can then perform a
* elf_end() on it.
*
* NOTE: if an elf_update(ref, ELF_C_WRITE) is done on the ref Elf
* descriptor then the memory image that the ELF_C_IMAGE
* is using has been discarded. The proper calling convention
* for this is as follows:
*
* elf1 = elf_begin(fd, ELF_C_WRITE, 0);
* ...
* elf_update(elf1, ELF_C_WRIMAGE); build memory image
* elf2 = elf_begin(0, ELF_C_IMAGE, elf1);
* ...
* elf_end(elf2);
* elf_updage(elf1, ELF_C_WRITE); flush memory image to disk
* elf_end(elf1);
*
*
* elf_begin(0, ELF_C_IMAGE, 0);
* returns a pointer to an elf descriptor as if it were opened
* with ELF_C_WRITE except that it has no file descriptor and it
* will not create a file. It's to be used with the command:
*
* elf_update(elf, ELF_C_WRIMAGE)
*
* which will build a memory image instead of a file image.
* The memory image is allocated via dynamic memory (malloc) and
* can be free with a subsequent call to
*
* elf_update(elf, ELF_C_WRITE)
*
* NOTE: that if elf_end(elf) is called it will not free the
* memory image if it is still allocated. It is then
* the callers responsiblity to free it via a call
* to free().
*
* Here is a potential calling sequence for this interface:
*
* elf1 = elf_begin(0, ELF_C_IMAGE, 0);
* ...
* elf_update(elf1, ELF_C_WRIMAGE); build memory image
* elf2 = elf_begin(0, ELF_C_IMAGE, elf1);
* ...
* image_ptr = elf32_getehdr(elf2); get pointer to image
* elf_end(elf2);
* elf_end(elf1);
* ...
* use image
* ...
* free(image_ptr);
*/
Elf *
{
unsigned work;
unsigned flags = 0;
{
_elf_seterr(ESEQ_VER, 0);
return (0);
}
switch (cmd) {
default:
_elf_seterr(EREQ_BEGIN, 0);
return (0);
case ELF_C_NULL:
return (0);
case ELF_C_IMAGE:
if (ref) {
char *image;
return (0);
}
}
/* FALLTHROUGH */
case ELF_C_WRITE:
return (0);
}
if (cmd == ELF_C_IMAGE)
return (elf);
case ELF_C_RDWR:
break;
case ELF_C_READ:
break;
}
/*
* A null ref asks for a new file
* Non-null ref bumps the activation count
* or gets next archive member
*/
if (ref == 0) {
return (0);
} else {
_elf_seterr(EREQ_RDWR, 0);
return (0);
}
/*
* new activation ?
*/
return (ref);
}
return (0);
}
}
return (elf);
}