hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

malloc.ha (753B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use rt;
      5 use unix::signal;
      6 
      7 let heap = rt::EMPTY_HEAP;
      8 
      9 // Reconfigure the process to handle a fatal condition, such as a segfault, as
     10 // safely as possible. Resets all signals (in case of faults in debug::) and
     11 // configures the runtime to use the debug heap (in case of heap overflow or
     12 // similar faults in the user program).
     13 fn begin_fatal() void = {
     14 	signal::resetall();
     15 	rt::setheap(&heap);
     16 	rt::onabort(default_abort);
     17 };
     18 
     19 // Enables the debug:: heap.
     20 fn begin_altheap() *rt::memory_heap = {
     21 	return rt::setheap(&heap);
     22 };
     23 
     24 // Restores the original heap corresponding to [[begin_altheap]].
     25 fn end_altheap(restore: *rt::memory_heap) void = {
     26 	rt::setheap(restore);
     27 };