native() 함수의 비밀을 알아냈습니다.
아주 가까운데에 있더군요.. ㅡ.ㅡ
invokeNativeFunction() 에 있는 NativeFunctionPtr 형 native 입니다.
즉, 함수포인터 였던거죠.
그래서 인즉 Object 파일을 분석하지 않으면 어떤 함수포인터가 호출되는지 알지 못하겠
더라구요. 저도 같이 Object 파일분석해서 올리겠습니다.
그럼 이번주 토요일에 뵙겠습니다.
void invokeNativeFunction(METHOD thisMethod)
{
...
NativeFunctionPtr native = thisMethod->u.native.code;
if (native == NULL) {
/* Native function not found; throw error */
/* The GC may get confused by the arguments on the stack */
setSP(getSP() - thisMethod->argCount);
START_TEMPORARY_ROOTS
DECLARE_TEMPORARY_ROOT(char*, className,
getClassName((CLASS)(thisMethod->ofClass)));
sprintf(str_buffer,
KVM_MSG_NATIVE_METHOD_NOT_FOUND_2STRPARAMS,
className, methodName(thisMethod));
END_TEMPORARY_ROOTS
fatalError(str_buffer);
}
#if INCLUDEDEBUGCODE
if (tracemethodcalls || tracemethodcallsverbose) {
frameTracing(thisMethod, "=>", +1);
}
saved_TemporaryRootsLength = TemporaryRootsLength;
#endif
#if USE_KNI
/* Note: Unlike many other Java VMs, KVM does not create */
/* stack frames for native function calls. This makes native */
/* function calls faster. However, at the same time it means */
/* that the native function programmer must be careful not to */
/* screw up the stack pointer when popping and pushing items */
/* to and from the operand stack. */
/* Because of the lack of stack frames for native functions, */
/* KNI calls need special assistance to access the parameters */
/* of a native method. Basically, we create a new "pseudo- */
/* local pointer" called "nativeLp" to point to the locals of */
/* the native method. Old-style (pre-KNI) native methods can */
/* simply ignore this new variable. */
if ((thisMethod->accessFlags & ACC_STATIC) && CurrentThread) {
CurrentThread->nativeLp = getSP() - (thisMethod->argCount);
} else {
CurrentThread->nativeLp = getSP() - (thisMethod->argCount-1);
}
#endif /* USE_KNI */
/* Call the native function we are supposed to call */
CurrentNativeMethod = thisMethod;
native();
...
}
아주 가까운데에 있더군요.. ㅡ.ㅡ
invokeNativeFunction() 에 있는 NativeFunctionPtr 형 native 입니다.
즉, 함수포인터 였던거죠.
그래서 인즉 Object 파일을 분석하지 않으면 어떤 함수포인터가 호출되는지 알지 못하겠
더라구요. 저도 같이 Object 파일분석해서 올리겠습니다.
그럼 이번주 토요일에 뵙겠습니다.
void invokeNativeFunction(METHOD thisMethod)
{
...
NativeFunctionPtr native = thisMethod->u.native.code;
if (native == NULL) {
/* Native function not found; throw error */
/* The GC may get confused by the arguments on the stack */
setSP(getSP() - thisMethod->argCount);
START_TEMPORARY_ROOTS
DECLARE_TEMPORARY_ROOT(char*, className,
getClassName((CLASS)(thisMethod->ofClass)));
sprintf(str_buffer,
KVM_MSG_NATIVE_METHOD_NOT_FOUND_2STRPARAMS,
className, methodName(thisMethod));
END_TEMPORARY_ROOTS
fatalError(str_buffer);
}
#if INCLUDEDEBUGCODE
if (tracemethodcalls || tracemethodcallsverbose) {
frameTracing(thisMethod, "=>", +1);
}
saved_TemporaryRootsLength = TemporaryRootsLength;
#endif
#if USE_KNI
/* Note: Unlike many other Java VMs, KVM does not create */
/* stack frames for native function calls. This makes native */
/* function calls faster. However, at the same time it means */
/* that the native function programmer must be careful not to */
/* screw up the stack pointer when popping and pushing items */
/* to and from the operand stack. */
/* Because of the lack of stack frames for native functions, */
/* KNI calls need special assistance to access the parameters */
/* of a native method. Basically, we create a new "pseudo- */
/* local pointer" called "nativeLp" to point to the locals of */
/* the native method. Old-style (pre-KNI) native methods can */
/* simply ignore this new variable. */
if ((thisMethod->accessFlags & ACC_STATIC) && CurrentThread) {
CurrentThread->nativeLp = getSP() - (thisMethod->argCount);
} else {
CurrentThread->nativeLp = getSP() - (thisMethod->argCount-1);
}
#endif /* USE_KNI */
/* Call the native function we are supposed to call */
CurrentNativeMethod = thisMethod;
native();
...
}
댓글 0
.