summaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-25 17:22:32 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-25 17:22:32 +0000
commit4f4bcfcd1a3b57317f601eeca5c61ed8916468f6 (patch)
treec6c213e9af883b283d6a6a5d9d380982e4656670 /modutils
parentc57a75d896431eda8d1c3dd018b34706bea67e81 (diff)
downloadbusybox-w32-4f4bcfcd1a3b57317f601eeca5c61ed8916468f6.tar.gz
busybox-w32-4f4bcfcd1a3b57317f601eeca5c61ed8916468f6.tar.bz2
busybox-w32-4f4bcfcd1a3b57317f601eeca5c61ed8916468f6.zip
Some more cleanups for insmod from Larry.
-Erik
Diffstat (limited to 'modutils')
-rw-r--r--modutils/insmod.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index c6642a052..4dd14c6bc 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -1,6 +1,7 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * Mini insmod implementation for busybox 3 * Mini insmod implementation for busybox
4 * This version of insmod now supports x86, ARM, SH3/4, powerpc, and MIPS.
4 * 5 *
5 * Copyright (C) 1999,2000,2001 by Lineo, inc. 6 * Copyright (C) 1999,2000,2001 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com> 7 * Written by Erik Andersen <andersen@lineo.com>
@@ -123,7 +124,7 @@
123#ifndef MODUTILS_MODULE_H 124#ifndef MODUTILS_MODULE_H
124static const int MODUTILS_MODULE_H = 1; 125static const int MODUTILS_MODULE_H = 1;
125 126
126#ident "$Id: insmod.c,v 1.58 2001/04/24 21:41:41 andersen Exp $" 127#ident "$Id: insmod.c,v 1.59 2001/04/25 17:22:32 andersen Exp $"
127 128
128/* This file contains the structures used by the 2.0 and 2.1 kernels. 129/* This file contains the structures used by the 2.0 and 2.1 kernels.
129 We do not use the kernel headers directly because we do not wish 130 We do not use the kernel headers directly because we do not wish
@@ -329,7 +330,7 @@ int delete_module(const char *);
329#ifndef MODUTILS_OBJ_H 330#ifndef MODUTILS_OBJ_H
330static const int MODUTILS_OBJ_H = 1; 331static const int MODUTILS_OBJ_H = 1;
331 332
332#ident "$Id: insmod.c,v 1.58 2001/04/24 21:41:41 andersen Exp $" 333#ident "$Id: insmod.c,v 1.59 2001/04/25 17:22:32 andersen Exp $"
333 334
334/* The relocatable object is manipulated using elfin types. */ 335/* The relocatable object is manipulated using elfin types. */
335 336
@@ -1787,7 +1788,10 @@ static int old_get_kernel_symbols(const char *m_name)
1787 1788
1788 nks = get_kernel_syms(NULL); 1789 nks = get_kernel_syms(NULL);
1789 if (nks <= 0) { 1790 if (nks <= 0) {
1790 perror_msg("get_kernel_syms: %s", m_name); 1791 if (nks)
1792 perror_msg("get_kernel_syms: %s", m_name);
1793 else
1794 error_msg("No kernel symbols");
1791 return 0; 1795 return 0;
1792 } 1796 }
1793 1797
@@ -1807,7 +1811,6 @@ static int old_get_kernel_symbols(const char *m_name)
1807 1811
1808 while (k->name[0] == '#' && k->name[1]) { 1812 while (k->name[0] == '#' && k->name[1]) {
1809 struct old_kernel_sym *k2; 1813 struct old_kernel_sym *k2;
1810 struct new_module_symbol *s;
1811 1814
1812 /* Find out how many symbols this module has. */ 1815 /* Find out how many symbols this module has. */
1813 for (k2 = k + 1; k2->name[0] != '#'; ++k2) 1816 for (k2 = k + 1; k2->name[0] != '#'; ++k2)
@@ -2277,7 +2280,7 @@ static int new_get_kernel_symbols(void)
2277 module_names = xmalloc(bufsize = 256); 2280 module_names = xmalloc(bufsize = 256);
2278 retry_modules_load: 2281 retry_modules_load:
2279 if (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) { 2282 if (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) {
2280 if (errno == ENOSPC) { 2283 if (errno == ENOSPC && bufsize < ret) {
2281 module_names = xrealloc(module_names, bufsize = ret); 2284 module_names = xrealloc(module_names, bufsize = ret);
2282 goto retry_modules_load; 2285 goto retry_modules_load;
2283 } 2286 }
@@ -2338,7 +2341,7 @@ static int new_get_kernel_symbols(void)
2338 syms = xmalloc(bufsize = 16 * 1024); 2341 syms = xmalloc(bufsize = 16 * 1024);
2339 retry_kern_sym_load: 2342 retry_kern_sym_load:
2340 if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) { 2343 if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) {
2341 if (errno == ENOSPC) { 2344 if (errno == ENOSPC && bufsize < ret) {
2342 syms = xrealloc(syms, bufsize = ret); 2345 syms = xrealloc(syms, bufsize = ret);
2343 goto retry_kern_sym_load; 2346 goto retry_kern_sym_load;
2344 } 2347 }
@@ -3022,6 +3025,12 @@ struct obj_file *obj_load(FILE * fp)
3022 for (i = 0; i < shnum; ++i) { 3025 for (i = 0; i < shnum; ++i) {
3023 struct obj_section *sec = f->sections[i]; 3026 struct obj_section *sec = f->sections[i];
3024 3027
3028 /* .modinfo should be contents only but gcc has no attribute for that.
3029 * The kernel may have marked .modinfo as ALLOC, ignore this bit.
3030 */
3031 if (strcmp(sec->name, ".modinfo") == 0)
3032 sec->header.sh_flags &= ~SHF_ALLOC;
3033
3025 if (sec->header.sh_flags & SHF_ALLOC) 3034 if (sec->header.sh_flags & SHF_ALLOC)
3026 obj_insert_section_load_order(f, sec); 3035 obj_insert_section_load_order(f, sec);
3027 3036
@@ -3045,22 +3054,20 @@ struct obj_file *obj_load(FILE * fp)
3045 3054
3046 /* Allocate space for a table of local symbols. */ 3055 /* Allocate space for a table of local symbols. */
3047 j = f->local_symtab_size = sec->header.sh_info; 3056 j = f->local_symtab_size = sec->header.sh_info;
3048 f->local_symtab = xmalloc(j *= 3057 f->local_symtab = xcalloc(j, sizeof(struct obj_symbol *));
3049 sizeof(struct obj_symbol *));
3050 memset(f->local_symtab, 0, j);
3051 3058
3052 /* Insert all symbols into the hash table. */ 3059 /* Insert all symbols into the hash table. */
3053 for (j = 1, ++sym; j < nsym; ++j, ++sym) { 3060 for (j = 1, ++sym; j < nsym; ++j, ++sym) {
3054 const char *name; 3061 const char *name;
3055 if (sym->st_name) 3062 if (sym->st_name)
3056 name = strtab + sym->st_name; 3063 name = strtab + sym->st_name;
3057 else 3064 else
3058 name = f->sections[sym->st_shndx]->name; 3065 name = f->sections[sym->st_shndx]->name;
3059 3066
3060 obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx, 3067 obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx,
3061 sym->st_value, sym->st_size); 3068 sym->st_value, sym->st_size);
3062 } 3069 }
3063 } 3070 }
3064 break; 3071 break;
3065 3072
3066 case SHT_RELM: 3073 case SHT_RELM:
@@ -3071,6 +3078,10 @@ struct obj_file *obj_load(FILE * fp)
3071 return NULL; 3078 return NULL;
3072 } 3079 }
3073 break; 3080 break;
3081 /* XXX Relocation code from modutils-2.3.19 is not here.
3082 * Why? That's about 20 lines of code from obj/obj_load.c,
3083 * which gets done in a second pass through the sections.
3084 * This BusyBox insmod does similar work in obj_relocate(). */
3074 } 3085 }
3075 } 3086 }
3076 3087