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

Side by Side Diff: runtime/vm/freelist.h

Issue 150563007: Fix crash bug in free list when allocating write protected memory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix gcc compiler warnings Created 6 years, 10 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
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 #ifndef VM_FREELIST_H_ 5 #ifndef VM_FREELIST_H_
6 #define VM_FREELIST_H_ 6 #define VM_FREELIST_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/bit_set.h" 10 #include "vm/bit_set.h"
11 #include "vm/raw_object.h" 11 #include "vm/raw_object.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 // FreeListElement describes a freelist element. Smallest FreeListElement is 15 // FreeListElement describes a freelist element. Smallest FreeListElement is
16 // two words in size. Second word of the raw object is used to keep a next_ 16 // two words in size. Second word of the raw object is used to keep a next_
17 // pointer to chain elements of the list together. For objects larger than the 17 // pointer to chain elements of the list together. For objects larger than the
18 // object size encodable in tags field, the size of the element is embedded in 18 // object size encodable in tags field, the size of the element is embedded in
19 // the element at the address following the next_ field. 19 // the element at the address following the next_ field.
20 class FreeListElement { 20 class FreeListElement {
21 public: 21 public:
22 // Maximum header size is three words (tags, next, and size).
23 static const intptr_t kHeaderSize = 3 * kWordSize;
24
25 FreeListElement* next() const { 22 FreeListElement* next() const {
26 return next_; 23 return next_;
27 } 24 }
28 uword next_address() const { 25 uword next_address() const {
29 return reinterpret_cast<uword>(&next_); 26 return reinterpret_cast<uword>(&next_);
30 } 27 }
31 28
32 void set_next(FreeListElement* next) { 29 void set_next(FreeListElement* next) {
33 next_ = next; 30 next_ = next;
34 } 31 }
35 32
36 intptr_t Size() { 33 intptr_t Size() {
37 intptr_t size = RawObject::SizeTag::decode(tags_); 34 intptr_t size = RawObject::SizeTag::decode(tags_);
38 if (size != 0) return size; 35 if (size != 0) return size;
39 return *SizeAddress(); 36 return *SizeAddress();
40 } 37 }
41 38
42 static FreeListElement* AsElement(uword addr, intptr_t size); 39 static FreeListElement* AsElement(uword addr, intptr_t size);
43 40
44 static void InitOnce(); 41 static void InitOnce();
45 42
43 static intptr_t HeaderSizeFor(intptr_t size);
44
46 // Used to allocate class for free list elements in Object::InitOnce. 45 // Used to allocate class for free list elements in Object::InitOnce.
47 class FakeInstance { 46 class FakeInstance {
48 public: 47 public:
49 FakeInstance() { } 48 FakeInstance() { }
50 static cpp_vtable vtable() { return 0; } 49 static cpp_vtable vtable() { return 0; }
51 static intptr_t InstanceSize() { return 0; } 50 static intptr_t InstanceSize() { return 0; }
52 static intptr_t NextFieldOffset() { return -kWordSize; } 51 static intptr_t NextFieldOffset() { return -kWordSize; }
53 static const ClassId kClassId = kFreeListElement; 52 static const ClassId kClassId = kFreeListElement;
54 static bool IsInstance() { return true; } 53 static bool IsInstance() { return true; }
55 54
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 BitSet<kNumLists> free_map_; 107 BitSet<kNumLists> free_map_;
109 108
110 FreeListElement* free_lists_[kNumLists + 1]; 109 FreeListElement* free_lists_[kNumLists + 1];
111 110
112 DISALLOW_COPY_AND_ASSIGN(FreeList); 111 DISALLOW_COPY_AND_ASSIGN(FreeList);
113 }; 112 };
114 113
115 } // namespace dart 114 } // namespace dart
116 115
117 #endif // VM_FREELIST_H_ 116 #endif // VM_FREELIST_H_
OLDNEW
« no previous file with comments | « runtime/vm/code_patcher.cc ('k') | runtime/vm/freelist.cc » ('j') | runtime/vm/freelist.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698