Subject: COMPAT_LINUX/powerpc: signals
To: None <tech-kern@netbsd.org>
From: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
List: tech-kern
Date: 01/11/2001 21:47:41
Signals are now nearly working, but I'm a bit confused by a strange
problem. Here is a sampe program:

#include <stdio.h>
#include <unistd.h>
#include <signal.h>

void* func (int, int, struct sigcontext*);


int main (int argc, char** argv) {
        printf("Starting execution\n");
        if (signal(SIGHUP,*func))
                perror ("signal() failed");     
        printf("signal() successful. Now sleeping\n");
        while (1) 
                sleep (600);
        printf("I should not come here\n");
        return 0;
}

void* func (int sig, int code, struct sigcontext* scp) {
        printf("Signal Handler: sig=%d  code=0x%x  scp=0x%lx\n",sig,
code, (unsigned long)scp);
        return NULL;
}

Here is what it does on Linux:
$ ./signal &
[1] 23358
Starting execution
signal() successful. Now sleeping
$ kill -1 23358 
Signal Handler: sig=1  code=0x7ffff9d0  scp=0x1

And here is the result of the same program, build for NetBSD, and
running on NetBSD (there is no emulation here)
$ ./signal &                               
Starting execution
[1] 177
signal() successful. Now sleeping
$ kill -1 177
Signal Handler: sig=1  code=0  scp=0x7fffe8d8

Seems code and scp are exchanged, and I see no reason for this. This is
really weird, I assume that I've missed something. Anyone has a LinuxPPC
box to try it? I'd like to be sure there is no mistake here.

If this code/scp exchange is confirmed, shouldn't we emulate the Linux
behavior, and pass exchanged code and scp to the signal handler?

Another problem, about Linux dynamic executables. Most of the time, they
work. But sometime, they crash at startup. A kernel trace shows this:
   186 ls       EMUL  "linux"
   186 ls       RET   olduname -1 errno -2 No such file or directory
   186 ls       PSIG  SIGILL SIG_DFL
   186 ls       NAMI  "ls.core"

The problem is quite rare, so I did not noticed it at once, I have no
way to predict when it will occur. It will show up only for dynamic
exeutables, not static ones. Take a look at what happens if I just run
the same executable (here Linux's ls) with the same arguments in a loop:

$ while [ 1 ] ; do ./ls /var/crash ; done
minfree
minfree
Illegal instruction (core dumped) 
minfree
minfree
minfree
minfree
minfree
minfree
minfree
Illegal instruction (core dumped) 
minfree
minfree
minfree
minfree
minfree
minfree
minfree
minfree
minfree
minfree
minfree
minfree
minfree

I have no idea why this occurs. it's surprising, because as far as I
know, if I invoke the same executable with the same arguments and
environement, the stack layout will be exactly the same, right? So I
beleive this cannot be caused by a bug in the way I set up the stack.
But there must be a bug somewhere, else it would not crash.

And it's really a random problem: sometimes, I can run my ls loop for
minutes without any failures.

Any idea?

-- 
Emmanuel Dreyfus
- Quel est le meilleur moyen d'accelerer un PC?
- 9,81 m/s^2
p99dreyf@criens.u-psud.fr