summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9f6b5d5)
2006-08-10 Gary Benson <gbenson@redhat.com>
* include/java-stack.h (GetAccessControlStack): Change return
type.
* stacktrace.cc (accesscontrol_trace_fn): Record the number of
Java frames encountered.
(GetAccessControlStack): Return a flag indicating whether a call to
doPrivileged was encountered rather than an array of method names.
* java/security/natVMAccessController.cc (getStack): Change return
type.
* java/security/VMAccessController.java (getStack): Likewise.
(getContext): Change to reflect the above.
From-SVN: r116058
+2006-08-10 Gary Benson <gbenson@redhat.com>
+
+ * include/java-stack.h (GetAccessControlStack): Change return
+ type.
+ * stacktrace.cc (accesscontrol_trace_fn): Record the number of
+ Java frames encountered.
+ (GetAccessControlStack): Return a flag indicating whether a call to
+ doPrivileged was encountered rather than an array of method names.
+ * java/security/natVMAccessController.cc (getStack): Change return
+ type.
+ * java/security/VMAccessController.java (getStack): Likewise.
+ (getContext): Change to reflect the above.
+
2006-08-09 Gary Benson <gbenson@redhat.com>
* stacktrace.cc (accesscontrol_trace_fn): Skip non-Java frames.
2006-08-09 Gary Benson <gbenson@redhat.com>
* stacktrace.cc (accesscontrol_trace_fn): Skip non-Java frames.
static void GetCallerInfo (jclass checkClass, jclass *, _Jv_Method **);
static JArray<jclass> *GetClassContext (jclass checkClass);
static ClassLoader *GetFirstNonSystemClassLoader (void);
static void GetCallerInfo (jclass checkClass, jclass *, _Jv_Method **);
static JArray<jclass> *GetClassContext (jclass checkClass);
static ClassLoader *GetFirstNonSystemClassLoader (void);
- static JArray<jobjectArray> *GetAccessControlStack ();
+ static jobjectArray GetAccessControlStack ();
inGetContext.set(Boolean.TRUE);
inGetContext.set(Boolean.TRUE);
- Object[][] stack = getStack();
+ Object[] stack = getStack();
Class[] classes = (Class[]) stack[0];
Class[] classes = (Class[]) stack[0];
- String[] methods = (String[]) stack[1];
+ boolean privileged = ((Boolean) stack[1]).booleanValue();
if (DEBUG)
debug("got trace of length " + classes.length);
if (DEBUG)
debug("got trace of length " + classes.length);
HashSet domains = new HashSet();
HashSet seenDomains = new HashSet();
AccessControlContext context = null;
HashSet domains = new HashSet();
HashSet seenDomains = new HashSet();
AccessControlContext context = null;
// We walk down the stack, adding each ProtectionDomain for each
// class in the call stack. If we reach a call to doPrivileged,
// we don't add any more stack frames. We skip the first three stack
// frames, since they comprise the calls to getStack, getContext,
// and AccessController.getContext.
// We walk down the stack, adding each ProtectionDomain for each
// class in the call stack. If we reach a call to doPrivileged,
// we don't add any more stack frames. We skip the first three stack
// frames, since they comprise the calls to getStack, getContext,
// and AccessController.getContext.
- for (int i = 3; i < classes.length && privileged < 2; i++)
+ for (int i = 3; i < classes.length; i++)
{
Class clazz = classes[i];
{
Class clazz = classes[i];
- String method = methods[i];
- debug("checking " + clazz + "." + method);
+ debug("checking " + clazz);
// subject to getClassLoader RuntimePermission
debug("loader = " + clazz.getClassLoader());
}
// subject to getClassLoader RuntimePermission
debug("loader = " + clazz.getClassLoader());
}
- // If the previous frame was a call to doPrivileged, then this is
- // the last frame we look at.
- if (privileged == 1)
- privileged = 2;
-
- if (clazz.equals (AccessController.class)
- && method.equals ("doPrivileged"))
+ if (privileged && i == classes.length - 2)
{
// If there was a call to doPrivileged with a supplied context,
// return that context. If using JAAS doAs*, it should be
{
// If there was a call to doPrivileged with a supplied context,
// return that context. If using JAAS doAs*, it should be
LinkedList l = (LinkedList) contexts.get();
if (l != null)
context = (AccessControlContext) l.getFirst();
LinkedList l = (LinkedList) contexts.get();
if (l != null)
context = (AccessControlContext) l.getFirst();
}
// subject to getProtectionDomain RuntimePermission
}
// subject to getProtectionDomain RuntimePermission
- * Returns a snapshot of the current call stack as a pair of arrays:
- * the first an array of classes in the call stack, the second an array
- * of strings containing the method names in the call stack. The two
- * arrays match up, meaning that method <i>i</i> is declared in class
- * <i>i</i>. The arrays are clean; it will only contain Java methods,
- * and no element of the list should be null.
+ * Returns a snapshot of the current call stack as a two-element
+ * array. The first element is an array of classes in the call
+ * stack, and the second element is a boolean value indicating
+ * whether the trace stopped early because a call to doPrivileged
+ * was encountered. If this boolean value is true then the call to
+ * doPrivileged will be the second-last frame in the returned trace.
- * @return A pair of arrays describing the current call stack. The first
- * element is an array of Class objects, and the second is an array
- * of Strings comprising the method names.
+ * @return A snapshot of the current call stack.
- private static native Object[][] getStack();
+ private static native Object[] getStack();
#include <java/security/VMAccessController.h>
#include <java/security/VMAccessController.h>
java::security::VMAccessController::getStack ()
{
return _Jv_StackTrace::GetAccessControlStack ();
java::security::VMAccessController::getStack ()
{
return _Jv_StackTrace::GetAccessControlStack ();
+#include <java/lang/Boolean.h>
#include <java/lang/Class.h>
#include <java/lang/Long.h>
#include <java/security/AccessController.h>
#include <java/lang/Class.h>
#include <java/lang/Long.h>
#include <java/security/AccessController.h>
+struct AccessControlTraceData
+{
+ jint length;
+ jboolean privileged;
+};
+
_Unwind_Reason_Code
_Jv_StackTrace::accesscontrol_trace_fn (_Jv_UnwindState *state)
{
_Unwind_Reason_Code
_Jv_StackTrace::accesscontrol_trace_fn (_Jv_UnwindState *state)
{
+ AccessControlTraceData *trace_data = (AccessControlTraceData *)
+ state->trace_data;
_Jv_StackFrame *frame = &state->frames[state->pos];
FillInFrameInfo (frame);
if (!(frame->klass && frame->meth))
return _URC_NO_REASON;
_Jv_StackFrame *frame = &state->frames[state->pos];
FillInFrameInfo (frame);
if (!(frame->klass && frame->meth))
return _URC_NO_REASON;
- bool *stopping = (bool *) state->trace_data;
- if (*stopping)
+ trace_data->length++;
+
+ // If the previous frame was a call to doPrivileged, then this is
+ // the last frame we look at.
+ if (trace_data->privileged)
return _URC_NORMAL_STOP;
if (frame->klass == &::java::security::AccessController::class$
&& strcmp (frame->meth->name->chars(), "doPrivileged") == 0)
return _URC_NORMAL_STOP;
if (frame->klass == &::java::security::AccessController::class$
&& strcmp (frame->meth->name->chars(), "doPrivileged") == 0)
+ trace_data->privileged = true;
_Jv_StackTrace::GetAccessControlStack (void)
{
int trace_size = 100;
_Jv_StackFrame frames[trace_size];
_Jv_UnwindState state (trace_size);
state.frames = (_Jv_StackFrame *) &frames;
_Jv_StackTrace::GetAccessControlStack (void)
{
int trace_size = 100;
_Jv_StackFrame frames[trace_size];
_Jv_UnwindState state (trace_size);
state.frames = (_Jv_StackFrame *) &frames;
+
+ AccessControlTraceData trace_data;
+ trace_data.length = 0;
+ trace_data.privileged = false;
+
state.trace_function = accesscontrol_trace_fn;
state.trace_function = accesscontrol_trace_fn;
- bool stopping = false;
- state.trace_data = (void *) &stopping;
+ state.trace_data = (void *) &trace_data;
UpdateNCodeMap();
_Unwind_Backtrace (UnwindTraceFn, &state);
UpdateNCodeMap();
_Unwind_Backtrace (UnwindTraceFn, &state);
- for (int i = 0; i < state.pos; i++)
- {
- _Jv_StackFrame *frame = &state.frames[i];
-
- if (frame->klass && frame->meth)
- length++;
- }
-
- jclass array_class = _Jv_GetArrayClass (&::java::lang::Object::class$, NULL);
- JArray<jobjectArray> *result =
- (JArray<jobjectArray> *) _Jv_NewObjectArray (2, array_class, NULL);
JArray<jclass> *classes = (JArray<jclass> *)
JArray<jclass> *classes = (JArray<jclass> *)
- _Jv_NewObjectArray (length, &::java::lang::Class::class$, NULL);
- JArray<jstring> *methods = (JArray<jstring> *)
- _Jv_NewObjectArray (length, &::java::lang::String::class$, NULL);
- jclass *c = elements (classes);
- jstring *m = elements (methods);
+ _Jv_NewObjectArray (trace_data.length, &::java::lang::Class::class$, NULL);
+ jclass *c = elements (classes);
for (int i = 0, j = 0; i < state.pos; i++)
{
for (int i = 0, j = 0; i < state.pos; i++)
{
if (!frame->klass || !frame->meth)
continue;
c[j] = frame->klass;
if (!frame->klass || !frame->meth)
continue;
c[j] = frame->klass;
- m[j] = JvNewStringUTF (frame->meth->name->chars());
- jobjectArray *elems = elements (result);
- elems[0] = (jobjectArray) classes;
- elems[1] = (jobjectArray) methods;
-
+ jobjectArray result =
+ (jobjectArray) _Jv_NewObjectArray (2, &::java::lang::Object::class$,
+ NULL);
+ jobject *r = elements (result);
+ r[0] = (jobject) classes;
+ r[1] = (jobject) new Boolean (trace_data.privileged);
+