aboutsummaryrefslogtreecommitdiff
path: root/modutils/modutils-24.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-01-31 14:22:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-01-31 14:22:24 +0000
commite35af567900ec2a7abb17e09cc5b5641f7faafe7 (patch)
treea1a065a9d053e10303720c90eb68b148701ebd8a /modutils/modutils-24.c
parentfc2a4fc2ba8022ce2ea6dc0f66ba4ef0be1fa805 (diff)
downloadbusybox-w32-e35af567900ec2a7abb17e09cc5b5641f7faafe7.tar.gz
busybox-w32-e35af567900ec2a7abb17e09cc5b5641f7faafe7.tar.bz2
busybox-w32-e35af567900ec2a7abb17e09cc5b5641f7faafe7.zip
modutils-24: use xasprintf and xzalloc where appropriate,
remove unreachanble code build system: correct some dependencies in config system init: convert one #if into if() - for Rob. function old new delta obj_string_patch 136 129 -7 bb_init_module_24 4759 4615 -144 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-151) Total: -151 bytes
Diffstat (limited to 'modutils/modutils-24.c')
-rw-r--r--modutils/modutils-24.c101
1 files changed, 36 insertions, 65 deletions
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c
index 7c7568639..4e112a06f 100644
--- a/modutils/modutils-24.c
+++ b/modutils/modutils-24.c
@@ -646,7 +646,7 @@ static enum obj_reloc arch_apply_relocation(struct obj_file *f,
646static void arch_create_got(struct obj_file *f); 646static void arch_create_got(struct obj_file *f);
647#if ENABLE_FEATURE_CHECK_TAINTED_MODULE 647#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
648static int obj_gpl_license(struct obj_file *f, const char **license); 648static int obj_gpl_license(struct obj_file *f, const char **license);
649#endif /* FEATURE_CHECK_TAINTED_MODULE */ 649#endif
650#endif /* obj.h */ 650#endif /* obj.h */
651//---------------------------------------------------------------------------- 651//----------------------------------------------------------------------------
652//--------end of modutils obj.h 652//--------end of modutils obj.h
@@ -1687,11 +1687,11 @@ static int arch_list_add(ElfW(RelM) *rel, struct arch_list_entry **list,
1687 } 1687 }
1688 1688
1689 if (pe == NULL) { 1689 if (pe == NULL) {
1690 pe = xmalloc(sizeof(struct arch_list_entry)); 1690 pe = xzalloc(sizeof(struct arch_list_entry));
1691 pe->next = *list; 1691 pe->next = *list;
1692 pe->addend = rel->r_addend; 1692 pe->addend = rel->r_addend;
1693 pe->offset = offset; 1693 pe->offset = offset;
1694 pe->inited = 0; 1694 /*pe->inited = 0;*/
1695 *list = pe; 1695 *list = pe;
1696 return size; 1696 return size;
1697 } 1697 }
@@ -2255,7 +2255,7 @@ add_symbols_from( struct obj_file *f,
2255 strcpy(name_buf, SYMBOL_PREFIX); 2255 strcpy(name_buf, SYMBOL_PREFIX);
2256 strcpy(name_buf + extra - 1, name); 2256 strcpy(name_buf + extra - 1, name);
2257 name = name_buf; 2257 name = name_buf;
2258#endif /* SYMBOL_PREFIX */ 2258#endif
2259 2259
2260 sym = obj_find_symbol(f, name); 2260 sym = obj_find_symbol(f, name);
2261 if (sym && !(ELF_ST_BIND(sym->info) == STB_LOCAL)) { 2261 if (sym && !(ELF_ST_BIND(sym->info) == STB_LOCAL)) {
@@ -2618,7 +2618,8 @@ static void new_get_kernel_symbols(void)
2618 2618
2619 /* Collect the kernel's symbols. */ 2619 /* Collect the kernel's symbols. */
2620 2620
2621 syms = xmalloc(bufsize = 16 * 1024); 2621 bufsize = 16 * 1024;
2622 syms = xmalloc(bufsize);
2622 retry_kern_sym_load: 2623 retry_kern_sym_load:
2623 if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) { 2624 if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) {
2624 if (errno == ENOSPC && bufsize < ret) { 2625 if (errno == ENOSPC && bufsize < ret) {
@@ -2802,10 +2803,8 @@ new_init_module(const char *m_name, struct obj_file *f, unsigned long m_size)
2802 module->ndeps = n_ext_modules_used; 2803 module->ndeps = n_ext_modules_used;
2803 } 2804 }
2804 2805
2805 module->init = 2806 module->init = obj_symbol_final_value(f, obj_find_symbol(f, SPFX "init_module"));
2806 obj_symbol_final_value(f, obj_find_symbol(f, SPFX "init_module")); 2807 module->cleanup = obj_symbol_final_value(f, obj_find_symbol(f, SPFX "cleanup_module"));
2807 module->cleanup =
2808 obj_symbol_final_value(f, obj_find_symbol(f, SPFX "cleanup_module"));
2809 2808
2810 sec = obj_find_section(f, "__ex_table"); 2809 sec = obj_find_section(f, "__ex_table");
2811 if (sec) { 2810 if (sec) {
@@ -2863,7 +2862,7 @@ obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
2863 size_t len = strlen(string) + 1; 2862 size_t len = strlen(string) + 1;
2864 char *loc; 2863 char *loc;
2865 2864
2866 p = xmalloc(sizeof(*p)); 2865 p = xzalloc(sizeof(*p));
2867 p->next = f->string_patches; 2866 p->next = f->string_patches;
2868 p->reloc_secidx = secidx; 2867 p->reloc_secidx = secidx;
2869 p->reloc_offset = offset; 2868 p->reloc_offset = offset;
@@ -2872,7 +2871,7 @@ obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset,
2872 strsec = obj_find_section(f, ".kstrtab"); 2871 strsec = obj_find_section(f, ".kstrtab");
2873 if (strsec == NULL) { 2872 if (strsec == NULL) {
2874 strsec = obj_create_alloced_section(f, ".kstrtab", 1, len); 2873 strsec = obj_create_alloced_section(f, ".kstrtab", 1, len);
2875 p->string_offset = 0; 2874 /*p->string_offset = 0;*/
2876 loc = strsec->contents; 2875 loc = strsec->contents;
2877 } else { 2876 } else {
2878 p->string_offset = strsec->header.sh_size; 2877 p->string_offset = strsec->header.sh_size;
@@ -2925,38 +2924,37 @@ static void obj_allocate_commons(struct obj_file *f)
2925 2924
2926 for (i = 0; i < HASH_BUCKETS; ++i) { 2925 for (i = 0; i < HASH_BUCKETS; ++i) {
2927 struct obj_symbol *sym; 2926 struct obj_symbol *sym;
2928 for (sym = f->symtab[i]; sym; sym = sym->next) 2927 for (sym = f->symtab[i]; sym; sym = sym->next) {
2929 if (sym->secidx == SHN_COMMON) { 2928 if (sym->secidx == SHN_COMMON) {
2930 /* Collect all COMMON symbols and sort them by size so as to 2929 /* Collect all COMMON symbols and sort them by size so as to
2931 minimize space wasted by alignment requirements. */ 2930 minimize space wasted by alignment requirements. */
2932 { 2931 struct common_entry **p, *n;
2933 struct common_entry **p, *n; 2932 for (p = &common_head; *p; p = &(*p)->next)
2934 for (p = &common_head; *p; p = &(*p)->next) 2933 if (sym->size <= (*p)->sym->size)
2935 if (sym->size <= (*p)->sym->size) 2934 break;
2936 break; 2935 n = alloca(sizeof(*n));
2937 2936 n->next = *p;
2938 n = alloca(sizeof(*n)); 2937 n->sym = sym;
2939 n->next = *p; 2938 *p = n;
2940 n->sym = sym;
2941 *p = n;
2942 }
2943 } 2939 }
2940 }
2944 } 2941 }
2945 2942
2946 for (i = 1; i < f->local_symtab_size; ++i) { 2943 for (i = 1; i < f->local_symtab_size; ++i) {
2947 struct obj_symbol *sym = f->local_symtab[i]; 2944 struct obj_symbol *sym = f->local_symtab[i];
2948 if (sym && sym->secidx == SHN_COMMON) { 2945 if (sym && sym->secidx == SHN_COMMON) {
2949 struct common_entry **p, *n; 2946 struct common_entry **p, *n;
2950 for (p = &common_head; *p; p = &(*p)->next) 2947 for (p = &common_head; *p; p = &(*p)->next) {
2951 if (sym == (*p)->sym) 2948 if (sym == (*p)->sym)
2952 break; 2949 break;
2953 else if (sym->size < (*p)->sym->size) { 2950 if (sym->size < (*p)->sym->size) {
2954 n = alloca(sizeof(*n)); 2951 n = alloca(sizeof(*n));
2955 n->next = *p; 2952 n->next = *p;
2956 n->sym = sym; 2953 n->sym = sym;
2957 *p = n; 2954 *p = n;
2958 break; 2955 break;
2959 } 2956 }
2957 }
2960 } 2958 }
2961 } 2959 }
2962 2960
@@ -3546,16 +3544,13 @@ static void check_tainted_module(struct obj_file *f, const char *m_name)
3546 case 1: 3544 case 1:
3547 set_tainted(fd, m_name, kernel_has_tainted, TAINT_PROPRIETORY_MODULE, "no license", ""); 3545 set_tainted(fd, m_name, kernel_has_tainted, TAINT_PROPRIETORY_MODULE, "no license", "");
3548 break; 3546 break;
3549 case 2: 3547 default: /* case 2: */
3550 /* The module has a non-GPL license so we pretend that the 3548 /* The module has a non-GPL license so we pretend that the
3551 * kernel always has a taint flag to get a warning even on 3549 * kernel always has a taint flag to get a warning even on
3552 * kernels without the proc flag. 3550 * kernels without the proc flag.
3553 */ 3551 */
3554 set_tainted(fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "non-GPL license - ", ptr); 3552 set_tainted(fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "non-GPL license - ", ptr);
3555 break; 3553 break;
3556 default:
3557 set_tainted(fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "Unexpected return from obj_gpl_license", "");
3558 break;
3559 } 3554 }
3560 3555
3561 if (flag_force_load) 3556 if (flag_force_load)
@@ -3564,9 +3559,9 @@ static void check_tainted_module(struct obj_file *f, const char *m_name)
3564 if (fd >= 0) 3559 if (fd >= 0)
3565 close(fd); 3560 close(fd);
3566} 3561}
3567#else /* FEATURE_CHECK_TAINTED_MODULE */ 3562#else /* !FEATURE_CHECK_TAINTED_MODULE */
3568#define check_tainted_module(x, y) do { } while (0); 3563#define check_tainted_module(x, y) do { } while (0);
3569#endif /* FEATURE_CHECK_TAINTED_MODULE */ 3564#endif
3570 3565
3571#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS 3566#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
3572/* add module source, timestamp, kernel version and a symbol for the 3567/* add module source, timestamp, kernel version and a symbol for the
@@ -3581,10 +3576,10 @@ get_module_version(struct obj_file *f, char str[STRVERSIONLEN])
3581{ 3576{
3582#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING 3577#if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
3583 return new_get_module_version(f, str); 3578 return new_get_module_version(f, str);
3584#else /* FEATURE_INSMOD_VERSION_CHECKING */ 3579#else
3585 strncpy(str, "???", sizeof(str)); 3580 strncpy(str, "???", sizeof(str));
3586 return -1; 3581 return -1;
3587#endif /* FEATURE_INSMOD_VERSION_CHECKING */ 3582#endif
3588} 3583}
3589 3584
3590/* add module source, timestamp, kernel version and a symbol for the 3585/* add module source, timestamp, kernel version and a symbol for the
@@ -3609,7 +3604,7 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
3609 char *name, *absolute_filename; 3604 char *name, *absolute_filename;
3610 char str[STRVERSIONLEN]; 3605 char str[STRVERSIONLEN];
3611 unsigned i; 3606 unsigned i;
3612 int l, lm_name, lfilename, use_ksymtab, version; 3607 int lm_name, lfilename, use_ksymtab, version;
3613 struct stat statbuf; 3608 struct stat statbuf;
3614 3609
3615 /* WARNING: was using realpath, but replaced by readlink to stop using 3610 /* WARNING: was using realpath, but replaced by readlink to stop using
@@ -3634,20 +3629,10 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
3634 * is 0xffffff, decimal 16777215. putting all three fields in 3629 * is 0xffffff, decimal 16777215. putting all three fields in
3635 * one symbol is less readable but saves kernel space. 3630 * one symbol is less readable but saves kernel space.
3636 */ 3631 */
3637 l = sizeof(symprefix) + /* "__insmod_" */
3638 lm_name + /* module name */
3639 2 + /* "_O" */
3640 lfilename + /* object filename */
3641 2 + /* "_M" */
3642 2 * sizeof(statbuf.st_mtime) + /* mtime in hex */
3643 2 + /* "_V" */
3644 8 + /* version in dec */
3645 1; /* nul */
3646 name = xmalloc(l);
3647 if (stat(absolute_filename, &statbuf) != 0) 3632 if (stat(absolute_filename, &statbuf) != 0)
3648 statbuf.st_mtime = 0; 3633 statbuf.st_mtime = 0;
3649 version = get_module_version(f, str); /* -1 if not found */ 3634 version = get_module_version(f, str); /* -1 if not found */
3650 snprintf(name, l, "%s%s_O%s_M%0*lX_V%d", 3635 name = xasprintf("%s%s_O%s_M%0*lX_V%d",
3651 symprefix, m_name, absolute_filename, 3636 symprefix, m_name, absolute_filename,
3652 (int)(2 * sizeof(statbuf.st_mtime)), statbuf.st_mtime, 3637 (int)(2 * sizeof(statbuf.st_mtime)), statbuf.st_mtime,
3653 version); 3638 version);
@@ -3662,34 +3647,20 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
3662 /* record where the persistent data is going, same address as previous symbol */ 3647 /* record where the persistent data is going, same address as previous symbol */
3663 3648
3664 if (f->persist) { 3649 if (f->persist) {
3665 l = sizeof(symprefix) + /* "__insmod_" */ 3650 name = xasprintf("%s%s_P%s",
3666 lm_name + /* module name */
3667 2 + /* "_P" */
3668 strlen(f->persist) + /* data store */
3669 1; /* nul */
3670 name = xmalloc(l);
3671 snprintf(name, l, "%s%s_P%s",
3672 symprefix, m_name, f->persist); 3651 symprefix, m_name, f->persist);
3673 sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE), 3652 sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
3674 sec->idx, sec->header.sh_addr, 0); 3653 sec->idx, sec->header.sh_addr, 0);
3675 if (use_ksymtab) 3654 if (use_ksymtab)
3676 new_add_ksymtab(f, sym); 3655 new_add_ksymtab(f, sym);
3677 } 3656 }
3678#endif /* _NOT_SUPPORTED_ */ 3657#endif
3679 /* tag the desired sections if size is non-zero */ 3658 /* tag the desired sections if size is non-zero */
3680 3659
3681 for (i = 0; i < ARRAY_SIZE(section_names); ++i) { 3660 for (i = 0; i < ARRAY_SIZE(section_names); ++i) {
3682 sec = obj_find_section(f, section_names[i]); 3661 sec = obj_find_section(f, section_names[i]);
3683 if (sec && sec->header.sh_size) { 3662 if (sec && sec->header.sh_size) {
3684 l = sizeof(symprefix) + /* "__insmod_" */ 3663 name = xasprintf("%s%s_S%s_L%ld",
3685 lm_name + /* module name */
3686 2 + /* "_S" */
3687 strlen(sec->name) + /* section name */
3688 2 + /* "_L" */
3689 8 + /* length in dec */
3690 1; /* nul */
3691 name = xmalloc(l);
3692 snprintf(name, l, "%s%s_S%s_L%ld",
3693 symprefix, m_name, sec->name, 3664 symprefix, m_name, sec->name,
3694 (long)sec->header.sh_size); 3665 (long)sec->header.sh_size);
3695 sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE), 3666 sym = obj_add_symbol(f, name, -1, ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
@@ -3855,7 +3826,7 @@ int FAST_FUNC bb_init_module_24(const char *m_filename, const char *options)
3855 } 3826 }
3856 } 3827 }
3857 k_crcs = 0; 3828 k_crcs = 0;
3858#endif /* FEATURE_INSMOD_VERSION_CHECKING */ 3829#endif
3859 3830
3860 if (query_module(NULL, 0, NULL, 0, NULL)) 3831 if (query_module(NULL, 0, NULL, 0, NULL))
3861 bb_error_msg_and_die("not configured to support old kernels"); 3832 bb_error_msg_and_die("not configured to support old kernels");
@@ -3869,7 +3840,7 @@ int FAST_FUNC bb_init_module_24(const char *m_filename, const char *options)
3869 3840
3870 if (m_crcs != k_crcs) 3841 if (m_crcs != k_crcs)
3871 obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash); 3842 obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash);
3872#endif /* FEATURE_INSMOD_VERSION_CHECKING */ 3843#endif
3873 3844
3874 /* Let the module know about the kernel symbols. */ 3845 /* Let the module know about the kernel symbols. */
3875 add_kernel_symbols(f); 3846 add_kernel_symbols(f);
@@ -3889,7 +3860,7 @@ int FAST_FUNC bb_init_module_24(const char *m_filename, const char *options)
3889 3860
3890#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS 3861#if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
3891 add_ksymoops_symbols(f, m_filename, m_name); 3862 add_ksymoops_symbols(f, m_filename, m_name);
3892#endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */ 3863#endif
3893 3864
3894 new_create_module_ksymtab(f); 3865 new_create_module_ksymtab(f);
3895 3866