!8263 [BugFix] Load JSPandaFile from safe memory for hot reload

Merge pull request !8263 from ZitongLi/hqf_sign_check
This commit is contained in:
openharmony_ci 2024-07-23 22:03:28 +00:00 committed by Gitee
commit 7ce80e70c4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 27 additions and 26 deletions

View File

@ -151,8 +151,8 @@ HWTEST_F_L0(QuickFixTest, HotReload_Buffer)
pfManager->AddJSPandaFile(baseFile);
pfManager->AddJSPandaFile(patchFile);
auto result = JSNApi::LoadPatch(instance, patchFileName, (void *)patchData, sizeof(patchData),
baseFileName, (void *)baseData, sizeof(baseData));
auto result = JSNApi::LoadPatch(instance, patchFileName, (uint8_t *)patchData, sizeof(patchData),
baseFileName, (uint8_t *)baseData, sizeof(baseData));
EXPECT_FALSE(result == PatchErrorCode::SUCCESS);
pfManager->RemoveJSPandaFile(baseFile.get());
@ -160,7 +160,7 @@ HWTEST_F_L0(QuickFixTest, HotReload_Buffer)
}
bool QuickFixQueryFunc(
std::string baseFileName, std::string &patchFileName, void ** patchBuffer, size_t &patchBufferSize)
std::string baseFileName, std::string &patchFileName, uint8_t ** patchBuffer, size_t &patchBufferSize)
{
if (baseFileName != QUICKFIX_ABC_PATH "multi_file/base/merge.abc") {
return false;
@ -173,8 +173,8 @@ bool QuickFixQueryFunc(
Parser parser;
auto res = parser.Parse(data);
void *bufferData = reinterpret_cast<void *>((const_cast<char *>(data)));
*patchBuffer = &bufferData;
uint8_t *bufferData = reinterpret_cast<uint8_t *>((const_cast<char *>(data)));
*patchBuffer = bufferData;
patchBufferSize = sizeof(data);
return true;
}

View File

@ -1559,15 +1559,15 @@ public:
static void GetStackAfterCallNapi(EcmaVM *vm);
static PatchErrorCode LoadPatch(EcmaVM *vm, const std::string &patchFileName, const std::string &baseFileName);
static PatchErrorCode LoadPatch(EcmaVM *vm,
const std::string &patchFileName, const void *patchBuffer, size_t patchSize,
const std::string &baseFileName, const void *baseBuffer, size_t baseSize);
const std::string &patchFileName, uint8_t *patchBuffer, size_t patchSize,
const std::string &baseFileName, uint8_t *baseBuffer, size_t baseSize);
static PatchErrorCode UnloadPatch(EcmaVM *vm, const std::string &patchFileName);
// check whether the exception is caused by quickfix methods.
static bool IsQuickFixCausedException(EcmaVM *vm, Local<ObjectRef> exception, const std::string &patchFileName);
// register quickfix query function.
static void RegisterQuickFixQueryFunc(EcmaVM *vm, std::function<bool(std::string baseFileName,
std::string &patchFileName,
void **patchBuffer,
uint8_t **patchBuffer,
size_t &patchSize)> callBack);
static bool IsBundle(EcmaVM *vm);
static void SetBundle(EcmaVM *vm, bool value);

View File

@ -3763,8 +3763,8 @@ PatchErrorCode JSNApi::LoadPatch(EcmaVM *vm, const std::string &patchFileName, c
}
PatchErrorCode JSNApi::LoadPatch(EcmaVM *vm,
const std::string &patchFileName, const void *patchBuffer, size_t patchSize,
const std::string &baseFileName, const void *baseBuffer, size_t baseSize)
const std::string &patchFileName, uint8_t *patchBuffer, size_t patchSize,
const std::string &baseFileName, uint8_t *baseBuffer, size_t baseSize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, PatchErrorCode::INTERNAL_ERROR);
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
@ -3801,7 +3801,7 @@ bool JSNApi::IsQuickFixCausedException(EcmaVM *vm, Local<ObjectRef> exception, c
*/
void JSNApi::RegisterQuickFixQueryFunc(EcmaVM *vm, std::function<bool(std::string baseFileName,
std::string &patchFileName,
void **patchBuffer,
uint8_t **patchBuffer,
size_t &patchSize)> callBack)
{
CROSS_THREAD_CHECK(vm);

View File

@ -32,7 +32,7 @@ QuickFixManager::~QuickFixManager()
void QuickFixManager::RegisterQuickFixQueryFunc(const std::function<bool(std::string baseFileName,
std::string &patchFileName,
void **patchBuffer,
uint8_t **patchBuffer,
size_t &patchSize)> callBack)
{
callBack_ = callBack;
@ -46,7 +46,7 @@ void QuickFixManager::LoadPatchIfNeeded(JSThread *thread, const JSPandaFile *bas
}
std::string patchFileName;
void *patchBuffer = nullptr;
uint8_t *patchBuffer = nullptr;
size_t patchSize = 0;
CString baseFileName = baseFile->GetJSPandaFileDesc();
bool needLoadPatch = callBack_(baseFileName.c_str(), patchFileName, &patchBuffer, patchSize);
@ -60,7 +60,7 @@ void QuickFixManager::LoadPatchIfNeeded(JSThread *thread, const JSPandaFile *bas
return;
}
std::shared_ptr<JSPandaFile> patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(
std::shared_ptr<JSPandaFile> patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFileSecure(
thread, patchFileName.c_str(), "", patchBuffer, patchSize);
if (patchFile == nullptr) {
LOG_ECMA(ERROR) << "load patch jsPandafile failed of: " << baseFileName;
@ -122,8 +122,8 @@ PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread, const std::string &p
}
PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread,
const std::string &patchFileName, const void *patchBuffer, size_t patchSize,
const std::string &baseFileName, const void *baseBuffer, size_t baseSize)
const std::string &patchFileName, uint8_t *patchBuffer, size_t patchSize,
const std::string &baseFileName, uint8_t *baseBuffer, size_t baseSize)
{
LOG_ECMA(INFO) << "Load patch, patch: " << patchFileName << ", base:" << baseFileName;
if (methodInfos_.find(baseFileName.c_str()) != methodInfos_.end()) {
@ -131,14 +131,14 @@ PatchErrorCode QuickFixManager::LoadPatch(JSThread *thread,
return PatchErrorCode::PATCH_HAS_LOADED;
}
std::shared_ptr<JSPandaFile> baseFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(
std::shared_ptr<JSPandaFile> baseFile = JSPandaFileManager::GetInstance()->LoadJSPandaFileSecure(
thread, baseFileName.c_str(), "", baseBuffer, baseSize);
if (baseFile == nullptr) {
LOG_ECMA(ERROR) << "find base jsPandafile failed";
return PatchErrorCode::FILE_NOT_FOUND;
}
std::shared_ptr<JSPandaFile> patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(
std::shared_ptr<JSPandaFile> patchFile = JSPandaFileManager::GetInstance()->LoadJSPandaFileSecure(
thread, patchFileName.c_str(), "", patchBuffer, patchSize);
if (patchFile == nullptr) {
LOG_ECMA(ERROR) << "load patch jsPandafile failed";

View File

@ -27,13 +27,13 @@ public:
void RegisterQuickFixQueryFunc(const std::function<bool(std::string baseFileName,
std::string &patchFileName,
void **patchBuffer,
uint8_t **patchBuffer,
size_t &patchSize)> callBack);
void LoadPatchIfNeeded(JSThread *thread, const JSPandaFile *baseFile);
PatchErrorCode LoadPatch(JSThread *thread, const std::string &patchFileName, const std::string &baseFileName);
PatchErrorCode LoadPatch(JSThread *thread,
const std::string &patchFileName, const void *patchBuffer, size_t patchSize,
const std::string &baseFileName, const void *baseBuffer, size_t baseSize);
const std::string &patchFileName, uint8_t *patchBuffer, size_t patchSize,
const std::string &baseFileName, uint8_t *baseBuffer, size_t baseSize);
PatchErrorCode UnloadPatch(JSThread *thread, const std::string &patchFileName);
bool IsQuickFixCausedException(JSThread *thread,
const JSHandle<JSTaggedValue> &exceptionInfo,
@ -54,7 +54,7 @@ private:
CMap<CString, PatchInfo> methodInfos_ {};
std::function<bool(std::string baseFileName,
std::string &patchFileName,
void **patchBuffer,
uint8_t **patchBuffer,
size_t &patchSize)> callBack_;
CMap<uint32_t, CString> baseClassInfo_ {};
CString currentBaseFileName_;

View File

@ -55,7 +55,7 @@ std::string GetHelper()
}
bool QuickFixQueryFuncColdPatch(std::string baseFileName, std::string &patchFileName,
void ** patchBuffer, size_t &patchBufferSize)
uint8_t ** patchBuffer, size_t &patchBufferSize)
{
return true;
}

View File

@ -33,7 +33,8 @@ namespace OHOS {
LOG_ECMA(ERROR) << "illegal input!";
return;
}
JSNApi::LoadPatch(vm, patchFileName, (void *)data, size, baseFileName, (void *)data, size);
JSNApi::LoadPatch(vm, patchFileName, const_cast<uint8_t *>(data), size,
baseFileName, const_cast<uint8_t *>(data), size);
JSNApi::DestroyJSVM(vm);
}
}

View File

@ -22,7 +22,7 @@ using namespace panda;
using namespace panda::ecmascript;
namespace OHOS {
bool QuickFixQueryFunc(std::string baseFileName, std::string &patchFileName, void **patchBuffer,
bool QuickFixQueryFunc(std::string baseFileName, std::string &patchFileName, uint8_t **patchBuffer,
size_t &patchBufferSize)
{
if (baseFileName != "multi_file/base/merge.abc") {
@ -35,7 +35,7 @@ namespace OHOS {
char *bufferData = new char[strlen(data) + 1];
size_t dataSize = strlen(data) + 1;
strcpy_s(bufferData, dataSize, data);
*patchBuffer = reinterpret_cast<void *>(bufferData);
*patchBuffer = reinterpret_cast<uint8_t *>(bufferData);
patchBufferSize = strlen(data);
return true;
}