metalsvm/include/metalsvm/stdlib.h
2012-08-08 10:11:15 +02:00

123 lines
3 KiB
C

/*
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
/**
* @author Stefan Lankes
* @file include/metalsvm/stdlib.h
* @brief Kernel space malloc and free functions and conversion functions
*
* This file contains some memory alloc and free calls for the kernel
* and conversion functions.
*/
#ifndef __STDLIB_H__
#define __STDLIB_H__
#include <metalsvm/config.h>
#include <metalsvm/tasks_types.h>
#include <asm/stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAP_KERNEL_SPACE (1 << 0)
#define MAP_USER_SPACE (1 << 1)
#define MAP_PAGE_TABLE (1 << 2)
#define MAP_NO_CACHE (1 << 3)
#define MAP_WT (1 << 5)
#define MAP_CODE (1 << 6)
#define MAP_READONLY (1 << 7)
#ifdef CONFIG_ROCKCREEK
#define MAP_MPE (1 << 8)
#endif
#define MAP_SVM_STRONG (1 << 9)
#define MAP_SVM_LAZYRELEASE (1 << 10)
#define MAP_SVM_INIT (1 << 11)
#define MAP_NO_ACCESS (1 << 12)
#define MAP_REMAP (1 << 13)
void NORETURN abort(void);
/** @brief Kernel's memory allocator function.
*
* This will just call mem_allocation with
* the flags MAP_KERNEL_SPACE and MAP_HEAP.
*
* @return Pointer to the new memory range
*/
void* kmalloc(size_t);
/** @brief Kernel's more general memory allocator function.
*
* This function lets you choose flags for the newly allocated memory.
*
* @param sz Desired size of the new memory
* @param flags Flags to specify
*
* @return Pointer to the new memory range
*/
void* mem_allocation(size_t sz, uint32_t flags);
/** @brief Free memory
*
* The kernel malloc doesn't track how
* much memory was allocated for which pointer,
* so you have to specify how much memory shall be freed.
*/
void kfree(void*, size_t);
/** @brief Create a new stack for a new task
*
* @return start address of the new stack
*/
void* create_stack(void);
/** @brief Delete stack of a finished task
*
* @param addr Pointer to the stack
* @return 0 on success
*/
int destroy_stack(task_t* addr);
/** @brief String to long
*
* This one is documented in newlib library.
*
* @return Long value of the parsed numerical string
*/
long strtol(const char* str, char** endptr, int base);
unsigned long strtoul(const char* nptr, char** endptr, int base);
/** @brief ASCII to integer
*
* Convenience function using strtol().
*
* @return Integer value of the parsed numerical string
*/
static inline int atoi(const char *str)
{
return (int)strtol(str, (char **)NULL, 10);
}
#ifdef __cplusplus
}
#endif
#endif