Skip to content

Commit

Permalink
Stackless issue #183: use a volatile pointer to call slp_switch()
Browse files Browse the repository at this point in the history
Prevent inlining slp_switch() more reliably. C standard guarantees to read
the value of a volatile variable from memory on each access. Therefore
the compiler does not know the called function and can't inline.

(cherry picked from commit 78f6b66)
  • Loading branch information
Anselm Kruis committed Nov 12, 2018
1 parent a8cf08d commit ae7db35
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 73 deletions.
6 changes: 5 additions & 1 deletion Stackless/core/slp_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ slp_transfer(PyCStackObject **cstprev, PyCStackObject *cst,
{
PyThreadState *ts = PyThreadState_GET();
int result;
/* Use a volatile pointer to prevent inlining of slp_switch().
* See Stackless issue 183
*/
static int (*volatile slp_switch_ptr)(void) = slp_switch;

/* since we change the stack we must assure that the protocol was met */
STACKLESS_ASSERT();
Expand Down Expand Up @@ -148,7 +152,7 @@ slp_transfer(PyCStackObject **cstprev, PyCStackObject *cst,
_cstprev = cstprev;
_cst = cst;
_prev = prev;
result = slp_switch();
result = slp_switch_ptr();
SLP_ASSERT_FRAME_IN_TRANSFER(ts);
if (!result) {
if (_cst) {
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_amd64_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,7 @@
"xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
#endif

/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register long *stackref, stsizediff;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_arm32_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@
#define STACK_MAGIC 0
#define REGS_TO_SAVE /*"r1", "r2", "r3", "r4",*/ "r5", "r6", "fp", "ip", "lr"

/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register int *stackref, stsizediff;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_mips_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@
"$23", "$30"
#endif
__asm__ volatile ("" : : : REGS_TO_SAVE);
/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register int *stackref, stsizediff;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_ppc_macosx.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@
"cr2", "cr3", "cr4"
#endif

/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
static int x = 0;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_ppc_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@
#define REGS_TO_SAVE "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", \
"r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r31", \
"cr2", "cr3", "cr4"
/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register int *stackref, stsizediff;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_s390_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"

/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register int *stackref, stsizediff;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_sparc_sun_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@

#define STACK_MAGIC 0

/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register int *stackref, stsizediff;
Expand Down
10 changes: 1 addition & 9 deletions Stackless/platf/switch_x86_unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,7 @@
/* Registers marked as clobbered, minimum set according to the ABI spec. */
#define REGS_CLOBBERED "ebx", "edi", "esi"

/*
* You may want to make the function static enable optimizations.
* However, the ABI SPEC does not apply to static functions. Therefore
* I make slp_switch a regular global function.
*/
#if 0
static
#endif
int
static int
slp_switch(void)
{
register int *stackref, stsizediff;
Expand Down

0 comments on commit ae7db35

Please sign in to comment.