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