From 25bcc2dfa67f7fee62ff2ee15e42655533e6da56 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 31 Jan 2017 16:00:58 +0100 Subject: [PATCH] libc: add Libc::Allocator that uses malloc/free --- repos/libports/include/libc/allocator.h | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 repos/libports/include/libc/allocator.h diff --git a/repos/libports/include/libc/allocator.h b/repos/libports/include/libc/allocator.h new file mode 100644 index 0000000000..eb67284033 --- /dev/null +++ b/repos/libports/include/libc/allocator.h @@ -0,0 +1,43 @@ +/* + * \brief Genode::Allocator that uses the libc's global heap + * \author Norman Feske + * \date 2017-01-31 + */ + +/* + * Copyright (C) 2017 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__LIBC__ALLOCATOR_H_ +#define _INCLUDE__LIBC__ALLOCATOR_H_ + +/* Genode includes */ +#include + +/* libc includes */ +#include + +namespace Libc { struct Allocator; } + + +struct Libc::Allocator : Genode::Allocator +{ + typedef Genode::size_t size_t; + + bool alloc(size_t size, void **out_addr) override + { + *out_addr = malloc(size); + return true; + } + + void free(void *addr, size_t size) override { ::free(addr); } + + bool need_size_for_free() const override { return false; } + + size_t overhead(size_t size) const override { return 0; } +}; + +#endif /* _INCLUDE__LIBC__ALLOCATOR_H_ */