7 #include <linux/module.h>
9 #include <linux/time.h>
10 #include <linux/kernel.h>
12 #include <linux/mman.h>
13 #include <linux/a.out.h>
14 #include <linux/errno.h>
15 #include <linux/signal.h>
16 #include <linux/string.h>
19 #include <linux/stat.h>
20 #include <linux/fcntl.h>
21 #include <linux/ptrace.h>
23 #include <linux/binfmts.h>
24 #include <linux/personality.h>
27 #include <linux/slab.h>
29 #include <asm/uaccess.h>
30 #include <asm/cacheflush.h>
31 #include <asm/a.out-core.h>
34 static int load_aout_library(
struct file*);
36 #ifdef CONFIG_COREDUMP
55 # define START_DATA(u) ((void __user *)u.start_data)
57 # define START_DATA(u) ((void __user *)((u.u_tsize << PAGE_SHIFT) + \
60 # define START_STACK(u) ((void __user *)u.start_stack)
97 if (
dump.u_dsize != 0) {
98 dump_start = START_DATA(
dump);
104 if (
dump.u_ssize != 0) {
105 dump_start = START_STACK(
dump);
115 #define aout_core_dump NULL
120 .load_binary = load_aout_binary,
121 .load_shlib = load_aout_library,
126 #define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
128 static int set_brk(
unsigned long start,
unsigned long end)
134 addr =
vm_brk(start, end - start);
146 static unsigned long __user *create_aout_tables(
char __user *
p,
struct linux_binprm * bprm)
152 int envc = bprm->
envc;
154 sp = (
void __user *)((-(
unsigned long)
sizeof(
char *)) & (
unsigned long) p);
173 put_user((
unsigned long) envp,--sp);
174 put_user((
unsigned long) argv,--sp);
208 unsigned long fd_offset;
212 ex = *((
struct exec *) bprm->
buf);
224 if (!bprm->
file->f_op || !bprm->
file->f_op->mmap)
236 if (ex.a_data + ex.a_bss > rlim)
246 SET_AOUT_PERSONALITY(bprm, ex);
252 current->mm->end_code = ex.a_text +
254 current->mm->end_data = ex.a_data +
259 current->mm->cached_hole_size = 0;
271 unsigned long text_addr, map_size;
278 map_size = ex.a_text+ex.a_data +
PAGE_SIZE - 1;
281 map_size = ex.a_text+ex.a_data;
289 error = bprm->
file->f_op->read(bprm->
file,
290 (
char __user *)text_addr,
291 ex.a_text+ex.a_data, &pos);
292 if ((
signed long)error < 0) {
299 if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
305 if ((fd_offset & ~PAGE_MASK) != 0 && printk_ratelimit())
308 "fd_offset is not page aligned. Please convert program: %s\n",
309 bprm->
file->f_path.dentry->d_name.name);
312 if (!bprm->
file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
313 loff_t pos = fd_offset;
317 ex.a_text+ex.a_data, &pos);
320 ex.a_text+ex.a_data);
337 fd_offset + ex.a_text);
353 (
unsigned long) create_aout_tables((
char __user *) bprm->
p, bprm);
355 regs->
gp = ex.a_gpvalue;
361 static int load_aout_library(
struct file *file)
369 inode = file->
f_path.dentry->d_inode;
372 error =
kernel_read(file, 0, (
char *) &ex,
sizeof(ex));
373 if (error !=
sizeof(ex))
387 if (!file->
f_op || !file->
f_op->mmap)
396 start_addr = ex.a_entry & 0xfffff000;
398 if ((
N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
401 if (printk_ratelimit())
404 "N_TXTOFF is not page aligned. Please convert library: %s\n",
405 file->
f_path.dentry->d_name.name);
407 vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
409 file->
f_op->read(file, (
char __user *)start_addr,
410 ex.a_text + ex.a_data, &pos);
412 (
unsigned long) start_addr + ex.a_text + ex.a_data);
418 error =
vm_mmap(file, start_addr, ex.a_text + ex.a_data,
423 if (error != start_addr)
427 bss = ex.a_text + ex.a_data + ex.a_bss;
429 error =
vm_brk(start_addr + len, bss - len);
431 if (error != start_addr + len)
439 static int __init init_aout_binfmt(
void)
441 register_binfmt(&aout_format);
445 static void __exit exit_aout_binfmt(
void)