OLD | NEW |
---|---|
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 #include <openssl/crypto.h> | |
6 | |
5 #include "vm/dart_api_message.h" | 7 #include "vm/dart_api_message.h" |
6 #include "vm/object.h" | 8 #include "vm/object.h" |
7 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
8 | 10 |
9 namespace dart { | 11 namespace dart { |
10 | 12 |
11 // TODO(sgjesse): When the external message format is done these | 13 // TODO(sgjesse): When the external message format is done these |
12 // duplicate constants from snapshot.cc should be removed. | 14 // duplicate constants from snapshot.cc should be removed. |
13 enum { | 15 enum { |
14 kInstanceId = ObjectStore::kMaxId, | 16 kInstanceId = ObjectStore::kMaxId, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 } | 75 } |
74 | 76 |
75 | 77 |
76 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt32(int32_t val) { | 78 Dart_CObject* ApiMessageReader::AllocateDartCObjectInt32(int32_t val) { |
77 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt32); | 79 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt32); |
78 value->value.as_int32 = val; | 80 value->value.as_int32 = val; |
79 return value; | 81 return value; |
80 } | 82 } |
81 | 83 |
82 | 84 |
85 Dart_CObject* ApiMessageReader::AllocateDartCObjectBigint(intptr_t length) { | |
86 // Allocate a Dart_CObject structure followed by an array of chars | |
87 // for the bigint hex string content. The pointer to the bigint | |
88 // content is set up to this area. | |
89 Dart_CObject* value = | |
90 reinterpret_cast<Dart_CObject*>( | |
91 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); | |
92 value->value.as_bigint = reinterpret_cast<char*>(value) + sizeof(*value); | |
93 value->type = Dart_CObject::kBigint; | |
94 return value; | |
95 } | |
96 | |
97 | |
83 Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { | 98 Dart_CObject* ApiMessageReader::AllocateDartCObjectDouble(double val) { |
84 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); | 99 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); |
85 value->value.as_double = val; | 100 value->value.as_double = val; |
86 return value; | 101 return value; |
87 } | 102 } |
88 | 103 |
89 | 104 |
90 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { | 105 Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) { |
91 // Allocate a Dart_CObject structure followed by an array of chars | 106 // Allocate a Dart_CObject structure followed by an array of chars |
92 // for the string content. The pointer to the string content is set | 107 // for the string content. The pointer to the string content is set |
(...skipping 18 matching lines...) Expand all Loading... | |
111 value->value.as_array.length = length; | 126 value->value.as_array.length = length; |
112 if (length > 0) { | 127 if (length > 0) { |
113 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 128 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
114 } else { | 129 } else { |
115 value->value.as_array.values = NULL; | 130 value->value.as_array.values = NULL; |
116 } | 131 } |
117 return value; | 132 return value; |
118 } | 133 } |
119 | 134 |
120 | 135 |
136 uint8_t* ApiMessageReader::AllocateTemp(intptr_t size) { | |
137 if (Isolate::Current() != NULL) { | |
138 return reinterpret_cast<uint8_t*>( | |
139 Isolate::Current()->current_zone()->Allocate(size)); | |
140 } else { | |
141 return reinterpret_cast<uint8_t*>( | |
142 ApiNativeScope::Current()->zone()->Allocate(size)); | |
143 } | |
144 } | |
145 | |
146 | |
121 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { | 147 Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) { |
122 // Read the class header information and lookup the class. | 148 // Read the class header information and lookup the class. |
123 intptr_t class_header = ReadIntptrValue(); | 149 intptr_t class_header = ReadIntptrValue(); |
124 intptr_t tags = ReadIntptrValue(); | 150 intptr_t tags = ReadIntptrValue(); |
125 USE(tags); | 151 USE(tags); |
126 intptr_t class_id; | 152 intptr_t class_id; |
127 | 153 |
128 // Reading of regular dart instances is not supported. | 154 // Reading of regular dart instances is not supported. |
129 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | 155 if (SerializedHeaderData::decode(class_header) == kInstanceId) { |
130 return NULL; | 156 return NULL; |
(...skipping 29 matching lines...) Expand all Loading... | |
160 if (type_arguments != &type_arguments_marker && | 186 if (type_arguments != &type_arguments_marker && |
161 type_arguments->type != Dart_CObject::kNull) { | 187 type_arguments->type != Dart_CObject::kNull) { |
162 return NULL; | 188 return NULL; |
163 } | 189 } |
164 for (int i = 0; i < len; i++) { | 190 for (int i = 0; i < len; i++) { |
165 value->value.as_array.values[i] = ReadObject(); | 191 value->value.as_array.values[i] = ReadObject(); |
166 } | 192 } |
167 return value; | 193 return value; |
168 break; | 194 break; |
169 } | 195 } |
196 case ObjectStore::kBigintClass: { | |
197 // Read in the HexCString representation of the bigint. | |
198 intptr_t len = ReadIntptrValue(); | |
199 char* hex_string = reinterpret_cast<char*>(AllocateTemp(len + 1)); | |
siva
2012/02/09 01:47:27
Why do you use this special temp Allocator and not
Søren Gjesse
2012/02/09 14:08:33
The idea was that temporary data should be freed b
| |
200 char* p = hex_string; | |
201 for (intptr_t i = 0; i < len; i++) { | |
202 *p = Read<uint8_t>(); | |
203 p++; | |
204 } | |
205 *p = '\0'; | |
206 // Convert the hex representation to decimal representation. | |
207 BIGNUM* bn = BN_new(); | |
208 BN_hex2bn(&bn, hex_string); | |
209 char* dec_string = BN_bn2dec(bn); | |
siva
2012/02/09 01:47:27
What is the advantage of converting this into a de
Søren Gjesse
2012/02/09 14:08:33
Keeping the hex string - no need for bigint operat
| |
210 len = strlen(dec_string); | |
211 Dart_CObject* object = AllocateDartCObjectBigint(len); | |
212 memmove(object->value.as_bigint, dec_string, len + 1); | |
213 OPENSSL_free(dec_string); | |
214 BN_free(bn); | |
215 return object; | |
216 break; | |
217 } | |
170 case ObjectStore::kDoubleClass: { | 218 case ObjectStore::kDoubleClass: { |
171 // Read the double value for the object. | 219 // Read the double value for the object. |
172 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); | 220 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); |
173 AddBackwardReference(object_id, object); | 221 AddBackwardReference(object_id, object); |
174 return object; | 222 return object; |
175 break; | 223 break; |
176 } | 224 } |
177 case ObjectStore::kOneByteStringClass: { | 225 case ObjectStore::kOneByteStringClass: { |
178 intptr_t len = ReadSmiValue(); | 226 intptr_t len = ReadSmiValue(); |
179 intptr_t hash = ReadSmiValue(); | 227 intptr_t hash = ReadSmiValue(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 return ReadObjectImpl(value); | 298 return ReadObjectImpl(value); |
251 } | 299 } |
252 | 300 |
253 | 301 |
254 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { | 302 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { |
255 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); | 303 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); |
256 backward_references_.Add(obj); | 304 backward_references_.Add(obj); |
257 } | 305 } |
258 | 306 |
259 } // namespace dart | 307 } // namespace dart |
OLD | NEW |