about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-02-08 20:47:52 -0800
committerBrian Anderson <banderson@mozilla.com>2012-02-09 19:00:15 -0800
commitae8ea4a78b113f67ade93152dc3dee1ded81a219 (patch)
tree14a2a25ade42291bace7ad46516b6a959c04714e /src/rt
parentb98df86c098ad3bb80c794fd0c2ead6ff1f608e7 (diff)
downloadrust-ae8ea4a78b113f67ade93152dc3dee1ded81a219.tar.gz
rust-ae8ea4a78b113f67ade93152dc3dee1ded81a219.zip
rt: Add constructors and destructors for stacks
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rust_stack.h18
-rw-r--r--src/rt/rust_task.cpp6
2 files changed, 21 insertions, 3 deletions
diff --git a/src/rt/rust_stack.h b/src/rt/rust_stack.h
index d665b4fa2c1..34d4dda742d 100644
--- a/src/rt/rust_stack.h
+++ b/src/rt/rust_stack.h
@@ -1,3 +1,6 @@
+#ifndef RUST_STACK_H
+#define RUST_STACK_H
+
 struct stk_seg {
     stk_seg *prev;
     stk_seg *next;
@@ -10,6 +13,19 @@ struct stk_seg {
     uint8_t data[];
 };
 
+template <class T>
+stk_seg *
+create_stack(T allocer, size_t sz) {
+  size_t total_sz = sizeof(stk_seg) + sz;
+  return (stk_seg *)allocer->malloc(total_sz, "stack");
+}
+
+template <class T>
+void
+destroy_stack(T allocer, stk_seg *stk) {
+  allocer->free(stk);
+}
+
 void
 config_valgrind_stack(stk_seg *stk);
 
@@ -21,3 +37,5 @@ add_stack_canary(stk_seg *stk);
 
 void
 check_stack_canary(stk_seg *stk);
+
+#endif /* RUST_STACK_H */
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp
index dc8b911778a..32245c5d9cd 100644
--- a/src/rt/rust_task.cpp
+++ b/src/rt/rust_task.cpp
@@ -538,7 +538,7 @@ void
 rust_task::free_stack(stk_seg *stk) {
     LOGPTR(thread, "freeing stk segment", (uintptr_t)stk);
     total_stack_sz -= user_stack_size(stk);
-    free(stk);
+    destroy_stack(this, stk);
 }
 
 void
@@ -581,8 +581,8 @@ rust_task::new_stack(size_t requested_sz) {
         fail();
     }
 
-    size_t sz = sizeof(stk_seg) + rust_stk_sz + RED_ZONE_SIZE;
-    stk_seg *new_stk = (stk_seg *)malloc(sz, "stack");
+    size_t sz = rust_stk_sz + RED_ZONE_SIZE;
+    stk_seg *new_stk = create_stack(this, sz);
     LOGPTR(thread, "new stk", (uintptr_t)new_stk);
     memset(new_stk, 0, sizeof(stk_seg));
     add_stack_canary(new_stk);