metalsvm/include/metalsvm/stdlib.h

117 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/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 General page allocator function
*
* This function allocates and maps whole pages.
* To avoid fragmentation you should use kmalloc() and kfree()!
*
* @param sz Desired size of the new memory
* @param flags Flags to for map_region(), vma_add()
*
* @return Pointer to the new memory range
*/
void* palloc(size_t sz, uint32_t flags);
/** @brief Free general kernel memory
*
* The pmalloc() doesn't track how much memory was allocated for which pointer,
* so you have to specify how much memory shall be freed.
*
* @param sz The size which should freed
*/
void pfree(void* addr, size_t sz);
/** @brief The memory allocator function
*
* This allocator uses a buddy system to manage free memory.
*
* @return Pointer to the new memory range
*/
void* kmalloc(size_t sz);
/** @brief The memory free function
*
* Releases memory allocated by malloc()
*
* @param addr The address to the memory block allocated by malloc()
*/
void kfree(void* 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