binfmt_aout.c

Andries.Brouwer@cwi.nl
Fri, 22 Oct 1999 22:34:22 +0200 (MET DST)


Yesterday or so I complained that my programs segfaulted under 2.2.13.
Not so strange, a mmap was missing and two offsets were wrong, if I am
not mistaken. (I could easily be - have not checked all details.)

Below a patch that fixes the problems for me.
Please do not put this in 2.2.14. As far as I can see the 2.2.13 patch on
binfmt_aout.c does not really serve any useful purpose, quite the contrary,
and after fixing the patch (which I do not claim to have done), the situation
is still worse than in 2.2.12.

Discussion:
1. Warnings: I hate getting a printk every 5 seconds.
Getting three warnings at boot time to remind me of
the fact (which I am well aware of) that there still
are many old ZMAGIC binaries, is amply sufficient.
2. Text of the warnings: "please convert" is easily said,
but nobody ever gave me the source for Maple, just to
mention one example. Conversion is often not possible.
3. Actual changes:
(i) fd_offset instead of 0 in call to do_mmap()
(ii) N_TXTOFF(ex) instead of 0 in call to do_mmap()
(iii) readded the mmap of bss - the fact that this was
missing caused the library segfaults.

Andries

10:23pm up 983 days, 10:12, 3 users, load average: 1.08, 1.02, 0.93

--- binfmt_aout.c-2.2.13 Fri Oct 22 00:29:47 1999
+++ binfmt_aout.c-2.2.13a Fri Oct 22 22:14:30 1999
@@ -389,35 +389,29 @@
flush_icache_range((unsigned long) 0,
(unsigned long) ex.a_text+ex.a_data);
} else {
- static unsigned long error_time, error_time2;
+ static int count1 = 0, count2 = 0;
if ((ex.a_text & 0xfff || ex.a_data & 0xfff) &&
- (N_MAGIC(ex) != NMAGIC) && (jiffies-error_time2) > 5*HZ)
- {
+ (N_MAGIC(ex) != NMAGIC) && count1++ < 3)
printk(KERN_NOTICE "executable not page aligned\n");
- error_time2 = jiffies;
- }

fd = open_dentry(bprm->dentry, O_RDONLY);
if (fd < 0)
return fd;
file = fget(fd);

- if ((fd_offset & ~PAGE_MASK) != 0 &&
- (jiffies-error_time) > 5*HZ)
- {
+ if ((fd_offset & ~PAGE_MASK) != 0 && count2++ < 3)
printk(KERN_WARNING
- "fd_offset is not page aligned. Please convert program: %s\n",
- file->f_dentry->d_name.name
- );
- error_time = jiffies;
- }
+ "fd_offset is not page aligned. "
+ "Consider converting program: %s\n",
+ file->f_dentry->d_name.name);

- if (!file->f_op || !file->f_op->mmap || ((fd_offset & ~PAGE_MASK) != 0)) {
+ if (!file->f_op || !file->f_op->mmap ||
+ (fd_offset & ~PAGE_MASK) != 0) {
fput(file);
sys_close(fd);
do_mmap(NULL, N_TXTADDR(ex), ex.a_text+ex.a_data,
PROT_READ|PROT_WRITE|PROT_EXEC,
- MAP_FIXED|MAP_PRIVATE, 0);
+ MAP_FIXED|MAP_PRIVATE, fd_offset);
read_exec(bprm->dentry, fd_offset,
(char *) N_TXTADDR(ex), ex.a_text+ex.a_data, 0);
flush_icache_range((unsigned long) N_TXTADDR(ex),
@@ -531,33 +525,32 @@
start_addr = ex.a_entry & 0xfffff000;

if ((N_TXTOFF(ex) & ~PAGE_MASK) != 0) {
- static unsigned long error_time;
+ static int count0 = 0;

- if ((jiffies-error_time) > 5*HZ)
- {
+ if (count0++ < 3)
printk(KERN_WARNING
- "N_TXTOFF is not page aligned. Please convert library: %s\n",
+ "N_TXTOFF is not page aligned. "
+ "Consider converting library: %s\n",
file->f_dentry->d_name.name);
- error_time = jiffies;
- }
+
do_mmap(NULL, start_addr, ex.a_text + ex.a_data,
PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_FIXED| MAP_PRIVATE, 0);
+ MAP_FIXED| MAP_PRIVATE, N_TXTOFF(ex));
read_exec(file->f_dentry, N_TXTOFF(ex),
(char *)start_addr, ex.a_text + ex.a_data, 0);
flush_icache_range((unsigned long) start_addr,
(unsigned long) start_addr + ex.a_text + ex.a_data);
retval = 0;
- goto out_putf;
+ } else {
+ /* Now use mmap to map the library into memory. */
+ error = do_mmap(file, start_addr, ex.a_text + ex.a_data,
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
+ N_TXTOFF(ex));
+ retval = error;
+ if (error != start_addr)
+ goto out_putf;
}
- /* Now use mmap to map the library into memory. */
- error = do_mmap(file, start_addr, ex.a_text + ex.a_data,
- PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
- N_TXTOFF(ex));
- retval = error;
- if (error != start_addr)
- goto out_putf;

len = PAGE_ALIGN(ex.a_text + ex.a_data);
bss = ex.a_text + ex.a_data + ex.a_bss;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/