1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*!
8  @addtogroup cc_pal_mem
9  @{
10  */
11 
12 /*!
13  @file
14  @brief This file contains functions for memory operations.
15 
16  The functions are generally implemented as wrappers to different
17  operating-system calls.
18 
19  \note None of the described functions validate the input parameters, so that
20  the behavior of the APIs in case of an illegal parameter is dependent on the
21  behavior of the operating system.
22  */
23 
24 
25 
26 #ifndef _CC_PAL_MEM_H
27 #define _CC_PAL_MEM_H
28 
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 #include "cc_pal_types.h"
36 #include "cc_pal_mem_plat.h"
37 #include "cc_pal_malloc_plat.h"
38 #include <stdlib.h>
39 #include <string.h>
40 
41     /*----------------------------
42       PUBLIC FUNCTIONS
43 -----------------------------------*/
44 
45     /**** ----- Memory Operations APIs ----- ****/
46 
47 /*!
48   @brief This function compares between two given buffers, according to the
49   given size.
50 
51   @return The return values are according to operating-system return values.
52  */
53 #define CC_PalMemCmp(aTarget, aSource, aSize) CC_PalMemCmpPlat(aTarget, aSource, aSize)
54 
55 /*!
56   @brief This function copies \p aSize bytes from the source buffer to the
57   destination buffer.
58 
59   @return void.
60  */
61 #define CC_PalMemCopy(aDestination, aSource, aSize) CC_PalMemCopyPlat(aDestination, aSource, aSize)
62 
63 /*!
64   @brief This function moves \p aSize bytes from the source buffer to the
65   destination buffer.
66 
67   This function supports overlapped buffers.
68 
69   @return void.
70  */
71 #define CC_PalMemMove(aDestination, aSource, aSize) CC_PalMemMovePlat(aDestination, aSource, aSize)
72 
73 
74 /*!
75   @brief This function sets \p aSize bytes of \p aChar in the given buffer.
76 
77   @return void.
78  */
79 #define CC_PalMemSet(aTarget, aChar, aSize) CC_PalMemSetPlat(aTarget, aChar, aSize)
80 
81 
82 /*!
83   @brief This function sets \p aSize bytes in the given buffer to zeroes.
84 
85   @return void.
86  */
87 #define CC_PalMemSetZero(aTarget, aSize) CC_PalMemSetZeroPlat(aTarget, aSize)
88 
89 
90 /*!
91   @brief This function allocates a memory buffer according to \p aSize.
92 
93   @return A pointer to the allocated buffer on success.
94   @return NULL on failure.
95  */
96 #define CC_PalMemMalloc(aSize) CC_PalMemMallocPlat(aSize)
97 
98 /*!
99   @brief This function reallocates a memory buffer according to \p aNewSize.
100          The content of the old buffer is moved to the new location.
101 
102   @return A pointer to the newly-allocated buffer on success.
103   @return NULL on failure.
104  */
105 #define CC_PalMemRealloc(aBuffer, aNewSize) CC_PalMemReallocPlat(aBuffer, aNewSize)
106 
107 /*!
108   @brief This function frees a previously-allocated buffer.
109 
110   @return void.
111  */
112 #define CC_PalMemFree(aBuffer) CC_PalMemFreePlat(aBuffer)
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 /*!
119  @}
120  */
121 
122 #endif
123 
124