<commit_before>/**
* @file
* Functions for managing kernel memory
*
* @date February 2012
* @author <NAME>
* @ingroup Mem
*/

/*
*  Copyright 2012 <NAME>
*
*  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.
*/

#ifndef MM_KMEMORY_H_
#define MM_KMEMORY_H_

#include "chaff.h"
#include "mm/physical.h"

/**
 * Maps a page to the given kernel virtual address
 *
 * The address supplied must be in the kernel virtual region (>= 0xF0000000).
 * You should almost always allocate the virtual address for this using @death.
 *
 * @note Implemented in pageMapping.c
 *
 * @param address address to map to
 * @param page page number to map to that address
 * @retval true the page was successfully mapped
 * @retval false the address given has already been mapped / is unmappable
 */
bool MemMapPage(void * address, MemPhysPage page);

/**<commit_msg>Added virtual allocator definitions to kmemory.h<commit_after>/**
* @file
* Functions for managing kernel memory
*
* @date February 2012
* @author <NAME>
* @ingroup Mem
*/

/*
*  Copyright 2012 <NAME>
*
*  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.
*/

#ifndef MM_KMEMORY_H_
#define MM_KMEMORY_H_

#include "chaff.h"
#include "mm/physical.h"

/**
 * Reserves virtual memory with the given size.
 * 
 * The memory reserved is placed in the high virtual memory zone and cannot be
 * used with physical devices. You generally use this function for large
 * allocations which do not need to be accessed by hardware.
 * 
 * The number of bytes given is rounded up to the next page offset
 * (only multiples of #PAGE_SIZE are allocated).
 * 
 * Memory is not actually allocated with this function, you must do it yourself
 * with MemMapPage() or MemVirtualAlloc().
 * 
 * @param bytes number of bytes to reserve
 * @return virtual memory address
 */
void * MemVirtualReserve(unsigned int bytes);

/**
 * Unreserves memory reserved by MemVirtualReserve()
 * 
 * Do not pass pointers from MemVirtualAlloc() to this function.
 * 
 * @param ptr pointer returned by MemVirtualReserve() to free
 */
void MemVirtualUnReserve(void * ptr);

/**
 * Allocates virtual memory with the given size.
 * 
 * This function is identical to MemVirtualReserve() except it allocates
 * physical memory for the allocated memory (you usually want this function).
 * 
 * @param bytes number of bytes to allcate
 * @return virtual memory address
 */
void * MemVirtualAlloc(unsigned int bytes);

/**
 * Frees memory allocated using MemVirtualAlloc()
 * 
 * Frees the physical memory and unreserves memory allocated using MemVirtualAlloc().
 * Do not pass pointers from MemVirtualReserve() to this function.
 * 
 * @param ptr pointer returned by MemVirtualAlloc() to free
 */
void MemVirtualFree(void * ptr);


/**
 * Maps a page to the given kernel virtual address
 *
 * The address supplied must be in the kernel virtual region (>= 0xF0000000).
 * You should almost always allocate the virtual address for this using MemVirtualReserve().
 *
 * @note Implemented in pageMapping.c
 *
 * @param address address to map to
 * @param page page number to map to that address
 * @retval true the page was successfully mapped
 * @retval false the address given has already been mapped / is unmappable
 */
bool MemMapPage(void * address, MemPhysPage page);

/**
{'fraction_non_alphanumeric': 0.07867010067899789, 'fraction_numerical': 0.009365488176071178, 'mean_word_length': 3.973224679860303, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5972987', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1139, 'n_words': 555}