Subject: Re: finding where is errno
To: Todd Vierling <email@example.com>
From: Emmanuel Dreyfus <firstname.lastname@example.org>
Date: 04/13/2002 20:56:38
> : I'm still working on COMPAT_IRIX. It seems that during signal delivery,
> : the kernel has to build a signal frame with a field containing errno
> : address in userspace. It is used by the signal trampoline to set errno
> : on sigreturn exit.
> I have a suspicion that this value might be passed to the kernel from the
> libc sigreturn call in an extra register. It's rather unusual for the
> kernel to have to grovel the ELF symbol tables to find such a beast.
On IRIX, the kernel already has to handle psection relocation and load (see
/sys/compat/irix/irix_syssgi.c:irix_mapelf()), I wouldn't be that suprised if
it also has to dig for errno.
I ran a test program on IRIX and checked registers using gdb at signal handler
invocation. errno address seems to be set there:
(gdb) x/32w $sp
0x7fff2ab0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7fff2ac0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7fff2ad0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7fff2ae0: 0x00000000 0x00000000 0x00000000 0x00000000
0x7fff2af0: 0x00000000 0x00000000 0x00000000 0x0fb4f9b0
0x7fff2b00: 0x00000000 0x80000001 0x00000000 0x7fff2b10
0x7fff2b10: 0x0000000f 0x00000000 0x00000000 0x00000000
0x7fff2b20: 0x00000000 0x00000000 0x7fff0000 0x00006b58
(gdb) x/1w 0x0fb4f9b0
0xfb4f9b0 <errno>: 0x00000000
If it's done at signal handler invocation, then
1) the kernel knows it
2) the user process always has a register pointing there.
3) another solution?
Dumping the registers during normal program operation shows no errno address,
hence solution 2) seems wrong.
(gdb) info reg
zero at v0 v1 a0 a1 a2 a3
R0 00000000 00000000 00000000 0000bded 0000bec8 00000001 00000026 00000000
t0 t1 t2 t3 t4 t5 t6 t7
R8 00000042 00000000 0fb4e931 00000042 00000040 00001000 0fb54fa0 00001000
s0 s1 s2 s3 s4 s5 s6 s7
R16 0000bec8 7fff2f74 7fff2f7c 7fff2fc8 00000000 00000000 00000000 00000000
t8 t9 k0 k1 gp sp fp ra
R24 0fb502e4 0fa4541c 00000000 8000003f 1000c0c0 7fff2ef8 00000000 00400e14
pc cause bad hi lo fsr fir
0fa455a4 00000008 00000000 00000050 00000073 00000000 00000000
UNIX *is* user friendly. It is just a bit selective about his friends