decl.h revision 3c573fcc51430b02603f62713f3f5d1b0b1aed1c
/*
* 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 (c) 1988 AT&T */
/* All Rights Reserved */
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _DECL_H
#define _DECL_H
#include <thread.h>
#include <note.h>
#include <_libelf.h>
#include <msg.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Data alignment
* An elf file is defined to have its structures aligned on
* appropriate boundaries. The following type lets the
* library test whether the file's alignment meets its own
* constraints in memory. This assumes every machine uses
* an alignment that is no greater than an object's size.
* The pointer isn't relevant for the file, but the code uses
* it to get memory alignment. ANSI C void * holds any pointer,
* making it appropriate here.
*/
typedef union
{
Elf32_Word w;
Elf32_Addr a;
Elf32_Off o;
} Elf32;
typedef union {
Elf64_Xword x;
Elf64_Word w;
Elf64_Addr a;
Elf64_Off o;
Elf_Void *p;
} Elf64;
/*
* Memory allocation
* Structures are obtained several ways: file mapping,
* malloc(), from the user. A status bit in the structures
* tells whether an object was obtained with malloc() and
* therefore should be released with free(). The bits
* named ...ALLOC indicate this.
*/
/*
* Data descriptor
* db_data must be first in the Dnode structure, because
* &db_data must == &Dnode.
*
* db_buf is a pointer to an allocated buffer. The same value
* goes into db_data.d_buf originally, but the user can touch
* it. If the data buffer is not to be freed, db_buf is null.
*
* When "reading" an input file's buffer, the data are left
* alone until needed. When they've been converted to internal
* form, the READY flag is set.
*
* db_raw points to a parallel raw buffer. Raw buffers
* have null db_raw.
*/
struct Dnode
{
unsigned db_uflags; /* user flags: ELF_F_... */
unsigned db_myflags; /* internal flags: DBF_... */
};
/*
* Section descriptor
* These are sometimes allocated in a block. If the SF_ALLOC
* bit is set in the flags, the Scn address may be passed to free.
* The caller must first follow the s_next list to the next freeable
* node, because free can clobber the s_next value in the block.
*/
struct Elf_Scn
{
int s_err; /* for delaying data error */
unsigned s_shflags; /* user shdr flags */
unsigned s_uflags; /* user flags */
unsigned s_myflags; /* SF_... */
};
/*
* Designates whether or not we are in a threaded_app.
*/
extern int *_elf_libc_threaded;
#ifdef __lock_lint
#else
#define SCNLOCK(x) \
if (elf_threaded) \
#endif
#ifdef __lock_lint
#else
#define SCNUNLOCK(x) \
if (elf_threaded) \
#endif
#ifdef __lock_lint
#define UPGRADELOCKS(e, s)\
#else
#define UPGRADELOCKS(e, s)\
if (elf_threaded) { \
}
#endif
#ifdef __lock_lint
#define DOWNGRADELOCKS(e, s)\
#else
#define DOWNGRADELOCKS(e, s)\
if (elf_threaded) { \
}
#endif
#ifdef __lock_lint
#define READLOCKS(e, s) \
#else
#define READLOCKS(e, s) \
if (elf_threaded) { \
}
#endif
#ifdef __lock_lint
#define READUNLOCKS(e, s) \
#else
#define READUNLOCKS(e, s) \
if (elf_threaded) { \
}
#endif
struct Snode32
{
};
struct Snode64
{
};
/*
* A file's status controls how the library can use file data.
* This is important to keep "raw" operations and "cooked"
* operations from interfering with each other.
*
* A file's status is "fresh" until something touches it.
* If the first thing is a raw operation, we freeze the data
* and force all cooking operations to make a copy. If the
* first operation cooks, raw operations use the file system.
*/
typedef enum
{
ES_FRESH = 0, /* unchanged */
ES_COOKED, /* translated */
ES_FROZEN /* raw, can't be translated */
} Status;
/*
* Elf descriptor
* The major handle between user code and the library.
*
* Descriptors can have parents: archive members reference
* the archive itself. Relevant "offsets:"
*
* ed_baseoff The file offset, relative to zero, to the first
* byte in the file. For all files, this gives
* the lseek(fd, ed_baseoff, 0) value.
*
* ed_memoff The offset from the beginning of the nesting file
* to the bytes of a member. For an archive member,
* this is the offset from the beginning of the
* archive to the member bytes (not the hdr). If an
* archive member slides, memoff changes.
*
* ed_siboff Similar to ed_memoff, this gives the offset from
* the beginning of the nesting file to the following
* sibling's header (not the sibling's bytes). This
* value is necessary, because of archive sliding.
*
* ed_nextoff For an archive, this gives the offset of the next
* member to process on elf_begin. That is,
* (ed_ident + ed_nextoff) gives pointer to member hdr.
*
* Keeping these absolute and relative offsets allows nesting of
* files, including archives within archives, etc. The only current
* nesting file is archive, but others might be supported.
*
* ed_image This is a pointer to the base memory image holding
* the file. Library code assumes the image is aligned
* to a boundary appropriate for any object. This must
* be true, because we get an image only from malloc
* or mmap, both of which guarantee alignment.
*/
struct Elf
{
int ed_activ; /* activation count */
int ed_fd; /* file descriptor */
char *ed_image; /* pointer to file image */
char *ed_wrimage; /* pointer to output image */
char *ed_ident; /* file start, getident() bytes */
char *ed_raw; /* raw file ptr */
unsigned *ed_vm; /* virtual memory map */
unsigned ed_encode; /* data encoding */
unsigned ed_version; /* file version */
int ed_class; /* file class */
char *ed_arstr; /* archive string table */
unsigned ed_myflags; /* EDF_... */
unsigned ed_ehflags; /* ehdr flags */
unsigned ed_phflags; /* phdr flags */
unsigned ed_uflags; /* elf descriptor flags */
};
#ifdef __lock_lint
#else
#define ELFRLOCK(e) \
if (elf_threaded) \
#endif
#ifdef __lock_lint
#else
#define ELFWLOCK(e) \
if (elf_threaded) \
#endif
#ifdef __lock_lint
#else
#define ELFUNLOCK(e) \
if (elf_threaded) \
#endif
typedef enum
{
OK_YES = 0,
OK_NO = ~0
} Okay;
#define _(a) a
/*
* Max size for an Elf error message string
*/
#define MAXELFERR 1024
/*
* General thread management macros
*/
#ifdef __lock_lint
#define ELFACCESSDATA(a, b) \
(void) mutex_lock(&_elf_globals_mutex); \
a = b; \
(void) mutex_unlock(&_elf_globals_mutex);
#else
#define ELFACCESSDATA(a, b) \
if (elf_threaded) { \
(void) mutex_lock(&_elf_globals_mutex); \
a = b; \
(void) mutex_unlock(&_elf_globals_mutex); \
} else \
a = b;
#endif
#ifdef __lock_lint
#define ELFRWLOCKINIT(lock) \
#else
#define ELFRWLOCKINIT(lock) \
if (elf_threaded) { \
}
#endif
#ifdef __lock_lint
#define ELFMUTEXINIT(lock) \
#else
#define ELFMUTEXINIT(lock) \
if (elf_threaded) { \
}
#endif
extern void _elf_arinit(Elf *);
extern Dnode *_elf_dnode(void);
extern char *_elf_outmap(int, size_t, unsigned *);
extern Snode32 *_elf32_snode(void);
extern Snode64 *_elf64_snode(void);
extern void _elf_unmap(char *, size_t);
extern int _elf32_ehdr(Elf *, int);
extern int _elf32_phdr(Elf *, int);
extern int _elf32_shdr(Elf *, int);
extern int _elf64_ehdr(Elf *, int);
extern int _elf64_phdr(Elf *, int);
extern int _elf64_shdr(Elf *, int);
extern int _elf_byte;
extern const Elf32_Ehdr _elf32_ehdr_init;
extern const Elf64_Ehdr _elf64_ehdr_init;
extern unsigned _elf_encode;
extern _elf_execfill_func_t *_elf_execfill_func;
extern void _elf_seterr(Msg, int);
extern const Snode32 _elf32_snode_init;
extern const Snode64 _elf64_snode_init;
extern const Dnode _elf_dnode_init;
extern unsigned _elf_work;
extern mutex_t _elf_globals_mutex;
/* CSTYLED */
#ifdef __cplusplus
}
#endif
#endif /* _DECL_H */