M4PSW_MemoryInterface.c revision 32ed3f4dad00f8a65f7e6b38402c70d5341c57eb
1/* 2 * Copyright (C) 2004-2011 NXP Software 3 * Copyright (C) 2011 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18************************************************************************* 19 * @file M4PSW_MemoryInterface.c 20 * @brief Memory Interface 21 * @note Implementation of the osal memory functions 22 ************************************************************************* 23*/ 24 25#include <stdlib.h> 26#include <memory.h> 27 28#include <time.h> 29#include "M4OSA_Memory.h" 30#ifndef M4VPS_ADVANCED_MEMORY_MANAGER 31/** 32 ************************************************************************ 33 * @fn M4OSA_MemAddr32 M4OSA_malloc(M4OSA_UInt32 size, 34 * M4OSA_CoreID coreID, 35 * M4OSA_Char* string) 36 * @brief this function allocates a memory block (at least 32 bits aligned) 37 * @note 38 * @param size (IN): size of allocated block in bytes 39 * @param coreID (IN): identification of the caller component 40 * @param string (IN): description of the allocated block (null terminated) 41 * @return address of the allocated block, M4OSA_NULL if no memory available 42 ************************************************************************ 43*/ 44 45M4OSA_MemAddr32 M4OSA_malloc(M4OSA_UInt32 size, 46 M4OSA_CoreID coreID, 47 M4OSA_Char* string) 48{ 49 M4OSA_MemAddr32 Address = M4OSA_NULL; 50 51 /** 52 * If size is 0, malloc on WIN OS allocates a zero-length item in 53 * the heap and returns a valid pointer to that item. 54 * On other platforms, malloc could returns an invalid pointer 55 * So, DON'T allocate memory of 0 byte */ 56 if (size == 0) 57 { 58 return Address; 59 } 60 61 if (size%4 != 0) 62 { 63 size = size + 4 - (size%4); 64 } 65 66 Address = (M4OSA_MemAddr32) malloc(size); 67 68 return Address; 69} 70 71 72/** 73 ************************************************************************ 74 * @fn M4OSA_Void M4OSA_free(M4OSA_MemAddr32 address) 75 * @brief this function free the provided memory block 76 * @note As in stlib.h, this function does nothing if address is NULL. 77 * @param address (IN): address of the block to free 78 * @return none 79 ************************************************************************ 80*/ 81 82M4OSA_Void M4OSA_free (M4OSA_MemAddr32 address) 83{ 84 free(address); 85} 86 87#endif 88 89