[rkward-cvs] SF.net SVN: rkward: [1458] trunk/rkward/rkward/rbackend/rkpthreadsupport. cpp
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri Feb 23 12:15:28 UTC 2007
Revision: 1458
http://svn.sourceforge.net/rkward/?rev=1458&view=rev
Author: tfry
Date: 2007-02-23 04:15:28 -0800 (Fri, 23 Feb 2007)
Log Message:
-----------
Make sure not to mix up stack top and bottom
Modified Paths:
--------------
trunk/rkward/rkward/rbackend/rkpthreadsupport.cpp
Modified: trunk/rkward/rkward/rbackend/rkpthreadsupport.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rkpthreadsupport.cpp 2007-02-23 11:31:44 UTC (rev 1457)
+++ trunk/rkward/rkward/rbackend/rkpthreadsupport.cpp 2007-02-23 12:15:28 UTC (rev 1458)
@@ -24,9 +24,11 @@
# include <pthread_np.h>
#endif
-/* This code is mostly borrowed from WINE (http://www.winehq.org) */
+/* Much of this code is borrowed from WINE (http://www.winehq.org) */
void RKGetCurrentThreadStackLimits (size_t *size, void **base) {
+ char dummy;
+ int direction;
#ifdef HAVE_PTHREAD_GETATTR_NP
pthread_attr_t attr;
pthread_getattr_np (pthread_self (), &attr);
@@ -39,17 +41,26 @@
pthread_attr_getstack (&attr, base, size);
pthread_attr_destroy (&attr);
#elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP)
- char dummy;
- size = pthread_get_stacksize_np (pthread_self ());
- base = pthread_get_stackaddr_np (pthread_self ());
- /* if base is too large assume it's the top of the stack instead */
- if ((char *) base > &dummy)
- base = (char *) base - size;
+ *size = pthread_get_stacksize_np (pthread_self ());
+ *base = pthread_get_stackaddr_np (pthread_self ());
#else
# warning Can't determine the stack limits of a pthread on this system
# warning R C stack checking will be disabled
- char dummy;
*base = &dummy;
*size = (unsigned long) -1;
+ return;
#endif
+ // in which direction does the stack grow?
+ {
+ char dummy2;
+ direction = (&dummy) > (&dummy2) ? 1 : -1;
+ }
+
+ // in which direction does the stack base lie?
+ int base_direction = (*base) > (&dummy) ? 1 : -1;
+
+ // switch base / top, if necessary
+ if (base_direction != direction) {
+ *base = ((char *) *base) + (direction * ((unsigned long) *size));
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list