common.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef MM_COMMON_H_
00036 #define MM_COMMON_H_
00037 
00038 #include <sys/types.h>
00039 #include <bool.h>
00040 #include <adt/list.h>
00041 
00042 #define MAX_ALLOC  (16 * 1024 * 1024)
00043 
00044 #define AREA_GRANULARITY  16
00045 #define AREA_SIZE         (4 * PAGE_SIZE)
00046 
00047 typedef struct {
00048         /* Address of the start of the block */
00049         void *addr;
00050         
00051         /* Size of the memory block */
00052         size_t size;
00053         
00054         /* Link to other blocks */
00055         link_t link;
00056 } mem_block_t;
00057 
00058 typedef struct {
00059         /* Address of the start of the area */
00060         void *addr;
00061         
00062         /* Size of the memory area */
00063         size_t size;
00064         /* Link to other areas */
00065         link_t link;
00066 } mem_area_t;
00067 
00068 /*
00069  * Subphase control structures: subphase termination conditions,
00070  * probabilities of individual actions, subphase control structure.
00071  */
00072 
00073 typedef struct {
00074         unsigned int max_cycles;
00075         unsigned int no_memory;
00076         unsigned int no_allocated;
00077 } sp_term_cond_t;
00078 
00079 typedef struct {
00080         unsigned int alloc;
00081         unsigned int free;
00082 } sp_action_prob_t;
00083 
00084 typedef struct {
00085         const char *name;
00086         sp_term_cond_t cond;
00087         sp_action_prob_t prob;
00088 } subphase_t;
00089 
00090 /*
00091  * Phase control structures: The minimum and maximum block size that
00092  * can be allocated during the phase execution, phase control structure.
00093  */
00094 
00095 typedef struct {
00096         size_t min_block_size;
00097         size_t max_block_size;
00098 } ph_alloc_size_t;
00099 
00100 typedef struct {
00101         const char *name;
00102         ph_alloc_size_t alloc;
00103         subphase_t *subphases;
00104 } phase_t;
00105 
00106 extern bool error_flag;
00107 extern size_t mem_allocated;
00108 extern size_t mem_blocks_count;
00109 
00110 #define RETURN_IF_ERROR \
00111         do { \
00112                 if (error_flag) \
00113                         return; \
00114         } while (0)
00115 
00116 extern void init_mem(void);
00117 extern void done_mem(void);
00118 
00119 extern mem_block_t *alloc_block(size_t);
00120 extern void free_block(mem_block_t *);
00121 extern void fill_block(mem_block_t *);
00122 extern void check_block(mem_block_t *);
00123 extern mem_block_t *get_random_block(void);
00124 
00125 extern mem_area_t *map_area(size_t);
00126 extern void fill_area(mem_area_t *);
00127 extern void unmap_area(mem_area_t *);
00128 
00129 #endif
00130 

Generated on Thu Jun 2 07:45:43 2011 for HelenOS/USB by  doxygen 1.4.7