Fix LDC, LDC_W, and INSTANCEOF opcodes, more debugging
[jamvm-avr32-jem.git] / src / frame.c
blob2b6db92311978874dd796e48a986ec7a0d475ca0
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007
3 * Robert Lougher <rob@lougher.org.uk>.
5 * This file is part of JamVM.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <stddef.h>
23 #include "jam.h"
25 /* The function getCallerFrame() is used in the code that does
26 security related stack-walking. It guards against invocation
27 via reflection. These frames must be skipped, else it will
28 appear that the caller was loaded by the boot loader. */
30 Frame *getCallerFrame(Frame *last) {
32 loop:
33 /* Skip the top frame, and check if the
34 previous is a dummy frame */
35 if((last = last->prev)->mb == NULL) {
37 /* Skip the dummy frame, and check if
38 * we're at the top of the stack */
39 if((last = last->prev)->prev == NULL)
40 return NULL;
42 /* Check if we were invoked via reflection */
43 if(last->mb->class == getReflectMethodClass()) {
45 /* There will be two frames for invoke. Skip
46 the first, and jump back. This also handles
47 recursive invocation via reflection. */
49 last = last->prev;
50 goto loop;
53 return last;
56 Class *getCallerCallerClass() {
57 Frame *last = getExecEnv()->last_frame->prev;
59 if((last->mb == NULL && (last = last->prev)->prev == NULL) ||
60 (last = getCallerFrame(last)) == NULL)
61 return NULL;
63 return last->mb->class;