mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Issue #194 - Use write barrier
When allocating vectors directly on the heap, use write barrier to ensure fill is moved to heap. This prevents the possibility of fill being corrupted.
This commit is contained in:
parent
36a4e91c5e
commit
a173ecb201
2 changed files with 9 additions and 0 deletions
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 0.5.1 - TBD
|
||||
|
||||
- Prevent potential memory corruption when working with large vectors that cannot be allocated on the stack.
|
||||
|
||||
## 0.5 - April 14, 2017
|
||||
|
||||
Features
|
||||
|
|
|
@ -2236,6 +2236,7 @@ object Cyc_make_vector(void *data, object cont, int argc, object len, ...)
|
|||
int i, ulen;
|
||||
size_t element_vec_size;
|
||||
va_list ap;
|
||||
make_pair(tmp_pair, NULL, NULL);
|
||||
va_start(ap, len);
|
||||
if (argc > 1) {
|
||||
fill = va_arg(ap, object);
|
||||
|
@ -2261,6 +2262,10 @@ object Cyc_make_vector(void *data, object cont, int argc, object len, ...)
|
|||
((vector) v)->tag = vector_tag;
|
||||
((vector) v)->num_elements = ulen;
|
||||
((vector) v)->elements = (object *)(((char *)v) + sizeof(vector_type));
|
||||
// Use write barrier to ensure fill is moved to heap if it is on the stack
|
||||
// Otherwise if next minor GC misses fill it could be catastrophic
|
||||
car(&tmp_pair) = fill;
|
||||
add_mutation(data, &tmp_pair, -1, fill);
|
||||
} else {
|
||||
v = alloca(sizeof(vector_type));
|
||||
((vector) v)->hdr.mark = gc_color_red;
|
||||
|
|
Loading…
Add table
Reference in a new issue