1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
121 return jcw_safe; |
121 return jcw_safe; |
122 |
122 |
123 } |
123 } |
124 |
124 |
125 intptr_t* sender_sp = NULL; |
125 intptr_t* sender_sp = NULL; |
|
126 intptr_t* sender_unextended_sp = NULL; |
126 address sender_pc = NULL; |
127 address sender_pc = NULL; |
|
128 intptr_t* saved_fp = NULL; |
127 |
129 |
128 if (is_interpreted_frame()) { |
130 if (is_interpreted_frame()) { |
129 // fp must be safe |
131 // fp must be safe |
130 if (!fp_safe) { |
132 if (!fp_safe) { |
131 return false; |
133 return false; |
132 } |
134 } |
133 |
135 |
134 sender_pc = (address) this->fp()[return_addr_offset]; |
136 sender_pc = (address) this->fp()[return_addr_offset]; |
|
137 // for interpreted frames, the value below is the sender "raw" sp, |
|
138 // which can be different from the sender unextended sp (the sp seen |
|
139 // by the sender) because of current frame local variables |
135 sender_sp = (intptr_t*) addr_at(sender_sp_offset); |
140 sender_sp = (intptr_t*) addr_at(sender_sp_offset); |
|
141 sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset]; |
|
142 saved_fp = (intptr_t*) this->fp()[link_offset]; |
136 |
143 |
137 } else { |
144 } else { |
138 // must be some sort of compiled/runtime frame |
145 // must be some sort of compiled/runtime frame |
139 // fp does not have to be safe (although it could be check for c1?) |
146 // fp does not have to be safe (although it could be check for c1?) |
140 |
147 |
142 if (_cb->frame_size() <= 0) { |
149 if (_cb->frame_size() <= 0) { |
143 return false; |
150 return false; |
144 } |
151 } |
145 |
152 |
146 sender_sp = _unextended_sp + _cb->frame_size(); |
153 sender_sp = _unextended_sp + _cb->frame_size(); |
|
154 sender_unextended_sp = sender_sp; |
147 // On Intel the return_address is always the word on the stack |
155 // On Intel the return_address is always the word on the stack |
148 sender_pc = (address) *(sender_sp-1); |
156 sender_pc = (address) *(sender_sp-1); |
|
157 // Note: frame::sender_sp_offset is only valid for compiled frame |
|
158 saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset); |
149 } |
159 } |
150 |
160 |
151 |
161 |
152 // If the potential sender is the interpreter then we can do some more checking |
162 // If the potential sender is the interpreter then we can do some more checking |
153 if (Interpreter::contains(sender_pc)) { |
163 if (Interpreter::contains(sender_pc)) { |
154 |
164 |
155 // ebp is always saved in a recognizable place in any code we generate. However |
165 // ebp is always saved in a recognizable place in any code we generate. However |
156 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp |
166 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp |
157 // is really a frame pointer. |
167 // is really a frame pointer. |
158 |
168 |
159 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); |
|
160 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); |
169 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); |
161 |
170 |
162 if (!saved_fp_safe) { |
171 if (!saved_fp_safe) { |
163 return false; |
172 return false; |
164 } |
173 } |
165 |
174 |
166 // construct the potential sender |
175 // construct the potential sender |
167 |
176 |
168 frame sender(sender_sp, saved_fp, sender_pc); |
177 frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc); |
169 |
178 |
170 return sender.is_interpreted_frame_valid(thread); |
179 return sender.is_interpreted_frame_valid(thread); |
171 |
180 |
172 } |
181 } |
173 |
182 |
192 return false; |
201 return false; |
193 } |
202 } |
194 |
203 |
195 // Could be the call_stub |
204 // Could be the call_stub |
196 if (StubRoutines::returns_to_call_stub(sender_pc)) { |
205 if (StubRoutines::returns_to_call_stub(sender_pc)) { |
197 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); |
|
198 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); |
206 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp); |
199 |
207 |
200 if (!saved_fp_safe) { |
208 if (!saved_fp_safe) { |
201 return false; |
209 return false; |
202 } |
210 } |
203 |
211 |
204 // construct the potential sender |
212 // construct the potential sender |
205 |
213 |
206 frame sender(sender_sp, saved_fp, sender_pc); |
214 frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc); |
207 |
215 |
208 // Validate the JavaCallWrapper an entry frame must have |
216 // Validate the JavaCallWrapper an entry frame must have |
209 address jcw = (address)sender.entry_frame_call_wrapper(); |
217 address jcw = (address)sender.entry_frame_call_wrapper(); |
210 |
218 |
211 bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp()); |
219 bool jcw_safe = (jcw < thread->stack_base()) && ( jcw > (address)sender.fp()); |
566 |
574 |
567 // validate the method we'd find in this potential sender |
575 // validate the method we'd find in this potential sender |
568 if (!m->is_valid_method()) return false; |
576 if (!m->is_valid_method()) return false; |
569 |
577 |
570 // stack frames shouldn't be much larger than max_stack elements |
578 // stack frames shouldn't be much larger than max_stack elements |
571 |
579 // this test requires the use the unextended_sp which is the sp as seen by |
572 if (fp() - sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { |
580 // the current frame, and not sp which is the "raw" pc which could point |
|
581 // further because of local variables of the callee method inserted after |
|
582 // method arguments |
|
583 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) { |
573 return false; |
584 return false; |
574 } |
585 } |
575 |
586 |
576 // validate bci/bcp |
587 // validate bci/bcp |
577 |
588 |