The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/libsa/malloc_unused

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*********************************************************************
    2 * free_all()
    3 *
    4 * Empties all memory regions so that their entire buffer space is
    5 * considered unused. This allows the client to restart without
    6 * having to reallocate memory for the allocator regions, which helps
    7 * performance when this package gets used serially.
    8 *********************************************************************/
    9 __private_extern__
   10 void free_all(void) {
   11     malloc_region * cur_region;
   12 
   13     queue_iterate(&malloc_region_list, cur_region, malloc_region *, links) {
   14 
   15         queue_init(&cur_region->block_list);
   16         cur_region->free_size = cur_region->region_size - sizeof(malloc_region);
   17         cur_region->free_address = &cur_region->buffer;
   18 
   19     }
   20 
   21     queue_init(&sorted_free_block_list);
   22 
   23 #ifdef CLIENT_DEBUG
   24     current_block_total = 0;
   25 #endif /* CLIENT_DEBUG */
   26 
   27     return;
   28 
   29 } /* free_all() */
   30 
   31 
   32 /*********************************************************************
   33 * malloc_size()
   34 *
   35 *********************************************************************/
   36 __private_extern__
   37 size_t malloc_size(void * address) {
   38     malloc_region * found_region = NULL;
   39     malloc_block  * found_block = NULL;
   40 
   41     malloc_find_block(address, &found_block, &found_region);
   42 
   43 
   44    /* If we couldn't find the requested block, 
   45     * the caller is in error so return 0.
   46     */
   47     if (found_block == NULL) {
   48         return 0;
   49         // FIXME: panic?
   50     }
   51 
   52     return (found_block->block_size - sizeof(malloc_block));
   53 
   54 } /* malloc_size() */
   55 
   56 
   57 /*********************************************************************
   58 * malloc_is_valid()
   59 *
   60 *********************************************************************/
   61 __private_extern__
   62 int malloc_is_valid(void * address){
   63     malloc_region * found_region = NULL;
   64     malloc_block  * found_block = NULL;
   65 
   66     malloc_find_block(address, &found_block, &found_region);
   67 
   68     if (found_block != NULL) {
   69         return 1;
   70     } else {
   71         return 0;
   72     }
   73 
   74 } /* malloc_is_valid() */
   75 
   76 

Cache object: e2ce60582c8c75b1bc059a8d03f6ff66


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.