Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mingw 32-bit: realign the stack in our callbacks #21324

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/threads/lib/threads.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use 5.008;
use strict;
use warnings;

our $VERSION = '2.37'; # remember to update version in POD!
our $VERSION = '2.38'; # remember to update version in POD!
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;

Expand Down Expand Up @@ -134,7 +134,7 @@ threads - Perl interpreter-based threads

=head1 VERSION

This document describes threads version 2.37
This document describes threads version 2.38

=head1 WARNING

Expand Down
2 changes: 1 addition & 1 deletion dist/threads/threads.xs
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ S_jmpenv_run(pTHX_ int action, ithread *thread,
return jmp_rc;
}


/* Starts executing the thread.
* Passed as the C level function to run in the new thread.
*/
#ifdef WIN32
PERL_STACK_REALIGN
STATIC THREAD_RET_TYPE
S_ithread_run(LPVOID arg)
#else
Expand Down
1 change: 1 addition & 0 deletions mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg)
}


PERL_STACK_REALIGN
#ifdef PERL_USE_3ARG_SIGHANDLER
Signal_t
Perl_csighandler(int sig, Siginfo_t *sip, void *uap)
Expand Down
27 changes: 27 additions & 0 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9099,6 +9099,33 @@ END_EXTERN_C

#define PERL_PARSE_ERROR_COUNT(f) (f)


/* Work around

https://github.com/Perl/perl5/issues/21313

Where gcc when generating code for 32-bit windows assumes the stack
is 16 byte aligned, where the system doesn't guarantee that.

The code generated by gcc itself does maintain 16 byte alignment,
but callbacks from the CRT or Windows APIs don't, so calls to
code that is generated to SSE instructions (like the quadmath code
by default), crashes when called from a callback.

Since other code other than quadmath might use SSE instructions,
also enable this outside of quadmath builds.

This change is a little risky: if an XS module uses callbacks
and those callbacks may also produce alignment errors, if that
becomes a problem we'll need to use the nuclear option: building
32-bit perl with -mstackrealign.
*/
#if defined(WIN32) && !defined(WIN64) && defined(__GNUC__)
# define PERL_STACK_REALIGN __attribute__((force_align_arg_pointer))
#else
# define PERL_STACK_REALIGN
#endif

/*

(KEEP THIS LAST IN perl.h!)
Expand Down
1 change: 1 addition & 0 deletions win32/perlhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ PerlProcGetTimeOfDay(struct IPerlProc* piPerl, struct timeval *t, void *z)
}

#ifdef USE_ITHREADS
PERL_STACK_REALIGN
static THREAD_RET_TYPE
win32_start_child(LPVOID arg)
{
Expand Down