LCOV - code coverage report
Current view: top level - core/src/mm - mm.h Hit Total Coverage
Test: ROOT-Sim develop Documentation Coverage Lines: 4 4 100.0 %
Date: 2021-03-02 11:24:52

          Line data    Source code
       1           1 : /**
       2             :  * @file mm/mm.h
       3             :  *
       4             :  * @brief Memory Manager main header
       5             :  *
       6             :  * Memory Manager main header
       7             :  *
       8             :  * SPDX-FileCopyrightText: 2008-2021 HPDCS Group <rootsim@googlegroups.com>
       9             :  * SPDX-License-Identifier: GPL-3.0-only
      10             :  */
      11             : #pragma once
      12             : 
      13             : #include <log/log.h>
      14             : 
      15             : #include <stddef.h>
      16             : #include <stdlib.h>
      17             : 
      18             : /**
      19             :  * @brief A version of the stdlib malloc() used internally
      20             :  * @param mem_size the size of the requested memory allocation
      21             :  * @return a pointer to the newly allocated memory area
      22             :  *
      23             :  * In case of memory allocation failure, a log message is taken and the
      24             :  * simulation is promptly aborted
      25             :  */
      26           1 : inline void *mm_alloc(size_t mem_size)
      27             : {
      28             :         void *ret = malloc(mem_size);
      29             : 
      30             :         if (__builtin_expect(mem_size && !ret, 0)) {
      31             :                 log_log(LOG_FATAL, "Out of memory!");
      32             :                 abort(); // TODO: this can be criticized as xmalloc() in gcc. We shall dump partial stats before.
      33             :         }
      34             :         return ret;
      35             : }
      36             : 
      37             : /**
      38             :  * @brief A version of the stdlib realloc() used internally
      39             :  * @param ptr a pointer to the memory area to reallocate
      40             :  * @param mem_size the new size of the memory allocation
      41             :  * @return a pointer to the newly allocated memory area
      42             :  *
      43             :  * In case of memory allocation failure, a log message is taken and the
      44             :  * simulation is promptly aborted
      45             :  */
      46           1 : inline void *mm_realloc(void *ptr, size_t mem_size)
      47             : {
      48             :         void *ret = realloc(ptr, mem_size);
      49             : 
      50             :         if(__builtin_expect(mem_size && !ret, 0)) {
      51             :                 log_log(LOG_FATAL, "Out of memory!");
      52             :                 abort(); // TODO: this can be criticized as xmalloc() in gcc. We shall dump partial stats before.
      53             :         }
      54             :         return ret;
      55             : }
      56             : 
      57             : /**
      58             :  * @brief A version of the stdlib free() used internally
      59             :  * @param ptr a pointer to the memory area to free
      60             :  */
      61           1 : inline void mm_free(void *ptr)
      62             : {
      63             :         free(ptr);
      64             : }

Generated by: LCOV version 1.14