From a62b7fe39f44ce7619c30b9b78398059518f7bf5 Mon Sep 17 00:00:00 2001 From: dongsenhao Date: Tue, 27 Jun 2023 10:53:29 +0800 Subject: [PATCH] Alarm cleaning Signed-off-by: dongsenhao --- libmeminfo/src/meminfo.cpp | 2 +- libpurgeablemem/c/src/purgeable_mem_c.c | 8 ++++---- libpurgeablemem/c/src/purgeable_memory.c | 2 +- libpurgeablemem/common/src/ux_page_table_c.c | 7 +++++-- libpurgeablemem/cpp/include/purgeable_mem.h | 1 - libpurgeablemem/cpp/src/purgeable_ashmem.cpp | 10 +++++----- libpurgeablemem/cpp/src/purgeable_mem.cpp | 8 ++++---- libpurgeablemem/cpp/src/purgeable_mem_base.cpp | 6 +++--- libpurgeablemem/interfaces/kits/c/purgeable_memory.h | 2 +- purgeable_builder/src/purgeable_pixelmap_builder.cpp | 5 ++++- 10 files changed, 28 insertions(+), 23 deletions(-) diff --git a/libmeminfo/src/meminfo.cpp b/libmeminfo/src/meminfo.cpp index d790514..6f85c97 100644 --- a/libmeminfo/src/meminfo.cpp +++ b/libmeminfo/src/meminfo.cpp @@ -64,7 +64,7 @@ uint64_t GetRssByPid(const int pid) std::istringstream isStatm(statm); isStatm >> vss >> rss; // pages - size = atoi(rss.c_str()) * PAGE_TO_KB; + size = static_cast(atoi(rss.c_str())) * PAGE_TO_KB; return size; } diff --git a/libpurgeablemem/c/src/purgeable_mem_c.c b/libpurgeablemem/c/src/purgeable_mem_c.c index feb50a0..942b265 100644 --- a/libpurgeablemem/c/src/purgeable_mem_c.c +++ b/libpurgeablemem/c/src/purgeable_mem_c.c @@ -47,7 +47,7 @@ static inline void LogPurgMemInfo_(struct PurgMem *obj) (unsigned long)(obj->builder), (unsigned long)(obj->uxPageTable)); } -static inline size_t RoundUp_(size_t val, size_t align) +static inline size_t RoundUp(size_t val, size_t align) { if (align == 0) { return val; @@ -67,7 +67,7 @@ static struct PurgMem *PurgMemCreate_(size_t len, struct PurgMemBuilder *builder PM_HILOG_ERROR_C(LOG_CORE, "%{public}s: malloc struct PurgMem fail", __func__); return NULL; } - size_t size = RoundUp_(len, PAGE_SIZE); + size_t size = RoundUp(len, PAGE_SIZE); int type = MAP_ANONYMOUS; type |= (UxpteIsEnabled() ? MAP_PURGEABLE : MAP_PRIVATE); pugObj->dataPtr = mmap(NULL, size, PROT_READ | PROT_WRITE, type, -1, 0); @@ -165,7 +165,7 @@ bool PurgMemDestroy(struct PurgMem *purgObj) } /* unmap purgeable mem region */ if (purgObj->dataPtr) { - size_t size = RoundUp_(purgObj->dataSizeInput, PAGE_SIZE); + size_t size = RoundUp(purgObj->dataSizeInput, PAGE_SIZE); if (munmap(purgObj->dataPtr, size) != 0) { PM_HILOG_ERROR_C(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); err = PM_UNMAP_PURG_FAIL; @@ -215,7 +215,7 @@ static inline bool PurgMemBuildData_(struct PurgMem *purgObj) { bool succ = false; /* clear content before rebuild */ - if (memset_s(purgObj->dataPtr, RoundUp_(purgObj->dataSizeInput, PAGE_SIZE), 0, purgObj->dataSizeInput) != EOK) { + if (memset_s(purgObj->dataPtr, RoundUp(purgObj->dataSizeInput, PAGE_SIZE), 0, purgObj->dataSizeInput) != EOK) { PM_HILOG_ERROR_C(LOG_CORE, "%{public}s, clear content fail", __func__); return succ; } diff --git a/libpurgeablemem/c/src/purgeable_memory.c b/libpurgeablemem/c/src/purgeable_memory.c index 4290dca..b0cf21b 100644 --- a/libpurgeablemem/c/src/purgeable_memory.c +++ b/libpurgeablemem/c/src/purgeable_memory.c @@ -68,7 +68,7 @@ size_t OH_PurgeableMemory_ContentSize(OH_PurgeableMemory *purgObj) } bool OH_PurgeableMemory_AppendModify(OH_PurgeableMemory *purgObj, - OH_PurgeableMemory_ModifyFunc func, void *funcPara) + OH_PurgeableMemory_ModifyFunc func, void *funcPara) { return PurgMemAppendModify((PurgMem *)purgObj, func, funcPara); } \ No newline at end of file diff --git a/libpurgeablemem/common/src/ux_page_table_c.c b/libpurgeablemem/common/src/ux_page_table_c.c index c6aa08f..de14c41 100644 --- a/libpurgeablemem/common/src/ux_page_table_c.c +++ b/libpurgeablemem/common/src/ux_page_table_c.c @@ -90,7 +90,7 @@ static inline size_t GetUxPageSize_(uint64_t dataAddr, size_t dataSize) return (UxptePageNo_(dataAddr + dataSize - 1) - UxptePageNo_(dataAddr) + 1) * PAGE_SIZE; } -static inline uint64_t RoundUp_(uint64_t val, size_t align) +static inline uint64_t RoundUp(uint64_t val, size_t align) { if (align == 0) { return val; @@ -325,8 +325,11 @@ static bool IsPresentAt_(UxPageTableStruct *upt, uint64_t addr) static PMState UxpteOps_(UxPageTableStruct *upt, uint64_t addr, size_t len, enum UxpteOp op) { + if (upt == NULL) { + return PM_BUILDER_NULL; + } uint64_t start = RoundDown_(addr, PAGE_SIZE); - uint64_t end = RoundUp_(addr + len, PAGE_SIZE); + uint64_t end = RoundUp(addr + len, PAGE_SIZE); if (start < upt->dataAddr || end > (upt->dataAddr + upt->dataSize)) { HILOG_ERROR(LOG_CORE, "%{public}s: addr(0x%{public}llx) start(0x%{public}llx) < dataAddr(0x%{public}llx)" " || end(0x%{public}llx) > dataAddr+dataSize(0x%{public}llx) out of bound", diff --git a/libpurgeablemem/cpp/include/purgeable_mem.h b/libpurgeablemem/cpp/include/purgeable_mem.h index 534edf0..090f6f2 100644 --- a/libpurgeablemem/cpp/include/purgeable_mem.h +++ b/libpurgeablemem/cpp/include/purgeable_mem.h @@ -32,7 +32,6 @@ public: ~PurgeableMem(); void ResizeData(size_t newSize) override; - protected: std::unique_ptr pageTable_ = nullptr; bool Pin() override; diff --git a/libpurgeablemem/cpp/src/purgeable_ashmem.cpp b/libpurgeablemem/cpp/src/purgeable_ashmem.cpp index 4e24983..42c4c48 100644 --- a/libpurgeablemem/cpp/src/purgeable_ashmem.cpp +++ b/libpurgeablemem/cpp/src/purgeable_ashmem.cpp @@ -29,7 +29,7 @@ namespace PurgeableMem { #endif #define LOG_TAG "PurgeableMem" -static inline size_t RoundUp_(size_t val, size_t align) +static inline size_t RoundUp(size_t val, size_t align) { if (align == 0) { return val; @@ -73,7 +73,7 @@ PurgeableAshMem::~PurgeableAshMem() { PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str()); if (!isChange_ && dataPtr_) { - if (munmap(dataPtr_, RoundUp_(dataSizeInput_, PAGE_SIZE)) != 0) { + if (munmap(dataPtr_, RoundUp(dataSizeInput_, PAGE_SIZE)) != 0) { PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); } else { if (UxpteIsEnabled() && !IsPurged()) { @@ -107,7 +107,7 @@ bool PurgeableAshMem::CreatePurgeableData_() if (dataSizeInput_ == 0) { return false; } - size_t size = RoundUp_(dataSizeInput_, PAGE_SIZE); + size_t size = RoundUp(dataSizeInput_, PAGE_SIZE); int fd = AshmemCreate("PurgeableAshmem", size); if (fd < 0) { return false; @@ -187,7 +187,7 @@ void PurgeableAshMem::ResizeData(size_t newSize) return; } if (dataPtr_) { - if (munmap(dataPtr_, RoundUp_(dataSizeInput_, PAGE_SIZE)) != 0) { + if (munmap(dataPtr_, RoundUp(dataSizeInput_, PAGE_SIZE)) != 0) { PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); } else { dataPtr_ = nullptr; @@ -203,7 +203,7 @@ void PurgeableAshMem::ResizeData(size_t newSize) bool PurgeableAshMem::ChangeAshmemData(size_t size, int fd, void *data) { if (dataPtr_) { - if (munmap(dataPtr_, RoundUp_(dataSizeInput_, PAGE_SIZE)) != 0) { + if (munmap(dataPtr_, RoundUp(dataSizeInput_, PAGE_SIZE)) != 0) { PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); } else { dataPtr_ = nullptr; diff --git a/libpurgeablemem/cpp/src/purgeable_mem.cpp b/libpurgeablemem/cpp/src/purgeable_mem.cpp index 896fd9f..55cccf5 100644 --- a/libpurgeablemem/cpp/src/purgeable_mem.cpp +++ b/libpurgeablemem/cpp/src/purgeable_mem.cpp @@ -29,7 +29,7 @@ namespace PurgeableMem { #endif #define LOG_TAG "PurgeableMem" -static inline size_t RoundUp_(size_t val, size_t align) +static inline size_t RoundUp(size_t val, size_t align) { if (align == 0) { return val; @@ -59,7 +59,7 @@ PurgeableMem::~PurgeableMem() { PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str()); if (dataPtr_) { - if (munmap(dataPtr_, RoundUp_(dataSizeInput_, PAGE_SIZE)) != 0) { + if (munmap(dataPtr_, RoundUp(dataSizeInput_, PAGE_SIZE)) != 0) { PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); } else { if (UxpteIsEnabled() && !IsPurged()) { @@ -82,7 +82,7 @@ bool PurgeableMem::CreatePurgeableData_() { PM_HILOG_DEBUG(LOG_CORE, "%{public}s", __func__); pageTable_ = nullptr; - size_t size = RoundUp_(dataSizeInput_, PAGE_SIZE); + size_t size = RoundUp(dataSizeInput_, PAGE_SIZE); unsigned int utype = MAP_ANONYMOUS; utype |= (UxpteIsEnabled() ? MAP_PURGEABLE : MAP_PRIVATE); int type = static_cast(utype); @@ -126,7 +126,7 @@ void PurgeableMem::ResizeData(size_t newSize) return; } if (dataPtr_) { - if (munmap(dataPtr_, RoundUp_(dataSizeInput_, PAGE_SIZE)) != 0) { + if (munmap(dataPtr_, RoundUp(dataSizeInput_, PAGE_SIZE)) != 0) { PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); } else { dataPtr_ = nullptr; diff --git a/libpurgeablemem/cpp/src/purgeable_mem_base.cpp b/libpurgeablemem/cpp/src/purgeable_mem_base.cpp index cb070c9..65fef8e 100644 --- a/libpurgeablemem/cpp/src/purgeable_mem_base.cpp +++ b/libpurgeablemem/cpp/src/purgeable_mem_base.cpp @@ -29,7 +29,7 @@ namespace PurgeableMem { #endif #define LOG_TAG "PurgeableMem" -static inline size_t RoundUp_(size_t val, size_t align) +static inline size_t RoundUp(size_t val, size_t align) { if (align == 0) { return val; @@ -183,7 +183,7 @@ bool PurgeableMemBase::ModifyContentByBuilder(std::unique_ptrAppendBuilder(std::move(modifier)); + builder_->AppendBuilder(std::move(modifier)); } else { builder_ = std::move(modifier); } @@ -221,7 +221,7 @@ bool PurgeableMemBase::BuildContent_() { bool succ = false; /* clear content before rebuild */ - if (memset_s(dataPtr_, RoundUp_(dataSizeInput_, PAGE_SIZE), 0, dataSizeInput_) != EOK) { + if (memset_s(dataPtr_, RoundUp(dataSizeInput_, PAGE_SIZE), 0, dataSizeInput_) != EOK) { PM_HILOG_ERROR(LOG_CORE, "%{public}s, clear content fail", __func__); return succ; } diff --git a/libpurgeablemem/interfaces/kits/c/purgeable_memory.h b/libpurgeablemem/interfaces/kits/c/purgeable_memory.h index 4125045..a228044 100644 --- a/libpurgeablemem/interfaces/kits/c/purgeable_memory.h +++ b/libpurgeablemem/interfaces/kits/c/purgeable_memory.h @@ -198,7 +198,7 @@ size_t OH_PurgeableMemory_ContentSize(OH_PurgeableMemory *purgObj); * @version 1.0 */ bool OH_PurgeableMemory_AppendModify(OH_PurgeableMemory *purgObj, - OH_PurgeableMemory_ModifyFunc func, void *funcPara); + OH_PurgeableMemory_ModifyFunc func, void *funcPara); #ifdef __cplusplus } diff --git a/purgeable_builder/src/purgeable_pixelmap_builder.cpp b/purgeable_builder/src/purgeable_pixelmap_builder.cpp index 0230f1f..11dad66 100644 --- a/purgeable_builder/src/purgeable_pixelmap_builder.cpp +++ b/purgeable_builder/src/purgeable_pixelmap_builder.cpp @@ -59,7 +59,10 @@ bool PurgeablePixelMapBuilder::Build(void *data, size_t size) StartTrace(HITRACE_TAG_ZIMAGE, ("OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::CopyData " + std::to_string(size))); - memcpy_s((char *)pixelMap_->GetPixels(), size, (char *)pixelMap->GetPixels(), size); + if (memcpy_s((char *)pixelMap_->GetPixels(), size, (char *)pixelMap->GetPixels(), size)) { + FinishTrace(HITRACE_TAG_ZIMAGE); + return false; + } DoRebuildSuccessCallback();