3ae4dcd41e
We're trying to get closer to doing correct move semantics for channel operations. This involves a lot of cleanup (such as removing the unused sched parameter from rust_vec constructor) and making circular_buffer kernel_owned. Added tagging for memory allocations. This means we give a string tag to everything we allocate. If we leak something and TRACK_ALLOCATIONS is enabled, then it's much easier now to tell exactly what is leaking.
74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
/*
|
|
* The Rust runtime uses memory regions to provide a primitive level of
|
|
* memory management and isolation between tasks, and domains.
|
|
*
|
|
* FIXME: Implement a custom lock-free malloc / free instead of relying solely
|
|
* on the standard malloc / free.
|
|
*/
|
|
|
|
#ifndef MEMORY_REGION_H
|
|
#define MEMORY_REGION_H
|
|
|
|
#include "sync/lock_and_signal.h"
|
|
|
|
class rust_srv;
|
|
|
|
class memory_region {
|
|
private:
|
|
struct alloc_header {
|
|
uint32_t magic;
|
|
int index;
|
|
const char *tag;
|
|
char data[];
|
|
};
|
|
|
|
alloc_header *get_header(void *mem);
|
|
|
|
rust_srv *_srv;
|
|
memory_region *_parent;
|
|
size_t _live_allocations;
|
|
array_list<alloc_header *> _allocation_list;
|
|
const bool _detailed_leaks;
|
|
const bool _synchronized;
|
|
lock_and_signal _lock;
|
|
bool _hack_allow_leaks;
|
|
|
|
void add_alloc();
|
|
void dec_alloc();
|
|
public:
|
|
memory_region(rust_srv *srv, bool synchronized);
|
|
memory_region(memory_region *parent);
|
|
void *malloc(size_t size, const char *tag, bool zero = true);
|
|
void *calloc(size_t size, const char *tag);
|
|
void *realloc(void *mem, size_t size);
|
|
void free(void *mem);
|
|
virtual ~memory_region();
|
|
// FIXME (236: This is a temporary hack to allow failing tasks that leak
|
|
// to not kill the entire process, which the test runner needs. Please
|
|
// kill with prejudice once unwinding works.
|
|
void hack_allow_leaks();
|
|
};
|
|
|
|
inline void *operator new(size_t size, memory_region ®ion,
|
|
const char *tag) {
|
|
return region.malloc(size, tag);
|
|
}
|
|
|
|
inline void *operator new(size_t size, memory_region *region,
|
|
const char *tag) {
|
|
return region->malloc(size, tag);
|
|
}
|
|
|
|
//
|
|
// Local Variables:
|
|
// mode: C++
|
|
// fill-column: 78;
|
|
// indent-tabs-mode: nil
|
|
// c-basic-offset: 4
|
|
// buffer-file-coding-system: utf-8-unix
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
// End:
|
|
//
|
|
|
|
#endif /* MEMORY_REGION_H */
|