From 31d44a623579fbca300f20bc751c7278c4375980 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Thu, 22 Feb 2001 17:21:43 +0000 Subject: use modutils for non Intel arch's --- mdk-stage1/insmod-modutils/include/config.h | 105 +++++++++ mdk-stage1/insmod-modutils/include/elf_alpha.h | 10 + mdk-stage1/insmod-modutils/include/elf_arm.h | 10 + mdk-stage1/insmod-modutils/include/elf_hppa.h | 9 + mdk-stage1/insmod-modutils/include/elf_hppa64.h | 9 + mdk-stage1/insmod-modutils/include/elf_i386.h | 10 + mdk-stage1/insmod-modutils/include/elf_ia64.h | 9 + mdk-stage1/insmod-modutils/include/elf_m68k.h | 10 + mdk-stage1/insmod-modutils/include/elf_mips.h | 24 ++ mdk-stage1/insmod-modutils/include/elf_ppc.h | 10 + mdk-stage1/insmod-modutils/include/elf_s390.h | 10 + mdk-stage1/insmod-modutils/include/elf_sparc.h | 10 + mdk-stage1/insmod-modutils/include/elf_sparc64.h | 27 +++ mdk-stage1/insmod-modutils/include/kallsyms.h | 131 +++++++++++ mdk-stage1/insmod-modutils/include/kerneld.h | 46 ++++ mdk-stage1/insmod-modutils/include/modstat.h | 55 +++++ mdk-stage1/insmod-modutils/include/module.h | 210 +++++++++++++++++ mdk-stage1/insmod-modutils/include/obj.h | 275 +++++++++++++++++++++++ mdk-stage1/insmod-modutils/include/util.h | 101 +++++++++ mdk-stage1/insmod-modutils/include/version.h | 1 + 20 files changed, 1072 insertions(+) create mode 100644 mdk-stage1/insmod-modutils/include/config.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_alpha.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_arm.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_hppa.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_hppa64.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_i386.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_ia64.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_m68k.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_mips.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_ppc.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_s390.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_sparc.h create mode 100644 mdk-stage1/insmod-modutils/include/elf_sparc64.h create mode 100644 mdk-stage1/insmod-modutils/include/kallsyms.h create mode 100644 mdk-stage1/insmod-modutils/include/kerneld.h create mode 100644 mdk-stage1/insmod-modutils/include/modstat.h create mode 100644 mdk-stage1/insmod-modutils/include/module.h create mode 100644 mdk-stage1/insmod-modutils/include/obj.h create mode 100644 mdk-stage1/insmod-modutils/include/util.h create mode 100644 mdk-stage1/insmod-modutils/include/version.h (limited to 'mdk-stage1/insmod-modutils/include') diff --git a/mdk-stage1/insmod-modutils/include/config.h b/mdk-stage1/insmod-modutils/include/config.h new file mode 100644 index 000000000..11da6a523 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/config.h @@ -0,0 +1,105 @@ +/* + * Configuration file management + * + * Copyright 1994, 1995, 1996, 1997: + * Jacques Gelinas + * Björn Ekwall February, March 1999 + * + * This file is part of the Linux modutils. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _CONFIG_H +#define _CONFIG_H + +#include +#include + +#define ETC_MODULES_CONF "/etc/modules.conf" + +#define EXEC_PRE_INSTALL 0 +#define EXEC_POST_INSTALL 1 +#define EXEC_PRE_REMOVE 2 +#define EXEC_POST_REMOVE 3 +#define EXEC_INSTALL 4 +#define EXEC_REMOVE 5 + +struct PATH_TYPE { + char *type; + char *path; +}; + +struct EXEC_TYPE { + int when; + char *module; + char *cmd; +}; + +typedef struct { + char *name; + GLOB_LIST *opts; + int autoclean; +} OPT_LIST; + +/* config.c */ +extern int flag_autoclean; +extern struct utsname uts_info; +extern char *aliaslist[]; +extern struct PATH_TYPE *modpath; +extern int nmodpath; +extern struct EXEC_TYPE *execs; +extern int nexecs; +extern char *insmod_opt; +extern char *config_file; +extern char *optlist[]; +extern char *prune[]; +extern OPT_LIST *opt_list; +extern OPT_LIST *abovelist; +extern OPT_LIST *belowlist; +extern OPT_LIST *prunelist; +extern OPT_LIST *probe_list; +extern OPT_LIST *probeall_list; +extern OPT_LIST *aliases; +extern time_t config_mtime; +extern int root_check_off; /* Check modules are owned by root? */ + +/* Information about generated files */ +struct gen_files { + char *base; /* xxx in /lib/modules/`uname -r`/modules.xxx */ + char *name; /* name actually used */ + time_t mtime; +}; + +extern struct gen_files gen_file[]; +extern const int gen_file_count; +/* The enum order must match the gen_file initialization order in config.c */ +enum gen_file_enum { + GEN_GENERIC_STRINGFILE, + GEN_PCIMAPFILE, + GEN_ISAPNPMAPFILE, + GEN_USBMAPFILE, + GEN_PARPORTMAPFILE, + GEN_DEPFILE, +}; + +extern char *persistdir; + +char *fgets_strip(char *buf, int sizebuf, FILE * fin, int *lineno); +int config_read(int all, char *force_ver, char *base_dir, char *conf_file); +GLOB_LIST *config_lstmod(const char *match, const char *type, int first_only); +char *search_module_path(const char *base); + +#endif /* _CONFIG_H */ diff --git a/mdk-stage1/insmod-modutils/include/elf_alpha.h b/mdk-stage1/insmod-modutils/include/elf_alpha.h new file mode 100644 index 000000000..f1ec66f1c --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_alpha.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for the Alpha. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS64 +#define ELFDATAM ELFDATA2LSB + +#define MATCH_MACHINE(x) (x == EM_ALPHA) + +#define SHT_RELM SHT_RELA +#define Elf64_RelM Elf64_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_arm.h b/mdk-stage1/insmod-modutils/include/elf_arm.h new file mode 100644 index 000000000..f6b531e88 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_arm.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for ARM. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2LSB + +#define MATCH_MACHINE(x) (x == EM_ARM) + +#define SHT_RELM SHT_REL +#define Elf32_RelM Elf32_Rel diff --git a/mdk-stage1/insmod-modutils/include/elf_hppa.h b/mdk-stage1/insmod-modutils/include/elf_hppa.h new file mode 100644 index 000000000..9a1bd34ce --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_hppa.h @@ -0,0 +1,9 @@ +/* Machine-specific elf macros for HP-PA. */ + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2MSB + +#define MATCH_MACHINE(x) (x == EM_PARISC) + +#define SHT_RELM SHT_RELA +#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_hppa64.h b/mdk-stage1/insmod-modutils/include/elf_hppa64.h new file mode 100644 index 000000000..05b201aef --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_hppa64.h @@ -0,0 +1,9 @@ +/* Machine-specific elf macros for HP-PA64. */ + +#define ELFCLASSM ELFCLASS64 +#define ELFDATAM ELFDATA2MSB + +#define MATCH_MACHINE(x) (x == EM_PARISC) + +#define SHT_RELM SHT_RELA +#define Elf64_RelM Elf64_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_i386.h b/mdk-stage1/insmod-modutils/include/elf_i386.h new file mode 100644 index 000000000..c6c2d326e --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_i386.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for i386 et al. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2LSB + +#define MATCH_MACHINE(x) (x == EM_386) + +#define SHT_RELM SHT_REL +#define Elf32_RelM Elf32_Rel diff --git a/mdk-stage1/insmod-modutils/include/elf_ia64.h b/mdk-stage1/insmod-modutils/include/elf_ia64.h new file mode 100644 index 000000000..b4d902956 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_ia64.h @@ -0,0 +1,9 @@ +/* Machine-specific elf macros for ia64. */ + +#define ELFCLASSM ELFCLASS64 +#define ELFDATAM ELFDATA2LSB + +#define MATCH_MACHINE(x) (x == EM_IA_64) + +#define SHT_RELM SHT_RELA +#define Elf64_RelM Elf64_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_m68k.h b/mdk-stage1/insmod-modutils/include/elf_m68k.h new file mode 100644 index 000000000..817fc8f2c --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_m68k.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for m68k. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2MSB + +#define MATCH_MACHINE(x) (x == EM_68K) + +#define SHT_RELM SHT_RELA +#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_mips.h b/mdk-stage1/insmod-modutils/include/elf_mips.h new file mode 100644 index 000000000..8a0430216 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_mips.h @@ -0,0 +1,24 @@ +/* Machine-specific elf macros for MIPS. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#ifdef __MIPSEB__ +#define ELFDATAM ELFDATA2MSB +#endif +#ifdef __MIPSEL__ +#define ELFDATAM ELFDATA2LSB +#endif + +/* Account for ELF spec changes. */ +#ifndef EM_MIPS_RS3_LE +#ifdef EM_MIPS_RS4_BE +#define EM_MIPS_RS3_LE EM_MIPS_RS4_BE +#else +#define EM_MIPS_RS3_LE 10 +#endif +#endif /* !EM_MIPS_RS3_LE */ + +#define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE) + +#define SHT_RELM SHT_REL +#define Elf32_RelM Elf32_Rel diff --git a/mdk-stage1/insmod-modutils/include/elf_ppc.h b/mdk-stage1/insmod-modutils/include/elf_ppc.h new file mode 100644 index 000000000..71596de8c --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_ppc.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for the PowerPC. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2MSB + +#define MATCH_MACHINE(x) (x == EM_PPC) + +#define SHT_RELM SHT_RELA +#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_s390.h b/mdk-stage1/insmod-modutils/include/elf_s390.h new file mode 100644 index 000000000..547d66b83 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_s390.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for i386 et al. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2MSB + +#define MATCH_MACHINE(x) (x == EM_S390) + +#define SHT_RELM SHT_RELA +#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_sparc.h b/mdk-stage1/insmod-modutils/include/elf_sparc.h new file mode 100644 index 000000000..9b5c348d9 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_sparc.h @@ -0,0 +1,10 @@ +/* Machine-specific elf macros for the Sparc. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS32 +#define ELFDATAM ELFDATA2MSB + +#define MATCH_MACHINE(x) (x == EM_SPARC) + +#define SHT_RELM SHT_RELA +#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_sparc64.h b/mdk-stage1/insmod-modutils/include/elf_sparc64.h new file mode 100644 index 000000000..158edd7e1 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/elf_sparc64.h @@ -0,0 +1,27 @@ +/* Machine-specific elf macros for the Sparc. */ +#ident "$Id$" + +#define ELFCLASSM ELFCLASS64 +#define ELFDATAM ELFDATA2MSB + +#ifndef EM_SPARCV9 +#define EM_SPARCV9 43 +#endif +#ifndef EM_SPARC64 +#define EM_SPARC64 11 +#endif +#define MATCH_MACHINE(x) ((x) == EM_SPARCV9 || (x) == EM_SPARC64) + +#define SHT_RELM SHT_RELA +#define Elf64_RelM Elf64_Rela + +#ifndef ELF64_R_SYM +#define ELF64_R_SYM(x) ((x) >> 32) +#define ELF64_R_TYPE(x) ((unsigned)(x)) +#endif + +#ifndef ELF64_ST_BIND +#define ELF64_ST_BIND(x) ((x) >> 4) +#define ELF64_ST_TYPE(x) ((x) & 0xf) +#endif + diff --git a/mdk-stage1/insmod-modutils/include/kallsyms.h b/mdk-stage1/insmod-modutils/include/kallsyms.h new file mode 100644 index 000000000..9748873cf --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/kallsyms.h @@ -0,0 +1,131 @@ +/* kallsyms headers + Copyright 2000 Keith Owens + + This file is part of the Linux modutils. It is exported to kernel + space so debuggers can access the kallsyms data. + + The kallsyms data contains all the non-stack symbols from a kernel + or a module. The kernel symbols are held between __start___kallsyms + and __stop___kallsyms. The symbols for a module are accessed via + the struct module chain which is based at module_list. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ident "$Id$" + +#ifndef MODUTILS_KALLSYMS_H +#define MODUTILS_KALLSYMS_H 1 + +/* Have to (re)define these ElfW entries here because external kallsyms + * code does not have access to modutils/include/obj.h. This code is + * included from user spaces tools (modutils) and kernel, they need + * different includes. + */ + +#ifndef ELFCLASS32 +#ifdef __KERNEL__ +#include +#else /* __KERNEL__ */ +#include +#endif /* __KERNEL__ */ +#endif /* ELFCLASS32 */ + +#ifndef ELFCLASSM +#define ELFCLASSM ELF_CLASS +#endif + +#ifndef ElfW +# if ELFCLASSM == ELFCLASS32 +# define ElfW(x) Elf32_ ## x +# define ELFW(x) ELF32_ ## x +# else +# define ElfW(x) Elf64_ ## x +# define ELFW(x) ELF64_ ## x +# endif +#endif + +/* Format of data in the kallsyms section. + * Most of the fields are small numbers but the total size and all + * offsets can be large so use the 32/64 bit types for these fields. + * + * Do not use sizeof() on these structures, modutils may be using extra + * fields. Instead use the size fields in the header to access the + * other bits of data. + */ + +struct kallsyms_header { + int size; /* Size of this header */ + ElfW(Word) total_size; /* Total size of kallsyms data */ + int sections; /* Number of section entries */ + ElfW(Off) section_off; /* Offset to first section entry */ + int section_size; /* Size of one section entry */ + int symbols; /* Number of symbol entries */ + ElfW(Off) symbol_off; /* Offset to first symbol entry */ + int symbol_size; /* Size of one symbol entry */ + ElfW(Off) string_off; /* Offset to first string */ + ElfW(Addr) start; /* Start address of first section */ + ElfW(Addr) end; /* End address of last section */ +}; + +struct kallsyms_section { + ElfW(Addr) start; /* Start address of section */ + ElfW(Word) size; /* Size of this section */ + ElfW(Off) name_off; /* Offset to section name */ + ElfW(Word) flags; /* Flags from section */ +}; + +struct kallsyms_symbol { + ElfW(Off) section_off; /* Offset to section that owns this symbol */ + ElfW(Addr) symbol_addr; /* Address of symbol */ + ElfW(Off) name_off; /* Offset to symbol name */ +}; + +#define KALLSYMS_SEC_NAME "__kallsyms" +#define KALLSYMS_IDX 2 /* obj_kallsyms creates kallsyms as section 2 */ + +#define kallsyms_next_sec(h,s) \ + ((s) = (struct kallsyms_section *)((char *)(s) + (h)->section_size)) +#define kallsyms_next_sym(h,s) \ + ((s) = (struct kallsyms_symbol *)((char *)(s) + (h)->symbol_size)) + +int kallsyms_symbol_to_address( + const char *name, /* Name to lookup */ + unsigned long *token, /* Which module to start with */ + const char **mod_name, /* Set to module name or "kernel" */ + unsigned long *mod_start, /* Set to start address of module */ + unsigned long *mod_end, /* Set to end address of module */ + const char **sec_name, /* Set to section name */ + unsigned long *sec_start, /* Set to start address of section */ + unsigned long *sec_end, /* Set to end address of section */ + const char **sym_name, /* Set to full symbol name */ + unsigned long *sym_start, /* Set to start address of symbol */ + unsigned long *sym_end /* Set to end address of symbol */ + ); + +int kallsyms_address_to_symbol( + unsigned long address, /* Address to lookup */ + const char **mod_name, /* Set to module name */ + unsigned long *mod_start, /* Set to start address of module */ + unsigned long *mod_end, /* Set to end address of module */ + const char **sec_name, /* Set to section name */ + unsigned long *sec_start, /* Set to start address of section */ + unsigned long *sec_end, /* Set to end address of section */ + const char **sym_name, /* Set to full symbol name */ + unsigned long *sym_start, /* Set to start address of symbol */ + unsigned long *sym_end /* Set to end address of symbol */ + ); + +#endif /* kallsyms.h */ diff --git a/mdk-stage1/insmod-modutils/include/kerneld.h b/mdk-stage1/insmod-modutils/include/kerneld.h new file mode 100644 index 000000000..3bc2c9d42 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/kerneld.h @@ -0,0 +1,46 @@ +/* Definitions for the Linux kerneld SYSV IPC interface. + This file was part of the Linux kernel, and so is covered by the GPL. */ + +#ifndef MODUTILS_KERNELD_H +#define MODUTILS_KERNELD_H + +#ident "$Id$" + +#define KERNELD_SYSTEM 1 +#define KERNELD_REQUEST_MODULE 2 /* "insmod" */ +#define KERNELD_RELEASE_MODULE 3 /* "rmmod" */ +#define KERNELD_DELAYED_RELEASE_MODULE 4 /* "rmmod" */ +#define KERNELD_CANCEL_RELEASE_MODULE 5 /* "rmmod" */ +#define KERNELD_REQUEST_ROUTE 6 /* net/ipv4/route.c */ +#define KERNELD_BLANKER 7 /* drivers/char/console.c */ +#define KERNELD_PNP 8 /* drivers/pnp/kerneld.c */ +#define KERNELD_ARP 256 /* net/ipv4/arp.c */ + +#ifdef NEW_KERNELD_PROTOCOL +# define OLDIPC_KERNELD 00040000 /* old kerneld message channel */ +# define IPC_KERNELD 00140000 /* new kerneld message channel */ +# define KDHDR (sizeof(long) + sizeof(short) + sizeof(short)) +# define NULL_KDHDR 0, 2, 0 +#else /* NEW_KERNELD_PROTOCOL */ +# define IPC_KERNELD 00040000 +# define KDHDR (sizeof(long)) +# define NULL_KDHDR 0 +#endif /* NEW_KERNELD_PROTOCOL */ + +#define KERNELD_MAXCMD 0x7ffeffff +#define KERNELD_MINSEQ 0x7fff0000 /* "commands" legal up to 0x7ffeffff */ +#define KERNELD_WAIT 0x80000000 +#define KERNELD_NOWAIT 0 + +struct kerneld_msg + { + long mtype; + long id; +#ifdef NEW_KERNELD_PROTOCOL + short version; + short pid; +#endif /* NEW_KERNELD_PROTOCOL */ + char text[1]; + }; + +#endif /* kerneld.h */ diff --git a/mdk-stage1/insmod-modutils/include/modstat.h b/mdk-stage1/insmod-modutils/include/modstat.h new file mode 100644 index 000000000..b8a58eeae --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/modstat.h @@ -0,0 +1,55 @@ +/* + * For kernel module status and information + * + * Add module_name_list and l_module_name_list. + * Keith Owens November 1999. + * Björn Ekwall February 1999. + * + * This file is part of the Linux modutils. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#ifndef _KERNEL_H +#define _KERNEL_H + +#define K_SYMBOLS 1 /* Want info about symbols */ +#define K_INFO 2 /* Want extended module info */ +#define K_REFS 4 /* Want info about references */ + +struct module_stat { + char *name; + unsigned long addr; + unsigned long modstruct; /* COMPAT_2_0! *//* depends on architecture? */ + unsigned long size; + unsigned long flags; + long usecount; + size_t nsyms; + struct module_symbol *syms; + size_t nrefs; + struct module_stat **refs; + unsigned long status; +}; + +extern struct module_stat *module_stat; +extern size_t n_module_stat; +extern char *module_name_list; +extern size_t l_module_name_list; +extern struct module_symbol *ksyms; +extern size_t nksyms; +extern int k_new_syscalls; + +int get_kernel_info(int type); + +#endif /* _KERNEL_H */ diff --git a/mdk-stage1/insmod-modutils/include/module.h b/mdk-stage1/insmod-modutils/include/module.h new file mode 100644 index 000000000..db49ab2b2 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/module.h @@ -0,0 +1,210 @@ +/* Definitions for the Linux module syscall interface. + Copyright 1996, 1997 Linux International. + + Contributed by Richard Henderson + + This file is part of the Linux modutils. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + +#ifndef MODUTILS_MODULE_H +#define MODUTILS_MODULE_H 1 + +#ident "$Id$" + +/* This file contains the structures used by the 2.0 and 2.1 kernels. + We do not use the kernel headers directly because we do not wish + to be dependant on a particular kernel version to compile insmod. */ + + +/*======================================================================*/ +/* The structures used by Linux 2.0. */ + +/* The symbol format used by get_kernel_syms(2). */ +struct old_kernel_sym +{ + unsigned long value; + char name[60]; +}; + +struct old_module_ref +{ + unsigned long module; /* kernel addresses */ + unsigned long next; +}; + +struct old_module_symbol +{ + unsigned long addr; + unsigned long name; +}; + +struct old_symbol_table +{ + int size; /* total, including string table!!! */ + int n_symbols; + int n_refs; + struct old_module_symbol symbol[0]; /* actual size defined by n_symbols */ + struct old_module_ref ref[0]; /* actual size defined by n_refs */ +}; + +struct old_mod_routines +{ + unsigned long init; + unsigned long cleanup; +}; + +struct old_module +{ + unsigned long next; + unsigned long ref; /* the list of modules that refer to me */ + unsigned long symtab; + unsigned long name; + int size; /* size of module in pages */ + unsigned long addr; /* address of module */ + int state; + unsigned long cleanup; /* cleanup routine */ +}; + +/* Sent to init_module(2) or'ed into the code size parameter. */ +#define OLD_MOD_AUTOCLEAN 0x40000000 /* big enough, but no sign problems... */ + +int get_kernel_syms(struct old_kernel_sym *); +int old_sys_init_module(const char *name, char *code, unsigned codesize, + struct old_mod_routines *, struct old_symbol_table *); + +/*======================================================================*/ +/* For sizeof() which are related to the module platform and not to the + environment isnmod is running in, use sizeof_xx instead of sizeof(xx). */ + +#define tgt_sizeof_char sizeof(char) +#define tgt_sizeof_short sizeof(short) +#define tgt_sizeof_int sizeof(int) +#define tgt_sizeof_long sizeof(long) +#define tgt_sizeof_char_p sizeof(char *) +#define tgt_sizeof_void_p sizeof(void *) +#define tgt_long long +#define tgt_long_fmt "l" + +/* This assumes that long long on a 32 bit system is equivalent to long on the + * equivalent 64 bit system. Also that void and char pointers are 8 bytes on + * all 64 bit systems. Add per system tweaks if it ever becomes necessary. + */ +#if defined(COMMON_3264) && defined(ONLY_64) +#undef tgt_long +#undef tgt_long_fmt +#undef tgt_sizeof_long +#undef tgt_sizeof_char_p +#undef tgt_sizeof_void_p +#define tgt_long long long +#define tgt_long_fmt "ll" +#define tgt_sizeof_long 8 +#define tgt_sizeof_char_p 8 +#define tgt_sizeof_void_p 8 +#endif + +/*======================================================================*/ +/* The structures used in Linux 2.1 onwards. */ + +/* Note: module_symbol does not use tgt_long intentionally */ +struct module_symbol +{ + unsigned long value; + unsigned long name; +}; + +struct module_ref +{ + unsigned tgt_long dep; /* kernel addresses */ + unsigned tgt_long ref; + unsigned tgt_long next_ref; +}; + +struct module +{ + unsigned tgt_long size_of_struct; /* == sizeof(module) */ + unsigned tgt_long next; + unsigned tgt_long name; + unsigned tgt_long size; + + tgt_long usecount; + unsigned tgt_long flags; /* AUTOCLEAN et al */ + + unsigned nsyms; + unsigned ndeps; + + unsigned tgt_long syms; + unsigned tgt_long deps; + unsigned tgt_long refs; + unsigned tgt_long init; + unsigned tgt_long cleanup; + unsigned tgt_long ex_table_start; + unsigned tgt_long ex_table_end; +#ifdef __alpha__ + unsigned tgt_long gp; +#endif + /* Everything after here is extension. */ + unsigned tgt_long read_start; /* Read data from existing module */ + unsigned tgt_long read_end; + unsigned tgt_long can_unload; + unsigned tgt_long runsize; + unsigned tgt_long kallsyms_start; + unsigned tgt_long kallsyms_end; + unsigned tgt_long archdata_start; + unsigned tgt_long archdata_end; + unsigned tgt_long kernel_data; +}; + +struct module_info +{ + unsigned long addr; + unsigned long size; + unsigned long flags; + long usecount; +}; + +/* Bits of module.flags. */ +#define NEW_MOD_RUNNING 1 +#define NEW_MOD_DELETED 2 +#define NEW_MOD_AUTOCLEAN 4 +#define NEW_MOD_VISITED 8 +#define NEW_MOD_USED_ONCE 16 +#define NEW_MOD_INITIALIZING 64 + +int sys_init_module(const char *name, const struct module *); +int query_module(const char *name, int which, void *buf, size_t bufsize, + size_t *ret); + +/* Values for query_module's which. */ + +#define QM_MODULES 1 +#define QM_DEPS 2 +#define QM_REFS 3 +#define QM_SYMBOLS 4 +#define QM_INFO 5 + +/*======================================================================*/ +/* The system calls unchanged between 2.0 and 2.1. */ + +unsigned long create_module(const char *, size_t); +int delete_module(const char *); + +/* In safe mode the last parameter is forced to be a module name and meta + * expansion is not allowed on that name. + */ +extern unsigned int safemode; + +#endif /* module.h */ diff --git a/mdk-stage1/insmod-modutils/include/obj.h b/mdk-stage1/insmod-modutils/include/obj.h new file mode 100644 index 000000000..b140c65c3 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/obj.h @@ -0,0 +1,275 @@ +/* Elf object file loading and relocation routines. + Copyright 1996, 1997 Linux International. + + Contributed by Richard Henderson + obj_free() added by Björn Ekwall March 1999 + + This file is part of the Linux modutils. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + +#ifndef MODUTILS_OBJ_H +#define MODUTILS_OBJ_H 1 + +#ident "$Id$" + +/* The relocatable object is manipulated using elfin types. */ + +#include +#include +#include ELF_MACHINE_H + +#ifndef ElfW +# if ELFCLASSM == ELFCLASS32 +# define ElfW(x) Elf32_ ## x +# define ELFW(x) ELF32_ ## x +# else +# define ElfW(x) Elf64_ ## x +# define ELFW(x) ELF64_ ## x +# endif +#endif + +#if defined(COMMON_3264) && defined(ONLY_32) +# define ObjW(x) obj32_ ## x +#else +# if defined(COMMON_3264) && defined(ONLY_64) +# define ObjW(x) obj64_ ## x +# else +# define ObjW(x) obj_ ## x +# endif +#endif + +/* For some reason this is missing from lib5. */ +#ifndef ELF32_ST_INFO +# define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) +#endif + +#ifndef ELF64_ST_INFO +# define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) +#endif + +struct obj_string_patch_struct; +struct obj_symbol_patch_struct; + +struct obj_section +{ + ElfW(Shdr) header; + const char *name; + char *contents; + struct obj_section *load_next; + int idx; +}; + +struct obj_symbol +{ + struct obj_symbol *next; /* hash table link */ + const char *name; + unsigned long value; + unsigned long size; + int secidx; /* the defining section index/module */ + int info; + int ksymidx; /* for export to the kernel symtab */ + int r_type; /* relocation type */ +}; + +/* Hardcode the hash table size. We shouldn't be needing so many + symbols that we begin to degrade performance, and we get a big win + by giving the compiler a constant divisor. */ + +#define HASH_BUCKETS 521 + +struct obj_file +{ + ElfW(Ehdr) header; + ElfW(Addr) baseaddr; + struct obj_section **sections; + struct obj_section *load_order; + struct obj_section **load_order_search_start; + struct obj_string_patch_struct *string_patches; + struct obj_symbol_patch_struct *symbol_patches; + int (*symbol_cmp)(const char *, const char *); + unsigned long (*symbol_hash)(const char *); + unsigned long local_symtab_size; + struct obj_symbol **local_symtab; + struct obj_symbol *symtab[HASH_BUCKETS]; + const char *filename; + char *persist; +}; + +enum obj_reloc +{ + obj_reloc_ok, + obj_reloc_overflow, + obj_reloc_dangerous, + obj_reloc_unhandled, + obj_reloc_constant_gp +}; + +struct obj_string_patch_struct +{ + struct obj_string_patch_struct *next; + int reloc_secidx; + ElfW(Addr) reloc_offset; + ElfW(Addr) string_offset; +}; + +struct obj_symbol_patch_struct +{ + struct obj_symbol_patch_struct *next; + int reloc_secidx; + ElfW(Addr) reloc_offset; + struct obj_symbol *sym; +}; + + +/* Generic object manipulation routines. */ + +#define obj_elf_hash ObjW(elf_hash) +#define obj_elf_hash_n ObjW(elf_hash_n) +#define obj_add_symbol ObjW(add_symbol) +#define obj_find_symbol ObjW(find_symbol) +#define obj_symbol_final_value ObjW(symbol_final_value) +#define obj_set_symbol_compare ObjW(set_symbol_compare) +#define obj_find_section ObjW(find_section) +#define obj_insert_section_load_order ObjW(insert_section_load_order) +#define obj_create_alloced_section ObjW(create_alloced_section) +#define obj_create_alloced_section_first \ + ObjW(create_alloced_section_first) +#define obj_extend_section ObjW(extend_section) +#define obj_string_patch ObjW(string_patch) +#define obj_symbol_patch ObjW(symbol_patch) +#define obj_check_undefineds ObjW(check_undefineds) +#define obj_clear_undefineds ObjW(clear_undefineds) +#define obj_allocate_commons ObjW(allocate_commons) +#define obj_load_size ObjW(load_size) +#define obj_relocate ObjW(relocate) +#define obj_load ObjW(load) +#define obj_free ObjW(free) +#define obj_create_image ObjW(create_image) +#define obj_addr_to_native_ptr ObjW(addr_to_native_ptr) +#define obj_native_ptr_to_addr ObjW(native_ptr_to_addr) +#define arch_new_file ObjW(arch_new_file) +#define arch_new_section ObjW(arch_new_section) +#define arch_new_symbol ObjW(arch_new_symbol) +#define arch_apply_relocation ObjW(arch_apply_relocation) +#define arch_create_got ObjW(arch_create_got) +#define arch_init_module ObjW(arch_init_module) +#define arch_load_proc_section ObjW(arch_load_proc_section) +#define arch_finalize_section_address ObjW(arch_finalize_section_address) +#define arch_archdata ObjW(arch_archdata) + +unsigned long obj_elf_hash (const char *); + +unsigned long obj_elf_hash_n (const char *, unsigned long len); + +struct obj_symbol *obj_add_symbol (struct obj_file *f, const char *name, + unsigned long symidx, int info, int secidx, + ElfW(Addr) value, unsigned long size); + +struct obj_symbol *obj_find_symbol (struct obj_file *f, + const char *name); + +ElfW(Addr) obj_symbol_final_value (struct obj_file *f, + struct obj_symbol *sym); + +void obj_set_symbol_compare (struct obj_file *f, + int (*cmp)(const char *, const char *), + unsigned long (*hash)(const char *)); + +struct obj_section *obj_find_section (struct obj_file *f, + const char *name); + +void obj_insert_section_load_order (struct obj_file *f, + struct obj_section *sec); + +struct obj_section *obj_create_alloced_section (struct obj_file *f, + const char *name, + unsigned long align, + unsigned long size); + +struct obj_section *obj_create_alloced_section_first (struct obj_file *f, + const char *name, + unsigned long align, + unsigned long size); + +void *obj_extend_section (struct obj_section *sec, unsigned long more); + +int obj_string_patch (struct obj_file *f, int secidx, ElfW(Addr) offset, + const char *string); + +int obj_symbol_patch (struct obj_file *f, int secidx, ElfW(Addr) offset, + struct obj_symbol *sym); + +int obj_check_undefineds (struct obj_file *f, int quiet); + +void obj_clear_undefineds (struct obj_file *f); + +void obj_allocate_commons (struct obj_file *f); + +unsigned long obj_load_size (struct obj_file *f); + +int obj_relocate (struct obj_file *f, ElfW(Addr) base); + +struct obj_file *obj_load (int f, Elf32_Half e_type, const char *filename); + +void obj_free (struct obj_file *f); + +int obj_create_image (struct obj_file *f, char *image); + +int obj_kallsyms (struct obj_file *fin, struct obj_file **fout); + +/* Architecture specific manipulation routines. */ + +struct obj_file *arch_new_file (void); + +struct obj_section *arch_new_section (void); + +struct obj_symbol *arch_new_symbol (void); + +enum obj_reloc arch_apply_relocation (struct obj_file *f, + struct obj_section *targsec, + struct obj_section *symsec, + struct obj_symbol *sym, + ElfW(RelM) *rel, ElfW(Addr) value); + +int arch_create_got (struct obj_file *f); + +struct module; +int arch_init_module (struct obj_file *f, struct module *); + +int arch_load_proc_section (struct obj_section *sec, int fp); + +int arch_finalize_section_address (struct obj_file *f, ElfW(Addr) base); + +int arch_archdata (struct obj_file *fin, struct obj_section *sec); + +#define ARCHDATA_SEC_NAME "__archdata" + +/* Pointers in objects can be 32 or 64 bit */ +union obj_ptr_4 { + Elf32_Word addr; + void *ptr; +}; +union obj_ptr_8 { + Elf64_Xword addr; + void *ptr; +}; + +void *obj_addr_to_native_ptr(ElfW(Addr)); + +ElfW(Addr) obj_native_ptr_to_addr(void *); + +#endif /* obj.h */ diff --git a/mdk-stage1/insmod-modutils/include/util.h b/mdk-stage1/insmod-modutils/include/util.h new file mode 100644 index 000000000..b2e4a67c3 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/util.h @@ -0,0 +1,101 @@ +/* Miscelaneous utility functions. + Copyright 1996, 1997 Linux International. + + Contributed by Richard Henderson + + This file is part of the Linux modutils. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + +#ifndef MODUTILS_UTIL_H +#define MODUTILS_UTIL_H 1 + +#ident "$Id$" + +#include +#include + +#define SHELL_META "&();|<>$`\"'\\!{}[]~=+:?*" /* Sum of bj0rn and Debian */ + +void *xmalloc(size_t); +void *xrealloc(void *, size_t); +char *xstrdup(const char *); +char *xstrcat(char *, const char *, size_t); +int xsystem(const char *, char *const[]); +int arch64(void); + +typedef int (*xftw_func_t)(const char *, const struct stat *); +extern int xftw(const char *directory, xftw_func_t); + +/* Error logging */ +extern int log; +extern int errors; +extern const char *error_file; + +extern int flag_verbose; +extern void verbose(const char *ctl,...); + +void error(const char *fmt, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 1, 2))) +#endif + ; + +void lprintf(const char *fmt, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 1, 2))) +#endif + ; + +void setsyslog(const char *program); + +/* + * Generic globlist + */ +typedef struct { + int pathc; /* Count of paths matched so far */ + char **pathv; /* List of matched pathnames. */ +} GLOB_LIST; +int meta_expand(char *pt, GLOB_LIST *g, char *base_dir, char *version, int type); +#define ME_BUILTIN_COMMAND 1 +#define ME_SHELL_COMMAND 2 +#define ME_GLOB 4 +#define ME_ALL (ME_GLOB|ME_SHELL_COMMAND|ME_BUILTIN_COMMAND) + +extern void snap_shot(const char *module_name, int number); +extern void snap_shot_log(const char *fmt,...); + +#ifdef CONFIG_USE_ZLIB +int gzf_open(const char *name, int mode); +int gzf_read(int fd, void *buf, size_t count); +off_t gzf_lseek(int fd, off_t offset, int whence); +void gzf_close(int fd); + +#else /* ! CONFIG_USE_ZLIB */ + +#include + +#define gzf_open open +#define gzf_read read +#define gzf_lseek lseek +#define gzf_close close + +#endif /* CONFIG_USE_ZLIB */ + +#define SYMPREFIX "__insmod_"; +extern const char symprefix[10]; /* Must be sizeof(SYMPREFIX), including nul */ + +#endif /* util.h */ diff --git a/mdk-stage1/insmod-modutils/include/version.h b/mdk-stage1/insmod-modutils/include/version.h new file mode 100644 index 000000000..51ca0eb29 --- /dev/null +++ b/mdk-stage1/insmod-modutils/include/version.h @@ -0,0 +1 @@ +#define MODUTILS_VERSION "2.4.2" -- cgit v1.2.1