// -*- Mode: C++ -*-
// vim:ft=cpp
/**
 * \file
 * \brief  Kumem allocator helper
 */
/*
 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
 *          Alexander Warg <warg@os.inf.tu-dresden.de>
 *     economic rights: Technische Universität Dresden (Germany)
 *
 * License: see LICENSE.spdx (in this directory or the directories above)
 */

#pragma once

#include <l4/re/env>

namespace L4Re { namespace Util {

/**
 * \defgroup l4re_util_kumem Kumem utiltities
 * \ingroup api_l4re_util
 */
/**@{*/

/**
 * Allocate state area.
 *
 * \param[out] mem          Pointer to memory that has been allocated.
 * \param      pages_order  Size to allocate, in log2 pages.
 * \param      task         Task to use for allocation.
 * \param      rm           Region manager to use for allocation.
 *
 * \retval 0   for success
 * \retval <0  error code on failure
 *
 * \note
 * The amount of kernel-user memory that can be allocated at once is limited by
 * the used kernel implementation. The minimum allocatable amount is one page.
 * A portable implementation should not depend on allocations greater than
 * 16KiB to succeed.
 */
int
kumem_alloc(l4_addr_t *mem, unsigned pages_order,
            L4::Cap<L4::Task> task = L4Re::Env::env()->task(),
            L4::Cap<L4Re::Rm> rm = L4Re::Env::env()->rm()) noexcept;

/**@}*/
}}
