Alarm cleaning

Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
This commit is contained in:
dongsenhao 2023-06-27 10:53:29 +08:00
parent 1a86ed63bb
commit a62b7fe39f
10 changed files with 28 additions and 23 deletions

View File

@ -64,7 +64,7 @@ uint64_t GetRssByPid(const int pid)
std::istringstream isStatm(statm); std::istringstream isStatm(statm);
isStatm >> vss >> rss; // pages isStatm >> vss >> rss; // pages
size = atoi(rss.c_str()) * PAGE_TO_KB; size = static_cast<int>(atoi(rss.c_str())) * PAGE_TO_KB;
return size; return size;
} }

View File

@ -47,7 +47,7 @@ static inline void LogPurgMemInfo_(struct PurgMem *obj)
(unsigned long)(obj->builder), (unsigned long)(obj->uxPageTable)); (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) { if (align == 0) {
return val; 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__); PM_HILOG_ERROR_C(LOG_CORE, "%{public}s: malloc struct PurgMem fail", __func__);
return NULL; return NULL;
} }
size_t size = RoundUp_(len, PAGE_SIZE); size_t size = RoundUp(len, PAGE_SIZE);
int type = MAP_ANONYMOUS; int type = MAP_ANONYMOUS;
type |= (UxpteIsEnabled() ? MAP_PURGEABLE : MAP_PRIVATE); type |= (UxpteIsEnabled() ? MAP_PURGEABLE : MAP_PRIVATE);
pugObj->dataPtr = mmap(NULL, size, PROT_READ | PROT_WRITE, type, -1, 0); 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 */ /* unmap purgeable mem region */
if (purgObj->dataPtr) { 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) { if (munmap(purgObj->dataPtr, size) != 0) {
PM_HILOG_ERROR_C(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__); PM_HILOG_ERROR_C(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__);
err = PM_UNMAP_PURG_FAIL; err = PM_UNMAP_PURG_FAIL;
@ -215,7 +215,7 @@ static inline bool PurgMemBuildData_(struct PurgMem *purgObj)
{ {
bool succ = false; bool succ = false;
/* clear content before rebuild */ /* 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__); PM_HILOG_ERROR_C(LOG_CORE, "%{public}s, clear content fail", __func__);
return succ; return succ;
} }

View File

@ -68,7 +68,7 @@ size_t OH_PurgeableMemory_ContentSize(OH_PurgeableMemory *purgObj)
} }
bool OH_PurgeableMemory_AppendModify(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); return PurgMemAppendModify((PurgMem *)purgObj, func, funcPara);
} }

View File

@ -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; 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) { if (align == 0) {
return val; 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) 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 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)) { 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)" 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", " || end(0x%{public}llx) > dataAddr+dataSize(0x%{public}llx) out of bound",

View File

@ -32,7 +32,6 @@ public:
~PurgeableMem(); ~PurgeableMem();
void ResizeData(size_t newSize) override; void ResizeData(size_t newSize) override;
protected: protected:
std::unique_ptr<UxPageTable> pageTable_ = nullptr; std::unique_ptr<UxPageTable> pageTable_ = nullptr;
bool Pin() override; bool Pin() override;

View File

@ -29,7 +29,7 @@ namespace PurgeableMem {
#endif #endif
#define LOG_TAG "PurgeableMem" #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) { if (align == 0) {
return val; return val;
@ -73,7 +73,7 @@ PurgeableAshMem::~PurgeableAshMem()
{ {
PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str()); PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str());
if (!isChange_ && dataPtr_) { 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__); PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__);
} else { } else {
if (UxpteIsEnabled() && !IsPurged()) { if (UxpteIsEnabled() && !IsPurged()) {
@ -107,7 +107,7 @@ bool PurgeableAshMem::CreatePurgeableData_()
if (dataSizeInput_ == 0) { if (dataSizeInput_ == 0) {
return false; return false;
} }
size_t size = RoundUp_(dataSizeInput_, PAGE_SIZE); size_t size = RoundUp(dataSizeInput_, PAGE_SIZE);
int fd = AshmemCreate("PurgeableAshmem", size); int fd = AshmemCreate("PurgeableAshmem", size);
if (fd < 0) { if (fd < 0) {
return false; return false;
@ -187,7 +187,7 @@ void PurgeableAshMem::ResizeData(size_t newSize)
return; return;
} }
if (dataPtr_) { 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__); PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__);
} else { } else {
dataPtr_ = nullptr; dataPtr_ = nullptr;
@ -203,7 +203,7 @@ void PurgeableAshMem::ResizeData(size_t newSize)
bool PurgeableAshMem::ChangeAshmemData(size_t size, int fd, void *data) bool PurgeableAshMem::ChangeAshmemData(size_t size, int fd, void *data)
{ {
if (dataPtr_) { 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__); PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__);
} else { } else {
dataPtr_ = nullptr; dataPtr_ = nullptr;

View File

@ -29,7 +29,7 @@ namespace PurgeableMem {
#endif #endif
#define LOG_TAG "PurgeableMem" #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) { if (align == 0) {
return val; return val;
@ -59,7 +59,7 @@ PurgeableMem::~PurgeableMem()
{ {
PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str()); PM_HILOG_DEBUG(LOG_CORE, "%{public}s %{public}s", __func__, ToString().c_str());
if (dataPtr_) { 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__); PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__);
} else { } else {
if (UxpteIsEnabled() && !IsPurged()) { if (UxpteIsEnabled() && !IsPurged()) {
@ -82,7 +82,7 @@ bool PurgeableMem::CreatePurgeableData_()
{ {
PM_HILOG_DEBUG(LOG_CORE, "%{public}s", __func__); PM_HILOG_DEBUG(LOG_CORE, "%{public}s", __func__);
pageTable_ = nullptr; pageTable_ = nullptr;
size_t size = RoundUp_(dataSizeInput_, PAGE_SIZE); size_t size = RoundUp(dataSizeInput_, PAGE_SIZE);
unsigned int utype = MAP_ANONYMOUS; unsigned int utype = MAP_ANONYMOUS;
utype |= (UxpteIsEnabled() ? MAP_PURGEABLE : MAP_PRIVATE); utype |= (UxpteIsEnabled() ? MAP_PURGEABLE : MAP_PRIVATE);
int type = static_cast<int>(utype); int type = static_cast<int>(utype);
@ -126,7 +126,7 @@ void PurgeableMem::ResizeData(size_t newSize)
return; return;
} }
if (dataPtr_) { 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__); PM_HILOG_ERROR(LOG_CORE, "%{public}s: munmap dataPtr fail", __func__);
} else { } else {
dataPtr_ = nullptr; dataPtr_ = nullptr;

View File

@ -29,7 +29,7 @@ namespace PurgeableMem {
#endif #endif
#define LOG_TAG "PurgeableMem" #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) { if (align == 0) {
return val; return val;
@ -183,7 +183,7 @@ bool PurgeableMemBase::ModifyContentByBuilder(std::unique_ptr<PurgeableMemBuilde
} }
/* log modify */ /* log modify */
if (builder_) { if (builder_) {
builder_->AppendBuilder(std::move(modifier)); builder_->AppendBuilder(std::move(modifier));
} else { } else {
builder_ = std::move(modifier); builder_ = std::move(modifier);
} }
@ -221,7 +221,7 @@ bool PurgeableMemBase::BuildContent_()
{ {
bool succ = false; bool succ = false;
/* clear content before rebuild */ /* 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__); PM_HILOG_ERROR(LOG_CORE, "%{public}s, clear content fail", __func__);
return succ; return succ;
} }

View File

@ -198,7 +198,7 @@ size_t OH_PurgeableMemory_ContentSize(OH_PurgeableMemory *purgObj);
* @version 1.0 * @version 1.0
*/ */
bool OH_PurgeableMemory_AppendModify(OH_PurgeableMemory *purgObj, bool OH_PurgeableMemory_AppendModify(OH_PurgeableMemory *purgObj,
OH_PurgeableMemory_ModifyFunc func, void *funcPara); OH_PurgeableMemory_ModifyFunc func, void *funcPara);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -59,7 +59,10 @@ bool PurgeablePixelMapBuilder::Build(void *data, size_t size)
StartTrace(HITRACE_TAG_ZIMAGE, ("OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::CopyData " + StartTrace(HITRACE_TAG_ZIMAGE, ("OHOS::PurgeableBuilder::PixelMapPurgeableMemBuilder::CopyData " +
std::to_string(size))); 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(); DoRebuildSuccessCallback();