source: trunk/kernel/mm/khm.h @ 634

Last change on this file since 634 was 619, checked in by alain, 6 years ago

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


File size: 4.2 KB
Line 
1/*
2 * khm.h - Kernel Heap Manager definition.
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Alain Greiner (2016,2017,2018,2019)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _HEAP_MANAGER_H_
26#define _HEAP_MANAGER_H_
27
28#include <kernel_config.h>
29#include <hal_kernel_types.h>
30#include <busylock.h>
31
32/*******************************************************************************************
33 * This structure defines a Kernel Heap Manager (KHM) in a given cluster.
34 * It is used to allocate memory objects, that too large, or not enough replicated
35 * to use a dedicated KCM allocator.
36 ******************************************************************************************/
37
38typedef struct khm_s
39{
40        busylock_t lock;           /*! lock protecting KHM allocator                          */
41        intptr_t   base;           /*! heap base address                                      */
42        uint32_t   size;           /*! heap size (bytes)                                      */
43        intptr_t   next;           /*! next free block address                                */
44}
45khm_t;
46
47/*******************************************************************************************
48 * This structure defines an allocated block descriptor for the KHM.
49 * This block descriptor is stored at the beginning of the allocated block.
50 * The returned pointer is the allocated memory block base + block descriptor size.
51 ******************************************************************************************/
52
53typedef struct khm_block_s
54{
55        uint32_t   busy;           /*! free block if zero                                     */
56        uint32_t   size;           /*! block size                                                   */
57}
58khm_block_t;
59
60
61/*******************************************************************************************
62 * This function initializes a KHM heap manager in a given cluster.
63 * It is used to allocate variable size memory objects, that are not
64 * enough replicated to justify a dedicated KCM allocator.
65 *******************************************************************************************
66 * @ khm        : pointer on KHM to initialize.
67 * @ heap_base  : heap base address.
68 * @ heap_size  : heap size in bytes.
69 ******************************************************************************************/
70void khm_init( khm_t    * khm );
71
72/*******************************************************************************************
73 * This function allocates a memory block from the local KHM.
74 * The actual size of the allocated block is the requested size, plus the block descriptor
75 * size, rounded to a cache line size.
76 *******************************************************************************************
77 * @ khm    : pointer on local kernel heap manager.
78 * @ size   : number of requested bytes (must be smaller than 2G bytes).
79 * @ returns a pointer on memory block if success / returns NULL if failure.
80 ******************************************************************************************/
81void * khm_alloc( khm_t    * khm,
82                  uint32_t   size );
83
84/*******************************************************************************************
85 * This function releases a previoully allocated memory block to the local KHM.
86 *******************************************************************************************
87 * @ ptr    : pointer on released block.
88 ******************************************************************************************/
89void  khm_free( void * ptr );
90
91#endif  /* _HEAP_MANAGER_H_ */
Note: See TracBrowser for help on using the repository browser.