| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: subr_kobj.c,v 1.35 2009/05/23 15:13:57 ad Exp $ */ | | 1 | /* $NetBSD: subr_kobj.c,v 1.36 2009/05/24 15:00:24 ad Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software developed for The NetBSD Foundation | | 7 | * This code is derived from software developed for The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -53,107 +53,48 @@ | | | @@ -53,107 +53,48 @@ |
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 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 | | 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 | | 55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 | * SUCH DAMAGE. | | 56 | * SUCH DAMAGE. |
57 | */ | | 57 | */ |
58 | | | 58 | |
59 | /* | | 59 | /* |
60 | * Kernel loader for ELF objects. | | 60 | * Kernel loader for ELF objects. |
61 | * | | 61 | * |
62 | * TODO: adjust kmem_alloc() calls to avoid needless fragmentation. | | 62 | * TODO: adjust kmem_alloc() calls to avoid needless fragmentation. |
63 | */ | | 63 | */ |
64 | | | 64 | |
65 | #include <sys/cdefs.h> | | 65 | #include <sys/cdefs.h> |
66 | __KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.35 2009/05/23 15:13:57 ad Exp $"); | | 66 | __KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.36 2009/05/24 15:00:24 ad Exp $"); |
67 | | | 67 | |
68 | #include "opt_modular.h" | | 68 | #include "opt_modular.h" |
69 | | | 69 | |
70 | #define ELFSIZE ARCH_ELFSIZE | | 70 | #include <sys/kobj_impl.h> |
71 | | | | |
72 | #include <sys/systm.h> | | | |
73 | #include <sys/kobj.h> | | | |
74 | #include <sys/errno.h> | | | |
75 | | | 71 | |
76 | #ifdef MODULAR | | 72 | #ifdef MODULAR |
77 | | | 73 | |
78 | #include <sys/param.h> | | 74 | #include <sys/param.h> |
79 | #include <sys/kernel.h> | | 75 | #include <sys/kernel.h> |
80 | #include <sys/kmem.h> | | 76 | #include <sys/kmem.h> |
81 | #include <sys/proc.h> | | 77 | #include <sys/proc.h> |
82 | #include <sys/namei.h> | | 78 | #include <sys/namei.h> |
83 | #include <sys/vnode.h> | | 79 | #include <sys/vnode.h> |
84 | #include <sys/fcntl.h> | | 80 | #include <sys/fcntl.h> |
85 | #include <sys/ksyms.h> | | 81 | #include <sys/ksyms.h> |
86 | #include <sys/module.h> | | 82 | #include <sys/module.h> |
87 | #include <sys/exec.h> | | | |
88 | #include <sys/exec_elf.h> | | | |
89 | | | 83 | |
90 | #include <machine/stdarg.h> | | 84 | #include <machine/stdarg.h> |
91 | | | 85 | |
92 | #include <uvm/uvm_extern.h> | | 86 | #include <uvm/uvm_extern.h> |
93 | | | 87 | |
94 | typedef struct { | | | |
95 | void *addr; | | | |
96 | Elf_Off size; | | | |
97 | int flags; | | | |
98 | int sec; /* Original section */ | | | |
99 | const char *name; | | | |
100 | } progent_t; | | | |
101 | | | | |
102 | typedef struct { | | | |
103 | Elf_Rel *rel; | | | |
104 | int nrel; | | | |
105 | int sec; | | | |
106 | size_t size; | | | |
107 | } relent_t; | | | |
108 | | | | |
109 | typedef struct { | | | |
110 | Elf_Rela *rela; | | | |
111 | int nrela; | | | |
112 | int sec; | | | |
113 | size_t size; | | | |
114 | } relaent_t; | | | |
115 | | | | |
116 | typedef enum kobjtype { | | | |
117 | KT_UNSET, | | | |
118 | KT_VNODE, | | | |
119 | KT_MEMORY | | | |
120 | } kobjtype_t; | | | |
121 | | | | |
122 | struct kobj { | | | |
123 | char ko_name[MAXMODNAME]; | | | |
124 | kobjtype_t ko_type; | | | |
125 | void *ko_source; | | | |
126 | ssize_t ko_memsize; | | | |
127 | vaddr_t ko_address; /* Relocation address */ | | | |
128 | Elf_Shdr *ko_shdr; | | | |
129 | progent_t *ko_progtab; | | | |
130 | relaent_t *ko_relatab; | | | |
131 | relent_t *ko_reltab; | | | |
132 | Elf_Sym *ko_symtab; /* Symbol table */ | | | |
133 | char *ko_strtab; /* String table */ | | | |
134 | char *ko_shstrtab; /* Section name string table */ | | | |
135 | size_t ko_size; /* Size of text/data/bss */ | | | |
136 | size_t ko_symcnt; /* Number of symbols */ | | | |
137 | size_t ko_strtabsz; /* Number of bytes in string table */ | | | |
138 | size_t ko_shstrtabsz; /* Number of bytes in scn str table */ | | | |
139 | size_t ko_shdrsz; | | | |
140 | int ko_nrel; | | | |
141 | int ko_nrela; | | | |
142 | int ko_nprogtab; | | | |
143 | bool ko_ksyms; | | | |
144 | bool ko_loaded; | | | |
145 | }; | | | |
146 | | | | |
147 | static int kobj_relocate(kobj_t, bool); | | 88 | static int kobj_relocate(kobj_t, bool); |
148 | static int kobj_checksyms(kobj_t, bool); | | 89 | static int kobj_checksyms(kobj_t, bool); |
149 | static void kobj_error(const char *, ...); | | 90 | static void kobj_error(const char *, ...); |
150 | static int kobj_read(kobj_t, void **, size_t, off_t); | | 91 | static int kobj_read(kobj_t, void **, size_t, off_t); |
151 | static int kobj_read_bits(kobj_t, void *, size_t, off_t); | | 92 | static int kobj_read_bits(kobj_t, void *, size_t, off_t); |
152 | static void kobj_jettison(kobj_t); | | 93 | static void kobj_jettison(kobj_t); |
153 | static void kobj_free(kobj_t, void *, size_t); | | 94 | static void kobj_free(kobj_t, void *, size_t); |
154 | static void kobj_close(kobj_t); | | 95 | static void kobj_close(kobj_t); |
155 | static int kobj_load(kobj_t); | | 96 | static int kobj_load(kobj_t); |
156 | | | 97 | |
157 | extern struct vm_map *module_map; | | 98 | extern struct vm_map *module_map; |
158 | | | 99 | |
159 | /* | | 100 | /* |