aboutsummaryrefslogtreecommitdiff
path: root/insmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'insmod.c')
-rw-r--r--insmod.c77
1 files changed, 34 insertions, 43 deletions
diff --git a/insmod.c b/insmod.c
index 7e90dfbd9..b3d5ac837 100644
--- a/insmod.c
+++ b/insmod.c
@@ -70,7 +70,7 @@
70#ifndef MODUTILS_MODULE_H 70#ifndef MODUTILS_MODULE_H
71#define MODUTILS_MODULE_H 1 71#define MODUTILS_MODULE_H 1
72 72
73#ident "$Id: insmod.c,v 1.15 2000/07/11 17:52:22 andersen Exp $" 73#ident "$Id: insmod.c,v 1.16 2000/07/14 01:51:25 kraai Exp $"
74 74
75/* This file contains the structures used by the 2.0 and 2.1 kernels. 75/* This file contains the structures used by the 2.0 and 2.1 kernels.
76 We do not use the kernel headers directly because we do not wish 76 We do not use the kernel headers directly because we do not wish
@@ -276,7 +276,7 @@ int delete_module(const char *);
276#ifndef MODUTILS_OBJ_H 276#ifndef MODUTILS_OBJ_H
277#define MODUTILS_OBJ_H 1 277#define MODUTILS_OBJ_H 1
278 278
279#ident "$Id: insmod.c,v 1.15 2000/07/11 17:52:22 andersen Exp $" 279#ident "$Id: insmod.c,v 1.16 2000/07/14 01:51:25 kraai Exp $"
280 280
281/* The relocatable object is manipulated using elfin types. */ 281/* The relocatable object is manipulated using elfin types. */
282 282
@@ -938,7 +938,7 @@ struct obj_symbol *obj_add_symbol(struct obj_file *f, const char *name,
938 /* Don't report an error if the symbol is coming from 938 /* Don't report an error if the symbol is coming from
939 the kernel or some external module. */ 939 the kernel or some external module. */
940 if (secidx <= SHN_HIRESERVE) 940 if (secidx <= SHN_HIRESERVE)
941 fprintf(stderr, "%s multiply defined\n", name); 941 errorMsg("%s multiply defined\n", name);
942 return sym; 942 return sym;
943 } 943 }
944 } 944 }
@@ -1201,7 +1201,7 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
1201 1201
1202 /* Also check that the parameter was not resolved from the kernel. */ 1202 /* Also check that the parameter was not resolved from the kernel. */
1203 if (sym == NULL || sym->secidx > SHN_HIRESERVE) { 1203 if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
1204 fprintf(stderr, "symbol for parameter %s not found\n", p); 1204 errorMsg("symbol for parameter %s not found\n", p);
1205 return 0; 1205 return 0;
1206 } 1206 }
1207 1207
@@ -1214,7 +1214,7 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
1214 str = alloca(strlen(q)); 1214 str = alloca(strlen(q));
1215 for (r = str, q++; *q != '"'; ++q, ++r) { 1215 for (r = str, q++; *q != '"'; ++q, ++r) {
1216 if (*q == '\0') { 1216 if (*q == '\0') {
1217 fprintf(stderr, "improperly terminated string argument for %s\n", p); 1217 errorMsg("improperly terminated string argument for %s\n", p);
1218 return 0; 1218 return 0;
1219 } else if (*q == '\\') 1219 } else if (*q == '\\')
1220 switch (*++q) { 1220 switch (*++q) {
@@ -1567,7 +1567,7 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1567 p = get_modinfo_value(f, key); 1567 p = get_modinfo_value(f, key);
1568 key += 5; 1568 key += 5;
1569 if (p == NULL) { 1569 if (p == NULL) {
1570 fprintf(stderr, "invalid parameter %s\n", key); 1570 errorMsg("invalid parameter %s\n", key);
1571 return 0; 1571 return 0;
1572 } 1572 }
1573 1573
@@ -1575,7 +1575,7 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1575 1575
1576 /* Also check that the parameter was not resolved from the kernel. */ 1576 /* Also check that the parameter was not resolved from the kernel. */
1577 if (sym == NULL || sym->secidx > SHN_HIRESERVE) { 1577 if (sym == NULL || sym->secidx > SHN_HIRESERVE) {
1578 fprintf(stderr, "symbol for parameter %s not found\n", key); 1578 errorMsg("symbol for parameter %s not found\n", key);
1579 return 0; 1579 return 0;
1580 } 1580 }
1581 1581
@@ -1603,8 +1603,7 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1603 str = alloca(strlen(q)); 1603 str = alloca(strlen(q));
1604 for (r = str, q++; *q != '"'; ++q, ++r) { 1604 for (r = str, q++; *q != '"'; ++q, ++r) {
1605 if (*q == '\0') { 1605 if (*q == '\0') {
1606 fprintf(stderr, 1606 errorMsg("improperly terminated string argument for %s\n",
1607 "improperly terminated string argument for %s\n",
1608 key); 1607 key);
1609 return 0; 1608 return 0;
1610 } else if (*q == '\\') 1609 } else if (*q == '\\')
@@ -1698,8 +1697,7 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1698 /* Get the size of each member */ 1697 /* Get the size of each member */
1699 /* Probably we should do that outside the loop ? */ 1698 /* Probably we should do that outside the loop ? */
1700 if (!isdigit(*(p + 1))) { 1699 if (!isdigit(*(p + 1))) {
1701 fprintf(stderr, 1700 errorMsg("parameter type 'c' for %s must be followed by"
1702 "parameter type 'c' for %s must be followed by"
1703 " the maximum size\n", key); 1701 " the maximum size\n", key);
1704 return 0; 1702 return 0;
1705 } 1703 }
@@ -1707,8 +1705,7 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1707 1705
1708 /* Check length */ 1706 /* Check length */
1709 if (strlen(str) >= charssize) { 1707 if (strlen(str) >= charssize) {
1710 fprintf(stderr, 1708 errorMsg("string too long for %s (max %ld)\n", key,
1711 "string too long for %s (max %ld)\n", key,
1712 charssize - 1); 1709 charssize - 1);
1713 return 0; 1710 return 0;
1714 } 1711 }
@@ -1737,8 +1734,7 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1737 break; 1734 break;
1738 1735
1739 default: 1736 default:
1740 fprintf(stderr, "unknown parameter type '%c' for %s\n", 1737 errorMsg("unknown parameter type '%c' for %s\n", *p, key);
1741 *p, key);
1742 return 0; 1738 return 0;
1743 } 1739 }
1744 } 1740 }
@@ -1757,22 +1753,21 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
1757 1753
1758 case ',': 1754 case ',':
1759 if (++n > max) { 1755 if (++n > max) {
1760 fprintf(stderr, "too many values for %s (max %d)\n", 1756 errorMsg("too many values for %s (max %d)\n", key, max);
1761 key, max);
1762 return 0; 1757 return 0;
1763 } 1758 }
1764 ++q; 1759 ++q;
1765 break; 1760 break;
1766 1761
1767 default: 1762 default:
1768 fprintf(stderr, "invalid argument syntax for %s\n", key); 1763 errorMsg("invalid argument syntax for %s\n", key);
1769 return 0; 1764 return 0;
1770 } 1765 }
1771 } 1766 }
1772 1767
1773 end_of_arg: 1768 end_of_arg:
1774 if (n < min) { 1769 if (n < min) {
1775 fprintf(stderr, "too few values for %s (min %d)\n", key, min); 1770 errorMsg("too few values for %s (min %d)\n", key, min);
1776 return 0; 1771 return 0;
1777 } 1772 }
1778 1773
@@ -2157,7 +2152,7 @@ int obj_check_undefineds(struct obj_file *f)
2157 sym->secidx = SHN_ABS; 2152 sym->secidx = SHN_ABS;
2158 sym->value = 0; 2153 sym->value = 0;
2159 } else { 2154 } else {
2160 fprintf(stderr, "unresolved symbol %s\n", sym->name); 2155 errorMsg("unresolved symbol %s\n", sym->name);
2161 ret = 0; 2156 ret = 0;
2162 } 2157 }
2163 } 2158 }
@@ -2380,11 +2375,11 @@ int obj_relocate(struct obj_file *f, ElfW(Addr) base)
2380 errmsg = "Unhandled relocation"; 2375 errmsg = "Unhandled relocation";
2381 bad_reloc: 2376 bad_reloc:
2382 if (extsym) { 2377 if (extsym) {
2383 fprintf(stderr, "%s of type %ld for %s\n", errmsg, 2378 errorMsg("%s of type %ld for %s\n", errmsg,
2384 (long) ELFW(R_TYPE) (rel->r_info), 2379 (long) ELFW(R_TYPE) (rel->r_info),
2385 strtab + extsym->st_name); 2380 strtab + extsym->st_name);
2386 } else { 2381 } else {
2387 fprintf(stderr, "%s of type %ld\n", errmsg, 2382 errorMsg("%s of type %ld\n", errmsg,
2388 (long) ELFW(R_TYPE) (rel->r_info)); 2383 (long) ELFW(R_TYPE) (rel->r_info));
2389 } 2384 }
2390 ret = 0; 2385 ret = 0;
@@ -2469,25 +2464,25 @@ struct obj_file *obj_load(FILE * fp)
2469 || f->header.e_ident[EI_MAG1] != ELFMAG1 2464 || f->header.e_ident[EI_MAG1] != ELFMAG1
2470 || f->header.e_ident[EI_MAG2] != ELFMAG2 2465 || f->header.e_ident[EI_MAG2] != ELFMAG2
2471 || f->header.e_ident[EI_MAG3] != ELFMAG3) { 2466 || f->header.e_ident[EI_MAG3] != ELFMAG3) {
2472 fprintf(stderr, "not an ELF file\n"); 2467 errorMsg("not an ELF file\n");
2473 return NULL; 2468 return NULL;
2474 } 2469 }
2475 if (f->header.e_ident[EI_CLASS] != ELFCLASSM 2470 if (f->header.e_ident[EI_CLASS] != ELFCLASSM
2476 || f->header.e_ident[EI_DATA] != ELFDATAM 2471 || f->header.e_ident[EI_DATA] != ELFDATAM
2477 || f->header.e_ident[EI_VERSION] != EV_CURRENT 2472 || f->header.e_ident[EI_VERSION] != EV_CURRENT
2478 || !MATCH_MACHINE(f->header.e_machine)) { 2473 || !MATCH_MACHINE(f->header.e_machine)) {
2479 fprintf(stderr, "ELF file not for this architecture\n"); 2474 errorMsg("ELF file not for this architecture\n");
2480 return NULL; 2475 return NULL;
2481 } 2476 }
2482 if (f->header.e_type != ET_REL) { 2477 if (f->header.e_type != ET_REL) {
2483 fprintf(stderr, "ELF file not a relocatable object\n"); 2478 errorMsg("ELF file not a relocatable object\n");
2484 return NULL; 2479 return NULL;
2485 } 2480 }
2486 2481
2487 /* Read the section headers. */ 2482 /* Read the section headers. */
2488 2483
2489 if (f->header.e_shentsize != sizeof(ElfW(Shdr))) { 2484 if (f->header.e_shentsize != sizeof(ElfW(Shdr))) {
2490 fprintf(stderr, "section header size mismatch: %lu != %lu\n", 2485 errorMsg("section header size mismatch: %lu != %lu\n",
2491 (unsigned long) f->header.e_shentsize, 2486 (unsigned long) f->header.e_shentsize,
2492 (unsigned long) sizeof(ElfW(Shdr))); 2487 (unsigned long) sizeof(ElfW(Shdr)));
2493 return NULL; 2488 return NULL;
@@ -2540,13 +2535,11 @@ struct obj_file *obj_load(FILE * fp)
2540 2535
2541#if SHT_RELM == SHT_REL 2536#if SHT_RELM == SHT_REL
2542 case SHT_RELA: 2537 case SHT_RELA:
2543 fprintf(stderr, 2538 errorMsg("RELA relocations not supported on this architecture\n");
2544 "RELA relocations not supported on this architecture\n");
2545 return NULL; 2539 return NULL;
2546#else 2540#else
2547 case SHT_REL: 2541 case SHT_REL:
2548 fprintf(stderr, 2542 errorMsg("REL relocations not supported on this architecture\n");
2549 "REL relocations not supported on this architecture\n");
2550 return NULL; 2543 return NULL;
2551#endif 2544#endif
2552 2545
@@ -2559,7 +2552,7 @@ struct obj_file *obj_load(FILE * fp)
2559 break; 2552 break;
2560 } 2553 }
2561 2554
2562 fprintf(stderr, "can't handle sections of type %ld\n", 2555 errorMsg("can't handle sections of type %ld\n",
2563 (long) sec->header.sh_type); 2556 (long) sec->header.sh_type);
2564 return NULL; 2557 return NULL;
2565 } 2558 }
@@ -2588,7 +2581,7 @@ struct obj_file *obj_load(FILE * fp)
2588 ElfW(Sym) * sym; 2581 ElfW(Sym) * sym;
2589 2582
2590 if (sec->header.sh_entsize != sizeof(ElfW(Sym))) { 2583 if (sec->header.sh_entsize != sizeof(ElfW(Sym))) {
2591 fprintf(stderr, "symbol size mismatch: %lu != %lu\n", 2584 errorMsg("symbol size mismatch: %lu != %lu\n",
2592 (unsigned long) sec->header.sh_entsize, 2585 (unsigned long) sec->header.sh_entsize,
2593 (unsigned long) sizeof(ElfW(Sym))); 2586 (unsigned long) sizeof(ElfW(Sym)));
2594 return NULL; 2587 return NULL;
@@ -2620,8 +2613,7 @@ struct obj_file *obj_load(FILE * fp)
2620 2613
2621 case SHT_RELM: 2614 case SHT_RELM:
2622 if (sec->header.sh_entsize != sizeof(ElfW(RelM))) { 2615 if (sec->header.sh_entsize != sizeof(ElfW(RelM))) {
2623 fprintf(stderr, 2616 errorMsg("relocation entry size mismatch: %lu != %lu\n",
2624 "relocation entry size mismatch: %lu != %lu\n",
2625 (unsigned long) sec->header.sh_entsize, 2617 (unsigned long) sec->header.sh_entsize,
2626 (unsigned long) sizeof(ElfW(RelM))); 2618 (unsigned long) sizeof(ElfW(RelM)));
2627 return NULL; 2619 return NULL;
@@ -2754,20 +2746,20 @@ extern int insmod_main( int argc, char **argv)
2754 } else { 2746 } else {
2755 m_version = old_get_module_version(f, m_strversion); 2747 m_version = old_get_module_version(f, m_strversion);
2756 if (m_version == -1) { 2748 if (m_version == -1) {
2757 fprintf(stderr, 2749 errorMsg("couldn't find the kernel version the module was "
2758 "couldn't find the kernel version the module was compiled for\n"); 2750 "compiled for\n");
2759 goto out; 2751 goto out;
2760 } 2752 }
2761 } 2753 }
2762 2754
2763 if (strncmp(k_strversion, m_strversion, STRVERSIONLEN) != 0) { 2755 if (strncmp(k_strversion, m_strversion, STRVERSIONLEN) != 0) {
2764 if (flag_force_load) { 2756 if (flag_force_load) {
2765 fprintf(stderr, "Warning: kernel-module version mismatch\n" 2757 errorMsg("Warning: kernel-module version mismatch\n"
2766 "\t%s was compiled for kernel version %s\n" 2758 "\t%s was compiled for kernel version %s\n"
2767 "\twhile this kernel is version %s\n", 2759 "\twhile this kernel is version %s\n",
2768 m_filename, m_strversion, k_strversion); 2760 m_filename, m_strversion, k_strversion);
2769 } else { 2761 } else {
2770 fprintf(stderr, "kernel-module version mismatch\n" 2762 errorMsg("kernel-module version mismatch\n"
2771 "\t%s was compiled for kernel version %s\n" 2763 "\t%s was compiled for kernel version %s\n"
2772 "\twhile this kernel is version %s.\n", 2764 "\twhile this kernel is version %s.\n",
2773 m_filename, m_strversion, k_strversion); 2765 m_filename, m_strversion, k_strversion);
@@ -2785,7 +2777,7 @@ extern int insmod_main( int argc, char **argv)
2785 goto out; 2777 goto out;
2786 k_crcs = new_is_kernel_checksummed(); 2778 k_crcs = new_is_kernel_checksummed();
2787#else 2779#else
2788 fprintf(stderr, "Not configured to support new kernels\n"); 2780 errorMsg("Not configured to support new kernels\n");
2789 goto out; 2781 goto out;
2790#endif 2782#endif
2791 } else { 2783 } else {
@@ -2794,7 +2786,7 @@ extern int insmod_main( int argc, char **argv)
2794 goto out; 2786 goto out;
2795 k_crcs = old_is_kernel_checksummed(); 2787 k_crcs = old_is_kernel_checksummed();
2796#else 2788#else
2797 fprintf(stderr, "Not configured to support old kernels\n"); 2789 errorMsg("Not configured to support old kernels\n");
2798 goto out; 2790 goto out;
2799#endif 2791#endif
2800 } 2792 }
@@ -2851,11 +2843,10 @@ extern int insmod_main( int argc, char **argv)
2851 case 0: 2843 case 0:
2852 break; 2844 break;
2853 case EEXIST: 2845 case EEXIST:
2854 fprintf(stderr, "A module named %s already exists\n", m_name); 2846 errorMsg("A module named %s already exists\n", m_name);
2855 goto out; 2847 goto out;
2856 case ENOMEM: 2848 case ENOMEM:
2857 fprintf(stderr, 2849 errorMsg("Can't allocate kernel memory for module; needed %lu bytes\n",
2858 "Can't allocate kernel memory for module; needed %lu bytes\n",
2859 m_size); 2850 m_size);
2860 goto out; 2851 goto out;
2861 default: 2852 default: