Init jitfort at app start.

Signed-off-by: luyifan<842825214@qq.com>
This commit is contained in:
luyifan 2024-07-29 15:58:11 +08:00
parent c85d3faad3
commit 9ab4a4743d
4 changed files with 30 additions and 9 deletions

View File

@ -195,9 +195,6 @@ static int SetXpmConfig(const AppSpawnMgr *content, const AppSpawningCtx *proper
if (IsNWebSpawnMode(content)) {
return 0;
}
AppSpawnMsgOwnerId *ownerInfo = (AppSpawnMsgOwnerId *)GetAppProperty(property, TLV_OWNER_INFO);
int ret = InitXpmRegion();
APPSPAWN_CHECK(ret == 0, return ret, "init xpm region failed: %{public}d", ret);
uint32_t len = 0;
char *provisionType = GetAppPropertyExt(property, MSG_EXT_NAME_PROVISION_TYPE, &len);
@ -206,13 +203,19 @@ static int SetXpmConfig(const AppSpawnMgr *content, const AppSpawningCtx *proper
provisionType = PROVISION_TYPE_DEBUG;
}
AppSpawnMsgOwnerId *ownerInfo = (AppSpawnMsgOwnerId *)GetAppProperty(property, TLV_OWNER_INFO);
int jitfortEnable = IsJitFortModeOn(property) ? 1 : 0;
int idType = PROCESS_OWNERID_UNINIT;
const char *ownerId = NULL;
if (strcmp(provisionType, PROVISION_TYPE_DEBUG) == 0) {
ret = SetXpmOwnerId(PROCESS_OWNERID_DEBUG, NULL);
idType = PROCESS_OWNERID_DEBUG;
} else if (ownerInfo == NULL) {
ret = SetXpmOwnerId(PROCESS_OWNERID_COMPAT, NULL);
idType = PROCESS_OWNERID_COMPAT;
} else {
ret = SetXpmOwnerId(PROCESS_OWNERID_APP, ownerInfo->ownerId);
idType = PROCESS_OWNERID_APP;
ownerId = ownerInfo->ownerId;
}
int ret = InitXpm(jitfortEnable, idType, ownerId);
APPSPAWN_CHECK(ret == 0, return ret, "set xpm region failed: %{public}d", ret);
#endif
return 0;
@ -460,14 +463,16 @@ static int SpawnGetSpawningFlag(AppSpawnMgr *content, AppSpawningCtx *property)
property->client.flags |= APP_BEGETCTL_BOOT;
APPSPAWN_LOGI("Spawning: prepare app %{public}s, start from begetctl", GetProcessName(property));
}
// check developer mode
property->client.flags |= CheckEnabled("const.security.developermode.state", "true") ? APP_DEVELOPER_MODE : 0;
property->client.flags |= content->flags;
return 0;
}
static int SpawnLoadConfig(AppSpawnMgr *content)
{
LoadSilkConfig();
// init flags that will not change until next reboot
content->flags |= CheckEnabled("const.security.developermode.state", "true") ? APP_DEVELOPER_MODE : 0;
content->flags |= CheckEnabled("persist.security.jitfort.enabled", "true") ? APP_JITFORT_MODE : 0;
return 0;
}

View File

@ -110,6 +110,7 @@ typedef struct TagAppSpawnMgr {
pid_t servicePid;
struct ListNode appQueue; // save app pid and name
uint32_t diedAppCount;
uint32_t flags;
struct ListNode diedQueue; // save app pid and name
struct ListNode appSpawnQueue; // save app pid and name
struct timespec perLoadStart;
@ -196,6 +197,11 @@ APPSPAWN_INLINE int IsDeveloperModeOn(const AppSpawningCtx *property)
return (property != NULL && ((property->client.flags & APP_DEVELOPER_MODE) == APP_DEVELOPER_MODE));
}
APPSPAWN_INLINE int IsJitFortModeOn(const AppSpawningCtx *property)
{
return (property != NULL && ((property->client.flags & APP_JITFORT_MODE) == APP_JITFORT_MODE));
}
APPSPAWN_INLINE int GetAppSpawnMsgType(const AppSpawningCtx *appProperty)
{
return (appProperty != NULL && appProperty->message != NULL) ?

View File

@ -865,6 +865,15 @@ HWTEST_F(AppSpawnAppMgrTest, App_Spawn_AppSpawningCtx_Msg_001, TestSize.Level0)
ret = IsDeveloperModeOn(nullptr);
EXPECT_EQ(ret, 0);
//IsJitFortModeOn
ret = IsJitFortModeOn(appCtx);
EXPECT_EQ(ret, 0);
appCtx->client.flags |= APP_JITFORT_MODE;
ret = IsJitFortModeOn(appCtx);
EXPECT_EQ(ret, 1);
ret = IsJitFortModeOn(nullptr);
EXPECT_EQ(ret, 0);
DeleteAppSpawningCtx(appCtx);
DeleteAppSpawnMgr(mgr);
}

View File

@ -61,6 +61,7 @@ extern "C" {
#define APP_COLD_START 0x01
#define APP_ASAN_DETECTOR 0x02
#define APP_DEVELOPER_MODE 0x04
#define APP_JITFORT_MODE 0x08
#define APP_BEGETCTL_BOOT 0x400
#define MAX_LEN_SHORT_NAME 16