Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: runtime/vm/intrinsifier_ia32.cc

Issue 10917223: Guard against allocation top overflow in ObjectArray_Allocate intrinsic. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/constants_x64.h ('k') | runtime/vm/intrinsifier_x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // The intrinsic code below is executed before a method has built its frame. 5 // The intrinsic code below is executed before a method has built its frame.
6 // The return address is on the stack and the arguments below it. 6 // The return address is on the stack and the arguments below it.
7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved.
8 // Each intrinsification method returns true if the corresponding 8 // Each intrinsification method returns true if the corresponding
9 // Dart method was intrinsified. 9 // Dart method was intrinsified.
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 __ cmpl(EDI, max_len); 51 __ cmpl(EDI, max_len);
52 __ j(GREATER, &fall_through); 52 __ j(GREATER, &fall_through);
53 intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1; 53 intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1;
54 __ leal(EDI, Address(EDI, TIMES_2, fixed_size)); // EDI is a Smi. 54 __ leal(EDI, Address(EDI, TIMES_2, fixed_size)); // EDI is a Smi.
55 ASSERT(kSmiTagShift == 1); 55 ASSERT(kSmiTagShift == 1);
56 __ andl(EDI, Immediate(-kObjectAlignment)); 56 __ andl(EDI, Immediate(-kObjectAlignment));
57 57
58 Isolate* isolate = Isolate::Current(); 58 Isolate* isolate = Isolate::Current();
59 Heap* heap = isolate->heap(); 59 Heap* heap = isolate->heap();
60 60
61 __ movl(EAX, Address::Absolute(heap->TopAddress()));
62 __ movl(EBX, EAX);
63
61 // EDI: allocation size. 64 // EDI: allocation size.
62 __ movl(EAX, Address::Absolute(heap->TopAddress())); 65 __ addl(EBX, EDI);
63 __ leal(EBX, Address(EAX, EDI, TIMES_1, 0)); 66 __ j(CARRY, &fall_through);
64 67
65 // Check if the allocation fits into the remaining space. 68 // Check if the allocation fits into the remaining space.
66 // EAX: potential new object start. 69 // EAX: potential new object start.
67 // EBX: potential next object start. 70 // EBX: potential next object start.
68 // EDI: allocation size. 71 // EDI: allocation size.
69 __ cmpl(EBX, Address::Absolute(heap->EndAddress())); 72 __ cmpl(EBX, Address::Absolute(heap->EndAddress()));
70 __ j(ABOVE_EQUAL, &fall_through); 73 __ j(ABOVE_EQUAL, &fall_through);
71 74
72 // Successfully allocated the object(s), now update top to point to 75 // Successfully allocated the object(s), now update top to point to
73 // next object start and initialize the object. 76 // next object start and initialize the object.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 __ j(EQUAL, &checked_ok, Assembler::kNearJump); 222 __ j(EQUAL, &checked_ok, Assembler::kNearJump);
220 __ CompareObject(EAX, Type::ZoneHandle(Type::Number())); 223 __ CompareObject(EAX, Type::ZoneHandle(Type::Number()));
221 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump); 224 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
222 __ Bind(&checked_ok); 225 __ Bind(&checked_ok);
223 } 226 }
224 __ movl(EBX, Address(ESP, + 2 * kWordSize)); // Index. 227 __ movl(EBX, Address(ESP, + 2 * kWordSize)); // Index.
225 __ testl(EBX, Immediate(kSmiTagMask)); 228 __ testl(EBX, Immediate(kSmiTagMask));
226 // Index not Smi. 229 // Index not Smi.
227 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); 230 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump);
228 __ movl(EAX, Address(ESP, + 3 * kWordSize)); // Array. 231 __ movl(EAX, Address(ESP, + 3 * kWordSize)); // Array.
232 __ CompareClassId(EAX, kArrayCid, EDI);
Ivan Posva 2012/09/12 21:26:34 ?
233 Label ok;
234 __ j(EQUAL, &ok);
235 __ int3();
236 __ Bind(&ok);
229 // Range check. 237 // Range check.
230 __ cmpl(EBX, FieldAddress(EAX, Array::length_offset())); 238 __ cmpl(EBX, FieldAddress(EAX, Array::length_offset()));
231 // Runtime throws exception. 239 // Runtime throws exception.
232 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump); 240 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump);
233 // Note that EBX is Smi, i.e, times 2. 241 // Note that EBX is Smi, i.e, times 2.
234 ASSERT(kSmiTagShift == 1); 242 ASSERT(kSmiTagShift == 1);
235 // Destroy ECX as we will not continue in the function. 243 // Destroy ECX as we will not continue in the function.
236 __ movl(ECX, Address(ESP, + 1 * kWordSize)); // Value. 244 __ movl(ECX, Address(ESP, + 1 * kWordSize)); // Value.
237 __ StoreIntoObject(EAX, 245 __ StoreIntoObject(EAX,
238 FieldAddress(EAX, EBX, TIMES_2, sizeof(RawArray)), 246 FieldAddress(EAX, EBX, TIMES_2, sizeof(RawArray)),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 377
370 // Set value into growable object array at specified index. 378 // Set value into growable object array at specified index.
371 // On stack: growable array (+3), index (+2), value (+1), return-address (+0). 379 // On stack: growable array (+3), index (+2), value (+1), return-address (+0).
372 bool Intrinsifier::GrowableArray_setIndexed(Assembler* assembler) { 380 bool Intrinsifier::GrowableArray_setIndexed(Assembler* assembler) {
373 if (FLAG_enable_type_checks) { 381 if (FLAG_enable_type_checks) {
374 return false; 382 return false;
375 } 383 }
376 Label fall_through; 384 Label fall_through;
377 __ movl(EBX, Address(ESP, + 2 * kWordSize)); // Index. 385 __ movl(EBX, Address(ESP, + 2 * kWordSize)); // Index.
378 __ movl(EAX, Address(ESP, + 3 * kWordSize)); // GrowableArray. 386 __ movl(EAX, Address(ESP, + 3 * kWordSize)); // GrowableArray.
387 __ CompareClassId(EAX, kGrowableObjectArrayCid, EDI);
388 Label ok;
389 __ j(EQUAL, &ok);
390 __ int3();
391 __ Bind(&ok);
379 __ testl(EBX, Immediate(kSmiTagMask)); 392 __ testl(EBX, Immediate(kSmiTagMask));
380 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi index. 393 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi index.
381 // Range check using _length field. 394 // Range check using _length field.
382 __ cmpl(EBX, FieldAddress(EAX, GrowableObjectArray::length_offset())); 395 __ cmpl(EBX, FieldAddress(EAX, GrowableObjectArray::length_offset()));
383 // Runtime throws exception. 396 // Runtime throws exception.
384 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump); 397 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump);
385 __ movl(EAX, FieldAddress(EAX, GrowableObjectArray::data_offset())); // data. 398 __ movl(EAX, FieldAddress(EAX, GrowableObjectArray::data_offset())); // data.
386 __ movl(EDI, Address(ESP, + 1 * kWordSize)); // Value. 399 __ movl(EDI, Address(ESP, + 1 * kWordSize)); // Value.
387 // Note that EBX is Smi, i.e, times 2. 400 // Note that EBX is Smi, i.e, times 2.
388 ASSERT(kSmiTagShift == 1); 401 ASSERT(kSmiTagShift == 1);
(...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 __ Bind(&is_true); 1436 __ Bind(&is_true);
1424 __ LoadObject(EAX, bool_true); 1437 __ LoadObject(EAX, bool_true);
1425 __ ret(); 1438 __ ret();
1426 return true; 1439 return true;
1427 } 1440 }
1428 1441
1429 #undef __ 1442 #undef __
1430 } // namespace dart 1443 } // namespace dart
1431 1444
1432 #endif // defined TARGET_ARCH_IA32 1445 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/constants_x64.h ('k') | runtime/vm/intrinsifier_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698