1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 /** 10 * @addtogroup OSAL 11 * @{ 12 * 13 * @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module. 14 * 15 * The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally, 16 * including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time, 17 * atomic, firmware, and I/O operation modules. 18 * 19 * @since 1.0 20 * @version 1.0 21 */ 22 23 /** 24 * @file osal_mem.h 25 * 26 * @brief Declares the driver memory request and release interfaces. 27 * 28 * @since 1.0 29 * @version 1.0 30 */ 31 #ifndef OSAL_MEM_H 32 #define OSAL_MEM_H 33 34 #include "hdf_base.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif /* __cplusplus */ 39 40 /** 41 * @brief Allocates memory of a specified size. 42 * 43 * @param size Indicates the size of memory to allocate. 44 * 45 * @return Returns the pointer to the allocated memory if the operation is successful; returns <b>NULL</b> otherwise. 46 * @since 1.0 47 * @version 1.0 48 */ 49 void *OsalMemAlloc(size_t size); 50 51 /** 52 * @brief Allocates memory of a specified size, and clears the allocated memory. 53 * 54 * @param size Indicates the size of memory to allocate. 55 * 56 * @return Returns the pointer to the allocated memory if the operation is successful; returns <b>NULL</b> otherwise. 57 * @since 1.0 58 * @version 1.0 59 */ 60 void *OsalMemCalloc(size_t size); 61 62 /** 63 * @brief Allocates memory of a specified size, and aligns the memory address on a given boundary. 64 * 65 * @param alignment Indicates the memory boundary alignment. The value must be a power of 2. 66 * @param size Indicates the size of memory to allocate. 67 * 68 * @return Returns the pointer to the allocated memory if the operation is successful; returns <b>NULL</b> otherwise. 69 * @since 1.0 70 * @version 1.0 71 */ 72 void *OsalMemAllocAlign(size_t alignment, size_t size); 73 74 /** 75 * @brief Releases memory. 76 * 77 * @param mem Indicates the pointer to the memory to release. 78 * @since 1.0 79 * @version 1.0 80 */ 81 void OsalMemFree(void *mem); 82 83 #ifdef __cplusplus 84 } 85 #endif /* __cplusplus */ 86 87 #endif /* OSAL_MEM_H */ 88 /** @} */ 89