linker.h revision 199767f8919635c4928607450d9e0abb932109ce
/*-
* Copyright (c) 1997-2000 Doug Rabson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _SYS_LINKER_H_
#define _SYS_LINKER_H_
#ifdef _KERNEL
#ifdef MALLOC_DECLARE
#endif
struct mod_depend;
/*
* Object representing a file which has been loaded by the linker.
*/
typedef struct linker_file* linker_file_t;
typedef int (*linker_function_name_callback_t)(const char *, void *);
/*
* expanded out linker_sym_t
*/
typedef struct linker_symval {
const char* name;
struct common_symbol {
char* name;
};
struct linker_file {
int refs; /* reference count */
int userrefs; /* kldload(2) count */
int flags;
char* filename; /* file which was loaded */
char* pathname; /* file name with full path */
int id; /* unique id */
int ndeps; /* number of dependencies */
int loadcnt; /* load counter value */
/*
* Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT)
* fields.
*/
int nenabled; /* number of enabled probes. */
int fbt_nentries; /* number of fbt entries created. */
};
/*
* Object implementing a class of file (a.out, elf, etc.)
*/
typedef struct linker_class *linker_class_t;
struct linker_class {
};
/*
* Function type used when iterating over the list of linker files.
*/
typedef int linker_predicate_t(linker_file_t, void *);
/*
* The "file" for the kernel.
*/
extern linker_file_t linker_kernel_file;
/*
* Obtain a reference to a module, loading it if required.
*/
/*
* Release a reference to a module, unloading it if there are no more
* references. Note that one should either provide a module name and
* optional version info or a linker file, but not both.
*/
/*
* Iterate over all of the currently loaded linker files calling the
* predicate function while the function returns 0. Returns the value
* returned by the last predicate function.
*/
/*
* Lookup a symbol in a file. If deps is TRUE, look in dependencies
* if not found in file.
*/
int _deps);
/*
* Lookup a linker set in a file. Return pointers to the first entry,
* last + 1, and count of entries. Use: for (p = start; p < stop; p++) {}
* void *start is really: "struct yoursetmember ***start;"
*/
/*
* List all functions in a file.
*/
linker_function_nameval_callback_t, void *);
/*
* Functions soley for use by the linker class handlers.
*/
/*
*/
long *_diffp);
long *offset);
/*
* stack(9) helper for situations where kernel locking is required.
*/
long *offset);
/* HWPMC helper */
void *linker_hwpmc_list_objects(void);
#endif /* _KERNEL */
/*
* Module information subtypes
*/
/* These values are MD on these two platforms */
#if !defined(__sparc64__) && !defined(__powerpc__)
#endif
#ifdef _KERNEL
})
#endif
#ifdef _KERNEL
/*
* Module lookup
*/
extern vm_offset_t preload_addr_relocate;
extern caddr_t preload_metadata;
extern void preload_delete_name(const char *_name);
#ifdef KLD_DEBUG
extern int kld_debug;
do { \
} while (0)
#else
#endif
/* Support functions */
int elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
typedef struct linker_ctf {
int ctfcnt; /* Number of CTF data bytes. */
int nsym; /* Number of symbols. */
const char *strtab; /* Ptr to the string table. */
int strcnt; /* Number of string bytes. */
long *typlenp; /* Ptr to number of type data entries. */
} linker_ctf_t;
/* values for type */
#define ELF_RELOC_REL 1
#define ELF_RELOC_RELA 2
/*
* This is version 1 of the KLD file status structure. It is identified
* by its _size_ in the version field.
*/
struct kld_file_stat_1 {
int version; /* set to sizeof(struct kld_file_stat_1) */
char name[MAXPATHLEN];
int refs;
int id;
};
#endif /* _KERNEL */
struct kld_file_stat {
int version; /* set to sizeof(struct kld_file_stat) */
char name[MAXPATHLEN];
int refs;
int id;
char pathname[MAXPATHLEN];
};
struct kld_sym_lookup {
int version; /* set to sizeof(struct kld_sym_lookup) */
char *symname; /* Symbol name we are looking up */
};
#define KLDSYM_LOOKUP 1
/*
* Flags for kldunloadf() and linker_file_unload()
*/
#define LINKER_UNLOAD_NORMAL 0
#define LINKER_UNLOAD_FORCE 1
#ifndef _KERNEL
int kldfirstmod(int _fileid);
#endif
#endif /* !_SYS_LINKER_H_ */