From d403d1c8bcbf926fe1a45a4776ced25662e2d0fd Mon Sep 17 00:00:00 2001 From: huyx Date: Thu, 7 Aug 2025 12:14:16 +0800 Subject: [PATCH 01/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 325 ++++++++++++++++++++++++++++------- 1 file changed, 261 insertions(+), 64 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 097e0aee6..4af632c2e 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -44,30 +44,13 @@ typedef struct { int hostId; - char *hostName; + const char *hostName; int schedPriority; int processPriority; int malloptKey; int malloptValue; } HostConfig; -static void StartMemoryHook(const char* processName) -{ - const char defaultValue[PARAM_BUF_LEN] = { 0 }; - const char targetPrefix[] = "startup:"; - const int targetPrefixLen = strlen(targetPrefix); - char paramValue[PARAM_BUF_LEN] = { 0 }; - int retParam = GetParameter("libc.hook_mode", defaultValue, paramValue, sizeof(paramValue)); - if (retParam <= 0 || strncmp(paramValue, targetPrefix, targetPrefixLen) != 0) { - return; - } - if (strstr(paramValue + targetPrefixLen, processName) != NULL) { - const int hookSignal = 36; // 36: native memory hooked signal - HDF_LOGE("raise hook signal %{public}d to %{public}s", hookSignal, processName); - raise(hookSignal); - } -} - bool HdfStringToInt(const char *str, int *value) { if (str == NULL || value == NULL) { @@ -86,6 +69,246 @@ bool HdfStringToInt(const char *str, int *value) return true; } +static void SetMallopt(int32_t malloptKey, int32_t malloptValue) +{ + int ret = mallopt(malloptKey, malloptValue); + if (ret != 1) { + HDF_LOGE("mallopt failed, malloptKey:%{public}d, malloptValue:%{public}d, ret:%{public}d", + malloptKey, malloptValue, ret); + return; + } + HDF_LOGI("host set mallopt succeed, mallopt:%{public}d %{public}d", malloptKey, malloptValue); +} + +typedef int32_t (*CommandFunc)(const char *str, HostConfig *config); +typedef struct CommandToFunc { + const char *opt; + CommandFunc func; +}CommandToFunc; + +static int32_t CommandIFunc(const char *str, HostConfig *config) +{ + if (!HdfStringToInt(str, &config->hostId)) { + HDF_LOGE("Invalid process ID: %{public}s", str); + return HDF_ERR_INVALID_PARAM; + } + return HDF_SUCCESS; +} + +static int32_t CommandNFunc(const char *str, HostConfig *config) +{ + config->hostName = str; + return HDF_SUCCESS; +} + +static int32_t CommandPFunc(const char *str, HostConfig *config) +{ + if (!HdfStringToInt(str, &config->processPriority)) { + HDF_LOGE("Invalid process ID: %{public}s", str); + } + return HDF_SUCCESS; +} + +static int32_t CommandSFunc(const char *str, HostConfig *config) +{ + if (!HdfStringToInt(str, &config->schedPriority)) { + HDF_LOGE("Invalid process ID: %{public}s", str); + } + return HDF_SUCCESS; +} + +static int32_t CommandMFunc(const char *str, HostConfig *config) +{ + if (!HdfStringToInt(str, &config->malloptKey)) { + HDF_LOGE("Invalid process ID: %{public}s", str); + } + return HDF_SUCCESS; +} + +static int32_t CommandVFunc(const char *str, HostConfig *config) +{ + if (!HdfStringToInt(str, &config->malloptValue)) { + HDF_LOGE("Invalid process ID: %{public}s", str); + } + return HDF_SUCCESS; +} + +static int32_t Command1005Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1005", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1006Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1006", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1007Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1007", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1008Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1008", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1009Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1009", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1010Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1010", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1011Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1011", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1012Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1012", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1013Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1013", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static int32_t Command1014Func(const char *str, HostConfig *config) +{ + int32_t key = -1; + int32_t value = -1; + if (!HdfStringToInt(str, &value)) { + HDF_LOGE("Invalid value: %{public}d", value); + } + if (!HdfStringToInt("-1014", &key)) { + HDF_LOGE("Invalid key: %{public}d", value); + } + SetMallopt(key, value); + return HDF_SUCCESS; +} + +static struct CommandToFunc commandFuncs[] = { + {"i", CommandIFunc}, + {"n", CommandNFunc}, + {"p", CommandPFunc}, + {"s", CommandSFunc}, + {"m", CommandMFunc}, + {"v", CommandVFunc}, + {"1005", Command1005Func}, + {"1006", Command1006Func}, + {"1007", Command1007Func}, + {"1008", Command1008Func}, + {"1009", Command1009Func}, + {"1010", Command1010Func}, + {"1011", Command1011Func}, + {"1012", Command1012Func}, + {"1013", Command1013Func}, + {"1014", Command1014Func}, +}; + +static void StartMemoryHook(const char* processName) +{ + const char defaultValue[PARAM_BUF_LEN] = { 0 }; + const char targetPrefix[] = "startup:"; + const int targetPrefixLen = strlen(targetPrefix); + char paramValue[PARAM_BUF_LEN] = { 0 }; + int retParam = GetParameter("libc.hook_mode", defaultValue, paramValue, sizeof(paramValue)); + if (retParam <= 0 || strncmp(paramValue, targetPrefix, targetPrefixLen) != 0) { + return; + } + if (strstr(paramValue + targetPrefixLen, processName) != NULL) { + const int hookSignal = 36; // 36: native memory hooked signal + HDF_LOGE("raise hook signal %{public}d to %{public}s", hookSignal, processName); + raise(hookSignal); + } +} + static void SetProcTitle(char **argv, const char *newTitle) { if (newTitle == NULL) { @@ -120,57 +343,31 @@ static void HdfSetProcPriority(int32_t procPriority, int32_t schedPriority) } } -static void SetMallopt(int32_t malloptKey, int32_t malloptValue) -{ - int ret = mallopt(malloptKey, malloptValue); - if (ret != 1) { - HDF_LOGE("mallopt failed, malloptKey:%{public}d, malloptValue:%{public}d, ret:%{public}d", - malloptKey, malloptValue, ret); +static int FindFunc(const char* opt_name, const char* value, HostConfig *config) { + for (size_t i = 0; i< sizeof(commandFuncs)/sizeof(commandFuncs[i]); ++i) { + if (strcmp(commandFuncs[i].opt, opt_name) == 0) { + return commandFuncs[i].func(value, config); + } } - HDF_LOGI("host set mallopt succeed, mallopt:%{public}d %{public}d", malloptKey, malloptValue); + HDF_LOGE("FindFunc failed: %{public}s", opt_name); + return HDF_ERR_INVALID_PARAM; } static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) { - int opt; - while ((opt = getopt(argc, argv, "i:n:p:s:m:v:")) != -1) { - switch (opt) { - case 'i': - if (!HdfStringToInt(optarg, &config->hostId)) { - HDF_LOGE("Invalid process ID: %{public}s", optarg); - return HDF_ERR_INVALID_PARAM; - } - break; - case 'n': - config->hostName = optarg; - break; - case 'p': - if (!HdfStringToInt(optarg, &config->processPriority)) { - HDF_LOGE("Invalid process priority: %{public}s", optarg); - return HDF_ERR_INVALID_PARAM; - } - break; - case 's': - if (!HdfStringToInt(optarg, &config->schedPriority)) { - HDF_LOGE("Invalid process priority: %{public}s", optarg); - return HDF_ERR_INVALID_PARAM; - } - break; - case 'm': - if (!HdfStringToInt(optarg, &config->malloptKey)) { - HDF_LOGE("Invalid mallopt key: %{public}s", optarg); - return HDF_ERR_INVALID_PARAM; - } - break; - case 'v': - if (!HdfStringToInt(optarg, &config->malloptValue)) { - HDF_LOGE("Invalid mallopt value: %{public}s", optarg); - return HDF_ERR_INVALID_PARAM; - } - break; - default: - HDF_LOGE("Unknown option: -%c", opt); - return HDF_ERR_INVALID_PARAM; + for (int i =1; i < argc; ++i) { + const char* arg = argv[i]; + + if (strncmp(arg, "-", 1) == 0) { + const char* opt_name = arg + 1; + + if (i + 1 >= argc) { + HDF_LOGE("Missing argument for -%{public}s", opt_name); + } + const char* value = argv[++i]; + if (FindFunc(opt_name, value, config) != HDF_SUCCESS) { + HDF_LOGE("argument Parse failed for -%s", opt_name); + } } } return HDF_SUCCESS; -- Gitee From 6ff1d584ed207c1c8e3cb8893cdc48ba7f2f96c0 Mon Sep 17 00:00:00 2001 From: huyx Date: Thu, 7 Aug 2025 13:43:30 +0800 Subject: [PATCH 02/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 4af632c2e..e9f352158 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -273,7 +273,7 @@ static int32_t Command1014Func(const char *str, HostConfig *config) return HDF_SUCCESS; } -static struct CommandToFunc commandFuncs[] = { +static struct CommandToFunc g_commandFuncs[] = { {"i", CommandIFunc}, {"n", CommandNFunc}, {"p", CommandPFunc}, @@ -343,30 +343,32 @@ static void HdfSetProcPriority(int32_t procPriority, int32_t schedPriority) } } -static int FindFunc(const char* opt_name, const char* value, HostConfig *config) { - for (size_t i = 0; i< sizeof(commandFuncs)/sizeof(commandFuncs[i]); ++i) { - if (strcmp(commandFuncs[i].opt, opt_name) == 0) { - return commandFuncs[i].func(value, config); +static int FindFunc(const char* optName, const char* value, HostConfig *config) +{ + for (size_t i = 0; i < sizeof(g_commandFuncs)/sizeof(g_commandFuncs[i]); ++i) { + if (strcmp(g_commandFuncs[i].opt, optName) == 0) { + return g_commandFuncs[i].func(value, config); } } - HDF_LOGE("FindFunc failed: %{public}s", opt_name); + HDF_LOGE("FindFunc failed: %{public}s", optName); return HDF_ERR_INVALID_PARAM; } static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) { - for (int i =1; i < argc; ++i) { + for (int i = 1; i < argc; ++i) { const char* arg = argv[i]; if (strncmp(arg, "-", 1) == 0) { - const char* opt_name = arg + 1; + const char* optName = arg + 1; if (i + 1 >= argc) { - HDF_LOGE("Missing argument for -%{public}s", opt_name); + HDF_LOGE("Missing argument for -%{public}s", optName); } - const char* value = argv[++i]; - if (FindFunc(opt_name, value, config) != HDF_SUCCESS) { - HDF_LOGE("argument Parse failed for -%s", opt_name); + int next_i = i + 1; + const char* value = argv[next_i]; + if (FindFunc(optName, value, config) != HDF_SUCCESS) { + HDF_LOGE("argument Parse failed for -%s", optName); } } } -- Gitee From b3f28676a3b7247a766803d034363fac94ec218b Mon Sep 17 00:00:00 2001 From: huyx Date: Thu, 7 Aug 2025 14:24:13 +0800 Subject: [PATCH 03/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index e9f352158..7771d7271 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -345,7 +345,7 @@ static void HdfSetProcPriority(int32_t procPriority, int32_t schedPriority) static int FindFunc(const char* optName, const char* value, HostConfig *config) { - for (size_t i = 0; i < sizeof(g_commandFuncs)/sizeof(g_commandFuncs[i]); ++i) { + for (size_t i = 0; i < sizeof(g_commandFuncs) / sizeof(g_commandFuncs[i]); ++i) { if (strcmp(g_commandFuncs[i].opt, optName) == 0) { return g_commandFuncs[i].func(value, config); } @@ -365,8 +365,8 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) if (i + 1 >= argc) { HDF_LOGE("Missing argument for -%{public}s", optName); } - int next_i = i + 1; - const char* value = argv[next_i]; + int next = i + 1; + const char* value = argv[next]; if (FindFunc(optName, value, config) != HDF_SUCCESS) { HDF_LOGE("argument Parse failed for -%s", optName); } -- Gitee From ced3620423c456372a173a6f011a8cd9ba57c2c2 Mon Sep 17 00:00:00 2001 From: huyx Date: Thu, 7 Aug 2025 22:08:54 +0800 Subject: [PATCH 04/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 240 +++++++++-------------------------- 1 file changed, 61 insertions(+), 179 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 7771d7271..b8b3642e0 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -51,17 +51,17 @@ typedef struct { int malloptValue; } HostConfig; -bool HdfStringToInt(const char *str, int *value) +bool HdfStringToInt(const char *value, int *value) { - if (str == NULL || value == NULL) { + if (value == NULL || value == NULL) { return false; } char *end = NULL; errno = 0; const int base = 10; - long result = strtol(str, &end, base); - if (end == str || end[0] != '\0' || errno == ERANGE || result > INT_MAX || result < INT_MIN) { + long result = strtol(value, &end, base); + if (end == value || end[0] != '\0' || errno == ERANGE || result > INT_MAX || result < INT_MIN) { return false; } @@ -80,193 +80,68 @@ static void SetMallopt(int32_t malloptKey, int32_t malloptValue) HDF_LOGI("host set mallopt succeed, mallopt:%{public}d %{public}d", malloptKey, malloptValue); } -typedef int32_t (*CommandFunc)(const char *str, HostConfig *config); +typedef int32_t (*CommandFunc)(const char *key, const char *value, HostConfig *config); typedef struct CommandToFunc { const char *opt; CommandFunc func; }CommandToFunc; -static int32_t CommandIFunc(const char *str, HostConfig *config) +static int32_t CommandIFunc(const char *key, const char *value, HostConfig *config) { - if (!HdfStringToInt(str, &config->hostId)) { - HDF_LOGE("Invalid process ID: %{public}s", str); + if (!HdfStringToInt(value, &config->hostId)) { + HDF_LOGE("Invalid process ID: %{public}s", value); return HDF_ERR_INVALID_PARAM; } return HDF_SUCCESS; } -static int32_t CommandNFunc(const char *str, HostConfig *config) +static int32_t CommandNFunc(const char *key, const char *value, HostConfig *config) { - config->hostName = str; + config->hostName = value; return HDF_SUCCESS; } -static int32_t CommandPFunc(const char *str, HostConfig *config) +static int32_t CommandPFunc(const char *key, const char *value, HostConfig *config) { - if (!HdfStringToInt(str, &config->processPriority)) { - HDF_LOGE("Invalid process ID: %{public}s", str); + if (!HdfStringToInt(value, &config->processPriority)) { + HDF_LOGE("Invalid process ID: %{public}s", value); } return HDF_SUCCESS; } -static int32_t CommandSFunc(const char *str, HostConfig *config) +static int32_t CommandSFunc(const char *key, const char *value, HostConfig *config) { - if (!HdfStringToInt(str, &config->schedPriority)) { - HDF_LOGE("Invalid process ID: %{public}s", str); + if (!HdfStringToInt(value, &config->schedPriority)) { + HDF_LOGE("Invalid process ID: %{public}s", value); } return HDF_SUCCESS; } -static int32_t CommandMFunc(const char *str, HostConfig *config) +static int32_t CommandMFunc(const char *key, const char *value, HostConfig *config) { - if (!HdfStringToInt(str, &config->malloptKey)) { - HDF_LOGE("Invalid process ID: %{public}s", str); + if (!HdfStringToInt(value, &config->malloptKey)) { + HDF_LOGE("Invalid process ID: %{public}s", value); } return HDF_SUCCESS; } -static int32_t CommandVFunc(const char *str, HostConfig *config) +static int32_t CommandVFunc(const char *key, const char *value, HostConfig *config) { - if (!HdfStringToInt(str, &config->malloptValue)) { - HDF_LOGE("Invalid process ID: %{public}s", str); + if (!HdfStringToInt(value, &config->malloptValue)) { + HDF_LOGE("Invalid process ID: %{public}s", value); } return HDF_SUCCESS; } -static int32_t Command1005Func(const char *str, HostConfig *config) +static int32_t CommandMathFunc(const char *key, const char *value, HostConfig *config) { - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { + int32_t malloptKey = 0; + int32_t malloptValue = 0; + int ret = 0; + if (!HdfStringToInt(value, &malloptValue)) { HDF_LOGE("Invalid value: %{public}d", value); } - if (!HdfStringToInt("-1005", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1006Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1006", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1007Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1007", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1008Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1008", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1009Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1009", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1010Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1010", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1011Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1011", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1012Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1012", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1013Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1013", &key)) { - HDF_LOGE("Invalid key: %{public}d", value); - } - SetMallopt(key, value); - return HDF_SUCCESS; -} - -static int32_t Command1014Func(const char *str, HostConfig *config) -{ - int32_t key = -1; - int32_t value = -1; - if (!HdfStringToInt(str, &value)) { - HDF_LOGE("Invalid value: %{public}d", value); - } - if (!HdfStringToInt("-1014", &key)) { + if (!HdfStringToInt(key, &malloptKey)) { HDF_LOGE("Invalid key: %{public}d", value); } SetMallopt(key, value); @@ -280,16 +155,16 @@ static struct CommandToFunc g_commandFuncs[] = { {"s", CommandSFunc}, {"m", CommandMFunc}, {"v", CommandVFunc}, - {"1005", Command1005Func}, - {"1006", Command1006Func}, - {"1007", Command1007Func}, - {"1008", Command1008Func}, - {"1009", Command1009Func}, - {"1010", Command1010Func}, - {"1011", Command1011Func}, - {"1012", Command1012Func}, - {"1013", Command1013Func}, - {"1014", Command1014Func}, + {"1005", CommandMathFunc}, + {"1006", CommandMathFunc}, + {"1007", CommandMathFunc}, + {"1008", CommandMathFunc}, + {"1009", CommandMathFunc}, + {"1010", CommandMathFunc}, + {"1011", CommandMathFunc}, + {"1012", CommandMathFunc}, + {"1013", CommandMathFunc}, + {"1014", CommandMathFunc}, }; static void StartMemoryHook(const char* processName) @@ -343,14 +218,14 @@ static void HdfSetProcPriority(int32_t procPriority, int32_t schedPriority) } } -static int FindFunc(const char* optName, const char* value, HostConfig *config) +static int FindFunc(const char* arg, const char* value, HostConfig *config) { for (size_t i = 0; i < sizeof(g_commandFuncs) / sizeof(g_commandFuncs[i]); ++i) { - if (strcmp(g_commandFuncs[i].opt, optName) == 0) { - return g_commandFuncs[i].func(value, config); + if (strcmp(g_commandFuncs[i].opt, arg) == 0) { + return g_commandFuncs[i].func(arg, value, config); } } - HDF_LOGE("FindFunc failed: %{public}s", optName); + HDF_LOGE("FindFunc failed: %{public}s", arg); return HDF_ERR_INVALID_PARAM; } @@ -358,18 +233,20 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) { for (int i = 1; i < argc; ++i) { const char* arg = argv[i]; - - if (strncmp(arg, "-", 1) == 0) { - const char* optName = arg + 1; - - if (i + 1 >= argc) { - HDF_LOGE("Missing argument for -%{public}s", optName); - } - int next = i + 1; - const char* value = argv[next]; - if (FindFunc(optName, value, config) != HDF_SUCCESS) { - HDF_LOGE("argument Parse failed for -%s", optName); - } + + if (arg == NULL) { + HDF_LOGE("NULL argument"); + return HDF_ERR_INVALID_PARAM; + } + + ++i; + if (i + 1 >= argc) { + HDF_LOGE("Missing argument for -%{public}s", arg); + return HDF_FAILURE; + } + const char* value = argv[i]; + if (FindFunc(arg, value, config) != HDF_SUCCESS) { + HDF_LOGE("argument Parse failed for -%s", arg); } } return HDF_SUCCESS; @@ -426,6 +303,11 @@ static int StartHostService(const HostConfig *config) int main(int argc, char **argv) { + if (argc < DEVHOST_MIN_INPUT_PARAM_NUM) { + HDF_LOGE("Devhost main parameter error, argc: %{public}d", argc); + return HDF_ERR_INVALID_PARAM; + } + HostConfig config = {0}; if (ParseCommandLineArgs(argc, argv, &config) != HDF_SUCCESS) { HDF_LOGE("ParseCommandLineArgs(argc, argv, &config) != HDF_SUCCESS"); -- Gitee From 386f2f0b15c98282678ecffb31bd65e78bc31e6d Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 09:36:54 +0800 Subject: [PATCH 05/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index b8b3642e0..6ff9be7de 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -51,17 +51,17 @@ typedef struct { int malloptValue; } HostConfig; -bool HdfStringToInt(const char *value, int *value) +bool HdfStringToInt(const char *str, int *value) { - if (value == NULL || value == NULL) { + if (str == NULL || value == NULL) { return false; } char *end = NULL; errno = 0; const int base = 10; - long result = strtol(value, &end, base); - if (end == value || end[0] != '\0' || errno == ERANGE || result > INT_MAX || result < INT_MIN) { + long result = strtol(str, &end, base); + if (end == str || end[0] != '\0' || errno == ERANGE || result > INT_MAX || result < INT_MIN) { return false; } @@ -239,7 +239,7 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) return HDF_ERR_INVALID_PARAM; } - ++i; + int next = i + 1; if (i + 1 >= argc) { HDF_LOGE("Missing argument for -%{public}s", arg); return HDF_FAILURE; @@ -304,8 +304,8 @@ static int StartHostService(const HostConfig *config) int main(int argc, char **argv) { if (argc < DEVHOST_MIN_INPUT_PARAM_NUM) { - HDF_LOGE("Devhost main parameter error, argc: %{public}d", argc); - return HDF_ERR_INVALID_PARAM; + HDF_LOGE("Devhost main parameter error, argc: %{public}d", argc); + return HDF_ERR_INVALID_PARAM; } HostConfig config = {0}; -- Gitee From c6c3590ec576c52705725c9e5528499f02cfc1ae Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 10:01:16 +0800 Subject: [PATCH 06/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 6ff9be7de..2a3b3c22b 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -139,10 +139,10 @@ static int32_t CommandMathFunc(const char *key, const char *value, HostConfig *c int32_t malloptValue = 0; int ret = 0; if (!HdfStringToInt(value, &malloptValue)) { - HDF_LOGE("Invalid value: %{public}d", value); + HDF_LOGE("Invalid value: %{public}s", value); } if (!HdfStringToInt(key, &malloptKey)) { - HDF_LOGE("Invalid key: %{public}d", value); + HDF_LOGE("Invalid key: %{public}s", key); } SetMallopt(key, value); return HDF_SUCCESS; -- Gitee From 630f6ea409b6304b7c671f49058886bd2bc374f8 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 10:23:03 +0800 Subject: [PATCH 07/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 2a3b3c22b..859394d34 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -144,7 +144,7 @@ static int32_t CommandMathFunc(const char *key, const char *value, HostConfig *c if (!HdfStringToInt(key, &malloptKey)) { HDF_LOGE("Invalid key: %{public}s", key); } - SetMallopt(key, value); + SetMallopt(malloptKey, malloptValue); return HDF_SUCCESS; } -- Gitee From 52ef1ed5bec1dac482d27399b25a82c7a554f498 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 10:40:38 +0800 Subject: [PATCH 08/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 1 - 1 file changed, 1 deletion(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 859394d34..c55054cdd 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -137,7 +137,6 @@ static int32_t CommandMathFunc(const char *key, const char *value, HostConfig *c { int32_t malloptKey = 0; int32_t malloptValue = 0; - int ret = 0; if (!HdfStringToInt(value, &malloptValue)) { HDF_LOGE("Invalid value: %{public}s", value); } -- Gitee From 14f0b194c647a8d014f9288fc331719a91a490f0 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 10:58:01 +0800 Subject: [PATCH 09/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index c55054cdd..cac0af4bd 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -243,7 +243,7 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) HDF_LOGE("Missing argument for -%{public}s", arg); return HDF_FAILURE; } - const char* value = argv[i]; + const char* value = argv[next]; if (FindFunc(arg, value, config) != HDF_SUCCESS) { HDF_LOGE("argument Parse failed for -%s", arg); } -- Gitee From 0833fe2a791e05836b883e20fe7d9217a2021d05 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 11:20:25 +0800 Subject: [PATCH 10/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 43 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index cac0af4bd..f64b07bfc 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -88,6 +88,7 @@ typedef struct CommandToFunc { static int32_t CommandIFunc(const char *key, const char *value, HostConfig *config) { + (void)key; if (!HdfStringToInt(value, &config->hostId)) { HDF_LOGE("Invalid process ID: %{public}s", value); return HDF_ERR_INVALID_PARAM; @@ -97,12 +98,14 @@ static int32_t CommandIFunc(const char *key, const char *value, HostConfig *conf static int32_t CommandNFunc(const char *key, const char *value, HostConfig *config) { + (void)key; config->hostName = value; return HDF_SUCCESS; } static int32_t CommandPFunc(const char *key, const char *value, HostConfig *config) { + (void)key; if (!HdfStringToInt(value, &config->processPriority)) { HDF_LOGE("Invalid process ID: %{public}s", value); } @@ -111,6 +114,7 @@ static int32_t CommandPFunc(const char *key, const char *value, HostConfig *conf static int32_t CommandSFunc(const char *key, const char *value, HostConfig *config) { + (void)key; if (!HdfStringToInt(value, &config->schedPriority)) { HDF_LOGE("Invalid process ID: %{public}s", value); } @@ -119,6 +123,7 @@ static int32_t CommandSFunc(const char *key, const char *value, HostConfig *conf static int32_t CommandMFunc(const char *key, const char *value, HostConfig *config) { + (void)key; if (!HdfStringToInt(value, &config->malloptKey)) { HDF_LOGE("Invalid process ID: %{public}s", value); } @@ -127,6 +132,7 @@ static int32_t CommandMFunc(const char *key, const char *value, HostConfig *conf static int32_t CommandVFunc(const char *key, const char *value, HostConfig *config) { + (void)key; if (!HdfStringToInt(value, &config->malloptValue)) { HDF_LOGE("Invalid process ID: %{public}s", value); } @@ -148,22 +154,22 @@ static int32_t CommandMathFunc(const char *key, const char *value, HostConfig *c } static struct CommandToFunc g_commandFuncs[] = { - {"i", CommandIFunc}, - {"n", CommandNFunc}, - {"p", CommandPFunc}, - {"s", CommandSFunc}, - {"m", CommandMFunc}, - {"v", CommandVFunc}, - {"1005", CommandMathFunc}, - {"1006", CommandMathFunc}, - {"1007", CommandMathFunc}, - {"1008", CommandMathFunc}, - {"1009", CommandMathFunc}, - {"1010", CommandMathFunc}, - {"1011", CommandMathFunc}, - {"1012", CommandMathFunc}, - {"1013", CommandMathFunc}, - {"1014", CommandMathFunc}, + {"-i", CommandIFunc}, + {"-n", CommandNFunc}, + {"-p", CommandPFunc}, + {"-s", CommandSFunc}, + {"-m", CommandMFunc}, + {"-v", CommandVFunc}, + {"-1005", CommandMathFunc}, + {"-1006", CommandMathFunc}, + {"-1007", CommandMathFunc}, + {"-1008", CommandMathFunc}, + {"-1009", CommandMathFunc}, + {"-1010", CommandMathFunc}, + {"-1011", CommandMathFunc}, + {"-1012", CommandMathFunc}, + {"-1013", CommandMathFunc}, + {"-1014", CommandMathFunc}, }; static void StartMemoryHook(const char* processName) @@ -230,7 +236,7 @@ static int FindFunc(const char* arg, const char* value, HostConfig *config) static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) { - for (int i = 1; i < argc; ++i) { + for (int i = 1; i < argc; i += 2) { const char* arg = argv[i]; if (arg == NULL) { @@ -238,12 +244,11 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) return HDF_ERR_INVALID_PARAM; } - int next = i + 1; if (i + 1 >= argc) { HDF_LOGE("Missing argument for -%{public}s", arg); return HDF_FAILURE; } - const char* value = argv[next]; + const char* value = argv[i]; if (FindFunc(arg, value, config) != HDF_SUCCESS) { HDF_LOGE("argument Parse failed for -%s", arg); } -- Gitee From 7a500cbeee18a690b4d6cce16bbf1f6480c8fec1 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 11:27:15 +0800 Subject: [PATCH 11/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index f64b07bfc..bc27e5451 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -244,11 +244,12 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) return HDF_ERR_INVALID_PARAM; } + int next = i + 1; if (i + 1 >= argc) { HDF_LOGE("Missing argument for -%{public}s", arg); return HDF_FAILURE; } - const char* value = argv[i]; + const char* value = argv[next]; if (FindFunc(arg, value, config) != HDF_SUCCESS) { HDF_LOGE("argument Parse failed for -%s", arg); } -- Gitee From d458bae71d7066f598a24991bb44db870d700f32 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 11:38:03 +0800 Subject: [PATCH 12/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index bc27e5451..d88e82941 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -139,7 +139,7 @@ static int32_t CommandVFunc(const char *key, const char *value, HostConfig *conf return HDF_SUCCESS; } -static int32_t CommandMathFunc(const char *key, const char *value, HostConfig *config) +static int32_t CommandNumFunc(const char *key, const char *value, HostConfig *config) { int32_t malloptKey = 0; int32_t malloptValue = 0; @@ -160,16 +160,16 @@ static struct CommandToFunc g_commandFuncs[] = { {"-s", CommandSFunc}, {"-m", CommandMFunc}, {"-v", CommandVFunc}, - {"-1005", CommandMathFunc}, - {"-1006", CommandMathFunc}, - {"-1007", CommandMathFunc}, - {"-1008", CommandMathFunc}, - {"-1009", CommandMathFunc}, - {"-1010", CommandMathFunc}, - {"-1011", CommandMathFunc}, - {"-1012", CommandMathFunc}, - {"-1013", CommandMathFunc}, - {"-1014", CommandMathFunc}, + {"-1005", CommandNumFunc}, + {"-1006", CommandNumFunc}, + {"-1007", CommandNumFunc}, + {"-1008", CommandNumFunc}, + {"-1009", CommandNumFunc}, + {"-1010", CommandNumFunc}, + {"-1011", CommandNumFunc}, + {"-1012", CommandNumFunc}, + {"-1013", CommandNumFunc}, + {"-1014", CommandNumFunc}, }; static void StartMemoryHook(const char* processName) @@ -225,7 +225,7 @@ static void HdfSetProcPriority(int32_t procPriority, int32_t schedPriority) static int FindFunc(const char* arg, const char* value, HostConfig *config) { - for (size_t i = 0; i < sizeof(g_commandFuncs) / sizeof(g_commandFuncs[i]); ++i) { + for (size_t i = 0; i < sizeof(g_commandFuncs) / sizeof(g_commandFuncs[0]); ++i) { if (strcmp(g_commandFuncs[i].opt, arg) == 0) { return g_commandFuncs[i].func(arg, value, config); } @@ -244,12 +244,12 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) return HDF_ERR_INVALID_PARAM; } - int next = i + 1; + int valueIndex = i + 1; if (i + 1 >= argc) { HDF_LOGE("Missing argument for -%{public}s", arg); return HDF_FAILURE; } - const char* value = argv[next]; + const char* value = argv[valueIndex]; if (FindFunc(arg, value, config) != HDF_SUCCESS) { HDF_LOGE("argument Parse failed for -%s", arg); } -- Gitee From 0f8a8405268e22ce5466af286c976af7b7a2d979 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 11:42:26 +0800 Subject: [PATCH 13/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index d88e82941..3416a80e8 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -240,16 +240,20 @@ static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) const char* arg = argv[i]; if (arg == NULL) { - HDF_LOGE("NULL argument"); - return HDF_ERR_INVALID_PARAM; + HDF_LOGE("NULL argument:arg"); + continue; } int valueIndex = i + 1; - if (i + 1 >= argc) { + if (valueIndex >= argc) { HDF_LOGE("Missing argument for -%{public}s", arg); - return HDF_FAILURE; + continue; } const char* value = argv[valueIndex]; + if (value == NULL) { + HDF_LOGE("NULL argument: value"); + continue; + } if (FindFunc(arg, value, config) != HDF_SUCCESS) { HDF_LOGE("argument Parse failed for -%s", arg); } -- Gitee From 8dc2bcec99f4e94ebde28a17904fe6d6e227cc45 Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 8 Aug 2025 12:01:24 +0800 Subject: [PATCH 14/14] =?UTF-8?q?devhost=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- adapter/uhdf2/host/devhost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 3416a80e8..9dcd4e45a 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -41,6 +41,7 @@ #define PARAM_BUF_LEN 128 #define MALLOPT_PARA_CNT 2 #define INVALID_PRIORITY "0" +#define DEVHOST_ARGUMENT 2 typedef struct { int hostId; @@ -236,7 +237,7 @@ static int FindFunc(const char* arg, const char* value, HostConfig *config) static int ParseCommandLineArgs(int argc, char **argv, HostConfig *config) { - for (int i = 1; i < argc; i += 2) { + for (int i = 1; i < argc; i += DEVHOST_ARGUMENT) { const char* arg = argv[i]; if (arg == NULL) { -- Gitee