1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
/*
* tclUnixInit.c --
*
* Contains the Unix-specific interpreter initialization functions.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright (c) 1999 by Scriptics Corporation.
* All rights reserved.
*
* RCS: @(#) $Id: tclUnixInit.c,v 1.73 2007/11/09 23:04:07 msofer Exp $
*/
#include "tclInt.h"
#include <stddef.h>
#include <locale.h>
#ifdef HAVE_LANGINFO
# include <langinfo.h>
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
/*
* tclUnixInit.c --
*
* Contains the Unix-specific interpreter initialization functions.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright (c) 1999 by Scriptics Corporation.
* All rights reserved.
*
* RCS: @(#) $Id: tclUnixInit.c,v 1.74 2007/11/10 03:41:23 das Exp $
*/
#include "tclInt.h"
#include <stddef.h>
#include <locale.h>
#ifdef HAVE_LANGINFO
# include <langinfo.h>
|
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
|
* Results:
* 1 if there is enough stack space to continue; 0 if not.
*
* Side effects:
* None.
*
* Remark: Unused in the core, to be removed.
*----------------------------------------------------------------------
*/
int
TclpCheckStackSpace(void)
{
#ifdef TCL_NO_STACK_CHECK
/*
* This function was normally unimplemented on Unix platforms and this
* implements old behavior, i.e. no stack checking performed.
*/
return 1;
#else
int localInt, *stackBound;
TclpGetCStackParams(&stackBound);
if (stackGrowsDown) {
return (&localInt > stackBound) ;
} else {
return (&localInt > stackBound) ;
}
#endif
}
/*
*----------------------------------------------------------------------
*
* TclpGetStackParams --
*
* Determine tha stack params for the current thread: in which
* direction does the stack grow, and what is the stack lower (resp
* upper) bound for safe invocation of a new command. This is used to
* cache the values needed for an efficient computation of
* TclpCheckStackSpace() when the interp is known.
*
* Results:
* Returns 1 if the stack grows down, in which case a stack lower bound
* is stored at stackBoundPtr. If the stack grows up, 0 is returned and
* an upper bound is stored at stackBoundPtr. If a bound cannot be
* determined NULL is stored at stackBoundPtr.
*/
int
TclpGetCStackParams(
int **stackBoundPtr)
{
#ifdef TCL_NO_STACK_CHECK
|
>
<
<
<
|
|
|
|
|
|
|
|
|
|
|
>
>
|
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
|
* Results:
* 1 if there is enough stack space to continue; 0 if not.
*
* Side effects:
* None.
*
* Remark: Unused in the core, to be removed.
*
*----------------------------------------------------------------------
*/
int
TclpCheckStackSpace(void)
{
#ifdef TCL_NO_STACK_CHECK
/*
* This function was normally unimplemented on Unix platforms and this
* implements old behavior, i.e. no stack checking performed.
*/
return 1;
#else
int localInt, *stackBound;
TclpGetCStackParams(&stackBound);
if (stackGrowsDown) {
return (&localInt < stackBound) ;
} else {
return (&localInt > stackBound) ;
}
#endif
}
/*
*----------------------------------------------------------------------
*
* TclpGetStackParams --
*
* Determine the stack params for the current thread: in which
* direction does the stack grow, and what is the stack lower (resp.
* upper) bound for safe invocation of a new command? This is used to
* cache the values needed for an efficient computation of
* TclpCheckStackSpace() when the interp is known.
*
* Results:
* Returns 1 if the stack grows down, in which case a stack lower bound
* is stored at stackBoundPtr. If the stack grows up, 0 is returned and
* an upper bound is stored at stackBoundPtr. If a bound cannot be
* determined NULL is stored at stackBoundPtr.
*
*----------------------------------------------------------------------
*/
int
TclpGetCStackParams(
int **stackBoundPtr)
{
#ifdef TCL_NO_STACK_CHECK
|
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
|
/*
* Not initialised!
*/
stackGrowsDown = StackGrowsDown(&localVar);
}
/*
* The first time through, we record the "outermost" stack frame.
*/
if (tsdPtr->outerVarPtr == NULL) {
tsdPtr->outerVarPtr = &localVar;
}
|
|
|
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
|
/*
* Not initialised!
*/
stackGrowsDown = StackGrowsDown(&localVar);
}
/*
* The first time through, we record the "outermost" stack frame.
*/
if (tsdPtr->outerVarPtr == NULL) {
tsdPtr->outerVarPtr = &localVar;
}
|
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
|
STACK_DEBUG(("skipping stack checks with success\n"));
}
*stackBoundPtr = NULL;
return 1; /* so that check always succeeds */
}
if (stackGrowsDown) {
*stackBoundPtr = (int *) ((char *)tsdPtr->outerVarPtr - tsdPtr->stackSize);
} else {
*stackBoundPtr = (int *) ((char *)tsdPtr->outerVarPtr + tsdPtr->stackSize);
}
return stackGrowsDown;
#endif
}
int
StackGrowsDown(
int *parent)
{
int here;
return (&here < parent);
}
/*
*----------------------------------------------------------------------
*
* GetStackSize --
*
* Discover what the stack size for the current thread/process actually
|
|
>
|
>
<
|
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
|
STACK_DEBUG(("skipping stack checks with success\n"));
}
*stackBoundPtr = NULL;
return 1; /* so that check always succeeds */
}
if (stackGrowsDown) {
*stackBoundPtr = (int *) ((char *)tsdPtr->outerVarPtr -
tsdPtr->stackSize);
} else {
*stackBoundPtr = (int *) ((char *)tsdPtr->outerVarPtr +
tsdPtr->stackSize);
}
return stackGrowsDown;
#endif
}
int
StackGrowsDown(
int *parent)
{
int here;
return (&here < parent);
}
/*
*----------------------------------------------------------------------
*
* GetStackSize --
*
* Discover what the stack size for the current thread/process actually
|