/*
 * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Created in Samsung Ukraine R&D Center (SRK) under a contract between
 * LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
 * and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 *
 * Created on: Dec 15, 2017
 * Author: Kostiantyn Volobuiev <k.volobuyev@samsung.com>
 * Brief: Module that responds for memory operations.
 */

#include "TzwMemory.h"

#if defined(TZ_MODEL_QCOM)
    #include <qsee_heap.h>
#elif defined(TZ_MODEL_BLOWFISH)
    #include <tee_internal_api.h>
#endif

void* tzwMalloc(const size_t n) {
    void* p = NULL;
#if defined(TZ_MODEL_BLOWFISH)
    p = TEE_Malloc(n, 0);
#elif defined(TZ_MODEL_QCOM)
    p = qsee_zalloc(n);
#endif
    return p;
}

void* tzwRealloc(void* ptr, uint32_t size) {
#if defined(TZ_MODEL_BLOWFISH)
    return TEE_Realloc(ptr, size);
#elif defined(TZ_MODEL_QCOM)
    return qsee_realloc(ptr, size);
#endif
}

void tzwFree(void* buf) {
    if (NULL != buf) {
#if defined(TZ_MODEL_BLOWFISH)
        TEE_Free(buf);
#elif defined(TZ_MODEL_QCOM)
        qsee_free(buf);
#endif
    }
}
