1. 程式人生 > >二進位制檔案格式裝載支援

二進位制檔案格式裝載支援

/*
 * This structure defines the functions that are used to load the binary formats that
 * linux accepts.
 */
struct linux_binfmt {
 struct list_head lh;
 struct module *module;
 int (*load_binary)(struct linux_binprm *);
 int (*load_shlib)(struct file *);
 int (*core_dump)(struct coredump_params *cprm);
 unsigned long min_coredump; /* minimal dump size */
};

static LIST_HEAD(formats); static DEFINE_RWLOCK(binfmt_lock);

void __register_binfmt(struct linux_binfmt * fmt, int insert) {  BUG_ON(!fmt);  if (WARN_ON(!fmt->load_binary))   return;  write_lock(&binfmt_lock);  insert ? list_add(&fmt->lh, &formats) :    list_add_tail(&fmt->lh, &formats);

 write_unlock(&binfmt_lock); }

EXPORT_SYMBOL(__register_binfmt);

void unregister_binfmt(struct linux_binfmt * fmt) {  write_lock(&binfmt_lock);  list_del(&fmt->lh);  write_unlock(&binfmt_lock); }

EXPORT_SYMBOL(unregister_binfmt);

static struct linux_binfmt aout_format = {
 .module  = THIS_MODULE,
 .load_binary = load_aout_binary,
 .load_shlib = load_aout_library,
 .core_dump = aout_core_dump,
 .min_coredump = PAGE_SIZE
};
static struct linux_binfmt elf_format = {
 .module  = THIS_MODULE,
 .load_binary = load_elf_binary,
 .load_shlib = load_elf_library,
 .core_dump = elf_core_dump,
 .min_coredump = ELF_EXEC_PAGESIZE,
};
static struct linux_binfmt script_format = {
 .module  = THIS_MODULE,
 .load_binary = load_script,
};