199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1997-2000 Doug Rabson
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SYS_LINKER_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SYS_LINKER_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/elf.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/kobj.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef MALLOC_DECLARE
199767f8919635c4928607450d9e0abb932109ceToomas SoomeMALLOC_DECLARE(M_LINKER);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct mod_depend;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Object representing a file which has been loaded by the linker.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct linker_file* linker_file_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef TAILQ_HEAD(, linker_file) linker_file_list_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef caddr_t linker_sym_t; /* opaque symbol */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef c_caddr_t c_linker_sym_t; /* const opaque symbol */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int (*linker_function_name_callback_t)(const char *, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * expanded out linker_sym_t
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct linker_symval {
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char* name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome caddr_t value;
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} linker_symval_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int (*linker_function_nameval_callback_t)(linker_file_t, int, linker_symval_t *, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct common_symbol {
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_ENTRY(common_symbol) link;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char* name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome caddr_t address;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct linker_file {
199767f8919635c4928607450d9e0abb932109ceToomas Soome KOBJ_FIELDS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int refs; /* reference count */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int userrefs; /* kldload(2) count */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_FILE_LINKED 0x1 /* file has been fully linked */
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_ENTRY(linker_file) link; /* list of all loaded files */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char* filename; /* file which was loaded */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char* pathname; /* file name with full path */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int id; /* unique id */
199767f8919635c4928607450d9e0abb932109ceToomas Soome caddr_t address; /* load address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t size; /* size of file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome caddr_t ctors_addr; /* address of .ctors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t ctors_size; /* size of .ctors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int ndeps; /* number of dependencies */
199767f8919635c4928607450d9e0abb932109ceToomas Soome linker_file_t* deps; /* list of dependencies */
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_HEAD(, common_symbol) common; /* list of common symbols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_HEAD(, module) modules; /* modules in this file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_ENTRY(linker_file) loaded; /* preload dependency support */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int loadcnt; /* load counter value */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Function Boundary Tracing (FBT) or Statically Defined Tracing (SDT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fields.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int nenabled; /* number of enabled probes. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int fbt_nentries; /* number of fbt entries created. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Object implementing a class of file (a.out, elf, etc.)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct linker_class *linker_class_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef TAILQ_HEAD(, linker_class) linker_class_list_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct linker_class {
199767f8919635c4928607450d9e0abb932109ceToomas Soome KOBJ_CLASS_FIELDS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome TAILQ_ENTRY(linker_class) link; /* list of all file classes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Function type used when iterating over the list of linker files.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int linker_predicate_t(linker_file_t, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The "file" for the kernel.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern linker_file_t linker_kernel_file;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Obtain a reference to a module, loading it if required.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_reference_module(const char* _modname, struct mod_depend *_verinfo,
199767f8919635c4928607450d9e0abb932109ceToomas Soome linker_file_t* _result);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Release a reference to a module, unloading it if there are no more
199767f8919635c4928607450d9e0abb932109ceToomas Soome * references. Note that one should either provide a module name and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * optional version info or a linker file, but not both.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_release_module(const char *_modname, struct mod_depend *_verinfo,
199767f8919635c4928607450d9e0abb932109ceToomas Soome linker_file_t _file);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Iterate over all of the currently loaded linker files calling the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * predicate function while the function returns 0. Returns the value
199767f8919635c4928607450d9e0abb932109ceToomas Soome * returned by the last predicate function.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_foreach(linker_predicate_t *_predicate, void *_context);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a symbol in a file. If deps is TRUE, look in dependencies
199767f8919635c4928607450d9e0abb932109ceToomas Soome * if not found in file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomecaddr_t linker_file_lookup_symbol(linker_file_t _file, const char* _name,
199767f8919635c4928607450d9e0abb932109ceToomas Soome int _deps);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a linker set in a file. Return pointers to the first entry,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * last + 1, and count of entries. Use: for (p = start; p < stop; p++) {}
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void *start is really: "struct yoursetmember ***start;"
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_lookup_set(linker_file_t _file, const char *_name,
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *_start, void *_stop, int *_count);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List all functions in a file.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_function_listall(linker_file_t,
199767f8919635c4928607450d9e0abb932109ceToomas Soome linker_function_nameval_callback_t, void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Functions soley for use by the linker class handlers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_add_class(linker_class_t _cls);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_file_unload(linker_file_t _file, int flags);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_load_dependencies(linker_file_t _lf);
199767f8919635c4928607450d9e0abb932109ceToomas Soomelinker_file_t linker_make_file(const char* _filename, linker_class_t _cls);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DDB Helpers, tuned specifically for ddb/db_kld.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_lookup(const char *_symstr, c_linker_sym_t *_sym);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_search_symbol(caddr_t _value, c_linker_sym_t *_sym,
199767f8919635c4928607450d9e0abb932109ceToomas Soome long *_diffp);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_symbol_values(c_linker_sym_t _sym, linker_symval_t *_symval);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen,
199767f8919635c4928607450d9e0abb932109ceToomas Soome long *offset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * stack(9) helper for situations where kernel locking is required.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_search_symbol_name(caddr_t value, char *buf, u_int buflen,
199767f8919635c4928607450d9e0abb932109ceToomas Soome long *offset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* HWPMC helper */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid *linker_hwpmc_list_objects(void);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Module information subtypes
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_END 0x0000 /* End of list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_NAME 0x0001 /* Name of module (string) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_TYPE 0x0002 /* Type of module (string) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_ADDR 0x0003 /* Loaded address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_SIZE 0x0004 /* Size of module */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_EMPTY 0x0005 /* Has been deleted */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_ARGS 0x0006 /* Parameters string */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFO_METADATA 0x8000 /* Module-specfic */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_AOUTEXEC 0x0001 /* a.out exec header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_ELFHDR 0x0002 /* ELF header */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_SSYM 0x0003 /* start of symbols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_ESYM 0x0004 /* end of symbols */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_DYNAMIC 0x0005 /* _DYNAMIC pointer */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* These values are MD on these two platforms */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !defined(__sparc64__) && !defined(__powerpc__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_ENVP 0x0006 /* envp[] */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_HOWTO 0x0007 /* boothowto */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_KERNEND 0x0008 /* kernend */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_SHDR 0x0009 /* section header table */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_CTORS_ADDR 0x000a /* address of .ctors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_CTORS_SIZE 0x000b /* size of .ctors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_FW_HANDLE 0x000c /* Firmware dependent handle */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_NOCOPY 0x8000 /* don't copy this metadata to the kernel */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MODINFOMD_DEPLIST (0x4001 | MODINFOMD_NOCOPY) /* depends on */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MD_FETCH(mdp, info, type) ({ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome type *__p; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __p = (type *)preload_search_info((mdp), MODINFO_METADATA | (info)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __p ? *__p : 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome})
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_HINTS_VERSION 1 /* linker.hints file version */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_HINTS_MAX (1 << 20) /* Allow at most 1MB for linker.hints */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Module lookup
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern vm_offset_t preload_addr_relocate;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_metadata;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void * preload_fetch_addr(caddr_t _mod);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern size_t preload_fetch_size(caddr_t _mod);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_by_name(const char *_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_by_type(const char *_type);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_next_name(caddr_t _base);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern caddr_t preload_search_info(caddr_t _mod, int _inf);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void preload_delete_name(const char *_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern void preload_bootstrap_relocate(vm_offset_t _offset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef KLD_DEBUG
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern int kld_debug;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KLD_DEBUG_FILE 1 /* file load/unload */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KLD_DEBUG_SYM 2 /* symbol lookup */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KLD_DPF(cat, args) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome do { \
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (kld_debug & KLD_DEBUG_##cat) printf args; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome } while (0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KLD_DPF(cat, args)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int elf_lookup_fn(linker_file_t, Elf_Size, int, Elf_Addr *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Support functions */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint elf_reloc(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint elf_reloc_local(linker_file_t _lf, Elf_Addr base, const void *_rel, int _type, elf_lookup_fn _lu);
199767f8919635c4928607450d9e0abb932109ceToomas SoomeElf_Addr elf_relocaddr(linker_file_t _lf, Elf_Addr addr);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst Elf_Sym *elf_get_sym(linker_file_t _lf, Elf_Size _symidx);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeconst char *elf_get_symname(linker_file_t _lf, Elf_Size _symidx);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct linker_ctf {
199767f8919635c4928607450d9e0abb932109ceToomas Soome const uint8_t *ctftab; /* Decompressed CTF data. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int ctfcnt; /* Number of CTF data bytes. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const Elf_Sym *symtab; /* Ptr to the symbol table. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int nsym; /* Number of symbols. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *strtab; /* Ptr to the string table. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int strcnt; /* Number of string bytes. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t **ctfoffp; /* Ptr to array of obj/fnc offsets. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t **typoffp; /* Ptr to array of type offsets. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome long *typlenp; /* Ptr to number of type data entries. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} linker_ctf_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint linker_ctf_get(linker_file_t, linker_ctf_t *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint elf_cpu_load_file(linker_file_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint elf_cpu_unload_file(linker_file_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* values for type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ELF_RELOC_REL 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ELF_RELOC_RELA 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is version 1 of the KLD file status structure. It is identified
199767f8919635c4928607450d9e0abb932109ceToomas Soome * by its _size_ in the version field.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct kld_file_stat_1 {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int version; /* set to sizeof(struct kld_file_stat_1) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char name[MAXPATHLEN];
199767f8919635c4928607450d9e0abb932109ceToomas Soome int refs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int id;
199767f8919635c4928607450d9e0abb932109ceToomas Soome caddr_t address; /* load address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t size; /* size in bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _KERNEL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct kld_file_stat {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int version; /* set to sizeof(struct kld_file_stat) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char name[MAXPATHLEN];
199767f8919635c4928607450d9e0abb932109ceToomas Soome int refs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int id;
199767f8919635c4928607450d9e0abb932109ceToomas Soome caddr_t address; /* load address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t size; /* size in bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char pathname[MAXPATHLEN];
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct kld_sym_lookup {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int version; /* set to sizeof(struct kld_sym_lookup) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *symname; /* Symbol name we are looking up */
199767f8919635c4928607450d9e0abb932109ceToomas Soome u_long symvalue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t symsize;
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KLDSYM_LOOKUP 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags for kldunloadf() and linker_file_unload()
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_UNLOAD_NORMAL 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LINKER_UNLOAD_FORCE 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _KERNEL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome__BEGIN_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldload(const char* _file);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldunload(int _fileid);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldunloadf(int _fileid, int flags);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldfind(const char* _file);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldnext(int _fileid);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldstat(int _fileid, struct kld_file_stat* _stat);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldfirstmod(int _fileid);
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint kldsym(int _fileid, int _cmd, void *_data);
199767f8919635c4928607450d9e0abb932109ceToomas Soome__END_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_SYS_LINKER_H_ */