1/* $NetBSD: kobj_impl.h,v 1.5 2016/07/20 13:36:19 maxv Exp $ */ 2 3/*- 4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software developed for The NetBSD Foundation 8 * by Andrew Doran. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/*- 33 * Copyright (c) 1998-2000 Doug Rabson 34 * Copyright (c) 2004 Peter Wemm 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * SUCH DAMAGE. 57 */ 58 59/* 60 * Data structures private to kobj, shared only with kernel grovellers. 61 */ 62 63#ifndef _SYS_KOBJ_IMPL_H_ 64#define _SYS_KOBJ_IMPL_H_ 65 66#define ELFSIZE ARCH_ELFSIZE 67 68#include <sys/systm.h> 69#include <sys/kobj.h> 70#include <sys/exec.h> 71#include <sys/exec_elf.h> 72#include <sys/module.h> 73 74typedef struct { 75 void *addr; 76 Elf_Off size; 77 int flags; 78 int sec; /* Original section */ 79 const char *name; 80} progent_t; 81 82typedef struct { 83 Elf_Rel *rel; 84 int nrel; 85 int sec; 86 size_t size; 87} relent_t; 88 89typedef struct { 90 Elf_Rela *rela; 91 int nrela; 92 int sec; 93 size_t size; 94} relaent_t; 95 96typedef enum kobjtype { 97 KT_UNSET, 98 KT_VNODE, 99 KT_MEMORY 100} kobjtype_t; 101 102typedef int (*kobj_read_fn)(kobj_t, void **, size_t, off_t, bool); 103typedef void (*kobj_close_fn)(kobj_t); 104 105struct kobj { 106 char ko_name[MAXMODNAME]; 107 kobjtype_t ko_type; 108 void *ko_source; 109 ssize_t ko_memsize; 110 vaddr_t ko_text_address; /* Address of text segment */ 111 vaddr_t ko_data_address; /* Address of data segment */ 112 vaddr_t ko_rodata_address; /* Address of rodata segment */ 113 Elf_Shdr *ko_shdr; 114 progent_t *ko_progtab; 115 relaent_t *ko_relatab; 116 relent_t *ko_reltab; 117 Elf_Sym *ko_symtab; /* Symbol table */ 118 char *ko_strtab; /* String table */ 119 char *ko_shstrtab; /* Section name string table */ 120 size_t ko_text_size; /* Size of text segment */ 121 size_t ko_data_size; /* Size of data/bss segment */ 122 size_t ko_rodata_size; /* Size of rodata segment */ 123 size_t ko_symcnt; /* Number of symbols */ 124 size_t ko_strtabsz; /* Number of bytes in string table */ 125 size_t ko_shstrtabsz; /* Number of bytes in scn str table */ 126 size_t ko_shdrsz; 127 int ko_nrel; 128 int ko_nrela; 129 int ko_nprogtab; 130 bool ko_ksyms; 131 bool ko_loaded; 132 kobj_read_fn ko_read; 133 kobj_close_fn ko_close; 134}; 135 136#ifdef _KERNEL 137int kobj_load(kobj_t); 138void kobj_setname(kobj_t, const char *); 139#endif 140 141#endif /* _SYS_KOBJ_IMPL_H_ */ 142