mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 23:53:55 +00:00
Move repositories to 'repos/' subdirectory
This patch changes the top-level directory layout as a preparatory step for improving the tools for managing 3rd-party source codes. The rationale is described in the issue referenced below. Issue #1082
This commit is contained in:
50
repos/demo/src/lib/mini_c/malloc_free.cc
Normal file
50
repos/demo/src/lib/mini_c/malloc_free.cc
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* \brief Mini C malloc() and free()
|
||||
* \author Norman Feske
|
||||
* \date 2006-07-21
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2013 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.
|
||||
*/
|
||||
|
||||
#include <base/env.h>
|
||||
#include <util/string.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
|
||||
extern "C" void *malloc(unsigned size)
|
||||
{
|
||||
/*
|
||||
* We store the size of the allocation at the very
|
||||
* beginning of the allocated block and return
|
||||
* the subsequent address. This way, we can retrieve
|
||||
* the size information when freeing the block.
|
||||
*/
|
||||
unsigned long real_size = size + sizeof(unsigned long);
|
||||
void *addr = 0;
|
||||
if (!env()->heap()->alloc(real_size, &addr))
|
||||
return 0;
|
||||
|
||||
*(unsigned long *)addr = real_size;
|
||||
return (unsigned long *)addr + 1;
|
||||
}
|
||||
|
||||
|
||||
extern "C" void *calloc(unsigned nmemb, unsigned size)
|
||||
{
|
||||
void *addr = malloc(nmemb*size);
|
||||
memset(addr, 0, nmemb*size);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
extern "C" void free(void *ptr)
|
||||
{
|
||||
unsigned long *addr = ((unsigned long *)ptr) - 1;
|
||||
env()->heap()->free(addr, *addr);
|
||||
}
|
Reference in New Issue
Block a user