diff --git a/headers/private/libroot/libroot_private.h b/headers/private/libroot/libroot_private.h
index d0676a6..79ec524 100644
a
|
b
|
void __init_env(const struct user_space_program_args *args);
|
36 | 36 | void __init_env_post_heap(void); |
37 | 37 | status_t __init_heap(void); |
38 | 38 | void __heap_terminate_after(void); |
| 39 | void __heap_before_fork(void); |
| 40 | void __heap_after_fork_child(void); |
| 41 | void __heap_after_fork_parent(void); |
39 | 42 | |
40 | 43 | void __init_time(addr_t commPageTable); |
41 | 44 | void __arch_init_time(struct real_time_data *data, bool setDefaults); |
diff --git a/src/system/libroot/posix/malloc/heap.cpp b/src/system/libroot/posix/malloc/heap.cpp
index 99aba54..e2cc553 100644
a
|
b
|
hoardHeap::hoardHeap(void)
|
132 | 132 | , _magic(HEAP_MAGIC) |
133 | 133 | #endif |
134 | 134 | { |
135 | | // Initialize the per-heap lock. |
136 | | hoardLockInit(_lock, "hoard heap"); |
| 135 | initLock(); |
137 | 136 | |
138 | 137 | for (int i = 0; i < SUPERBLOCK_FULLNESS_GROUP; i++) { |
139 | 138 | for (int j = 0; j < SIZE_CLASSES; j++) { |
diff --git a/src/system/libroot/posix/malloc/heap.h b/src/system/libroot/posix/malloc/heap.h
index f42962e..42e9eb4 100644
a
|
b
|
class hoardHeap {
|
115 | 115 | // Unlock this heap. |
116 | 116 | inline void unlock(void); |
117 | 117 | |
| 118 | // Init this heap lock. |
| 119 | inline void initLock(void); |
| 120 | |
118 | 121 | // Set our index number (which heap we are). |
119 | 122 | inline void setIndex(int i); |
120 | 123 | |
… |
… |
hoardHeap::unlock(void)
|
444 | 447 | } |
445 | 448 | |
446 | 449 | |
| 450 | void |
| 451 | hoardHeap::initLock(void) |
| 452 | { |
| 453 | // Initialize the per-heap lock. |
| 454 | hoardLockInit(_lock, "hoard heap"); |
| 455 | } |
| 456 | |
| 457 | |
447 | 458 | size_t |
448 | 459 | hoardHeap::align(const size_t sz) |
449 | 460 | { |
diff --git a/src/system/libroot/posix/malloc/processheap.h b/src/system/libroot/posix/malloc/processheap.h
index f222289..2c94af9 100644
a
|
b
|
class processHeap : public hoardHeap {
|
67 | 67 | // Get a thread heap index. |
68 | 68 | inline int getHeapIndex(void); |
69 | 69 | |
| 70 | // Get thread heap max. |
| 71 | inline int getMaxThreadHeaps(void); |
| 72 | |
70 | 73 | // Get the thread heap with index i. |
71 | 74 | inline HEAPTYPE & getHeap(int i); |
72 | 75 | |
… |
… |
processHeap::getHeapIndex(void)
|
199 | 202 | } |
200 | 203 | |
201 | 204 | |
| 205 | // Return the maximum number of heaps. |
| 206 | |
| 207 | int |
| 208 | processHeap::getMaxThreadHeaps(void) |
| 209 | { |
| 210 | return fMaxThreadHeaps; |
| 211 | } |
| 212 | |
| 213 | |
202 | 214 | superblock * |
203 | 215 | processHeap::acquire(const int sizeclass, hoardHeap * dest) |
204 | 216 | { |
diff --git a/src/system/libroot/posix/malloc/wrapper.cpp b/src/system/libroot/posix/malloc/wrapper.cpp
index c83336a..f3e1384 100644
a
|
b
|
getAllocator(void)
|
256 | 256 | } |
257 | 257 | |
258 | 258 | |
| 259 | extern "C" void |
| 260 | __heap_before_fork(void) |
| 261 | { |
| 262 | static processHeap *pHeap = getAllocator(); |
| 263 | for (int i = 0; i < pHeap->getMaxThreadHeaps(); i++) |
| 264 | pHeap->getHeap(i).lock(); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | extern "C" void |
| 269 | __heap_after_fork_child(void) |
| 270 | { |
| 271 | static processHeap *pHeap = getAllocator(); |
| 272 | for (int i = 0; i < pHeap->getMaxThreadHeaps(); i++) |
| 273 | pHeap->getHeap(i).initLock(); |
| 274 | } |
| 275 | |
| 276 | |
| 277 | extern "C" void |
| 278 | __heap_after_fork_parent(void) |
| 279 | { |
| 280 | static processHeap *pHeap = getAllocator(); |
| 281 | for (int i = 0; i < pHeap->getMaxThreadHeaps(); i++) |
| 282 | pHeap->getHeap(i).unlock(); |
| 283 | } |
| 284 | |
| 285 | |
259 | 286 | // #pragma mark - public functions |
260 | 287 | |
261 | 288 | |
diff --git a/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp b/src/system/libroot/posix/malloc_debug/malloc_debug_api.cpp
index 3d3b062..bf38d4c 100644
a
|
b
|
__heap_terminate_after()
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
| 205 | extern "C" void |
| 206 | __heap_before_fork(void) |
| 207 | { |
| 208 | } |
| 209 | |
| 210 | |
| 211 | extern "C" void |
| 212 | __heap_after_fork_child(void) |
| 213 | { |
| 214 | } |
| 215 | |
| 216 | |
| 217 | extern "C" void |
| 218 | __heap_after_fork_parent(void) |
| 219 | { |
| 220 | } |
| 221 | |
| 222 | |
205 | 223 | // #pragma mark - Public API |
206 | 224 | |
207 | 225 | |
diff --git a/src/system/libroot/posix/unistd/fork.c b/src/system/libroot/posix/unistd/fork.c
index 8d8a963..8b4ae8e 100644
a
|
b
|
fork(void)
|
135 | 135 | |
136 | 136 | // call preparation hooks |
137 | 137 | call_fork_hooks(sPrepareHooks); |
| 138 | __heap_before_fork(); |
138 | 139 | |
139 | 140 | thread = _kern_fork(); |
140 | 141 | if (thread < 0) { |
… |
… |
fork(void)
|
156 | 157 | // calling the kernel. |
157 | 158 | __gRuntimeLoader->reinit_after_fork(); |
158 | 159 | __reinit_pwd_backend_after_fork(); |
| 160 | __heap_after_fork_child(); |
159 | 161 | |
160 | 162 | call_fork_hooks(sChildHooks); |
161 | 163 | } else { |
162 | 164 | // we are the parent |
| 165 | __heap_after_fork_parent(); |
163 | 166 | call_fork_hooks(sParentHooks); |
164 | 167 | mutex_unlock(&sForkLock); |
165 | 168 | } |