2003-11-29 04:55:59 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
my $in = shift;
|
|
|
|
my $tls_offsets = shift;
|
|
|
|
my $out = shift;
|
|
|
|
my $sigfe = shift;
|
|
|
|
|
|
|
|
$main::first = 0;
|
|
|
|
if (!defined($in) || !defined($out) || !defined($sigfe)) {
|
|
|
|
die "usage: $0 deffile.in cygtls.h deffile.def sigfe.s\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
require $tls_offsets;
|
|
|
|
|
|
|
|
open(IN, $in) or die "$0: couldn't open \"$in\" - $!\n";
|
|
|
|
my @top = ();
|
|
|
|
while (<IN>) {
|
|
|
|
push(@top, $_);
|
|
|
|
last if /^\s*exports\s*$/i;
|
|
|
|
}
|
|
|
|
my $libline = <IN>;
|
|
|
|
my @in = <IN>;
|
|
|
|
close(IN);
|
|
|
|
|
|
|
|
my %sigfe = ();
|
|
|
|
my @data = ();
|
|
|
|
my @nosigfuncs = ();
|
|
|
|
my @out = ();
|
|
|
|
for (@in) {
|
|
|
|
/\sDATA$/o and do {
|
|
|
|
push(@data, $_);
|
|
|
|
next;
|
|
|
|
};
|
|
|
|
chomp;
|
|
|
|
if (/=/o) {
|
|
|
|
if (s/\s+NOSIGFE\s*$//) {
|
|
|
|
} elsif (s/ SIGFE$//) {
|
|
|
|
my $func = (split(' '))[2];
|
|
|
|
$sigfe{$func} = '_sigfe_' . $func;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my ($func, $sigfe) = m%^\s*(\S+)(?:\s+((?:NO)?SIGR?FE))?$%o;
|
|
|
|
if (defined($sigfe) && $sigfe =~ /^NO/o) {
|
|
|
|
$_ = $func;
|
|
|
|
} else {
|
|
|
|
$sigfe ||= 'sigfe';
|
|
|
|
$_ = '_' . lc($sigfe) . '_' . $func;
|
|
|
|
$sigfe{$func} = $_;
|
|
|
|
$_ = $func . ' = ' . $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s/(\S)\s+(\S)/$1 $2/go;
|
|
|
|
s/(\S)\s+$/$1/o;
|
|
|
|
s/^\s+(\S)/$1/o;
|
|
|
|
push(@out, $_ . "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (@out) {
|
|
|
|
my ($alias, $func) = /^(\S+) = (\S+)\s*$/o;
|
|
|
|
$_ = $alias . ' = ' . $sigfe{$func} . "\n"
|
|
|
|
if defined($func) && $sigfe{$func};
|
|
|
|
}
|
|
|
|
open(OUT, '>', $out) or die "$0: couldn't open \"$out\" - $!\n";
|
|
|
|
print OUT @top, @data, @out;
|
|
|
|
close OUT;
|
|
|
|
|
|
|
|
open(SIGFE, '>', $sigfe) or die "$0: couldn't open sigfe file \"$sigfe\" - $!\n";
|
|
|
|
|
|
|
|
for my $k (sort keys %sigfe) {
|
|
|
|
print SIGFE fefunc($k, $sigfe{$k});
|
|
|
|
}
|
|
|
|
close SIGFE;
|
|
|
|
|
|
|
|
sub fefunc {
|
|
|
|
my $func = '_' . shift;
|
|
|
|
my $fe = '_' . shift;
|
|
|
|
my $extra;
|
|
|
|
my $res = <<EOF;
|
|
|
|
.extern $func
|
|
|
|
.global $fe
|
|
|
|
$fe:
|
|
|
|
pushl \$$func
|
|
|
|
jmp __sigfe
|
|
|
|
|
|
|
|
EOF
|
|
|
|
if (!$main::first++) {
|
|
|
|
$res = <<EOF . longjmp () . $res;
|
|
|
|
.text
|
|
|
|
|
2004-03-06 03:09:04 +08:00
|
|
|
.stabs "_sigfe:F(0,1)",36,0,0,__sigfe
|
2003-11-29 04:55:59 +08:00
|
|
|
__sigfe:
|
2004-02-12 11:01:58 +08:00
|
|
|
pushl %ebx
|
2003-11-29 04:55:59 +08:00
|
|
|
pushl %edx
|
2004-02-12 11:01:58 +08:00
|
|
|
1: movl %fs:4,%edx # location of bottom of stack
|
2004-03-09 09:24:08 +08:00
|
|
|
incl $tls::incyg(%edx)
|
2004-02-12 11:01:58 +08:00
|
|
|
movl \$1,%eax # potential lock value
|
|
|
|
lock xchgl %eax,$tls::stacklock(%edx) # see if we can grab it
|
2004-02-14 03:34:32 +08:00
|
|
|
movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock
|
2004-03-07 12:57:47 +08:00
|
|
|
testl %eax,%eax # it will be zero
|
2004-02-12 11:01:58 +08:00
|
|
|
jz 2f # if so
|
|
|
|
xorl %eax,%eax # nope. It was not zero
|
|
|
|
call _low_priority_sleep # should be a short-time thing, so
|
|
|
|
jmp 1b # sleep and loop
|
2004-03-09 09:24:08 +08:00
|
|
|
2: movl \$4,%eax # have the lock, now increment the
|
2004-02-12 11:01:58 +08:00
|
|
|
xadd %eax,$tls::stackptr(%edx) # stack pointer and get pointer
|
|
|
|
leal __sigbe,%ebx # new place to return to
|
|
|
|
xchgl %ebx,12(%esp) # exchange with real return value
|
|
|
|
movl %ebx,(%eax) # store real return value on alt stack
|
|
|
|
decl $tls::stacklock(%edx) # remove lock
|
|
|
|
popl %edx # restore saved value
|
|
|
|
popl %ebx
|
2003-11-29 04:55:59 +08:00
|
|
|
ret
|
|
|
|
|
2004-02-09 03:59:27 +08:00
|
|
|
.global __sigbe
|
2003-11-29 04:55:59 +08:00
|
|
|
.stabs "_sigbe:F(0,1)",36,0,0,__sigbe
|
|
|
|
__sigbe:
|
2004-02-12 11:01:58 +08:00
|
|
|
pushl %ebx
|
|
|
|
pushl %edx # return here after cygwin syscall
|
|
|
|
pushl %eax # don't clobber
|
|
|
|
1: movl %fs:4,%edx # address of bottom of tls
|
|
|
|
movl \$1,%eax # potential lock value
|
|
|
|
lock xchgl %eax,$tls::stacklock(%edx) # see if we can grab it
|
2004-02-14 03:34:32 +08:00
|
|
|
movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock
|
2004-03-07 12:57:47 +08:00
|
|
|
testl %eax,%eax # it will be zero
|
2004-02-12 11:01:58 +08:00
|
|
|
jz 2f # if so
|
|
|
|
xorl %eax,%eax # nope. not zero
|
|
|
|
call _low_priority_sleep # sleep
|
|
|
|
jmp 1b # and loop
|
|
|
|
2: movl \$-4,%eax # now decrement aux stack
|
|
|
|
xadd %eax,$tls::stackptr(%edx) # and get pointer
|
2004-02-12 12:55:29 +08:00
|
|
|
xorl %ebx,%ebx
|
2004-03-04 13:31:14 +08:00
|
|
|
xchgl %ebx,-4(%eax) # get return address from signal stack
|
|
|
|
xchgl %ebx,8(%esp) # restore ebx/real return address
|
2004-03-07 12:57:47 +08:00
|
|
|
decl $tls::incyg(%edx)
|
2004-02-12 11:01:58 +08:00
|
|
|
decl $tls::stacklock(%edx) # release lock
|
2004-02-09 03:59:27 +08:00
|
|
|
popl %eax
|
2004-02-12 11:01:58 +08:00
|
|
|
popl %edx
|
2004-02-09 03:59:27 +08:00
|
|
|
ret
|
|
|
|
|
2004-03-06 03:09:04 +08:00
|
|
|
.global _sigreturn
|
|
|
|
.stabs "sigreturn:F(0,1)",36,0,0,_sigreturn
|
|
|
|
_sigreturn:
|
2004-03-09 09:24:08 +08:00
|
|
|
movl %fs:4,%ebx
|
|
|
|
incl $tls::incyg(%ebx)
|
2004-03-06 03:09:04 +08:00
|
|
|
addl \$4,%esp # Remove argument
|
|
|
|
call _set_process_mask\@4
|
|
|
|
|
2004-03-09 09:24:08 +08:00
|
|
|
1: movl \$1,%eax # potential lock value
|
|
|
|
lock xchgl %eax,$tls::stacklock(%ebx) # see if we can grab it
|
|
|
|
movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
|
2004-03-07 12:57:47 +08:00
|
|
|
testl %eax,%eax # it will be zero
|
2004-03-06 03:09:04 +08:00
|
|
|
jz 2f # if so
|
|
|
|
xorl %eax,%eax # nope. not zero
|
|
|
|
call _low_priority_sleep # sleep
|
|
|
|
jmp 1b # and loop
|
2004-03-09 09:24:08 +08:00
|
|
|
2: popl %edx # saved errno
|
|
|
|
testl %edx,%edx # Is it < 0
|
2004-03-06 03:09:04 +08:00
|
|
|
jl 3f # yup. ignore it
|
2004-03-09 09:24:08 +08:00
|
|
|
movl $tls::errno_addr(%ebx),%eax
|
|
|
|
movl %edx,(%eax)
|
2004-03-06 03:09:04 +08:00
|
|
|
3: movl \$-4,%eax # now decrement aux stack
|
2004-03-09 09:24:08 +08:00
|
|
|
xadd %eax,$tls::stackptr(%ebx) # and get pointer
|
2004-03-06 03:09:04 +08:00
|
|
|
xorl %ebp,%ebp
|
|
|
|
xchgl %ebp,-4(%eax) # get return address from signal stack
|
|
|
|
xchgl %ebp,28(%esp) # store real return address
|
2004-03-09 09:24:08 +08:00
|
|
|
decl $tls::incyg(%ebx)
|
|
|
|
decl $tls::stacklock(%ebx) # unlock
|
2004-03-06 03:09:04 +08:00
|
|
|
|
|
|
|
popl %eax
|
|
|
|
popl %ebx
|
|
|
|
popl %ecx
|
|
|
|
popl %edx
|
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
popf
|
|
|
|
ret
|
|
|
|
|
|
|
|
.global _sigdelayed
|
|
|
|
.stabs "sigdelayed:F(0,1)",36,0,0,_sigdelayed
|
|
|
|
_sigdelayed:
|
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
pushf
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
pushl %edx
|
|
|
|
pushl %ecx
|
|
|
|
pushl %ebx
|
|
|
|
pushl %eax
|
|
|
|
movl %fs:4,%ebx
|
2004-03-09 09:24:08 +08:00
|
|
|
incl $tls::incyg(%ebx)
|
2004-03-06 03:09:04 +08:00
|
|
|
pushl $tls::saved_errno(%ebx) # saved errno
|
|
|
|
3: pushl $tls::oldmask(%ebx) # oldmask
|
|
|
|
pushl $tls::sig(%ebx) # signal argument
|
|
|
|
pushl \$_sigreturn
|
|
|
|
|
|
|
|
call _reset_signal_arrived\@0
|
|
|
|
pushl $tls::func(%ebx) # signal func
|
|
|
|
pushl $tls::newmask(%ebx) # newmask - eaten by set_process_mask
|
|
|
|
|
|
|
|
call _set_process_mask\@4
|
|
|
|
cmpl \$0,$tls::threadkill(%ebx)#pthread_kill signal?
|
|
|
|
jnz 4f #yes. Callee clears signal number
|
|
|
|
movl \$0,$tls::sig(%ebx) # zero the signal number as a
|
|
|
|
# flag to the signal handler thread
|
|
|
|
# that it is ok to set up sigsave
|
2004-03-09 09:24:08 +08:00
|
|
|
4: decl $tls::incyg(%ebx)
|
|
|
|
ret
|
2004-03-06 03:09:04 +08:00
|
|
|
|
2004-02-12 11:01:58 +08:00
|
|
|
.global __ZN7_cygtls3popEv
|
|
|
|
__ZN7_cygtls3popEv:
|
2004-02-09 03:59:27 +08:00
|
|
|
1: pushl %ebx
|
2004-02-12 11:01:58 +08:00
|
|
|
pushl %edx # FIXME: needed?
|
2004-02-09 03:59:27 +08:00
|
|
|
movl %eax,%edx
|
|
|
|
movl \$-4,%ebx
|
|
|
|
xadd %ebx,$tls::pstackptr(%edx)
|
2004-02-12 12:55:29 +08:00
|
|
|
xorl %eax,%eax
|
2004-02-09 12:04:24 +08:00
|
|
|
xchgl %eax,-4(%ebx)
|
2004-02-12 11:01:58 +08:00
|
|
|
popl %edx # FIXME: needed?
|
2004-02-09 03:59:27 +08:00
|
|
|
popl %ebx
|
2003-11-29 04:55:59 +08:00
|
|
|
ret
|
|
|
|
|
2004-02-12 11:01:58 +08:00
|
|
|
.global __ZN7_cygtls4lockEv
|
|
|
|
__ZN7_cygtls4lockEv:
|
|
|
|
pushl %edi
|
|
|
|
movl %eax,%edi
|
2004-02-09 03:59:27 +08:00
|
|
|
1: movl \$1,%eax
|
2004-02-12 11:01:58 +08:00
|
|
|
lock xchgl %eax,$tls::pstacklock(%edi)
|
2004-03-07 12:57:47 +08:00
|
|
|
testl %eax,%eax
|
2004-02-09 03:59:27 +08:00
|
|
|
jz 2f
|
|
|
|
xorl %eax,%eax
|
|
|
|
call _low_priority_sleep
|
|
|
|
jmp 1b
|
2004-02-12 11:01:58 +08:00
|
|
|
2: popl %edi
|
2004-02-09 03:59:27 +08:00
|
|
|
ret
|
|
|
|
|
2004-02-12 11:01:58 +08:00
|
|
|
.global __ZN7_cygtls6unlockEv
|
|
|
|
__ZN7_cygtls6unlockEv:
|
2004-02-09 03:59:27 +08:00
|
|
|
decl $tls::pstacklock(%eax)
|
|
|
|
ret
|
|
|
|
|
2004-02-12 11:01:58 +08:00
|
|
|
.global __ZN7_cygtls6lockedEv
|
|
|
|
__ZN7_cygtls6lockedEv:
|
|
|
|
movl $tls::pstacklock(%eax),%eax
|
|
|
|
ret
|
|
|
|
|
2004-03-04 13:31:14 +08:00
|
|
|
.extern __ZN7_cygtls19call_signal_handlerEv
|
|
|
|
stabilize_sig_stack:
|
|
|
|
1: movl %fs:4,%edx
|
2004-03-09 09:24:08 +08:00
|
|
|
incl $tls::incyg(%edx)
|
2004-03-04 13:31:14 +08:00
|
|
|
movl \$1,%eax
|
|
|
|
lock xchgl %eax,$tls::stacklock(%edx)
|
|
|
|
movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock
|
2004-03-07 12:57:47 +08:00
|
|
|
testl %eax,%eax
|
2004-03-04 13:31:14 +08:00
|
|
|
jz 2f
|
|
|
|
xorl %eax,%eax
|
|
|
|
call _low_priority_sleep
|
|
|
|
jmp 1b
|
|
|
|
2: cmpl \$0,$tls::sig(%edx)
|
|
|
|
jz 3f
|
|
|
|
decl $tls::stacklock(%edx) # unlock
|
|
|
|
movl \$-$tls::sizeof__cygtls,%eax # point to beginning
|
|
|
|
addl %edx,%eax # of tls block
|
|
|
|
call __ZN7_cygtls19call_signal_handlerEv
|
|
|
|
jmp 1b
|
2004-03-09 09:24:08 +08:00
|
|
|
3: decl $tls::incyg(%edx)
|
|
|
|
ret
|
2003-11-29 04:55:59 +08:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub longjmp {
|
|
|
|
return <<EOF;
|
|
|
|
|
2004-02-19 04:48:38 +08:00
|
|
|
.globl _setjmp
|
|
|
|
_setjmp:
|
2003-11-29 04:55:59 +08:00
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
2004-02-19 04:48:38 +08:00
|
|
|
pushl %edi
|
2003-11-29 04:55:59 +08:00
|
|
|
movl 8(%ebp),%edi
|
2004-02-19 04:48:38 +08:00
|
|
|
movl %eax,0(%edi)
|
|
|
|
movl %ebx,4(%edi)
|
|
|
|
movl %ecx,8(%edi)
|
|
|
|
movl %edx,12(%edi)
|
|
|
|
movl %esi,16(%edi)
|
|
|
|
movl -4(%ebp),%eax
|
|
|
|
movl %eax,20(%edi)
|
|
|
|
movl 0(%ebp),%eax
|
|
|
|
movl %eax,24(%edi)
|
|
|
|
movl %esp,%eax
|
|
|
|
addl \$12,%eax
|
|
|
|
movl %eax,28(%edi)
|
|
|
|
movl 4(%ebp),%eax
|
|
|
|
movl %eax,32(%edi)
|
|
|
|
movw %es,%ax
|
|
|
|
movw %ax,36(%edi)
|
|
|
|
movw %fs,%ax
|
|
|
|
movw %ax,38(%edi)
|
|
|
|
movw %gs,%ax
|
|
|
|
movw %ax,40(%edi)
|
|
|
|
movw %ss,%ax
|
|
|
|
movw %ax,42(%edi)
|
|
|
|
pushl %edx
|
|
|
|
call stabilize_sig_stack
|
|
|
|
movl $tls::stackptr(%edx),%eax # save stack pointer contents
|
|
|
|
decl $tls::stacklock(%edx)
|
|
|
|
popl %edx
|
|
|
|
movl %eax,44(%edi)
|
|
|
|
popl %edi
|
|
|
|
movl \$0,%eax
|
|
|
|
leave
|
|
|
|
ret
|
|
|
|
|
|
|
|
.globl _longjmp
|
|
|
|
_longjmp:
|
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
movl 8(%ebp),%edi # address of buffer
|
|
|
|
call stabilize_sig_stack
|
|
|
|
movl 44(%edi),%eax # get old signal stack
|
|
|
|
movl %eax,$tls::stackptr(%edx) # restore
|
|
|
|
decl $tls::stacklock(%edx) # relinquish lock
|
|
|
|
|
2003-11-29 04:55:59 +08:00
|
|
|
movl 12(%ebp),%eax
|
|
|
|
testl %eax,%eax
|
2004-02-12 11:01:58 +08:00
|
|
|
jne 3f
|
2003-11-29 04:55:59 +08:00
|
|
|
incl %eax
|
2004-02-12 11:01:58 +08:00
|
|
|
|
|
|
|
3: movl %eax,0(%edi)
|
2003-11-29 04:55:59 +08:00
|
|
|
movl 24(%edi),%ebp
|
|
|
|
pushfl
|
|
|
|
popl %ebx
|
|
|
|
movw 42(%edi),%ax
|
|
|
|
movw %ax,%ss
|
|
|
|
movl 28(%edi),%esp
|
|
|
|
pushl 32(%edi)
|
|
|
|
pushl %ebx
|
|
|
|
movw 36(%edi),%ax
|
|
|
|
movw %ax,%es
|
|
|
|
movw 40(%edi),%ax
|
|
|
|
movw %ax,%gs
|
|
|
|
movl 0(%edi),%eax
|
|
|
|
movl 4(%edi),%ebx
|
|
|
|
movl 8(%edi),%ecx
|
|
|
|
movl 16(%edi),%esi
|
2004-02-12 11:01:58 +08:00
|
|
|
movl 12(%edi),%edx
|
2003-11-29 04:55:59 +08:00
|
|
|
movl 20(%edi),%edi
|
|
|
|
popfl
|
|
|
|
ret
|
|
|
|
EOF
|
|
|
|
}
|