From df2a1c74b8a7123c138ee09f4db51ef6d9d37f42 Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Mon, 24 Feb 2025 09:50:42 +0800 Subject: [PATCH] add AshmemGetSizeRaw to support larger size Issue: https://gitee.com/openharmony/commonlibrary_c_utils/issues/IBOA36?from=project-issue Signed-off-by: chenkeyu --- base/include/ashmem.h | 8 ++++++++ base/src/ashmem.cpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/base/include/ashmem.h b/base/include/ashmem.h index 78d9304..910212c 100644 --- a/base/include/ashmem.h +++ b/base/include/ashmem.h @@ -69,6 +69,14 @@ int AshmemSetProt(int fd, int prot); */ int AshmemGetSize(int fd); +/** + * @brief Obtains the size of a specific Ashmem region in the kernel. + * + * @param fd Indicates the file descriptor of an Ashmem region. + * @return Returns the size of the Ashmem region. + */ +long AshmemGetSizeRaw(int fd); + /** * @brief Provides the Ashmem class implemented in c_utils to * operate the Anonymous Shared Memory (Ashmem). diff --git a/base/src/ashmem.cpp b/base/src/ashmem.cpp index c65ee8a..5feea32 100644 --- a/base/src/ashmem.cpp +++ b/base/src/ashmem.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +138,11 @@ int AshmemGetSize(int fd) return TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL)); } +long AshmemGetSizeRaw(int fd) +{ + return TEMP_FAILURE_RETRY(syscall(SYS_ioctl, fd, ASHMEM_GET_SIZE, NULL)); +} + Ashmem::Ashmem(int fd, int32_t size) : memoryFd_(fd), memorySize_(size), flag_(0), startAddr_(nullptr) { } -- Gitee