text: /*
   * ESPRESSIF MIT License
   *
   * Copyright (c) 2017 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
   *
   * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
   * it is free of charge, to any person obtaining a copy of this software and associated
   * documentation files (the "Software"), to deal in the Software without restriction, including
   * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
   * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
   * to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in all copies or
   * substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
   * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
   * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   *
   */
  
  #include <string.h>
  #include <stdio.h>
  #include <sys/types.h>
  
  #include <k_api.h>
  #include "aos/kernel.h"
  
  void* malloc(size_t size)
  {
      void *mem;
  
  #if (RHINO_CONFIG_MM_DEBUG > 0u)
      mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
      aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
  #else
      mem = aos_malloc(size);
  #endif
  
      return mem;
  }
  
  void* calloc(size_t count, size_t size)
  {
      void *mem;
  
  #if (RHINO_CONFIG_MM_DEBUG > 0u)
      mem = aos_malloc((count * size) | AOS_UNSIGNED_INT_MSB);
      aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
  #else
      mem = aos_malloc(count * size);
  #endif
  
      if (mem) {
          bzero(mem, count * size);
      }
  
      return mem;
  }
  
  void free(void* ptr)
  {
      aos_free(ptr);
  }
  
  void* realloc(void* ptr, size_t size)
  {
      void *mem;
  
  #if (RHINO_CONFIG_MM_DEBUG > 0u)
      mem = aos_realloc(ptr, size | AOS_UNSIGNED_INT_MSB);
      aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
  #else
      mem = aos_realloc(ptr, size);
  #endif
  
      return mem;
  }
  
  void *zalloc(size_t size)
  {
      void *mem;
  
  #if (RHINO_CONFIG_MM_DEBUG > 0u)
      mem = aos_zalloc(size | AOS_UNSIGNED_INT_MSB);
      aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
  #else
      mem = aos_zalloc(size);
  #endif
  
      return mem;
  }
  
  