From e54808fe0e342f6a7ce7bfb9e06113ebb7034e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyipeng=E2=80=9D?= Date: Tue, 18 Oct 2022 22:05:32 +0800 Subject: [PATCH 01/60] fixed c308e06 from https://gitee.com/wang-yi-peng/drivers_framework/pulls/1478 Fix:repair USB test case failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyipeng” --- .../liteos/model/usb/host/src/usb_pnp_notify.c | 4 ---- framework/model/usb/src/usb_ddk_pnp_loader.c | 4 ---- .../usb/device/src/usb_device_lite_cdcacm_test.c | 3 ++- .../usb/device/src/usb_device_lite_sdk_if_test.c | 15 +++++++++------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 1dfc095f9..2d74f89e8 100644 --- a/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -550,10 +550,6 @@ static int32_t UsbPnpNotifyFirstReportDevice(struct HdfDeviceIoClient *client) OsalMutexLock(&g_usbPnpNotifyDevicelistLock); DLIST_FOR_EACH_ENTRY_SAFE( pnpNotifyDevicePos, pnpNotifyDeviceTemp, &g_usbPnpDeviceListHead, struct UsbPnpNotifyDeviceList, deviceList) { - if (pnpNotifyDevicePos == NULL) { - HDF_LOGE("%{public}s:%{public}d pnpNotifyDevicePos is null", __func__, __LINE__); - return HDF_FAILURE; - } int32_t ret = UsbPnpNotifyHdfSendEvent(client->device, pnpNotifyDevicePos->device); if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s:%{public}d UsbPnpNotifyHdfSendEvent failed, ret=%{public}d", __func__, __LINE__, ret); diff --git a/framework/model/usb/src/usb_ddk_pnp_loader.c b/framework/model/usb/src/usb_ddk_pnp_loader.c index 5fa4c507c..551766e46 100644 --- a/framework/model/usb/src/usb_ddk_pnp_loader.c +++ b/framework/model/usb/src/usb_ddk_pnp_loader.c @@ -739,10 +739,6 @@ static struct UsbPnpDeviceListTable *UsbDdkPnpLoaderAddInterface( struct UsbPnpDeviceListTable *deviceListTableTemp = NULL; DLIST_FOR_EACH_ENTRY_SAFE( deviceListTablePos, deviceListTableTemp, &g_usbPnpDeviceTableListHead, struct UsbPnpDeviceListTable, list) { - if (deviceListTablePos == NULL) { - HDF_LOGE("deviceListTablePos is null"); - return NULL; - } if ((strcmp(deviceListTablePos->moduleName, idTable->moduleName) == 0) && (strcmp(deviceListTablePos->serviceName, idTable->serviceName) == 0) && (strcmp(deviceListTablePos->deviceMatchAttr, idTable->deviceMatchAttr) == 0) && diff --git a/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c b/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c index 31225bb12..1b1312bd3 100644 --- a/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c +++ b/framework/test/unittest/model/usb/device/src/usb_device_lite_cdcacm_test.c @@ -329,7 +329,8 @@ static void ParsePipes(struct AcmDevice *acmDevice, const struct UsbFnInterface { struct UsbFnPipeInfo pipeInfo = {0}; for (uint32_t j = 0; j < fnIface->info.numPipes; j++) { - if (UsbFnGetInterfacePipeInfo((struct UsbFnInterface *)fnIface, j, &pipeInfo) != HDF_SUCCESS) { + int32_t ret = UsbFnGetInterfacePipeInfo((struct UsbFnInterface *)fnIface, j, &pipeInfo); + if (ret != HDF_SUCCESS) { return; } if (pipeInfo.type == USB_PIPE_TYPE_INTERRUPT) { diff --git a/framework/test/unittest/model/usb/device/src/usb_device_lite_sdk_if_test.c b/framework/test/unittest/model/usb/device/src/usb_device_lite_sdk_if_test.c index 936d1072d..f58d9c841 100644 --- a/framework/test/unittest/model/usb/device/src/usb_device_lite_sdk_if_test.c +++ b/framework/test/unittest/model/usb/device/src/usb_device_lite_sdk_if_test.c @@ -189,8 +189,8 @@ int32_t UsbFnDviceTestGetDevice(void) const struct UsbFnDevice *device = NULL; const char *udcName = "100e0000.hidwc3_0"; device = UsbFnGetDevice(udcName); - if (device != NULL) { - HDF_LOGE("%s: get device success!!", __func__); + if (device == NULL) { + HDF_LOGE("%s: get device failed", __func__); return HDF_FAILURE; } return HDF_SUCCESS; @@ -878,6 +878,7 @@ int32_t UsbFnDviceTestAllocCtrlRequest004(void) return HDF_FAILURE; } + // 0x801: Represents the length of the requested data, testing greater than 2048. struct UsbFnRequest *req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0x801); if (req == NULL) { HDF_LOGE("%s: alloc req failed", __func__); @@ -921,6 +922,7 @@ int32_t UsbFnDviceTestAllocCtrlRequest006(void) return HDF_FAILURE; } + // 0x800: Represents the length of the requested data, testing equal to 2048. struct UsbFnRequest *req = UsbFnAllocCtrlRequest(g_acmDevice->ctrlIface.handle, 0x800); if (req == NULL) { HDF_LOGE("%s: alloc req fail", __func__); @@ -1300,7 +1302,7 @@ int32_t UsbFnDviceTestGetRequestStatus(void) return HDF_FAILURE; } - UsbRequestStatus status; + UsbRequestStatus status = 0; int32_t ret = UsbFnGetRequestStatus(notifyReq, &status); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: get status error", __func__); @@ -1332,7 +1334,7 @@ int32_t UsbFnDviceTestGetRequestStatus002(void) return HDF_FAILURE; } - UsbRequestStatus status; + UsbRequestStatus status = 0; int32_t ret = UsbFnGetRequestStatus(notifyReq, &status); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: get status error", __func__); @@ -1392,7 +1394,7 @@ int32_t UsbFnDviceTestGetRequestStatus004(void) return HDF_FAILURE; } - UsbRequestStatus status; + UsbRequestStatus status = 0; int32_t ret = UsbFnSubmitRequestAsync(notifyReq); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: get status error", __func__); @@ -1417,7 +1419,7 @@ int32_t UsbFnDviceTestGetRequestStatus004(void) int32_t UsbFnDviceTestGetRequestStatus005(void) { - UsbRequestStatus status; + UsbRequestStatus status = 0; struct UsbFnRequest *notifyReq = NULL; int32_t ret = UsbFnGetRequestStatus(notifyReq, &status); if (ret == HDF_SUCCESS) { @@ -1507,6 +1509,7 @@ int32_t UsbFnDviceTestStartReceEvent(void) return HDF_FAILURE; } + // 0xff: Represents the type of event to handle and can receive all events. int32_t ret = UsbFnStartRecvInterfaceEvent(g_acmDevice->ctrlIface.fn, 0xff, NULL, g_acmDevice); if (ret == HDF_SUCCESS) { HDF_LOGE("%s: start receive event success!!", __func__); -- Gitee From 48690a3730635241e009cbf189b3dfdde139b7da Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Thu, 20 Oct 2022 18:00:21 +0800 Subject: [PATCH 02/60] fixed 9f408a9 from https://gitee.com/chenpan0560/drivers_hdf_core_temp/pulls/1485 fix:mk_file_add_config.py file alarm modification Signed-off-by: chenpan0560 --- framework/tools/hc-gen/src/ast.cpp | 2 +- framework/tools/hc-gen/src/ast.h | 2 +- .../driver_add/linux/mk_file_add_config.py | 34 ++++++++++++------- .../hdf_dev_eco_tool/resources/settings.json | 4 +-- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/framework/tools/hc-gen/src/ast.cpp b/framework/tools/hc-gen/src/ast.cpp index 36a5c822b..2617274cd 100644 --- a/framework/tools/hc-gen/src/ast.cpp +++ b/framework/tools/hc-gen/src/ast.cpp @@ -723,7 +723,7 @@ ConfigTerm::ConfigTerm(const ConfigTerm &term) : ConfigTerm(term.name_, nullptr) lineno_ = term.lineno_; } -ConfigTerm::ConfigTerm(std::string name, const std::shared_ptr &value) +ConfigTerm::ConfigTerm(const std::string &name, const std::shared_ptr &value) : AstObject(name, PARSEROP_CONFTERM, 0), signNum_(0) { if (value != nullptr) { diff --git a/framework/tools/hc-gen/src/ast.h b/framework/tools/hc-gen/src/ast.h index 0a166dc28..acc944ac9 100644 --- a/framework/tools/hc-gen/src/ast.h +++ b/framework/tools/hc-gen/src/ast.h @@ -214,7 +214,7 @@ class ConfigTerm : public AstObject { public: ConfigTerm(const ConfigTerm &term); - ConfigTerm(std::string name, const std::shared_ptr &value); + ConfigTerm(const std::string &name, const std::shared_ptr &value); ConfigTerm(Token &name, const std::shared_ptr &value); diff --git a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py index 70fdcb81f..2f069becc 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/linux/mk_file_add_config.py @@ -35,13 +35,7 @@ def find_makefile_file_end_index(date_lines, model_name): return result_tuple -def audio_linux_makefile_operation(path, args_tuple): - source_path, head_path, module, driver, root, devices = args_tuple - makefile_gn_path = path - date_lines = hdf_utils.read_file_lines(makefile_gn_path) - judge_result = judge_driver_config_exists(date_lines, driver_name=driver) - if judge_result: - return +def formate_mk_config_build(source_path, date_lines, devices, root): if len(source_path) > 1: sources_line = "" obj_first_line = "\nobj-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\" + "\n" @@ -51,15 +45,18 @@ def audio_linux_makefile_operation(path, args_tuple): temp_dict = analyze_parent_path( date_lines, source, "", devices, root) try: - temp_dict['source_path'] = temp_dict.get('source_path').strip(".c") + temp_dict['source_path'] = temp_dict.get( + 'source_path').strip(".c") except KeyError as _: continue finally: pass if source == source_path[-1]: - sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + "\n" + sources_line += temp_handle.substitute( + temp_dict).replace("temp_flag", "$(") + "\n" else: - sources_line += temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + " \\" + "\n" + sources_line += temp_handle.substitute( + temp_dict).replace("temp_flag", "$(") + " \\" + "\n" build_resource = obj_first_line + sources_line else: build_resource = "LOCAL_SRCS += $(${file_parent_path})/${source_path}\n" @@ -68,6 +65,17 @@ def audio_linux_makefile_operation(path, args_tuple): temp_dict = analyze_parent_path( date_lines, source, "", devices, root) build_resource = temp_handle.substitute(temp_dict).replace("temp_flag", "$(") + return build_resource + + +def audio_linux_makefile_operation(path, args_tuple): + source_path, head_path, module, driver, root, devices = args_tuple + makefile_gn_path = path + date_lines = hdf_utils.read_file_lines(makefile_gn_path) + judge_result = judge_driver_config_exists(date_lines, driver_name=driver) + if judge_result: + return + build_resource = formate_mk_config_build(source_path, date_lines, devices, root) head_line = [] ccflags_first_line = "\nccflags-$(CONFIG_DRIVERS_HDF_${model_name_upper}_${driver_name_upper}) += \\" + "\n" temp_line = "\t\t\t\t-I$(srctree)/$(${file_parent_path})/${head_path}" @@ -76,9 +84,11 @@ def audio_linux_makefile_operation(path, args_tuple): temp_dict = analyze_parent_path( date_lines, "", head_file, devices, root) if head_file == head_path[-1]: - temp_str = "".join([temp_handle.substitute(temp_dict).replace("temp_flag", "$("), "\n"]) + temp_str = "".join([temp_handle.substitute( + temp_dict).replace("temp_flag", "$("), "\n"]) else: - temp_str = "".join([temp_handle.substitute(temp_dict).replace("temp_flag", "$("), " \\", "\n"]) + temp_str = "".join([temp_handle.substitute( + temp_dict).replace("temp_flag", "$("), " \\", "\n"]) head_line.append(temp_str) build_head = ccflags_first_line + "".join(head_line) makefile_add_template = build_resource + build_head diff --git a/framework/tools/hdf_dev_eco_tool/resources/settings.json b/framework/tools/hdf_dev_eco_tool/resources/settings.json index 8a30f969b..e9f889720 100644 --- a/framework/tools/hdf_dev_eco_tool/resources/settings.json +++ b/framework/tools/hdf_dev_eco_tool/resources/settings.json @@ -34,11 +34,11 @@ "passwd_group_config": { "passwd": { "path": "base/startup/init/services/etc/passwd", - "info_temp": "${peripheral_name}_host:x:${uid}:${uid}:::/bin/false\n" + "info_temp": "{peripheral_name}_host:x:{uid}:{uid}:::/bin/false\n" }, "group": { "path": "base/startup/init/services/etc/group", - "info_temp": "${peripheral_name}_host:x:${gid}:\n" + "info_temp": "{peripheral_name}_host:x:{gid}:\n" } }, "drivers_path_relative_framework": "drivers/hdf_core/framework", -- Gitee From e00999df5ae6334c139b315334f181bb6a9d15c3 Mon Sep 17 00:00:00 2001 From: jiaziyangnewer Date: Fri, 21 Oct 2022 16:49:51 +0800 Subject: [PATCH 03/60] fix:Cancel use of reserved identifiers Signed-off-by: jiaziyangnewer --- adapter/khdf/linux/platform/uart/uart_adapter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/khdf/linux/platform/uart/uart_adapter.c b/adapter/khdf/linux/platform/uart/uart_adapter.c index 0d3b27f7d..ce0b8d807 100644 --- a/adapter/khdf/linux/platform/uart/uart_adapter.c +++ b/adapter/khdf/linux/platform/uart/uart_adapter.c @@ -83,7 +83,7 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si loff_t pos = 0; int ret; struct file *fp = NULL; - char __user *p = (__force char __user *)data; + char *p = (char *)data; mm_segment_t oldfs; uint32_t tmp = 0; @@ -111,7 +111,7 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s loff_t pos = 0; int ret; struct file *fp = NULL; - char __user *p = (__force char __user *)data; + char *p = (char *)data; mm_segment_t oldfs; if (host == NULL || host->priv == NULL || data == NULL || size == 0) { -- Gitee From 8b73c53fca98e0c31836e9b8b09bef32882f1fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cguodongqi=E2=80=9D?= Date: Fri, 21 Oct 2022 15:21:47 +0800 Subject: [PATCH 04/60] fixed 3ddad33 from https://gitee.com/guo-dongqi/drivers_hdf_core/pulls/1488 fix: clear driver tools warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “guodongqi” --- adapter/uhdf2/hdi/src/object_collector.cpp | 2 +- .../test/unittest/utils/hcs_parser/unittest/hcs_config_test.c | 2 +- framework/tools/hc-gen/src/ast.h | 1 - framework/tools/hc-gen/src/token.h | 2 -- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/adapter/uhdf2/hdi/src/object_collector.cpp b/adapter/uhdf2/hdi/src/object_collector.cpp index 7ac795c1a..78a9ac71d 100644 --- a/adapter/uhdf2/hdi/src/object_collector.cpp +++ b/adapter/uhdf2/hdi/src/object_collector.cpp @@ -35,7 +35,7 @@ bool ObjectCollector::ConstructorRegister(const std::u16string &interfaceName, c return false; } std::lock_guard lock(mutex_); - constructorMapper_.insert({interfaceName, std::move(constructor)}); + constructorMapper_.emplace(interfaceName, std::move(constructor)); return true; } diff --git a/framework/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c b/framework/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c index 107cfc405..2261bb258 100644 --- a/framework/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c +++ b/framework/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c @@ -447,7 +447,7 @@ int HcsTestGetUint16ArrayElemSuccess(void) uint16_t data[DATA_TEST_ARRAY_LENGTH] = { 0 }; // the test data is 0, 1, 2, 3, 4, 5, 256, 257. const uint16_t testData[DATA_TEST_ARRAY_LENGTH] = { TEST_DATA_ZERO, TEST_DATA_ONE, TEST_DATA_TWO, TEST_DATA_THREE, - TEST_DATA_FOUR, TEST_DATA_FIVE, TEST_DATA_256, TEST_DATA_257 }; + TEST_DATA_FOUR, TEST_DATA_FIVE, TEST_DATA_256, TEST_DATA_257 }; int32_t i; int32_t count; if (!TestGetRootNode()) { diff --git a/framework/tools/hc-gen/src/ast.h b/framework/tools/hc-gen/src/ast.h index 0a166dc28..6706bf793 100644 --- a/framework/tools/hc-gen/src/ast.h +++ b/framework/tools/hc-gen/src/ast.h @@ -452,7 +452,6 @@ private: std::ostream &operator<<(std::ostream &stream, const AstObject &t); std::ostream &operator<<(std::ostream &stream, const ConfigNode &t); std::ostream &operator<<(std::ostream &stream, const ConfigTerm &t); - } // namespace Hardware } // namespace OHOS diff --git a/framework/tools/hc-gen/src/token.h b/framework/tools/hc-gen/src/token.h index 47b5b6083..9ccf2ed88 100644 --- a/framework/tools/hc-gen/src/token.h +++ b/framework/tools/hc-gen/src/token.h @@ -44,9 +44,7 @@ struct Token { }; std::ostream &operator<<(std::ostream &stream, const Token &token); - std::string TokenType2String(int32_t type); - } // namespace Hardware } // namespace OHOS -- Gitee From d2bf02022a15c739a8a497b0c3b9220c3907737b Mon Sep 17 00:00:00 2001 From: wu Date: Mon, 24 Oct 2022 05:57:13 -0700 Subject: [PATCH 05/60] fixed a2bf9bd from https://gitee.com/zhiminwu123/drivers_hdf_core/pulls/1495 fix: usb alarms for hdf_core Signed-off-by: wu --- framework/model/usb/src/usb_ddk_pnp_loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/model/usb/src/usb_ddk_pnp_loader.c b/framework/model/usb/src/usb_ddk_pnp_loader.c index 551766e46..21bf81fc2 100644 --- a/framework/model/usb/src/usb_ddk_pnp_loader.c +++ b/framework/model/usb/src/usb_ddk_pnp_loader.c @@ -392,7 +392,7 @@ static int32_t UsbDdkPnpLoaderParseIdInfClass(const struct DeviceResourceNode *n return HDF_FAILURE; } if (devResIface->GetUint8Array( - node, "interfaceSubClass", table->interfaceSubClass, table->interfaceSubClassLength, 0) != HDF_SUCCESS) { + node, "interfaceSubClass", table->interfaceSubClass, table->interfaceSubClassLength, 0) != HDF_SUCCESS) { HDF_LOGE("%s: read interfaceSubClass fail!", __func__); return HDF_FAILURE; } @@ -417,7 +417,7 @@ static int32_t UsbDdkPnpLoaderParseIdInferface(const struct DeviceResourceNode * return HDF_FAILURE; } if (devResIface->GetUint8Array( - node, "interfaceProtocol", table->interfaceProtocol, table->interfaceProtocolLength, 0) != HDF_SUCCESS) { + node, "interfaceProtocol", table->interfaceProtocol, table->interfaceProtocolLength, 0) != HDF_SUCCESS) { HDF_LOGE("%s: read interfaceProtocol fail!", __func__); return HDF_FAILURE; } -- Gitee From 73e58bc1e0c99340f946c11dcb6105b1cfd7f03b Mon Sep 17 00:00:00 2001 From: jiachanglin Date: Wed, 26 Oct 2022 02:41:12 +0000 Subject: [PATCH 06/60] fixed a7445d6 from https://gitee.com/jiachanglin/drivers_hdf_core/pulls/1500 fix:modify wlan codex Signed-off-by: jiachanglin --- framework/model/network/bluetooth/hdf_reset.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/model/network/bluetooth/hdf_reset.h b/framework/model/network/bluetooth/hdf_reset.h index 9859140db..3afce5cff 100644 --- a/framework/model/network/bluetooth/hdf_reset.h +++ b/framework/model/network/bluetooth/hdf_reset.h @@ -11,6 +11,6 @@ #include "hdf_chip.h" #include "hdf_chip_config.h" -struct HdfReset *CreateVirtualReset(const struct HdfResetConfig *powers); +struct HdfReset *CreateVirtualReset(const struct HdfResetConfig *resetConfig); -#endif \ No newline at end of file +#endif -- Gitee From ae169471f023d99bb372bc39ae8f4ca20e7657d3 Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Wed, 26 Oct 2022 17:22:05 +0800 Subject: [PATCH 07/60] fix: fix thread name duplication issue in the framework on monthly branch Signed-off-by: xuxiaoqing --- adapter/uhdf2/manager/src/devmgr_uevent.c | 2 +- .../adapter/syscall/src/hdf_syscall_adapter.c | 12 +++++++++++- framework/support/posix/src/osal_thread.c | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/adapter/uhdf2/manager/src/devmgr_uevent.c b/adapter/uhdf2/manager/src/devmgr_uevent.c index 02309dfce..461dbcf45 100644 --- a/adapter/uhdf2/manager/src/devmgr_uevent.c +++ b/adapter/uhdf2/manager/src/devmgr_uevent.c @@ -555,7 +555,7 @@ int32_t DevMgrUeventReceiveStart(void) struct OsalThreadParam threadCfg; (void)memset_s(&threadCfg, sizeof(threadCfg), 0, sizeof(threadCfg)); - threadCfg.name = "DevMgrUeventThread"; + threadCfg.name = "DevMgrUevent"; threadCfg.priority = OSAL_THREAD_PRI_HIGH; threadCfg.stackSize = DEVMGR_UEVENT_STACK_SIZE; diff --git a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c index efc560add..f1228a6ed 100644 --- a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,9 @@ #define TIMEOUT_US 100000 // 100ms #define LOAD_IOSERVICE_WAIT_TIME 10 // ms #define LOAD_IOSERVICE_WAIT_COUNT 20 // ms +#define THREAD_NAME_LEN_MAX 16 + +atomic_int g_evtListenerCount = 0; static bool HaveOnlyOneElement(const struct DListHead *head) { @@ -440,9 +444,15 @@ static int32_t HdfDevListenerThreadStart(struct HdfDevListenerThread *thread) return HDF_ERR_IO; } } + char threadName[THREAD_NAME_LEN_MAX] = {0}; + ret = sprintf_s(threadName, THREAD_NAME_LEN_MAX, "%s%d", "event_listen", g_evtListenerCount++); + if (ret < 0) { + HDF_LOGE("%{public}s generate thread name failed", __func__); + return HDF_FAILURE; + } struct OsalThreadParam config = { - .name = "hdf_event_listener", + .name = threadName, .priority = OSAL_THREAD_PRI_DEFAULT, .stackSize = 0, }; diff --git a/framework/support/posix/src/osal_thread.c b/framework/support/posix/src/osal_thread.c index 4ecc88f26..37294b0e3 100644 --- a/framework/support/posix/src/osal_thread.c +++ b/framework/support/posix/src/osal_thread.c @@ -7,6 +7,7 @@ */ #include "osal_thread.h" +#include #include #include "hdf_base.h" #include "hdf_log.h" @@ -18,6 +19,7 @@ #endif #define HDF_LOG_TAG osal_thread +#define THREAD_NAME_LEN_MAX 16 typedef void *(*PosixEntry)(void *data); @@ -87,13 +89,21 @@ int32_t OsalThreadDestroy(struct OsalThread *thread) return HDF_SUCCESS; } -static int OsalCreatePthread(pthread_t *threadId, pthread_attr_t *attribute, struct ThreadWrapper *para) +static int OsalCreatePthread(pthread_t *threadId, pthread_attr_t *attribute, struct ThreadWrapper *para, char *name) { + char threadName[THREAD_NAME_LEN_MAX] = {0}; + int resultCode = pthread_create(threadId, attribute, (PosixEntry)para->threadEntry, para->entryPara); if (resultCode != 0) { HDF_LOGE("pthread_create errorno: %d", resultCode); return resultCode; } + if (name != NULL) { + resultCode = strncpy_s(threadName, THREAD_NAME_LEN_MAX, name, THREAD_NAME_LEN_MAX - 1); + if (resultCode == EOK) { + pthread_setname_np(*threadId, threadName); + } + } resultCode = pthread_detach(*threadId); if (resultCode != 0) { HDF_LOGE("pthread_detach errorno: %d", resultCode); @@ -149,7 +159,7 @@ int32_t OsalThreadStart(struct OsalThread *thread, const struct OsalThreadParam goto DEAL_FAIL; } - resultCode = OsalCreatePthread(¶->id, &attribute, thread->realThread); + resultCode = OsalCreatePthread(¶->id, &attribute, thread->realThread, param->name); if (resultCode != 0) { HDF_LOGE("OsalCreatePthread errorno: %d", resultCode); goto DEAL_FAIL; @@ -160,4 +170,3 @@ DEAL_FAIL: (void)OsalThreadDestroy(thread); return HDF_FAILURE; } - -- Gitee From 8b07472fb667f5ad245c942bbecd2208b13d6b7b Mon Sep 17 00:00:00 2001 From: yannikli Date: Tue, 18 Oct 2022 15:59:43 +0800 Subject: [PATCH 08/60] fixed e348f08 from https://gitee.com/yannikli/drivers_hdf_core/pulls/1476 Fix up service Signed-off-by: yannikli Change-Id: Ief765f245ca06437a25942edfc422e95fb866366 --- .../linux/model/usb/host/src/usb_pnp_notify.c | 46 ++++++++++++++++++- .../core/shared/include/hdf_usb_pnp_manage.h | 1 + 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c b/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c index 489fecbe7..e56e56c10 100644 --- a/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c +++ b/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c @@ -34,6 +34,9 @@ #ifndef USB_GADGET_REMOVE #define USB_GADGET_REMOVE 0x0006 #endif +#ifndef BASE_CLASS_HUB +#define BASE_CLASS_HUB 0x09 +#endif static wait_queue_head_t g_usbPnpNotifyReportWait; static wait_queue_head_t g_gadgetPnpNotifyReportWait; @@ -51,6 +54,7 @@ struct DListHead g_usbPnpInfoListHead; #if USB_PNP_NOTIFY_TEST_MODE == true struct UsbPnpNotifyMatchInfoTable *g_testUsbPnpInfo = NULL; #endif +static int32_t g_isGadgetAdd = 0; static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void) { @@ -394,6 +398,36 @@ ERROR_DEVICE_INFO: return ret; } +static int32_t UsbPnpNotifyFirstGetDevice(struct usb_device *usbDev, void *data) +{ + int32_t ret; + struct UsbPnpDeviceInfo *deviceInfo = NULL; + union UsbPnpDeviceInfoData pnpInfoData; + void *eventData = (void *)usbDev; + if (usbDev->descriptor.bDeviceClass == BASE_CLASS_HUB) { + return HDF_SUCCESS; + } + + ret = UsbPnpNotifyGetDeviceInfo(eventData, &pnpInfoData, &deviceInfo); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:%d UsbPnpNotifyGetDeviceInfo failed, ret=%d", __func__, __LINE__, ret); + return ret; + } + ret = UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:%d UsbPnpNotifyAddInitInfo failed, ret=%d", __func__, __LINE__, ret); + return ret; + } + + HDF_LOGI("%s:%d device information, %d usbDevAddr=%llu, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", + __func__, __LINE__, USB_PNP_DRIVER_GETDEVICES, deviceInfo->info.usbDevAddr, + deviceInfo->info.devNum, deviceInfo->info.busNum, deviceInfo->info.numInfos, + deviceInfo->info.deviceInfo.vendorId, deviceInfo->info.deviceInfo.productId); + deviceInfo->status = USB_PNP_DEVICE_ADD_STATUS; + + return ret; +} + #if USB_PNP_NOTIFY_TEST_MODE == true static void TestReadPnpInfo(struct HdfSBuf *data) { @@ -655,8 +689,10 @@ static int32_t UsbPnpNotifyCallback(struct notifier_block *self, unsigned long a break; } if (action == USB_GADGET_ADD) { + g_isGadgetAdd = 1; g_gadgetPnpNotifyType = USB_PNP_DRIVER_GADGET_ADD; } else { + g_isGadgetAdd = 0; g_gadgetPnpNotifyType = USB_PNP_DRIVER_GADGET_REMOVE; } OsalMutexUnlock(&g_gadgetSendEventLock); @@ -745,11 +781,12 @@ static int32_t UsbPnpNotifyDispatch( struct HdfDeviceIoClient *client, int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t ret = HDF_SUCCESS; + static int32_t isFirstGetDevice = 0; HDF_LOGI("%s: received cmd = %d", __func__, cmd); OsalMutexLock(&g_usbSendEventLock); - if (USB_PNP_DRIVER_GETDEVICES != cmd) { + if (USB_PNP_DRIVER_GETDEVICES != cmd || USB_PNP_DRIVER_GET_GADGET_LINK_STATUS != cmd) { g_usbPnpNotifyCmdType = cmd; } @@ -778,8 +815,15 @@ static int32_t UsbPnpNotifyDispatch( break; #endif case USB_PNP_DRIVER_GETDEVICES: + if (isFirstGetDevice == 0) { + usb_for_each_dev(NULL, UsbPnpNotifyFirstGetDevice); + isFirstGetDevice = 1; + } UsbPnpGetDevices(reply); break; + case USB_PNP_DRIVER_GET_GADGET_LINK_STATUS: + HdfSbufWriteInt32(reply, g_isGadgetAdd); + break; default: ret = HDF_ERR_NOT_SUPPORT; break; diff --git a/framework/core/shared/include/hdf_usb_pnp_manage.h b/framework/core/shared/include/hdf_usb_pnp_manage.h index d68f76fe2..0f0c811d1 100644 --- a/framework/core/shared/include/hdf_usb_pnp_manage.h +++ b/framework/core/shared/include/hdf_usb_pnp_manage.h @@ -31,6 +31,7 @@ enum UsbPnpNotifyServiceCmd { USB_PNP_DRIVER_GADGET_REMOVE, USB_PNP_DRIVER_PORT_HOST = 40, USB_PNP_DRIVER_PORT_DEVICE, + USB_PNP_DRIVER_GET_GADGET_LINK_STATUS, }; enum UsbPnpNotifyRemoveType { -- Gitee From d29f6adfe819156233308cb73d7b6af0e4177cf5 Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Sat, 29 Oct 2022 16:09:06 +0800 Subject: [PATCH 09/60] fixed f4ebae8 from https://gitee.com/xuxiaoqing16/threadPRmonthly/pulls/1511 fix: fix the cppcheck of the framework Signed-off-by: xuxiaoqing --- framework/support/posix/src/osal_thread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework/support/posix/src/osal_thread.c b/framework/support/posix/src/osal_thread.c index 37294b0e3..2ccf0d2ab 100644 --- a/framework/support/posix/src/osal_thread.c +++ b/framework/support/posix/src/osal_thread.c @@ -91,14 +91,13 @@ int32_t OsalThreadDestroy(struct OsalThread *thread) static int OsalCreatePthread(pthread_t *threadId, pthread_attr_t *attribute, struct ThreadWrapper *para, char *name) { - char threadName[THREAD_NAME_LEN_MAX] = {0}; - int resultCode = pthread_create(threadId, attribute, (PosixEntry)para->threadEntry, para->entryPara); if (resultCode != 0) { HDF_LOGE("pthread_create errorno: %d", resultCode); return resultCode; } if (name != NULL) { + char threadName[THREAD_NAME_LEN_MAX] = {0}; resultCode = strncpy_s(threadName, THREAD_NAME_LEN_MAX, name, THREAD_NAME_LEN_MAX - 1); if (resultCode == EOK) { pthread_setname_np(*threadId, threadName); -- Gitee From 48e98fa762c0e7a3e2a9f14131cae056f7098ae0 Mon Sep 17 00:00:00 2001 From: jiaziyangnewer Date: Mon, 31 Oct 2022 11:15:50 +0800 Subject: [PATCH 10/60] fix:Fix inconsistency between file declaration and function Signed-off-by: jiaziyangnewer --- .../khdf/liteos/platform/include/gpio_dev.h | 2 +- .../support/platform/include/dma/dmac_core.h | 24 +++++++++---------- .../support/platform/src/dma/dmac_core.c | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/adapter/khdf/liteos/platform/include/gpio_dev.h b/adapter/khdf/liteos/platform/include/gpio_dev.h index 457b9f43d..1b2c4b82d 100644 --- a/adapter/khdf/liteos/platform/include/gpio_dev.h +++ b/adapter/khdf/liteos/platform/include/gpio_dev.h @@ -56,7 +56,7 @@ typedef struct GpioBitInfo { unsigned char irqEnable; #define GPIO_IRQ_ENABLE 1 #define GPIO_IRQ_DISABLE 0 - irqFunc irqHandler; + irqFunc irqHandler; unsigned int irqType; #define IRQ_TYPE_NONE 0x00000000 #define IRQ_TYPE_EDGE_RISING 0x00000001 diff --git a/framework/support/platform/include/dma/dmac_core.h b/framework/support/platform/include/dma/dmac_core.h index 9c42a1b69..42018816e 100644 --- a/framework/support/platform/include/dma/dmac_core.h +++ b/framework/support/platform/include/dma/dmac_core.h @@ -152,50 +152,50 @@ struct DmaCntlr { }; #ifdef LOSCFG_DRIVERS_HDF_PLATFORM_DMAC -struct DmaCntlr *DmaCntlrCreate(const struct HdfDeviceObject *dev); +struct DmaCntlr *DmaCntlrCreate(struct HdfDeviceObject *dev); -void DmaCntlrDestroy(const struct DmaCntlr *cntlr); +void DmaCntlrDestroy(struct DmaCntlr *cntlr); -int32_t DmacCntlrAdd(const struct DmaCntlr *cntlr); +int32_t DmacCntlrAdd(struct DmaCntlr *cntlr); -void DmacCntlrRemove(const struct DmaCntlr *cntlr); +void DmacCntlrRemove(struct DmaCntlr *cntlr); -int32_t DmaCntlrTransfer(const struct DmaCntlr *cntlr, const struct DmacMsg *msg); +int32_t DmaCntlrTransfer(struct DmaCntlr *cntlr, struct DmacMsg *msg); -uintptr_t DmaGetCurrChanDestAddr(const struct DmaCntlr *cntlr, uint16_t chan); +uintptr_t DmaGetCurrChanDestAddr(struct DmaCntlr *cntlr, uint16_t chan); #else -static inline struct DmaCntlr *DmaCntlrCreate(const struct HdfDeviceObject *dev) +static inline struct DmaCntlr *DmaCntlrCreate(struct HdfDeviceObject *dev) { (void)dev; return NULL; } -static inline void DmaCntlrDestroy(const struct DmaCntlr *cntlr) +static inline void DmaCntlrDestroy(struct DmaCntlr *cntlr) { (void)cntlr; return; } -static inline int32_t DmacCntlrAdd(const struct DmaCntlr *cntlr) +static inline int32_t DmacCntlrAdd(struct DmaCntlr *cntlr) { (void)cntlr; return HDF_ERR_NOT_SUPPORT; } -static inline void DmacCntlrRemove(const struct DmaCntlr *cntlr) +static inline void DmacCntlrRemove(struct DmaCntlr *cntlr) { (void)cntlr; return; } -static inline int32_t DmaCntlrTransfer(const struct DmaCntlr *cntlr, const struct DmacMsg *msg) +static inline int32_t DmaCntlrTransfer(struct DmaCntlr *cntlr, struct DmacMsg *msg) { (void)cntlr; (void)msg; return HDF_ERR_NOT_SUPPORT; } -static inline uintptr_t DmaGetCurrChanDestAddr(const struct DmaCntlr *cntlr, uint16_t chan) +static inline uintptr_t DmaGetCurrChanDestAddr(struct DmaCntlr *cntlr, uint16_t chan) { (void)cntlr; (void)chan; diff --git a/framework/support/platform/src/dma/dmac_core.c b/framework/support/platform/src/dma/dmac_core.c index 2942896be..58698ede6 100644 --- a/framework/support/platform/src/dma/dmac_core.c +++ b/framework/support/platform/src/dma/dmac_core.c @@ -110,7 +110,7 @@ static int32_t DmacCntlrCheck(struct DmaCntlr *cntlr) return HDF_SUCCESS; } -struct DmaCntlr *DmaCntlrCreate(const struct HdfDeviceObject *device) +struct DmaCntlr *DmaCntlrCreate(struct HdfDeviceObject *device) { struct DmaCntlr *cntlr = NULL; -- Gitee From 5a61c5d079b9c6cd22e2286e7b89deef199b1c20 Mon Sep 17 00:00:00 2001 From: yueyan Date: Mon, 17 Oct 2022 18:07:37 +0800 Subject: [PATCH 11/60] fixed c0e7f63 from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1474 fix:add Euqal member method of hdi object Signed-off-by: yueyan --- adapter/uhdf2/include/hdi/hdi_base.h | 5 ++++ .../tools/hdi-gen/ast/ast_array_type.cpp | 5 +++- .../codegen/c_client_proxy_code_emitter.cpp | 24 ++++++++++++++++++- .../codegen/c_client_proxy_code_emitter.h | 2 ++ .../codegen/c_interface_code_emitter.cpp | 15 ++++++++++-- .../codegen/c_interface_code_emitter.h | 2 ++ .../codegen/c_service_impl_code_emitter.cpp | 18 ++++++++++++-- .../codegen/c_service_impl_code_emitter.h | 2 ++ .../codegen/cpp_client_proxy_code_emitter.cpp | 15 ++++++++++++ .../codegen/cpp_client_proxy_code_emitter.h | 2 ++ 10 files changed, 84 insertions(+), 6 deletions(-) diff --git a/adapter/uhdf2/include/hdi/hdi_base.h b/adapter/uhdf2/include/hdi/hdi_base.h index c896db2f5..ce6324d27 100644 --- a/adapter/uhdf2/include/hdi/hdi_base.h +++ b/adapter/uhdf2/include/hdi/hdi_base.h @@ -25,6 +25,11 @@ class HdiBase : virtual public OHOS::RefBase { public: HdiBase() = default; virtual ~HdiBase() = default; + + inline virtual bool Equal(const sptr &other) + { + return this == other.GetRefPtr(); + } }; #define DECLARE_HDI_DESCRIPTOR(DESCRIPTOR) \ diff --git a/framework/tools/hdi-gen/ast/ast_array_type.cpp b/framework/tools/hdi-gen/ast/ast_array_type.cpp index 84b502f3c..1756f68d3 100644 --- a/framework/tools/hdi-gen/ast/ast_array_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_array_type.cpp @@ -514,7 +514,10 @@ void ASTArrayType::EmitMemoryRecycle( return false; } - return elementType_->IsStringType() ? true : false; + if (elementType_->IsStructType() || elementType_->IsStringType()) { + return true; + } + return false; }; if (elementTypeNeedFree()) { if (Options::GetInstance().DoGenerateKernelCode()) { diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp index e17089cc4..ae62f7162 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp @@ -264,6 +264,8 @@ void CClientProxyCodeEmitter::EmitProxyMethodImpls(StringBuilder &sb) if (!isKernelCode_) { sb.Append("\n"); EmitProxyAsObjectMethodImpl(sb); + sb.Append("\n"); + EmitProxyObjectEqualMethodImpl(sb); } } @@ -462,6 +464,25 @@ void CClientProxyCodeEmitter::EmitProxyAsObjectMethodImpl(StringBuilder &sb) sb.Append("}\n"); } +void CClientProxyCodeEmitter::EmitProxyObjectEqualMethodImpl(StringBuilder &sb) +{ + sb.AppendFormat("static bool %sEqual(struct %s *self, struct %s *other)\n", proxyName_.c_str(), + interfaceName_.c_str(), interfaceName_.c_str()); + sb.Append("{\n"); + sb.Append(TAB).Append("if (self == NULL || other == NULL) {\n"); + sb.Append(TAB).Append(TAB).Append("return false;\n"); + sb.Append(TAB).Append("}\n\n"); + sb.Append(TAB).AppendFormat("struct %s *selfProxy = CONTAINER_OF(self, struct %s, impl);\n", + proxyName_.c_str(), proxyName_.c_str()); + sb.Append(TAB).AppendFormat("struct %s *otherProxy = CONTAINER_OF(other, struct %s, impl);\n", + proxyName_.c_str(), proxyName_.c_str()); + sb.Append(TAB).Append("if (selfProxy->remote == NULL || otherProxy->remote == NULL) {\n"); + sb.Append(TAB).Append(TAB).Append("return false;\n"); + sb.Append(TAB).Append("}\n"); + sb.Append(TAB).Append("return selfProxy->remote->index == otherProxy->remote->index;\n"); + sb.Append("}\n"); +} + void CClientProxyCodeEmitter::EmitProxyConstruction(StringBuilder &sb) { std::string objName = "impl"; @@ -480,7 +501,8 @@ void CClientProxyCodeEmitter::EmitProxyConstruction(StringBuilder &sb) baseName_.c_str(), getVerMethod->GetName().c_str()); if (!isKernelCode_) { - sb.Append(TAB).AppendFormat("%s->AsObject = %sProxyAsObject;\n", objName.c_str(), baseName_.c_str()); + sb.Append(TAB).AppendFormat("%s->AsObject = %sAsObject;\n", objName.c_str(), proxyName_.c_str()); + sb.Append(TAB).AppendFormat("%s->Equal = %sEqual;\n", objName.c_str(), proxyName_.c_str()); } sb.Append("}\n"); diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h index cd3c4bbb2..20fa47595 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h @@ -70,6 +70,8 @@ private: void EmitProxyAsObjectMethodImpl(StringBuilder &sb); + void EmitProxyObjectEqualMethodImpl(StringBuilder &sb); + void EmitProxyConstruction(StringBuilder &); void EmitProxyExternalMethodImpl(StringBuilder &sb); diff --git a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp index f9579c659..e00e6488f 100644 --- a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp @@ -130,9 +130,14 @@ void CInterfaceCodeEmitter::EmitInterfaceMethods(StringBuilder &sb, const std::s } EmitInterfaceMethod(interface_->GetVersionMethod(), sb, prefix); - if (!isKernelCode_ && !Options::GetInstance().DoPassthrough()) { + if (!isKernelCode_) { + if (!Options::GetInstance().DoPassthrough()) { + sb.Append("\n"); + EmitAsObjectMethod(sb, TAB); + } + sb.Append("\n"); - EmitAsObjectMethod(sb, TAB); + EmitObjectEqualMethod(sb, TAB); } } @@ -165,6 +170,12 @@ void CInterfaceCodeEmitter::EmitAsObjectMethod(StringBuilder &sb, const std::str sb.Append(prefix).AppendFormat("struct HdfRemoteService* (*AsObject)(struct %s *self);\n", interfaceName_.c_str()); } +void CInterfaceCodeEmitter::EmitObjectEqualMethod(StringBuilder &sb, const std::string &prefix) +{ + sb.Append(prefix).AppendFormat("bool (*Equal)(struct %s *self, struct %s *other);\n", + interfaceName_.c_str(), interfaceName_.c_str()); +} + void CInterfaceCodeEmitter::EmitExternalMethod(StringBuilder &sb) { if (Options::GetInstance().DoPassthrough() && interface_->IsSerializable()) { diff --git a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h index a84e0ba29..0e823a190 100644 --- a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h @@ -46,6 +46,8 @@ private: void EmitAsObjectMethod(StringBuilder &sb, const std::string &prefix); + void EmitObjectEqualMethod(StringBuilder &sb, const std::string &prefix); + void EmitExternalMethod(StringBuilder &sb); void EmitInterfaceGetMethodDecl(StringBuilder &sb); diff --git a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp index 3f749f476..9795277d4 100644 --- a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp @@ -179,6 +179,8 @@ void CServiceImplCodeEmitter::EmitServiceImplMethodImpls(StringBuilder &sb, cons sb.Append("\n"); EmitServiceImplGetVersionMethod(sb, prefix); + sb.Append("\n"); + EmitServiceImplEqualMethod(sb, prefix); } void CServiceImplCodeEmitter::EmitServiceImplMethodImpl( @@ -231,6 +233,18 @@ void CServiceImplCodeEmitter::EmitServiceImplGetVersionMethod(StringBuilder &sb, sb.Append(prefix).Append("}\n"); } +void CServiceImplCodeEmitter::EmitServiceImplEqualMethod(StringBuilder &sb, const std::string &prefix) +{ + sb.Append(prefix).AppendFormat("static bool %sEqual(struct %s *self, struct %s *other)\n", baseName_.c_str(), + interfaceName_.c_str(), interfaceName_.c_str()); + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).Append("if (self == NULL || other == NULL) {\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).Append("return self == other;\n"); + sb.Append(prefix).Append("}\n"); +} + void CServiceImplCodeEmitter::EmitKernelServiceImplGetMethod(StringBuilder &sb) { std::string objName = "service"; @@ -289,7 +303,7 @@ void CServiceImplCodeEmitter::EmitServiceImplGetMethod(StringBuilder &sb) sb.Append(TAB).AppendFormat("%s->interface.%s = %s%s;\n", objName.c_str(), method->GetName().c_str(), baseName_.c_str(), method->GetName().c_str()); } - + sb.Append(TAB).AppendFormat("%s->interface.Equal = %sEqual;\n", objName.c_str(), baseName_.c_str()); sb.Append(TAB).AppendFormat("return &%s->interface;\n", objName.c_str()); sb.Append("}\n"); } @@ -310,7 +324,7 @@ void CServiceImplCodeEmitter::EmitKernelServiceImplReleaseMethod(StringBuilder & void CServiceImplCodeEmitter::EmitServiceImplReleaseMethod(StringBuilder &sb) { if (interface_->IsSerializable()) { - sb.AppendFormat("void %sServiceRelease(struct %s *instance)\n", baseName_.c_str(), interfaceName_.c_str()); + sb.AppendFormat("void %sRelease(struct %s *instance)\n", implName_.c_str(), interfaceName_.c_str()); } else { sb.AppendFormat("void %sImplRelease(struct %s *instance)\n", baseName_.c_str(), interfaceName_.c_str()); } diff --git a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h index d8d429e3c..b198b479d 100644 --- a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h @@ -48,6 +48,8 @@ private: void EmitServiceImplGetVersionMethod(StringBuilder &sb, const std::string &prefix); + void EmitServiceImplEqualMethod(StringBuilder &sb, const std::string &prefix); + void EmitServiceImplGetMethod(StringBuilder &sb); void EmitKernelServiceImplReleaseMethod(StringBuilder &sb); diff --git a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp index 4e7177e33..678a8cbf5 100644 --- a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp @@ -112,6 +112,8 @@ void CppClientProxyCodeEmitter::EmitProxyMethodDecls(StringBuilder &sb, const st } EmitProxyMethodDecl(interface_->GetVersionMethod(), sb, prefix); + sb.Append("\n"); + EmitProxyEqualMethods(sb, prefix); } void CppClientProxyCodeEmitter::EmitProxyMethodDecl( @@ -138,6 +140,19 @@ void CppClientProxyCodeEmitter::EmitProxyMethodDecl( } } +void CppClientProxyCodeEmitter::EmitProxyEqualMethods(StringBuilder &sb, const std::string &prefix) +{ + sb.Append(prefix).Append("inline bool Equal(const sptr &other) override\n"); + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).Append("if (other == nullptr) {\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).AppendFormat("%s *otherProxy = static_cast<%s *>(other.GetRefPtr());\n", + proxyName_.c_str(), proxyName_.c_str()); + sb.Append(prefix + TAB).Append("return this->AsObject() == otherProxy->AsObject();\n"); + sb.Append(prefix).Append("}\n"); +} + void CppClientProxyCodeEmitter::EmitProxyConstants(StringBuilder &sb, const std::string &prefix) { sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()); diff --git a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h index e5cdeebae..86ac99198 100644 --- a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h @@ -38,6 +38,8 @@ private: void EmitProxyMethodDecl(const AutoPtr &method, StringBuilder &sb, const std::string &prefix); + void EmitProxyEqualMethods(StringBuilder &sb, const std::string &prefix); + void EmitProxyConstants(StringBuilder &sb, const std::string &prefix); void EmitProxyMethodParameter(const AutoPtr ¶m, StringBuilder &sb, const std::string &prefix); -- Gitee From c8d6e8e098a20c44e81dfed90e6c27c31191ff6a Mon Sep 17 00:00:00 2001 From: yueyan Date: Wed, 2 Nov 2022 19:16:48 +0800 Subject: [PATCH 12/60] fix:modify fuzz test case condition Signed-off-by: yueyan --- .../registerservicestatuslistener_fuzzer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/framework/test/fuzztest/hdimanager/registerservicestatuslistener_fuzzer/registerservicestatuslistener_fuzzer.cpp b/framework/test/fuzztest/hdimanager/registerservicestatuslistener_fuzzer/registerservicestatuslistener_fuzzer.cpp index 3e7bec8f8..f758b715d 100644 --- a/framework/test/fuzztest/hdimanager/registerservicestatuslistener_fuzzer/registerservicestatuslistener_fuzzer.cpp +++ b/framework/test/fuzztest/hdimanager/registerservicestatuslistener_fuzzer/registerservicestatuslistener_fuzzer.cpp @@ -17,6 +17,7 @@ #include "iservmgr_hdi.h" #include "iservstat_listener_hdi.h" #include "parcel.h" +#include "osal_time.h" using namespace OHOS::HDI::ServiceManager::V1_0; @@ -34,6 +35,8 @@ void RegisterServStatListenerFuzzer::OnReceive(const ServiceStatus &status) } // namespace OHOS namespace OHOS { +constexpr size_t THRESHOLD = 10; +constexpr size_t WAIT_THRESHOLD = 100; sptr g_servManager = IServiceManager::Get(); sptr g_servStatListener = new RegisterServStatListenerFuzzer(); @@ -54,12 +57,17 @@ bool RegisterServiceStatusListenerFuzzTest(const uint8_t *data, size_t size) result = true; } + OsalMSleep(WAIT_THRESHOLD); return result; } } // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size < OHOS::THRESHOLD) { + return HDF_SUCCESS; + } + OHOS::RegisterServiceStatusListenerFuzzTest(data, size); return HDF_SUCCESS; } -- Gitee From 17b939d4f8ed172d3a087f5d6d27f70036afa637 Mon Sep 17 00:00:00 2001 From: YUJIA Date: Sat, 5 Nov 2022 15:40:33 +0000 Subject: [PATCH 13/60] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1?= =?UTF-8?q?520=20:=20fix:add=20=E2=80=9CEuqal=E2=80=9D=20member=20method?= =?UTF-8?q?=20of=20hdi=20object(monthly)'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/uhdf2/include/hdi/hdi_base.h | 5 ---- .../tools/hdi-gen/ast/ast_array_type.cpp | 5 +--- .../codegen/c_client_proxy_code_emitter.cpp | 24 +------------------ .../codegen/c_client_proxy_code_emitter.h | 2 -- .../codegen/c_interface_code_emitter.cpp | 15 ++---------- .../codegen/c_interface_code_emitter.h | 2 -- .../codegen/c_service_impl_code_emitter.cpp | 18 ++------------ .../codegen/c_service_impl_code_emitter.h | 2 -- .../codegen/cpp_client_proxy_code_emitter.cpp | 15 ------------ .../codegen/cpp_client_proxy_code_emitter.h | 2 -- 10 files changed, 6 insertions(+), 84 deletions(-) diff --git a/adapter/uhdf2/include/hdi/hdi_base.h b/adapter/uhdf2/include/hdi/hdi_base.h index ce6324d27..c896db2f5 100644 --- a/adapter/uhdf2/include/hdi/hdi_base.h +++ b/adapter/uhdf2/include/hdi/hdi_base.h @@ -25,11 +25,6 @@ class HdiBase : virtual public OHOS::RefBase { public: HdiBase() = default; virtual ~HdiBase() = default; - - inline virtual bool Equal(const sptr &other) - { - return this == other.GetRefPtr(); - } }; #define DECLARE_HDI_DESCRIPTOR(DESCRIPTOR) \ diff --git a/framework/tools/hdi-gen/ast/ast_array_type.cpp b/framework/tools/hdi-gen/ast/ast_array_type.cpp index 1756f68d3..84b502f3c 100644 --- a/framework/tools/hdi-gen/ast/ast_array_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_array_type.cpp @@ -514,10 +514,7 @@ void ASTArrayType::EmitMemoryRecycle( return false; } - if (elementType_->IsStructType() || elementType_->IsStringType()) { - return true; - } - return false; + return elementType_->IsStringType() ? true : false; }; if (elementTypeNeedFree()) { if (Options::GetInstance().DoGenerateKernelCode()) { diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp index ae62f7162..e17089cc4 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp @@ -264,8 +264,6 @@ void CClientProxyCodeEmitter::EmitProxyMethodImpls(StringBuilder &sb) if (!isKernelCode_) { sb.Append("\n"); EmitProxyAsObjectMethodImpl(sb); - sb.Append("\n"); - EmitProxyObjectEqualMethodImpl(sb); } } @@ -464,25 +462,6 @@ void CClientProxyCodeEmitter::EmitProxyAsObjectMethodImpl(StringBuilder &sb) sb.Append("}\n"); } -void CClientProxyCodeEmitter::EmitProxyObjectEqualMethodImpl(StringBuilder &sb) -{ - sb.AppendFormat("static bool %sEqual(struct %s *self, struct %s *other)\n", proxyName_.c_str(), - interfaceName_.c_str(), interfaceName_.c_str()); - sb.Append("{\n"); - sb.Append(TAB).Append("if (self == NULL || other == NULL) {\n"); - sb.Append(TAB).Append(TAB).Append("return false;\n"); - sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("struct %s *selfProxy = CONTAINER_OF(self, struct %s, impl);\n", - proxyName_.c_str(), proxyName_.c_str()); - sb.Append(TAB).AppendFormat("struct %s *otherProxy = CONTAINER_OF(other, struct %s, impl);\n", - proxyName_.c_str(), proxyName_.c_str()); - sb.Append(TAB).Append("if (selfProxy->remote == NULL || otherProxy->remote == NULL) {\n"); - sb.Append(TAB).Append(TAB).Append("return false;\n"); - sb.Append(TAB).Append("}\n"); - sb.Append(TAB).Append("return selfProxy->remote->index == otherProxy->remote->index;\n"); - sb.Append("}\n"); -} - void CClientProxyCodeEmitter::EmitProxyConstruction(StringBuilder &sb) { std::string objName = "impl"; @@ -501,8 +480,7 @@ void CClientProxyCodeEmitter::EmitProxyConstruction(StringBuilder &sb) baseName_.c_str(), getVerMethod->GetName().c_str()); if (!isKernelCode_) { - sb.Append(TAB).AppendFormat("%s->AsObject = %sAsObject;\n", objName.c_str(), proxyName_.c_str()); - sb.Append(TAB).AppendFormat("%s->Equal = %sEqual;\n", objName.c_str(), proxyName_.c_str()); + sb.Append(TAB).AppendFormat("%s->AsObject = %sProxyAsObject;\n", objName.c_str(), baseName_.c_str()); } sb.Append("}\n"); diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h index 20fa47595..cd3c4bbb2 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.h @@ -70,8 +70,6 @@ private: void EmitProxyAsObjectMethodImpl(StringBuilder &sb); - void EmitProxyObjectEqualMethodImpl(StringBuilder &sb); - void EmitProxyConstruction(StringBuilder &); void EmitProxyExternalMethodImpl(StringBuilder &sb); diff --git a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp index e00e6488f..f9579c659 100644 --- a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp @@ -130,14 +130,9 @@ void CInterfaceCodeEmitter::EmitInterfaceMethods(StringBuilder &sb, const std::s } EmitInterfaceMethod(interface_->GetVersionMethod(), sb, prefix); - if (!isKernelCode_) { - if (!Options::GetInstance().DoPassthrough()) { - sb.Append("\n"); - EmitAsObjectMethod(sb, TAB); - } - + if (!isKernelCode_ && !Options::GetInstance().DoPassthrough()) { sb.Append("\n"); - EmitObjectEqualMethod(sb, TAB); + EmitAsObjectMethod(sb, TAB); } } @@ -170,12 +165,6 @@ void CInterfaceCodeEmitter::EmitAsObjectMethod(StringBuilder &sb, const std::str sb.Append(prefix).AppendFormat("struct HdfRemoteService* (*AsObject)(struct %s *self);\n", interfaceName_.c_str()); } -void CInterfaceCodeEmitter::EmitObjectEqualMethod(StringBuilder &sb, const std::string &prefix) -{ - sb.Append(prefix).AppendFormat("bool (*Equal)(struct %s *self, struct %s *other);\n", - interfaceName_.c_str(), interfaceName_.c_str()); -} - void CInterfaceCodeEmitter::EmitExternalMethod(StringBuilder &sb) { if (Options::GetInstance().DoPassthrough() && interface_->IsSerializable()) { diff --git a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h index 0e823a190..a84e0ba29 100644 --- a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h @@ -46,8 +46,6 @@ private: void EmitAsObjectMethod(StringBuilder &sb, const std::string &prefix); - void EmitObjectEqualMethod(StringBuilder &sb, const std::string &prefix); - void EmitExternalMethod(StringBuilder &sb); void EmitInterfaceGetMethodDecl(StringBuilder &sb); diff --git a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp index 9795277d4..3f749f476 100644 --- a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp @@ -179,8 +179,6 @@ void CServiceImplCodeEmitter::EmitServiceImplMethodImpls(StringBuilder &sb, cons sb.Append("\n"); EmitServiceImplGetVersionMethod(sb, prefix); - sb.Append("\n"); - EmitServiceImplEqualMethod(sb, prefix); } void CServiceImplCodeEmitter::EmitServiceImplMethodImpl( @@ -233,18 +231,6 @@ void CServiceImplCodeEmitter::EmitServiceImplGetVersionMethod(StringBuilder &sb, sb.Append(prefix).Append("}\n"); } -void CServiceImplCodeEmitter::EmitServiceImplEqualMethod(StringBuilder &sb, const std::string &prefix) -{ - sb.Append(prefix).AppendFormat("static bool %sEqual(struct %s *self, struct %s *other)\n", baseName_.c_str(), - interfaceName_.c_str(), interfaceName_.c_str()); - sb.Append(prefix).Append("{\n"); - sb.Append(prefix + TAB).Append("if (self == NULL || other == NULL) {\n"); - sb.Append(prefix + TAB + TAB).Append("return false;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).Append("return self == other;\n"); - sb.Append(prefix).Append("}\n"); -} - void CServiceImplCodeEmitter::EmitKernelServiceImplGetMethod(StringBuilder &sb) { std::string objName = "service"; @@ -303,7 +289,7 @@ void CServiceImplCodeEmitter::EmitServiceImplGetMethod(StringBuilder &sb) sb.Append(TAB).AppendFormat("%s->interface.%s = %s%s;\n", objName.c_str(), method->GetName().c_str(), baseName_.c_str(), method->GetName().c_str()); } - sb.Append(TAB).AppendFormat("%s->interface.Equal = %sEqual;\n", objName.c_str(), baseName_.c_str()); + sb.Append(TAB).AppendFormat("return &%s->interface;\n", objName.c_str()); sb.Append("}\n"); } @@ -324,7 +310,7 @@ void CServiceImplCodeEmitter::EmitKernelServiceImplReleaseMethod(StringBuilder & void CServiceImplCodeEmitter::EmitServiceImplReleaseMethod(StringBuilder &sb) { if (interface_->IsSerializable()) { - sb.AppendFormat("void %sRelease(struct %s *instance)\n", implName_.c_str(), interfaceName_.c_str()); + sb.AppendFormat("void %sServiceRelease(struct %s *instance)\n", baseName_.c_str(), interfaceName_.c_str()); } else { sb.AppendFormat("void %sImplRelease(struct %s *instance)\n", baseName_.c_str(), interfaceName_.c_str()); } diff --git a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h index b198b479d..d8d429e3c 100644 --- a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.h @@ -48,8 +48,6 @@ private: void EmitServiceImplGetVersionMethod(StringBuilder &sb, const std::string &prefix); - void EmitServiceImplEqualMethod(StringBuilder &sb, const std::string &prefix); - void EmitServiceImplGetMethod(StringBuilder &sb); void EmitKernelServiceImplReleaseMethod(StringBuilder &sb); diff --git a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp index 678a8cbf5..4e7177e33 100644 --- a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.cpp @@ -112,8 +112,6 @@ void CppClientProxyCodeEmitter::EmitProxyMethodDecls(StringBuilder &sb, const st } EmitProxyMethodDecl(interface_->GetVersionMethod(), sb, prefix); - sb.Append("\n"); - EmitProxyEqualMethods(sb, prefix); } void CppClientProxyCodeEmitter::EmitProxyMethodDecl( @@ -140,19 +138,6 @@ void CppClientProxyCodeEmitter::EmitProxyMethodDecl( } } -void CppClientProxyCodeEmitter::EmitProxyEqualMethods(StringBuilder &sb, const std::string &prefix) -{ - sb.Append(prefix).Append("inline bool Equal(const sptr &other) override\n"); - sb.Append(prefix).Append("{\n"); - sb.Append(prefix + TAB).Append("if (other == nullptr) {\n"); - sb.Append(prefix + TAB + TAB).Append("return false;\n"); - sb.Append(prefix + TAB).Append("}\n"); - sb.Append(prefix + TAB).AppendFormat("%s *otherProxy = static_cast<%s *>(other.GetRefPtr());\n", - proxyName_.c_str(), proxyName_.c_str()); - sb.Append(prefix + TAB).Append("return this->AsObject() == otherProxy->AsObject();\n"); - sb.Append(prefix).Append("}\n"); -} - void CppClientProxyCodeEmitter::EmitProxyConstants(StringBuilder &sb, const std::string &prefix) { sb.Append(prefix).AppendFormat("static inline BrokerDelegator<%s> delegator_;\n", proxyName_.c_str()); diff --git a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h index 86ac99198..e5cdeebae 100644 --- a/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/cpp_client_proxy_code_emitter.h @@ -38,8 +38,6 @@ private: void EmitProxyMethodDecl(const AutoPtr &method, StringBuilder &sb, const std::string &prefix); - void EmitProxyEqualMethods(StringBuilder &sb, const std::string &prefix); - void EmitProxyConstants(StringBuilder &sb, const std::string &prefix); void EmitProxyMethodParameter(const AutoPtr ¶m, StringBuilder &sb, const std::string &prefix); -- Gitee From 83e2430427f67ac8ea50267f2866e3f711e924ba Mon Sep 17 00:00:00 2001 From: zhang Date: Fri, 11 Nov 2022 15:27:38 +0800 Subject: [PATCH 14/60] fix:the hdf driver process supports critical parameter configuration on 1018 branch Signed-off-by: zhang --- .../tools/hc-gen/src/startup_cfg_gen.cpp | 58 +++++++++++++++++-- framework/tools/hc-gen/src/startup_cfg_gen.h | 3 + 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.cpp b/framework/tools/hc-gen/src/startup_cfg_gen.cpp index 322dda4d2..95dcd06bf 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.cpp +++ b/framework/tools/hc-gen/src/startup_cfg_gen.cpp @@ -31,12 +31,13 @@ static constexpr const char *BOOT_CONFIG_BOTTOM = static constexpr const char *SERVICE_TOP = " {\n" " \"name\" : "; -static constexpr const char *PATH_INFO = " \"path\" : [\"/vendor/bin/hdf_devhost\", "; -static constexpr const char *UID_INFO = " \"uid\" : "; -static constexpr const char *GID_INFO = " \"gid\" : ["; -static constexpr const char *CAPS_INFO = " \"caps\" : ["; -static constexpr const char *DYNAMIC_INFO = " \"ondemand\" : true,\n"; -static constexpr const char *SECON_INFO = " \"secon\" : \"u:r:"; +static constexpr const char *PATH_INFO = " \"path\" : [\"/vendor/bin/hdf_devhost\", "; +static constexpr const char *UID_INFO = " \"uid\" : "; +static constexpr const char *GID_INFO = " \"gid\" : ["; +static constexpr const char *CAPS_INFO = " \"caps\" : ["; +static constexpr const char *DYNAMIC_INFO = " \"ondemand\" : true,\n"; +static constexpr const char *SECON_INFO = " \"secon\" : \"u:r:"; +static constexpr const char *CRITICAL_INFO = " \"critical\" : ["; StartupCfgGen::StartupCfgGen(const std::shared_ptr &ast) : Generator(ast) { @@ -96,17 +97,27 @@ bool StartupCfgGen::Initialize() void StartupCfgGen::HostInfoOutput(const std::string &name, bool end) { ofs_ << SERVICE_TOP << "\"" << name << "\",\n"; + if (hostInfoMap_[name].dynamicLoad) { ofs_ << DYNAMIC_INFO; } + ofs_ << PATH_INFO << "\"" << hostInfoMap_[name].hostId << "\", \"" << name <<"\"],\n"; ofs_ << UID_INFO << "\"" << hostInfoMap_[name].hostUID <<"\",\n"; ofs_ << GID_INFO << hostInfoMap_[name].hostGID <<"],\n"; + if (!hostInfoMap_[name].hostCaps.empty()) { ofs_ << CAPS_INFO << hostInfoMap_[name].hostCaps <<"],\n"; } + + if (!hostInfoMap_[name].hostCritical.empty()) { + ofs_ << CRITICAL_INFO << hostInfoMap_[name].hostCritical <<"],\n"; + } + ofs_ << SECON_INFO << name << ":s0\"\n"; + ofs_ << TAB TAB << "}"; + if (!end) { ofs_<< ","; } @@ -121,6 +132,7 @@ void StartupCfgGen::InitHostInfo(HostInfo &hostData) hostData.hostGID = ""; hostData.hostPriority = 0; hostData.hostId = 0; + hostData.hostCritical = ""; } bool StartupCfgGen::TemplateNodeSeparate() @@ -184,6 +196,31 @@ void StartupCfgGen::GetConfigArray(const std::shared_ptr &term, std:: } } +void StartupCfgGen::GetConfigIntArray(const std::shared_ptr &term, std::string &config) +{ + if (term == nullptr) { + return; + } + + std::shared_ptr intArrayObj = term->Child(); + if (intArrayObj == nullptr) { + return; + } + + uint16_t arraySize = ConfigArray::CastFrom(intArrayObj)->ArraySize(); + std::shared_ptr object = intArrayObj->Child(); + while (arraySize != 0 && object != nullptr) { + std::string value = std::to_string(object->IntegerValue()); + config.append(value); + if (arraySize != 1) { + config.append(", "); + } + + object = object->Next(); + arraySize--; + } +} + void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, HostInfo &hostData) { uint32_t preload; @@ -196,6 +233,7 @@ void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, devInfo = devInfo->Next(); continue; } + devNodeInfo = devInfo->Child(); while (devNodeInfo != nullptr) { current = devNodeInfo->Lookup("preload", PARSEROP_CONFTERM); @@ -203,10 +241,12 @@ void StartupCfgGen::GetHostLoadMode(const std::shared_ptr &hostInfo, devNodeInfo = devNodeInfo->Next(); continue; } + preload = current->Child()->IntegerValue(); if (preload == 0 || preload == 1) { hostData.dynamicLoad = false; } + devNodeInfo = devNodeInfo->Next(); } devInfo = devInfo->Next(); @@ -252,6 +292,7 @@ bool StartupCfgGen::GetHostInfo() hostInfo = hostInfo->Next(); continue; } + InitHostInfo(hostData); serviceName = object->Child()->StringValue(); @@ -271,7 +312,12 @@ bool StartupCfgGen::GetHostInfo() object = hostInfo->Lookup("caps", PARSEROP_CONFTERM); GetConfigArray(object, hostData.hostCaps); + GetHostLoadMode(hostInfo, hostData); + + object = hostInfo->Lookup("critical", PARSEROP_CONFTERM); + GetConfigIntArray(object, hostData.hostCritical); + hostData.hostId = hostId; hostInfoMap_.insert(make_pair(serviceName, hostData)); hostId++; diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.h b/framework/tools/hc-gen/src/startup_cfg_gen.h index 3fd4708b6..e2f70cdc5 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.h +++ b/framework/tools/hc-gen/src/startup_cfg_gen.h @@ -19,6 +19,7 @@ struct HostInfo { std::string hostCaps; std::string hostUID; std::string hostGID; + std::string hostCritical; uint32_t hostPriority; uint32_t hostId; bool dynamicLoad; @@ -59,6 +60,8 @@ private: static void GetConfigArray(const std::shared_ptr &term, std::string &config); + static void GetConfigIntArray(const std::shared_ptr &term, std::string &config); + static void GetHostLoadMode(const std::shared_ptr &hostInfo, HostInfo &hostData); static void GetHostGID(const std::shared_ptr &term, std::string &config, const std::string &name); -- Gitee From b6fcc9eba5711eb9f0a0b06e5a346beb97fd0945 Mon Sep 17 00:00:00 2001 From: zhang Date: Mon, 14 Nov 2022 15:38:34 +0800 Subject: [PATCH 15/60] fix:optimizing the concurrent processing of hdf framework in managing services on 1018 branch Signed-off-by: zhang --- .../manager/include/devsvc_manager_stub.h | 11 + .../uhdf2/manager/src/devhost_service_proxy.c | 4 +- .../uhdf2/manager/src/devmgr_service_full.c | 35 +++- .../uhdf2/manager/src/devsvc_manager_stub.c | 193 ++++++++++++++++-- 4 files changed, 211 insertions(+), 32 deletions(-) diff --git a/adapter/uhdf2/manager/include/devsvc_manager_stub.h b/adapter/uhdf2/manager/include/devsvc_manager_stub.h index f3bd79c21..296b1b9f6 100644 --- a/adapter/uhdf2/manager/include/devsvc_manager_stub.h +++ b/adapter/uhdf2/manager/include/devsvc_manager_stub.h @@ -18,6 +18,8 @@ #include "devsvc_manager.h" #include "hdf_remote_service.h" +#include "hdf_slist.h" +#include "osal_mutex.h" #define DEVICE_SERVICE_MANAGER "hdf_device_service_manager" #define DEVICE_SERVICE_MANAGER_SA_ID 5100 @@ -27,6 +29,15 @@ struct DevSvcManagerStub { struct HdfRemoteService *remote; struct HdfDeathRecipient recipient; bool started; + struct OsalMutex devSvcStubMutex; + struct HdfSList devObjHolderList; +}; + +struct HdfDeviceObjectHolder { + struct HdfDeviceObject devObj; + uintptr_t remoteSvcAddr; + char *serviceName; + struct HdfSListNode entry; }; struct HdfObject *DevSvcManagerStubCreate(void); diff --git a/adapter/uhdf2/manager/src/devhost_service_proxy.c b/adapter/uhdf2/manager/src/devhost_service_proxy.c index 20c3b4eb1..196195acd 100644 --- a/adapter/uhdf2/manager/src/devhost_service_proxy.c +++ b/adapter/uhdf2/manager/src/devhost_service_proxy.c @@ -81,7 +81,7 @@ void DevHostServiceProxyOnRemoteDied(struct HdfDeathRecipient *recipient, struct if (task == NULL) { return; } - struct HdfMessage *message = HdfMessageObtain(0); + struct HdfMessage *message = HdfMessageObtain(sizeof(void *)); if (message == NULL) { return; } @@ -89,6 +89,7 @@ void DevHostServiceProxyOnRemoteDied(struct HdfDeathRecipient *recipient, struct struct HdfDeathRecipient, recipient, struct DevHostServiceProxy, recipient); message->messageId = DEVMGR_MESSAGE_DEVHOST_DIED; message->data[0] = (void *)(uintptr_t)proxy->hostId; + message->data[1] = (void *)service; HDF_LOGD("%{public}s: host %{public}u dead, respawn it", __FUNCTION__, proxy->hostId); task->SendMessage(task, message, false); } @@ -100,6 +101,7 @@ void DevHostServiceProxyConstruct( inst->super.AddDevice = DevHostServiceProxyAddDevice; inst->super.DelDevice = DevHostServiceProxyDelDevice; inst->recipient.OnRemoteDied = DevHostServiceProxyOnRemoteDied; + remote->target = (struct HdfObject *)inst; HdfRemoteServiceAddDeathRecipient(remote, &inst->recipient); } diff --git a/adapter/uhdf2/manager/src/devmgr_service_full.c b/adapter/uhdf2/manager/src/devmgr_service_full.c index b7e763d9c..628c277b5 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_full.c +++ b/adapter/uhdf2/manager/src/devmgr_service_full.c @@ -30,25 +30,38 @@ static Map g_hostMap = {0}; #define HOST_INIT_DIE_NUM 1 #define HOST_MAX_DIE_NUM 3 -static void CleanupDiedHostResources(struct DevHostServiceClnt *hostClnt) +static void CleanupDiedHostResources(struct DevHostServiceClnt *hostClnt, struct HdfRemoteService *service) { OsalMutexLock(&hostClnt->hostLock); hostClnt->hostPid = INVALID_PID; - if (hostClnt->hostService != NULL) { - struct DevHostServiceProxy *hostProxy = (struct DevHostServiceProxy *)hostClnt->hostService; + struct DevHostServiceProxy *hostProxy = (struct DevHostServiceProxy *)hostClnt->hostService; + if (hostProxy != NULL) { + if ((hostProxy->remote != NULL) && ((uintptr_t)hostProxy->remote == (uintptr_t)service)) { + HDF_LOGI("%{public}s hostId: %{public}u remove current hostService", __func__, hostClnt->hostId); + DevHostServiceProxyRecycle(hostProxy); + hostClnt->hostService = NULL; + HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete); + } else { + hostProxy = (struct DevHostServiceProxy *)service->target; + HDF_LOGI("%{public}s hostId: %{public}u remove old hostService", __func__, hostClnt->hostId); + DevHostServiceProxyRecycle(hostProxy); + } + } else { + hostProxy = (struct DevHostServiceProxy *)service->target; + HDF_LOGI("%{public}s hostId: %{public}u remove old hostService, and current hostService is null", + __func__, hostClnt->hostId); DevHostServiceProxyRecycle(hostProxy); - hostClnt->hostService = NULL; } - HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete); OsalMutexUnlock(&hostClnt->hostLock); } -static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt *hostClnt) +static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt *hostClnt, + struct HdfRemoteService *service) { bool isHostEmpty = HdfSListIsEmpty(&hostClnt->devices); - CleanupDiedHostResources(hostClnt); + CleanupDiedHostResources(hostClnt, service); if (isHostEmpty || hostClnt->stopFlag) { return 0; } @@ -83,7 +96,8 @@ static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt * return INVALID_PID; } -void DevmgrServiceFullOnDeviceHostDied(struct DevmgrServiceFull *inst, uint32_t hostId) +static void DevmgrServiceFullOnDeviceHostDied(struct DevmgrServiceFull *inst, uint32_t hostId, + struct HdfRemoteService *service) { (void)hostId; struct DevHostServiceClnt *hostClnt = NULL; @@ -94,7 +108,7 @@ void DevmgrServiceFullOnDeviceHostDied(struct DevmgrServiceFull *inst, uint32_t OsalMutexLock(&inst->super.devMgrMutex); DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &inst->super.hosts, struct DevHostServiceClnt, node) { if (hostClnt->hostId == hostId) { - int32_t ret = DevmgrServiceFullHandleDeviceHostDied(hostClnt); + int32_t ret = DevmgrServiceFullHandleDeviceHostDied(hostClnt, service); if (ret == INVALID_PID) { HDF_LOGE("%{public}s: failed to respawn host %{public}s", __func__, hostClnt->hostName); } @@ -115,7 +129,8 @@ int32_t DevmgrServiceFullDispatchMessage(struct HdfMessageTask *task, struct Hdf switch (msg->messageId) { case DEVMGR_MESSAGE_DEVHOST_DIED: { int hostId = (int)(uintptr_t)msg->data[0]; - DevmgrServiceFullOnDeviceHostDied(fullService, hostId); + struct HdfRemoteService *service = (struct HdfRemoteService *)msg->data[1]; + DevmgrServiceFullOnDeviceHostDied(fullService, hostId, service); break; } default: { diff --git a/adapter/uhdf2/manager/src/devsvc_manager_stub.c b/adapter/uhdf2/manager/src/devsvc_manager_stub.c index 91ff50e79..2db146d3b 100644 --- a/adapter/uhdf2/manager/src/devsvc_manager_stub.c +++ b/adapter/uhdf2/manager/src/devsvc_manager_stub.c @@ -70,41 +70,132 @@ static int32_t ListServicePermCheck() return HDF_SUCCESS; } +static bool CheckServiceObjectValidNoLock(const struct DevSvcManagerStub *stub, const struct HdfDeviceObject *service) +{ + if (service == NULL || service->priv == NULL) { + HDF_LOGW("%{public}s service object is null", __func__); + return false; + } + + struct HdfSListIterator it; + HdfSListIteratorInit(&it, &stub->devObjHolderList); + while (HdfSListIteratorHasNext(&it)) { + struct HdfSListNode *node = HdfSListIteratorNext(&it); + struct HdfDeviceObjectHolder *holder = + HDF_SLIST_CONTAINER_OF(struct HdfSListNode, node, struct HdfDeviceObjectHolder, entry); + + if (((uintptr_t)(&holder->devObj) == (uintptr_t)service) && (holder->serviceName != NULL) && + (strcmp(holder->serviceName, (char *)service->priv) == 0)) { + HDF_LOGD("%{public}s %{public}s service object is valid", __func__, holder->serviceName); + return true; + } + } + + HDF_LOGW("%{public}s %{public}s service object is invalid", __func__, (char *)service->priv); + return false; +} + +static bool CheckRemoteObjectValidNoLock(const struct DevSvcManagerStub *stub, const struct HdfRemoteService *service) +{ + if (service == NULL) { + HDF_LOGW("%{public}s remote object is null", __func__); + return false; + } + + struct HdfSListIterator it; + HdfSListIteratorInit(&it, &stub->devObjHolderList); + while (HdfSListIteratorHasNext(&it)) { + struct HdfSListNode *node = HdfSListIteratorNext(&it); + struct HdfDeviceObjectHolder *holder = + HDF_SLIST_CONTAINER_OF(struct HdfSListNode, node, struct HdfDeviceObjectHolder, entry); + + if (holder->remoteSvcAddr == (uintptr_t)service) { + HDF_LOGD("%{public}s remote object is valid", __func__); + return true; + } + } + + HDF_LOGW("%{public}s remote object is invalid", __func__); + return false; +} + +static void ReleaseServiceObjectHolder(struct DevSvcManagerStub *stub, struct HdfDeviceObjectHolder *devObjHolder) +{ + if (devObjHolder != NULL) { + struct HdfDeviceObject *serviceObject = &devObjHolder->devObj; + struct HdfRemoteService *serviceRemote = (struct HdfRemoteService *)serviceObject->service; + HdfRemoteServiceRemoveDeathRecipient(serviceRemote, &stub->recipient); + HdfRemoteServiceRecycle((struct HdfRemoteService *)serviceObject->service); + serviceObject->service = NULL; + OsalMemFree(serviceObject->priv); + serviceObject->priv = NULL; + OsalMemFree(devObjHolder->serviceName); + devObjHolder->serviceName = NULL; + OsalMemFree(devObjHolder); + } +} + static struct HdfDeviceObject *ObtainServiceObject( struct DevSvcManagerStub *stub, const char *name, struct HdfRemoteService *service) { - struct HdfDeviceObject *serviceObject = OsalMemCalloc(sizeof(struct HdfDeviceObject)); - if (serviceObject == NULL) { + struct HdfDeviceObjectHolder *serviceObjectHolder = OsalMemCalloc(sizeof(*serviceObjectHolder)); + if (serviceObjectHolder == NULL) { return NULL; } + + serviceObjectHolder->remoteSvcAddr = (uintptr_t)service; + serviceObjectHolder->serviceName = (void *)HdfStringCopy(name); + if (serviceObjectHolder->serviceName == NULL) { + OsalMemFree(serviceObjectHolder); + return NULL; + } + + struct HdfDeviceObject *serviceObject = &serviceObjectHolder->devObj; serviceObject->priv = (void *)HdfStringCopy(name); if (serviceObject->priv == NULL) { - OsalMemFree(serviceObject); + OsalMemFree(serviceObjectHolder->serviceName); + OsalMemFree(serviceObjectHolder); return NULL; } serviceObject->service = (struct IDeviceIoService *)service; service->target = (struct HdfObject *)serviceObject; + OsalMutexLock(&stub->devSvcStubMutex); + HdfSListAdd(&stub->devObjHolderList, &serviceObjectHolder->entry); + OsalMutexUnlock(&stub->devSvcStubMutex); + HdfRemoteServiceAddDeathRecipient(service, &stub->recipient); + return serviceObject; } static void ReleaseServiceObject(struct DevSvcManagerStub *stub, struct HdfDeviceObject *serviceObject) { + OsalMutexLock(&stub->devSvcStubMutex); if (serviceObject == NULL) { + OsalMutexUnlock(&stub->devSvcStubMutex); return; } + if (serviceObject->priv == NULL) { + OsalMutexUnlock(&stub->devSvcStubMutex); HDF_LOGW("release service object has empty name, may broken object"); return; } + + if (!CheckServiceObjectValidNoLock(stub, serviceObject)) { + OsalMutexUnlock(&stub->devSvcStubMutex); + return; + } + struct HdfRemoteService *serviceRemote = (struct HdfRemoteService *)serviceObject->service; HdfRemoteServiceRemoveDeathRecipient(serviceRemote, &stub->recipient); - HdfRemoteServiceRecycle((struct HdfRemoteService *)serviceObject->service); - OsalMemFree(serviceObject->priv); - serviceObject->priv = NULL; - serviceObject->service = NULL; - OsalMemFree(serviceObject); + + struct HdfDeviceObjectHolder *serviceObjectHolder = (struct HdfDeviceObjectHolder *)serviceObject; + HdfSListRemove(&stub->devObjHolderList, &serviceObjectHolder->entry); + ReleaseServiceObjectHolder(stub, serviceObjectHolder); + + OsalMutexUnlock(&stub->devSvcStubMutex); } static int32_t DevSvcMgrStubGetPara( @@ -154,7 +245,7 @@ static int32_t DevSvcManagerStubAddService(struct IDevSvcManager *super, struct if (DevSvcMgrStubGetPara(data, &info, &service) != HDF_SUCCESS) { return ret; } - + struct HdfDeviceObject *serviceObject = ObtainServiceObject(stub, info.servName, service); if (serviceObject == NULL) { return HDF_ERR_MALLOC_FAIL; @@ -225,13 +316,33 @@ static int32_t DevSvcManagerStubGetService(struct IDevSvcManager *super, struct if (ret != HDF_SUCCESS) { return ret; } - struct HdfRemoteService *remoteService = (struct HdfRemoteService *)super->GetService(super, name); + struct HdfDeviceObject *serviceObject = super->GetObject(super, name); + if (serviceObject == NULL) { + HDF_LOGE("StubGetService service %{public}s not found", name); + return HDF_FAILURE; + } + + const char *svcMgrName = "hdf_device_manager"; + if (strcmp(name, svcMgrName) != 0) { + OsalMutexLock(&stub->devSvcStubMutex); + if (!CheckServiceObjectValidNoLock(stub, serviceObject)) { + OsalMutexUnlock(&stub->devSvcStubMutex); + HDF_LOGE("StubGetService service %{public}s is invalid", name); + return HDF_FAILURE; + } + } + struct HdfRemoteService *remoteService = (struct HdfRemoteService *)serviceObject->service; if (remoteService != NULL) { - ret = HDF_SUCCESS; HdfSbufWriteRemoteService(reply, remoteService); - HDF_LOGI("service %{public}s found", name); + ret = HDF_SUCCESS; + HDF_LOGI("StubGetService service %{public}s found", name); } else { - HDF_LOGE("service %{public}s not found", name); + HDF_LOGE("StubGetService %{public}s remoteService is null", name); + ret = HDF_FAILURE; + } + + if (strcmp(name, svcMgrName) != 0) { + OsalMutexUnlock(&stub->devSvcStubMutex); } return ret; @@ -276,17 +387,26 @@ static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, stru return HDF_DEV_ERR_NO_DEVICE_SERVICE; } + OsalMutexLock(&stub->devSvcStubMutex); + if (!CheckServiceObjectValidNoLock(stub, serviceObject)) { + OsalMutexUnlock(&stub->devSvcStubMutex); + HDF_LOGI("StubRemoveService service %{public}s is invalid", name); + return HDF_FAILURE; + } + const char *servName = (const char *)serviceObject->priv; if (servName == NULL) { + OsalMutexUnlock(&stub->devSvcStubMutex); HDF_LOGE("remove service %{public}s is broken object", name); return HDF_ERR_INVALID_OBJECT; } if (strcmp(name, servName) != 0) { + OsalMutexUnlock(&stub->devSvcStubMutex); HDF_LOGE("remove service %{public}s name mismatch with %{public}s", name, servName); return HDF_ERR_INVALID_OBJECT; } - + OsalMutexUnlock(&stub->devSvcStubMutex); super->RemoveService(super, name); HDF_LOGI("service %{public}s removed", name); @@ -397,19 +517,29 @@ void DevSvcManagerOnServiceDied(struct HdfDeathRecipient *recipient, struct HdfR } struct IDevSvcManager *iSvcMgr = &stub->super.super; - struct HdfDeviceObject *serviceObject = (struct HdfDeviceObject *)remote->target; + if (iSvcMgr->GetService == NULL || iSvcMgr->RemoveService == NULL) { + HDF_LOGI("%{public}s:invalid svcmgr object", __func__); + return; + } - if (serviceObject == NULL || serviceObject->priv == NULL) { - HDF_LOGI("%{public}s:invalid service object", __func__); + OsalMutexLock(&stub->devSvcStubMutex); + if (!CheckRemoteObjectValidNoLock(stub, remote)) { + OsalMutexUnlock(&stub->devSvcStubMutex); return; } + struct HdfDeviceObject *serviceObject = (struct HdfDeviceObject *)remote->target; - if (iSvcMgr->GetService == NULL || iSvcMgr->RemoveService == NULL) { - HDF_LOGI("%{public}s:invalid svcmgr object", __func__); + if (!CheckServiceObjectValidNoLock(stub, serviceObject)) { + OsalMutexUnlock(&stub->devSvcStubMutex); return; } - char *serviceName = (char *)serviceObject->priv; + char *serviceName = HdfStringCopy((char *)serviceObject->priv); + OsalMutexUnlock(&stub->devSvcStubMutex); + if (serviceName == NULL) { + HDF_LOGI("%{public}s HdfStringCopy fail", __func__); + return; + } struct HdfObject *service = iSvcMgr->GetService(iSvcMgr, serviceName); HDF_LOGI("service %{public}s died", serviceName); @@ -419,6 +549,7 @@ void DevSvcManagerOnServiceDied(struct HdfDeathRecipient *recipient, struct HdfR } ReleaseServiceObject(stub, serviceObject); + OsalMemFree(serviceName); } int DevSvcManagerStubStart(struct IDevSvcManager *svcmgr) @@ -468,6 +599,8 @@ static bool DevSvcManagerStubConstruct(struct DevSvcManagerStub *inst) return false; } inst->super.super.StartService = DevSvcManagerStubStart; + OsalMutexInit(&inst->devSvcStubMutex); + HdfSListInit(&inst->devObjHolderList); return true; } @@ -488,13 +621,31 @@ struct HdfObject *DevSvcManagerStubCreate(void) return (struct HdfObject *)instance; } +static void DevObjHolderListReleaseNoLock(struct DevSvcManagerStub *stub) +{ + struct HdfSListIterator it; + HdfSListIteratorInit(&it, &stub->devObjHolderList); + while (HdfSListIteratorHasNext(&it)) { + struct HdfSListNode *node = HdfSListIteratorNext(&it); + HdfSListIteratorRemove(&it); + struct HdfDeviceObjectHolder *holder = + HDF_SLIST_CONTAINER_OF(struct HdfSListNode, node, struct HdfDeviceObjectHolder, entry); + + ReleaseServiceObjectHolder(stub, holder); + } +} + void DevSvcManagerStubRelease(struct HdfObject *object) { - struct DevmgrServiceStub *instance = (struct DevmgrServiceStub *)object; + struct DevSvcManagerStub *instance = (struct DevSvcManagerStub *)object; if (instance != NULL) { if (instance->remote != NULL) { HdfRemoteServiceRecycle(instance->remote); instance->remote = NULL; } + OsalMutexLock(&instance->devSvcStubMutex); + DevObjHolderListReleaseNoLock(instance); + OsalMutexUnlock(&instance->devSvcStubMutex); + OsalMutexDestroy(&instance->devSvcStubMutex); } } -- Gitee From 4f13b1eb016c1174e20f1f1a876dee3f1ee16379 Mon Sep 17 00:00:00 2001 From: zhangcui Date: Wed, 16 Nov 2022 02:57:07 +0000 Subject: [PATCH 16/60] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=8A=93=E5=8F=96host?= =?UTF-8?q?=20=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=90=AF=E5=8A=A8=E5=86=85?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangcui --- adapter/uhdf2/host/BUILD.gn | 1 + adapter/uhdf2/host/devhost.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/adapter/uhdf2/host/BUILD.gn b/adapter/uhdf2/host/BUILD.gn index 36ffd0de6..5232da34f 100644 --- a/adapter/uhdf2/host/BUILD.gn +++ b/adapter/uhdf2/host/BUILD.gn @@ -124,6 +124,7 @@ if (defined(ohos_lite)) { external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", ] } else { external_deps = [ "hilog:libhilog" ] diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 8bd856a8d..06f376a31 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -20,7 +20,7 @@ #include #include "securec.h" - +#include "parameter.h" #include "devhost_service.h" #include "devhost_service_full.h" #include "hdf_base.h" @@ -30,6 +30,24 @@ #define HDF_LOG_TAG hdf_device_host #define DEVHOST_INPUT_PARAM_NUM 3 #define DEVHOST_INPUT_PARAM_HOSTID_POS 1 +#define PARAM_BUF_LEN 128 + +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) { @@ -81,6 +99,7 @@ int main(int argc, char **argv) const char *hostName = argv[argc - 1]; HDF_LOGI("hdf device host %{public}s %{public}d start", hostName, hostId); SetProcTitle(argv, hostName); + StartMemoryHook(hostName); struct IDevHostService *instance = DevHostServiceNewInstance(hostId, hostName); if (instance == NULL || instance->StartService == NULL) { -- Gitee From 1d750739e1c6098d9ae1ea6b0e1fccba24b464e9 Mon Sep 17 00:00:00 2001 From: yueyan Date: Wed, 16 Nov 2022 16:36:23 +0800 Subject: [PATCH 17/60] fixed cd532f2 from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1560 fix:increase stack size of thread Signed-off-by: yueyan --- framework/test/unittest/osal/osal_all_test.c | 2 +- framework/test/unittest/osal/osal_list_test.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/test/unittest/osal/osal_all_test.c b/framework/test/unittest/osal/osal_all_test.c index 30ad5d143..3d10d2fe0 100644 --- a/framework/test/unittest/osal/osal_all_test.c +++ b/framework/test/unittest/osal/osal_all_test.c @@ -547,7 +547,7 @@ static int ThreadTest(void *arg) return 0; } -#define HDF_TEST_STACK_SIZE 10000 +#define HDF_TEST_STACK_SIZE (1024 * 16) // 16KB static void OsaThreadTest1(void) { struct OsalThreadParam threadCfg; diff --git a/framework/test/unittest/osal/osal_list_test.c b/framework/test/unittest/osal/osal_list_test.c index 14619b42d..a0f7073fd 100644 --- a/framework/test/unittest/osal/osal_list_test.c +++ b/framework/test/unittest/osal/osal_list_test.c @@ -21,7 +21,7 @@ #define HDF_LOG_TAG osal_test #define HDF_THREAD_TEST_SLEEP_MS 200 -#define HDF_TEST_STACK_SIZE 10000 +#define HDF_TEST_STACK_SIZE (1024 * 16) // 16KB typedef void(*EventHandle)(int para); -- Gitee From b060ea4f9f967ba5acb901e84a0981a6dce23a85 Mon Sep 17 00:00:00 2001 From: zhang Date: Mon, 21 Nov 2022 14:55:04 +0800 Subject: [PATCH 18/60] fix:Clear the alarm of the DevHostServiceProxyConstruct function Signed-off-by: zhang --- adapter/uhdf2/manager/src/devhost_service_proxy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adapter/uhdf2/manager/src/devhost_service_proxy.c b/adapter/uhdf2/manager/src/devhost_service_proxy.c index 196195acd..c0d2c996f 100644 --- a/adapter/uhdf2/manager/src/devhost_service_proxy.c +++ b/adapter/uhdf2/manager/src/devhost_service_proxy.c @@ -101,7 +101,10 @@ void DevHostServiceProxyConstruct( inst->super.AddDevice = DevHostServiceProxyAddDevice; inst->super.DelDevice = DevHostServiceProxyDelDevice; inst->recipient.OnRemoteDied = DevHostServiceProxyOnRemoteDied; - remote->target = (struct HdfObject *)inst; + if (remote != NULL) { + remote->target = (struct HdfObject *)inst; + } + HdfRemoteServiceAddDeathRecipient(remote, &inst->recipient); } -- Gitee From 8e8ea43c89416f2c41c2acb0a627f963a547c2ac Mon Sep 17 00:00:00 2001 From: mn_manan Date: Mon, 21 Nov 2022 10:57:52 +0800 Subject: [PATCH 19/60] fixed 7472c7e from https://gitee.com/mn_manan/drivers_hdf_core/pulls/1565 fix: update the data type of light Signed-off-by: mn_manan --- .../misc/light/driver/include/light_driver.h | 26 ++++++++++++------- .../misc/light/driver/src/light_driver.c | 6 ++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/framework/model/misc/light/driver/include/light_driver.h b/framework/model/misc/light/driver/include/light_driver.h index 2b1531279..55e15338d 100644 --- a/framework/model/misc/light/driver/include/light_driver.h +++ b/framework/model/misc/light/driver/include/light_driver.h @@ -77,6 +77,12 @@ enum LightId { LIGHT_ID_BUTT, }; +enum HdfLightType { + HDF_LIGHT_TYPE_SINGLE_COLOR = 1, + HDF_LIGHT_TYPE_RGB_COLOR = 2, + HDF_LIGHT_TYPE_WRGB_COLOR = 3, +}; + enum LightFlashMode { LIGHT_FLASH_NONE = 0, LIGHT_FLASH_TIMED = 1, @@ -90,19 +96,21 @@ struct LightFlashEffect { }; struct WRGBColor { - int w; - int r; - int g; - int b; + uint8_t w; + uint8_t r; + uint8_t g; + uint8_t b; }; + struct RGBColor { - int brightness; - int r; - int g; - int b; + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t reserved; }; union ColorValue { + int32_t singleColor; struct RGBColor rgbColor; struct WRGBColor wrgbColor; }; @@ -120,7 +128,7 @@ struct LightInfo { char lightName[NAME_MAX_LEN]; uint32_t lightId; uint32_t lightNumber; - int32_t reserved; + int32_t lightType; }; struct LightDeviceInfo { diff --git a/framework/model/misc/light/driver/src/light_driver.c b/framework/model/misc/light/driver/src/light_driver.c index 4c980d704..cca589f1e 100644 --- a/framework/model/misc/light/driver/src/light_driver.c +++ b/framework/model/misc/light/driver/src/light_driver.c @@ -67,9 +67,9 @@ static int32_t GetAllLightInfo(struct HdfSBuf *data, struct HdfSBuf *reply) return HDF_FAILURE; } - lightInfo.reserved = 0; - if (!HdfSbufWriteUint32(reply, lightInfo.reserved)) { - HDF_LOGE("%s: write reserved failed", __func__); + lightInfo.lightType = HDF_LIGHT_TYPE_RGB_COLOR; + if (!HdfSbufWriteUint32(reply, lightInfo.lightType)) { + HDF_LOGE("%s: write lightType failed", __func__); return HDF_FAILURE; } } -- Gitee From 513474fef382a9f207779b4a13da3acf3e157f09 Mon Sep 17 00:00:00 2001 From: zhang Date: Wed, 23 Nov 2022 19:18:34 +0800 Subject: [PATCH 20/60] fix:Optimize DevMgrTest use cases Signed-off-by: zhang --- .../uhdf2/host/test/unittest/devmgr_test.cpp | 67 ++++++++++++++++--- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp index 5950d9d18..2b592a90b 100644 --- a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp +++ b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp @@ -13,29 +13,39 @@ * limitations under the License. */ -#include -#include -#include + #include -#include "hdf_log.h" -#include "osal_mem.h" -#include "securec.h" + +#include +#include +#include #define HDF_LOG_TAG driver_manager namespace OHOS { using namespace testing::ext; +static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; + class DevMgrTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp(); void TearDown(); + static const uint32_t waitTime = 30; + static const uint32_t timeout = 200; + static struct HDIServiceManager *servmgr; + static struct HDIDeviceManager *devmgr; }; +struct HDIServiceManager *DevMgrTest::servmgr = nullptr; +struct HDIDeviceManager *DevMgrTest::devmgr = nullptr; + void DevMgrTest::SetUpTestCase() { + servmgr = HDIServiceManagerGet(); + devmgr = HDIDeviceManagerGet(); } void DevMgrTest::TearDownTestCase() @@ -51,14 +61,51 @@ void DevMgrTest::TearDown() } /* -* @tc.name: DriverLoaderTest_001 +* @tc.name: DriverLoaderTest * @tc.desc: driver load test * @tc.type: FUNC * @tc.require: AR000DT1TK */ -HWTEST_F(DevMgrTest, DriverLoaderTest_001, TestSize.Level1) +HWTEST_F(DevMgrTest, DriverLoaderTest, TestSize.Level1) +{ + ASSERT_TRUE(servmgr != nullptr); + ASSERT_TRUE(devmgr != nullptr); + + int ret = devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); + ASSERT_EQ(ret, HDF_SUCCESS); + + struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + uint32_t cnt = 0; + while (sampleService == nullptr && cnt < timeout) { + OsalMSleep(waitTime); + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + cnt++; + } + + ASSERT_TRUE(sampleService != nullptr); +} +/* +* @tc.name: DriverUnLoaderTest +* @tc.desc: driver unload test +* @tc.type: FUNC +* @tc.require: AR000DT1TK +*/ +HWTEST_F(DevMgrTest, DriverUnLoaderTest, TestSize.Level1) { - bool flag = true; - EXPECT_TRUE(flag); + ASSERT_TRUE(servmgr != nullptr); + ASSERT_TRUE(devmgr != nullptr); + + int ret = devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + ASSERT_EQ(ret, HDF_SUCCESS); + + uint32_t cnt = 0; + struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + while (sampleService != nullptr && cnt < timeout) { + OsalMSleep(waitTime); + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + cnt++; + } + + ASSERT_TRUE(sampleService == nullptr); } } // namespace OHOS -- Gitee From 2b63b0e59d2d4b44eb8f04e536c1b89984928415 Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Thu, 24 Nov 2022 19:27:35 +0800 Subject: [PATCH 21/60] fixed dc4f392 from https://gitee.com/xuxiaoqing16/drivers_hdf_core/pulls/1564 fix: fix the fuzz stress test failure caused by thread name Signed-off-by: xuxiaoqing --- .../adapter/syscall/src/hdf_syscall_adapter.c | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c index f1228a6ed..9c75c9e4b 100644 --- a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -13,8 +13,9 @@ #include #include #include -#include #include +#include +#include #include #include "hdf_base.h" @@ -37,8 +38,6 @@ #define LOAD_IOSERVICE_WAIT_COUNT 20 // ms #define THREAD_NAME_LEN_MAX 16 -atomic_int g_evtListenerCount = 0; - static bool HaveOnlyOneElement(const struct DListHead *head) { if (head->next != head && head->next->next == head) { @@ -219,6 +218,19 @@ static int32_t AssignPfds(struct HdfDevListenerThread *thread, struct pollfd **p return pfdCount; } +static void SetThreadName(void) +{ + char newTitle[THREAD_NAME_LEN_MAX] = {0}; + + int32_t tid = syscall(SYS_gettid); + int32_t ret = sprintf_s(newTitle, THREAD_NAME_LEN_MAX, "%s%d", "evt_list_", tid); + if (ret > 0) { + ret = prctl(PR_SET_NAME, newTitle); + } + + return; +} + #define POLL_WAIT_TIME_MS 100 static int32_t HdfDevEventListenTask(void *para) { @@ -228,6 +240,7 @@ static int32_t HdfDevEventListenTask(void *para) int32_t pollCount = 0; thread->status = LISTENER_RUNNING; + SetThreadName(); while (!thread->shouldStop) { if (thread->pollChanged) { pollCount = AssignPfds(thread, &pfds, &pfdSize); @@ -444,15 +457,9 @@ static int32_t HdfDevListenerThreadStart(struct HdfDevListenerThread *thread) return HDF_ERR_IO; } } - char threadName[THREAD_NAME_LEN_MAX] = {0}; - ret = sprintf_s(threadName, THREAD_NAME_LEN_MAX, "%s%d", "event_listen", g_evtListenerCount++); - if (ret < 0) { - HDF_LOGE("%{public}s generate thread name failed", __func__); - return HDF_FAILURE; - } struct OsalThreadParam config = { - .name = threadName, + .name = "evt_listen", .priority = OSAL_THREAD_PRI_DEFAULT, .stackSize = 0, }; -- Gitee From 726baf5b26d87c0aed21d41da1d2889c9edafdb7 Mon Sep 17 00:00:00 2001 From: yueyan Date: Thu, 24 Nov 2022 17:52:53 +0800 Subject: [PATCH 22/60] fixed 41af322 from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1578 fix:add parameter checking code Signed-off-by: yueyan --- .../tools/hdi-gen/ast/ast_array_type.cpp | 48 +++++++++++++++++- .../tools/hdi-gen/ast/ast_interface_type.cpp | 50 ++++++++++++++++--- .../tools/hdi-gen/ast/ast_interface_type.h | 3 ++ framework/tools/hdi-gen/ast/ast_map_type.cpp | 7 ++- framework/tools/hdi-gen/ast/ast_smq_type.cpp | 5 ++ .../tools/hdi-gen/ast/ast_string_type.cpp | 2 + .../codegen/c_client_proxy_code_emitter.cpp | 2 +- .../codegen/c_custom_types_code_emitter.cpp | 2 + .../codegen/c_interface_code_emitter.cpp | 5 -- .../codegen/c_interface_code_emitter.h | 2 - .../codegen/c_service_driver_code_emitter.cpp | 4 +- .../codegen/c_service_stub_code_emitter.cpp | 19 +++++-- .../tools/hdi-gen/codegen/code_emitter.cpp | 25 +++++++++- .../tools/hdi-gen/codegen/code_emitter.h | 3 +- .../codegen/cpp_custom_types_code_emitter.cpp | 2 + .../codegen/cpp_interface_code_emitter.cpp | 4 ++ .../codegen/cpp_service_stub_code_emitter.cpp | 6 ++- framework/tools/hdi-gen/parser/parser.cpp | 5 ++ framework/tools/hdi-gen/util/common.h | 5 ++ 19 files changed, 173 insertions(+), 26 deletions(-) diff --git a/framework/tools/hdi-gen/ast/ast_array_type.cpp b/framework/tools/hdi-gen/ast/ast_array_type.cpp index 84b502f3c..5908e1135 100644 --- a/framework/tools/hdi-gen/ast/ast_array_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_array_type.cpp @@ -103,6 +103,8 @@ void ASTArrayType::EmitCWriteVar(const std::string &parcelName, const std::strin return; } + sb.Append(prefix).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, + lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix).AppendFormat("if (%s == NULL || %s == 0) {\n", name.c_str(), lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("if (!HdfSbufWriteUint32(%s, 0)) {\n", parcelName.c_str()); sb.Append(prefix + TAB + TAB) @@ -139,6 +141,8 @@ void ASTArrayType::EmitCProxyWriteOutVar(const std::string &parcelName, const st const std::string &ecName, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) const { std::string lenName = StringHelper::Format("*%sLen", name.c_str()); + sb.Append(prefix).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, + lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix).AppendFormat("if (!HdfSbufWriteUint32(%s, %s)) {\n", parcelName.c_str(), lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); @@ -174,6 +178,9 @@ void ASTArrayType::EmitCProxyReadVar(const std::string &parcelName, const std::s sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("%s(*%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, + lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); + if (Options::GetInstance().DoGenerateKernelCode()) { sb.Append(prefix).AppendFormat("for (i = 0; i < *%s; i++) {\n", lenName.c_str()); } else { @@ -220,6 +227,8 @@ void ASTArrayType::EmitCStubReadVar(const std::string &parcelName, const std::st sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, + lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix).AppendFormat("if (%s > 0) {\n", lenName.c_str()); EmitCMallocVar(name, lenName, false, ecName, gotoLabel, sb, prefix + TAB); @@ -257,6 +266,9 @@ void ASTArrayType::EmitCStubReadOutVar(const std::string &buffSizeName, const st sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, + lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); + sb.Append(prefix + TAB).AppendFormat("if (%s > 0) {\n", lenName.c_str()); EmitCMallocVar(name, lenName, false, ecName, gotoLabel, sb, prefix + TAB + TAB); sb.Append(prefix + TAB).Append("}\n"); @@ -326,6 +338,8 @@ void ASTArrayType::EmitCppReadVar(const std::string &parcelName, const std::stri } sb.Append(prefix).AppendFormat("uint32_t %sSize = %s.ReadUint32();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s(%sSize, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, + name.c_str(), MAX_BUFF_SIZE_MACRO); sb.Append(prefix).AppendFormat("%s.clear();\n", name.c_str()); sb.Append(prefix).AppendFormat("%s.reserve(%sSize);\n", name.c_str(), name.c_str()); sb.Append(prefix).AppendFormat( @@ -356,7 +370,8 @@ void ASTArrayType::EmitCMarshalling(const std::string &name, StringBuilder &sb, return; } - sb.Append(prefix).AppendFormat("if (!HdfSbufWriteUint32(data, %s)) {\n", lenName.c_str()); + sb.Append(prefix).AppendFormat( + "if (%s > %s || !HdfSbufWriteUint32(data, %s)) {\n", lenName.c_str(), MAX_BUFF_SIZE_MACRO, lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", lenName.c_str()); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n"); @@ -395,6 +410,12 @@ void ASTArrayType::EmitCUnMarshalling(const std::string &name, const std::string sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n"); + + sb.Append(prefix).AppendFormat("if (%s > %s) {\n", lenName.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: %s is invalid data\", __func__);\n", lenName.c_str()); + sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix).Append("}\n"); + sb.Append(prefix).AppendFormat("if (%s > 0) {\n", lenName.c_str()); std::string newPrefix = prefix + TAB; @@ -488,6 +509,8 @@ void ASTArrayType::EmitCppUnMarshalling(const std::string &parcelName, const std } sb.Append(prefix).AppendFormat("uint32_t %s = %s.ReadUint32();\n", sizeName.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat( + "%s(%s, >, %s, false);\n", CHECK_VALUE_RETURN_MACRO, sizeName.c_str(), MAX_BUFF_SIZE_MACRO); sb.Append(prefix).AppendFormat("%s.clear();\n", name.c_str()); sb.Append(prefix).AppendFormat("%s.reserve(%s);\n", name.c_str(), sizeName.c_str()); sb.Append(prefix).AppendFormat( @@ -824,6 +847,11 @@ void ASTArrayType::EmitCReadMethods( sb.Append(prefix + TAB + TAB).Append("return false;\n"); sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).AppendFormat("if (elementCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: invalid elementCount\", __func__);\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).Append("if (elementCount == 0) {\n"); sb.Append(prefix + TAB + TAB).Append("goto FINISHED;\n"); sb.Append(prefix + TAB).Append("}\n\n"); @@ -885,6 +913,12 @@ void ASTArrayType::EmitCStubReadMethodBody(StringBuilder &sb, const std::string sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read element count\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); + + sb.Append(prefix).AppendFormat("if (elementCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid elementCount\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).Append("if (elementCount == 0) {\n"); sb.Append(prefix + TAB).Append("*count = elementCount;\n"); sb.Append(prefix + TAB).Append("return true;\n"); @@ -932,6 +966,10 @@ void ASTArrayType::EmitCWriteStrArrayMethods( sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: invalid sbuf\", __func__);\n"); sb.Append(prefix + TAB + TAB).Append("return false;\n"); sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).AppendFormat("if (count > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: invalid count\", __func__);\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n\n"); sb.Append(prefix + TAB).Append("if (!HdfSbufWriteUint32(parcel, count)) {\n"); sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: failed to write count of array\", __func__);\n"); sb.Append(prefix + TAB + TAB).Append("return false;\n"); @@ -980,6 +1018,10 @@ void ASTArrayType::EmitCReadStrArrayMethodBody(StringBuilder &sb, const std::str sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read count of array\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("if (dataCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid dataCount\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n\n"); sb.Append(prefix).Append("if (dataCount == 0) {\n"); sb.Append(prefix + TAB).Append("*count = dataCount;\n"); sb.Append(prefix + TAB).Append("return true;\n"); @@ -1057,6 +1099,10 @@ void ASTArrayType::EmitCStubReadStrArrayMethodBody(StringBuilder &sb, const std: sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read count of array\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("if (dataCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid dataCount\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n\n"); sb.Append(prefix).Append("if (dataCount == 0) {\n"); sb.Append(prefix + TAB).Append("*count = dataCount;\n"); sb.Append(prefix + TAB).Append("return true;\n"); diff --git a/framework/tools/hdi-gen/ast/ast_interface_type.cpp b/framework/tools/hdi-gen/ast/ast_interface_type.cpp index 87c9b2d47..d7e57487e 100644 --- a/framework/tools/hdi-gen/ast/ast_interface_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_interface_type.cpp @@ -165,12 +165,13 @@ void ASTInterfaceType::EmitCppReadVar(const std::string &parcelName, const std:: const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat("sptr<%s> %s = hdi_facecast<%s>(%s.ReadRemoteObject());\n", name_.c_str(), - name.c_str(), name_.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat( - "%s = hdi_facecast<%s>(%s.ReadRemoteObject());\n", name.c_str(), name_.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("sptr<%s> %s;\n", name_.c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat( + "if (!ReadInterface<%s>(%s, %s)) {\n", name_.c_str(), parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read interface object\", __func__);\n"); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTInterfaceType::EmitJavaWriteVar( @@ -211,11 +212,17 @@ void ASTInterfaceType::RegisterWriteMethod(Options::Language language, SerMode m void ASTInterfaceType::RegisterReadMethod(Options::Language language, SerMode mode, UtilMethodMap &methods) const { using namespace std::placeholders; - std::string methodName = StringHelper::Format("Read%s", name_.c_str()); + switch (language) { - case Options::Language::C: + case Options::Language::C: { + std::string methodName = StringHelper::Format("Read%s", name_.c_str()); methods.emplace(methodName, std::bind(&ASTInterfaceType::EmitCReadMethods, this, _1, _2, _3, _4)); break; + } + case Options::Language::CPP: { + methods.emplace("ReadInterface", std::bind(&ASTInterfaceType::EmitCppReadMethods, this, _1, _2, _3, _4)); + break; + } default: break; } @@ -272,5 +279,34 @@ void ASTInterfaceType::EmitCReadMethods(StringBuilder &sb, const std::string &pr sb.Append(prefix + TAB).AppendFormat("return %sGet(remote);\n", name_.c_str()); sb.Append(prefix).Append("}\n"); } + +void ASTInterfaceType::EmitCppReadMethods(StringBuilder &sb, const std::string &prefix, + const std::string &methodPrefix, bool isDecl) const +{ + std::string methodName = StringHelper::Format("%sReadInterface", methodPrefix.c_str(), name_.c_str()); + sb.Append(prefix).AppendFormat("template\n"); + sb.Append(prefix).AppendFormat("static bool %s(MessageParcel &parcel, sptr& object)", + methodName.c_str()); + if (isDecl) { + sb.Append(";\n"); + return; + } else { + sb.Append("\n"); + } + + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).Append("sptr remote = parcel.ReadRemoteObject();\n"); + sb.Append(prefix + TAB).Append("if (remote == nullptr) {\n"); + sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: read an invalid remote object\", __func__);\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).Append("object = hdi_facecast(remote);\n"); + sb.Append(prefix + TAB).Append("if (object == nullptr) {\n"); + sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: failed to cast interface object\", __func__);\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).Append("return true;\n"); + sb.Append(prefix).Append("}\n"); +} } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_interface_type.h b/framework/tools/hdi-gen/ast/ast_interface_type.h index 7c4ac0e9d..84bbafa55 100644 --- a/framework/tools/hdi-gen/ast/ast_interface_type.h +++ b/framework/tools/hdi-gen/ast/ast_interface_type.h @@ -154,6 +154,9 @@ public: void EmitCReadMethods( StringBuilder &sb, const std::string &prefix, const std::string &methodPrefix, bool isDecl) const; + + void EmitCppReadMethods( + StringBuilder &sb, const std::string &prefix, const std::string &methodPrefix, bool isDecl) const; private: std::string license_; diff --git a/framework/tools/hdi-gen/ast/ast_map_type.cpp b/framework/tools/hdi-gen/ast/ast_map_type.cpp index 8b6efa8b1..465e0a2b0 100644 --- a/framework/tools/hdi-gen/ast/ast_map_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_map_type.cpp @@ -106,8 +106,9 @@ void ASTMapType::EmitCppReadVar(const std::string &parcelName, const std::string sb.Append(prefix).AppendFormat("%s %s;\n", EmitCppType().c_str(), name.c_str()); } sb.Append(prefix).AppendFormat("uint32_t %sSize = %s.ReadUint32();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s(%sSize, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, + name.c_str(), MAX_BUFF_SIZE_MACRO); sb.Append(prefix).AppendFormat("for (uint32_t i = 0; i < %sSize; ++i) {\n", name.c_str()); - std::string KeyName = StringHelper::Format("key%d", innerLevel); std::string valueName = StringHelper::Format("value%d", innerLevel); innerLevel++; @@ -143,8 +144,10 @@ void ASTMapType::EmitCppUnMarshalling(const std::string &parcelName, const std:: sb.Append(prefix).AppendFormat("%s %s;\n", EmitCppType().c_str(), memberName.c_str()); } sb.Append(prefix).AppendFormat("uint32_t %sSize = %s.ReadUint32();\n", memberName.c_str(), parcelName.c_str()); - sb.Append(prefix).AppendFormat("for (uint32_t i = 0; i < %sSize; ++i) {\n", memberName.c_str()); + sb.Append(prefix).AppendFormat("%s(%sSize, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, + memberName.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("for (uint32_t i = 0; i < %sSize; ++i) {\n", memberName.c_str()); std::string KeyName = StringHelper::Format("key%d", innerLevel); std::string valueName = StringHelper::Format("value%d", innerLevel); innerLevel++; diff --git a/framework/tools/hdi-gen/ast/ast_smq_type.cpp b/framework/tools/hdi-gen/ast/ast_smq_type.cpp index 4971dd139..9e1772f47 100644 --- a/framework/tools/hdi-gen/ast/ast_smq_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_smq_type.cpp @@ -139,6 +139,11 @@ void ASTAshmemType::EmitCppReadVar(const std::string &parcelName, const std::str } else { sb.Append(prefix).AppendFormat("%s = %s.ReadAshmem();\n", name.c_str(), parcelName.c_str()); } + + sb.Append(prefix).AppendFormat("if (%s == nullptr) {\n", name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: read an invalid ashmem object\", __func__);\n"); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_string_type.cpp b/framework/tools/hdi-gen/ast/ast_string_type.cpp index 240516a3d..a3dc9587e 100644 --- a/framework/tools/hdi-gen/ast/ast_string_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_string_type.cpp @@ -118,6 +118,8 @@ void ASTStringType::EmitCStubReadOutVar(const std::string &buffSizeName, const s sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, + lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix + TAB).AppendFormat("if (%s > 0) {\n", lenName.c_str()); sb.Append(prefix + TAB + TAB) diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp index e17089cc4..bb5b9c46b 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp @@ -694,7 +694,7 @@ void CClientProxyCodeEmitter::EmitProxySetInterfaceDesc( void CClientProxyCodeEmitter::EmitProxyCreateProxyObject(const std::string &clientObjName, const std::string &remoteName, const std::string &recycleFuncName, StringBuilder &sb, const std::string &prefix) { - sb.Append(prefix).AppendFormat("struct %sProxy *proxy = (struct %sProxy *)OsalMemAlloc(sizeof(struct %sProxy));\n", + sb.Append(prefix).AppendFormat("struct %sProxy *proxy = (struct %sProxy *)OsalMemCalloc(sizeof(struct %sProxy));\n", baseName_.c_str(), baseName_.c_str(), baseName_.c_str()); sb.Append(prefix).Append("if (proxy == NULL) {\n"); sb.Append(prefix + TAB) diff --git a/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp index 48a8fdc00..9f90ce9dd 100644 --- a/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_custom_types_code_emitter.cpp @@ -86,6 +86,8 @@ void CCustomTypesCodeEmitter::EmitCustomTypesHeaderFile() sb.Append("\n"); EmitHeaderInclusions(sb); sb.Append("\n"); + EmitInterfaceBuffSizeMacro(sb); + sb.Append("\n"); EmitHeadExternC(sb); sb.Append("\n"); EmitCustomTypeDecls(sb); diff --git a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp index f9579c659..ad5aa1dc5 100644 --- a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.cpp @@ -109,11 +109,6 @@ void CInterfaceCodeEmitter::EmitInterfaceVersionMacro(StringBuilder &sb) sb.AppendFormat("#define %s %u\n", minorVerName_.c_str(), ast_->GetMinorVer()); } -void CInterfaceCodeEmitter::EmitInterfaceBuffSizeMacro(StringBuilder &sb) -{ - sb.AppendFormat("#define %s (4 * 1024) // 4KB\n", bufferSizeMacroName_.c_str()); -} - void CInterfaceCodeEmitter::EmitInterfaceDefinition(StringBuilder &sb) { sb.AppendFormat("struct %s {\n", interfaceName_.c_str()); diff --git a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h index a84e0ba29..19ed34fe7 100644 --- a/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h +++ b/framework/tools/hdi-gen/codegen/c_interface_code_emitter.h @@ -36,8 +36,6 @@ private: void EmitInterfaceVersionMacro(StringBuilder &sb); - void EmitInterfaceBuffSizeMacro(StringBuilder &sb); - void EmitInterfaceDefinition(StringBuilder &sb); void EmitInterfaceMethods(StringBuilder &sb, const std::string &prefix); diff --git a/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp index 1fadbafa5..57e79ea4b 100644 --- a/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_driver_code_emitter.cpp @@ -186,7 +186,7 @@ void CServiceDriverCodeEmitter::EmitKernelDriverBind(StringBuilder &sb) sb.Append(TAB).Append("HDF_LOGI(\"%{public}s: driver bind start\", __func__);\n"); sb.Append("\n"); - sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = (struct Hdf%sHost *)OsalMemAlloc(", baseName_.c_str(), + sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = (struct Hdf%sHost *)OsalMemCalloc(", baseName_.c_str(), hostName_.c_str(), baseName_.c_str()); sb.AppendFormat("sizeof(struct Hdf%sHost));\n", baseName_.c_str()); sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName_.c_str()); @@ -223,7 +223,7 @@ void CServiceDriverCodeEmitter::EmitDriverBind(StringBuilder &sb) sb.Append(TAB).Append(TAB).Append("return ret;\n"); sb.Append(TAB).Append("}\n\n"); - sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = (struct Hdf%sHost *)OsalMemAlloc(", baseName_.c_str(), + sb.Append(TAB).AppendFormat("struct Hdf%sHost *%s = (struct Hdf%sHost *)OsalMemCalloc(", baseName_.c_str(), hostName_.c_str(), baseName_.c_str()); sb.AppendFormat("sizeof(struct Hdf%sHost));\n", baseName_.c_str()); sb.Append(TAB).AppendFormat("if (%s == NULL) {\n", hostName_.c_str()); diff --git a/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp index 998964552..9db085cb7 100644 --- a/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp @@ -357,7 +357,7 @@ void CServiceStubCodeEmitter::EmitReadStubMethodParameter(const AutoPtrGetTypeKind() == TypeKind::TYPE_INTERFACE) { type->EmitCStubReadVar(parcelName, param->GetName(), errorCodeName_, gotoLabel, sb, prefix); } else if (type->GetTypeKind() == TypeKind::TYPE_STRUCT) { - sb.Append(prefix).AppendFormat("%s = (%s*)OsalMemAlloc(sizeof(%s));\n", param->GetName().c_str(), + sb.Append(prefix).AppendFormat("%s = (%s*)OsalMemCalloc(sizeof(%s));\n", param->GetName().c_str(), type->EmitCType(TypeMode::NO_MODE).c_str(), type->EmitCType(TypeMode::NO_MODE).c_str()); sb.Append(prefix).AppendFormat("if (%s == NULL) {\n", param->GetName().c_str()); sb.Append(prefix + TAB) @@ -369,7 +369,7 @@ void CServiceStubCodeEmitter::EmitReadStubMethodParameter(const AutoPtrGetTypeKind() == TypeKind::TYPE_UNION) { std::string cpName = StringHelper::Format("%sCp", param->GetName().c_str()); type->EmitCStubReadVar(parcelName, cpName, errorCodeName_, gotoLabel, sb, prefix); - sb.Append(prefix).AppendFormat("%s = (%s*)OsalMemAlloc(sizeof(%s));\n", param->GetName().c_str(), + sb.Append(prefix).AppendFormat("%s = (%s*)OsalMemCalloc(sizeof(%s));\n", param->GetName().c_str(), type->EmitCType(TypeMode::NO_MODE).c_str(), type->EmitCType(TypeMode::NO_MODE).c_str()); sb.Append(prefix).AppendFormat("if (%s == NULL) {\n", param->GetName().c_str()); sb.Append(prefix + TAB) @@ -432,7 +432,7 @@ void CServiceStubCodeEmitter::EmitOutVarMemInitialize(const AutoPtrIsStringType() || type->IsArrayType() || type->IsListType()) { param->EmitCStubReadOutVar( - bufferSizeMacroName_, flagOfSetMemName_, parcelName, errorCodeName_, gotoLabel, sb, prefix); + MAX_BUFF_SIZE_MACRO, flagOfSetMemName_, parcelName, errorCodeName_, gotoLabel, sb, prefix); sb.Append("\n"); } } @@ -440,6 +440,19 @@ void CServiceStubCodeEmitter::EmitOutVarMemInitialize(const AutoPtr &method, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) { + sb.Append(prefix).Append("if (serviceImpl == NULL) {\n"); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid serviceImpl object\", __func__);\n"); + sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_OBJECT;\n", errorCodeName_.c_str()); + sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix).Append("}\n\n"); + + sb.Append(prefix).AppendFormat("if (serviceImpl->%s == NULL) {\n", method->GetName().c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: invalid interface function %s \", __func__);\n", + method->GetName().c_str()); + sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_NOT_SUPPORT;\n", errorCodeName_.c_str()); + sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix).Append("}\n\n"); + if (method->GetParameterNumber() == 0) { sb.Append(prefix).AppendFormat( "%s = serviceImpl->%s(serviceImpl);\n", errorCodeName_.c_str(), method->GetName().c_str()); diff --git a/framework/tools/hdi-gen/codegen/code_emitter.cpp b/framework/tools/hdi-gen/codegen/code_emitter.cpp index 62d7ef3c4..c1f3f01b6 100644 --- a/framework/tools/hdi-gen/codegen/code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/code_emitter.cpp @@ -56,7 +56,6 @@ bool CodeEmitter::Reset(const AutoPtr &ast, const std::string &targetDirect majorVerName_ = StringHelper::Format("%s_MAJOR_VERSION", ConstantName(interfaceName_).c_str()); minorVerName_ = StringHelper::Format("%s_MINOR_VERSION", ConstantName(interfaceName_).c_str()); - bufferSizeMacroName_ = StringHelper::Format("%s_BUFF_MAX_SIZE", ConstantName(baseName_).c_str()); std::string prefix = StringHelper::Format("%c%s", tolower(baseName_[0]), baseName_.substr(1).c_str()); dataParcelName_ = prefix + "Data"; @@ -259,5 +258,29 @@ void CodeEmitter::EmitUtilMethods( methodPair.second(sb, "", prefix, isDecl); } } + +void CodeEmitter::EmitInterfaceBuffSizeMacro(StringBuilder &sb) +{ + sb.AppendFormat("#ifndef %s\n", MAX_BUFF_SIZE_MACRO); + sb.AppendFormat("#define %s (%s)\n", MAX_BUFF_SIZE_MACRO, MAX_BUFF_SIZE_VALUE); + sb.Append("#endif\n\n"); + + sb.AppendFormat("#ifndef %s\n", CHECK_VALUE_RETURN_MACRO); + sb.AppendFormat("#define %s(lv, compare, rv, ret) do { \\\n", CHECK_VALUE_RETURN_MACRO); + sb.Append(TAB).Append("if ((lv) compare (rv)) { \\\n"); + sb.Append(TAB).Append(TAB).Append("return ret; \\\n"); + sb.Append(TAB).Append("} \\\n"); + sb.Append("} while (false)\n"); + sb.Append("#endif\n\n"); + + sb.AppendFormat("#ifndef %s\n", CHECK_VALUE_RET_GOTO_MACRO); + sb.AppendFormat("#define %s(lv, compare, rv, ret, value, table) do { \\\n", CHECK_VALUE_RET_GOTO_MACRO); + sb.Append(TAB).Append("if ((lv) compare (rv)) { \\\n"); + sb.Append(TAB).Append(TAB).Append("ret = value; \\\n"); + sb.Append(TAB).Append(TAB).Append("goto table; \\\n"); + sb.Append(TAB).Append("} \\\n"); + sb.Append("} while (false)\n"); + sb.Append("#endif\n"); +} } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/codegen/code_emitter.h b/framework/tools/hdi-gen/codegen/code_emitter.h index 9deb94441..983e0db80 100644 --- a/framework/tools/hdi-gen/codegen/code_emitter.h +++ b/framework/tools/hdi-gen/codegen/code_emitter.h @@ -118,6 +118,8 @@ protected: virtual void EmitUtilMethods( StringBuilder &sb, const std::string &prefix, const UtilMethodMap &methods, bool isDecl); + void EmitInterfaceBuffSizeMacro(StringBuilder &sb); + protected: bool isKernelCode_ = false; AutoPtr ast_ = nullptr; @@ -135,7 +137,6 @@ protected: std::string implFullName_; std::string majorVerName_; std::string minorVerName_; - std::string bufferSizeMacroName_; std::string dataParcelName_; std::string replyParcelName_; diff --git a/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp index ca0e3558c..6348db16b 100644 --- a/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp @@ -90,6 +90,8 @@ void CppCustomTypesCodeEmitter::EmitCustomTypesHeaderFile() sb.Append("\n"); EmitHeaderFileInclusions(sb); sb.Append("\n"); + EmitInterfaceBuffSizeMacro(sb); + sb.Append("\n"); EmitBeginNamespace(sb); sb.Append("\n"); EmitUsingNamespace(sb); diff --git a/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp index 842ecfdd0..bd819d76b 100644 --- a/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_interface_code_emitter.cpp @@ -46,6 +46,10 @@ void CppInterfaceCodeEmitter::EmitInterfaceHeaderFile() EmitInterfaceInclusions(sb); sb.Append("\n"); EmitInterfaceVersionMacro(sb); + if (!Options::GetInstance().DoPassthrough()) { + sb.Append("\n"); + EmitInterfaceBuffSizeMacro(sb); + } sb.Append("\n"); EmitBeginNamespace(sb); EmitUsingNamespace(sb); diff --git a/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp index 06541a12b..16e2b336d 100644 --- a/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp @@ -412,8 +412,12 @@ void CppServiceStubCodeEmitter::EmitLocalVariable( AutoPtr type = param->GetType(); if (type->IsStringType() || type->IsArrayType() || type->IsListType()) { sb.Append(prefix).AppendFormat("if (%s) {\n", flagOfSetMemName_.c_str()); + std::string capacityName = "capacity"; sb.Append(prefix + TAB) - .AppendFormat("%s.reserve(%s.ReadUint32());\n", param->GetName().c_str(), parcelName.c_str()); + .AppendFormat("uint32_t %s = %s.ReadUint32();\n", capacityName.c_str(), parcelName.c_str()); + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, + capacityName.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).AppendFormat("%s.reserve(%s);\n", param->GetName().c_str(), capacityName.c_str()); sb.Append(prefix).Append("}\n"); } } diff --git a/framework/tools/hdi-gen/parser/parser.cpp b/framework/tools/hdi-gen/parser/parser.cpp index 91a72f369..3712feb98 100644 --- a/framework/tools/hdi-gen/parser/parser.cpp +++ b/framework/tools/hdi-gen/parser/parser.cpp @@ -451,6 +451,11 @@ void Parser::ParseInterfaceBody(const AutoPtr &interface) lexer_.GetToken(); } + token = lexer_.PeekToken(); + if (token.kind_ == TokenType::SEMICOLON) { + lexer_.GetToken(); + } + interface->AddVersionMethod(CreateGetVersionMethod()); } diff --git a/framework/tools/hdi-gen/util/common.h b/framework/tools/hdi-gen/util/common.h index 757a0bb4b..64a52eb57 100644 --- a/framework/tools/hdi-gen/util/common.h +++ b/framework/tools/hdi-gen/util/common.h @@ -19,6 +19,11 @@ namespace HDI { #else constexpr char SEPARATOR = '\\'; #endif + + constexpr const char *MAX_BUFF_SIZE_MACRO = "HDI_BUFF_MAX_SIZE"; + constexpr const char *MAX_BUFF_SIZE_VALUE = "1024 * 4"; + constexpr const char *CHECK_VALUE_RETURN_MACRO = "HDI_CHECK_VALUE_RETURN"; + constexpr const char *CHECK_VALUE_RET_GOTO_MACRO = "HDI_CHECK_VALUE_RET_GOTO"; } } -- Gitee From 35d707ae6967ccb1cf1890a25b3794b091d44555 Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Sat, 26 Nov 2022 17:09:09 +0800 Subject: [PATCH 23/60] fixed 9eb5bf5 from https://gitee.com/xuxiaoqing16/drivers_hdf_core/pulls/1586 fix: fix the cppcheck warning of framework Signed-off-by: xuxiaoqing --- framework/core/adapter/syscall/src/hdf_syscall_adapter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c index 9c75c9e4b..9bf19430f 100644 --- a/framework/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/framework/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -226,6 +226,9 @@ static void SetThreadName(void) int32_t ret = sprintf_s(newTitle, THREAD_NAME_LEN_MAX, "%s%d", "evt_list_", tid); if (ret > 0) { ret = prctl(PR_SET_NAME, newTitle); + if (ret < 0) { + HDF_LOGE("%s: failed to set thread name, errno is %d", __func__, errno); + } } return; -- Gitee From 428c639b0acf7610cfc6f369c1f6818601cd6d4e Mon Sep 17 00:00:00 2001 From: yueyan Date: Thu, 24 Nov 2022 13:37:52 +0800 Subject: [PATCH 24/60] fixed 7f8ec1a from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1575 fix:add hcb file path Signed-off-by: yueyan --- adapter/uhdf2/shared/src/hcb_config_entry.c | 32 +++++++++++++++++---- framework/include/utils/hdf_base.h | 1 + 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/adapter/uhdf2/shared/src/hcb_config_entry.c b/adapter/uhdf2/shared/src/hcb_config_entry.c index e3ff2f0a2..ae6b8161f 100644 --- a/adapter/uhdf2/shared/src/hcb_config_entry.c +++ b/adapter/uhdf2/shared/src/hcb_config_entry.c @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include "hcs_dm_parser.h" #include "hcs_tree_if.h" @@ -23,6 +24,7 @@ #ifdef __OHOS_STANDARD_SYS__ #define HOST_CONFIG_PATH HDF_CONFIG_DIR +#define HOST_CHIP_PROD_CONFIG_PATH HDF_CHIP_PROD_CONFIG_DIR #else #define HOST_CONFIG_PATH "/system/etc/hdfconfig" #endif @@ -34,6 +36,28 @@ static int GetProductName(char *name, int maxLen) return strcpy_s(name, maxLen, "default"); } +static bool GetConfigFilePath(const char *productName, char *configPath, size_t configPathLen) +{ + static const char *adapterConfigPath[] = { + HOST_CONFIG_PATH, + HOST_CHIP_PROD_CONFIG_PATH, + }; + + size_t pathNum = sizeof(adapterConfigPath) / sizeof(adapterConfigPath[0]); + for (size_t i = 0; i < pathNum; ++i) { + if (sprintf_s(configPath, configPathLen - 1, "%s/hdf_%s.hcb", adapterConfigPath[i], productName) < 0) { + HDF_LOGE("failed to generate file path"); + continue; + } + + if (access(configPath, F_OK | R_OK) == 0) { + return true; + } + HDF_LOGD("invalid config file path or permission:%{public}s", configPath); + } + return false; +} + const struct DeviceResourceNode *HdfGetHcsRootNode(void) { char productName[PRODUCT_NAME_MAX] = { 0 }; @@ -44,14 +68,12 @@ const struct DeviceResourceNode *HdfGetHcsRootNode(void) return NULL; } - ret = sprintf_s(configPath, PATH_MAX - 1, "%s/hdf_%s.hcb", HOST_CONFIG_PATH, productName); - if (ret < 0) { - HDF_LOGE("config path error"); + if (!GetConfigFilePath(productName, configPath, PATH_MAX)) { + HDF_LOGE("failed to get config file path"); return NULL; } - const char *configFileName = configPath; - SetHcsBlobPath(configFileName); + SetHcsBlobPath(configPath); const struct DeviceResourceNode *mgrRoot = HcsGetRootNode(); return mgrRoot; } diff --git a/framework/include/utils/hdf_base.h b/framework/include/utils/hdf_base.h index ba1800a22..c3356a08c 100644 --- a/framework/include/utils/hdf_base.h +++ b/framework/include/utils/hdf_base.h @@ -103,6 +103,7 @@ typedef enum { #define HDF_LIBRARY_DIR "/vendor/lib" #define HDF_ETC_DIR "/vendor/etc" #define HDF_CONFIG_DIR "/vendor/etc/hdfconfig" +#define HDF_CHIP_PROD_CONFIG_DIR "/chip_prod/etc/hdfconfig" #define HDF_MODULE_DIR "/vendor/modules/" #endif -- Gitee From 1326589ffe41ddd4ea7079cf95ad0e6a7a9a9edd Mon Sep 17 00:00:00 2001 From: zhang Date: Tue, 29 Nov 2022 14:35:14 +0800 Subject: [PATCH 25/60] The probability of the hdf framework fails to pull up the service Signed-off-by: zhang --- framework/core/manager/src/devmgr_service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 1728726d9..54c1fee31 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -276,7 +276,9 @@ static int DevmgrServiceAttachDeviceHost( return HDF_FAILURE; } + (void)OsalMutexLock(&hostClnt->hostLock); hostClnt->hostService = hostService; + (void)OsalMutexUnlock(&hostClnt->hostLock); return DevHostServiceClntInstallDriver(hostClnt); } -- Gitee From aa3c794002df6b54802aed66dc108f81f2765512 Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 3 Dec 2022 15:59:41 +0800 Subject: [PATCH 26/60] fix:Add test cases related to query devices and services Signed-off-by: zhang --- .../servmgr/service_manager_hdi_c_test.cpp | 26 +++++++ .../test/servmgr/service_manager_hdi_test.cpp | 68 +++++++++++++++++++ .../test/unittest/sample_driver/sample_hdi.h | 2 + .../sample_driver/sample_hdi_service.cpp | 21 ++++++ .../sample_driver/sample_hdi_service_stub.cpp | 11 +++ framework/core/host/include/devhost_service.h | 8 +++ 6 files changed, 136 insertions(+) diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp index 61bdbb24a..5d7c9c4ec 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_c_test.cpp @@ -564,4 +564,30 @@ HWTEST_F(HdfServiceMangerHdiCTest, ServMgrTest011, TestSize.Level1) close(memFd); } + +HWTEST_F(HdfServiceMangerHdiCTest, DevMgrQueryUsableDeviceTest, TestSize.Level1) +{ + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + ASSERT_TRUE(devmgr != nullptr); + + struct DeviceInfoList list; + int32_t ret = devmgr->QueryUsableDeviceInfo(devmgr, &list); + ASSERT_TRUE(ret == HDF_SUCCESS); + + devmgr->FreeQueryDeviceList(devmgr, &list); + HDIDeviceManagerRelease(devmgr); +} + +HWTEST_F(HdfServiceMangerHdiCTest, DevMgrQueryUnusableDeviceTest, TestSize.Level1) +{ + struct HDIDeviceManager *devmgr = HDIDeviceManagerGet(); + ASSERT_TRUE(devmgr != nullptr); + + struct DeviceInfoList list; + int32_t ret = devmgr->QueryUnusableDeviceInfo(devmgr, &list); + ASSERT_TRUE(ret == HDF_SUCCESS); + + devmgr->FreeQueryDeviceList(devmgr, &list); + HDIDeviceManagerRelease(devmgr); +} } // namespace OHOS \ No newline at end of file diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 6c7824fd3..dfa0fc5b4 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -41,6 +41,8 @@ using OHOS::HDI::ServiceManager::V1_0::IServiceManager; using OHOS::HDI::ServiceManager::V1_0::IServStatListener; using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; +using OHOS::HDI::DeviceManager::V1_0::HdiDevHostInfo; +using OHOS::HDI::ServiceManager::V1_0::HdiServiceInfo; static constexpr const char *TEST_SERVICE_NAME = "sample_driver_service"; static constexpr const char16_t *TEST_SERVICE_INTERFACE_DESC = u"hdf.test.sampele_service"; static constexpr int PAYLOAD_NUM = 1234; @@ -649,4 +651,70 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest014, TestSize.Level1) status = servmgr->UnregisterServiceStatusListener(listener); ASSERT_EQ(status, HDF_SUCCESS); } + +HWTEST_F(HdfServiceMangerHdiTest, ListAllServiceTest, TestSize.Level1) +{ + auto servmgr = IServiceManager::Get(); + ASSERT_TRUE(servmgr != nullptr); + + std::vector serviceInfos; + int ret = servmgr->ListAllService(serviceInfos); + ASSERT_TRUE(ret == HDF_SUCCESS); + ASSERT_TRUE(serviceInfos.size() != 0); +} + +HWTEST_F(HdfServiceMangerHdiTest, ListAllDeviceTest, TestSize.Level1) +{ + auto devmgr = IDeviceManager::Get(); + ASSERT_TRUE(devmgr != nullptr); + + std::vector deviceInfos; + int ret = devmgr->ListAllDevice(deviceInfos); + ASSERT_TRUE(ret == HDF_SUCCESS); + ASSERT_TRUE(deviceInfos.size() != 0); +} + +HWTEST_F(HdfServiceMangerHdiTest, EndSampleHostTest, TestSize.Level1) +{ + auto servmgr = IServiceManager::Get(); + ASSERT_TRUE(servmgr != nullptr); + + auto devmgr = IDeviceManager::Get(); + ASSERT_TRUE(devmgr != nullptr); + + int ret = devmgr->LoadDevice(TEST_SERVICE_NAME); + ASSERT_TRUE(ret == HDF_SUCCESS); + + constexpr int WAIT_COUNT = 1000; + constexpr int MSLEEP_TIME = 10; + auto sampleService = servmgr->GetService(TEST_SERVICE_NAME); + uint32_t cnt = 0; + while (sampleService == nullptr && cnt < WAIT_COUNT) { + OsalMSleep(MSLEEP_TIME); + sampleService = servmgr->GetService(TEST_SERVICE_NAME); + cnt++; + } + ASSERT_TRUE(sampleService != nullptr); + + OHOS::MessageParcel data; + OHOS::MessageParcel reply; + OHOS::MessageOption option; + ret = data.WriteInterfaceToken(TEST_SERVICE_INTERFACE_DESC); + ASSERT_EQ(ret, true); + + ret = sampleService->SendRequest(SAMPLE_END_HOST, data, reply, option); + ASSERT_TRUE(ret == HDF_SUCCESS); + + ret = devmgr->UnloadDevice(TEST_SERVICE_NAME); + ASSERT_TRUE(ret == HDF_SUCCESS); + + sampleService = servmgr->GetService(TEST_SERVICE_NAME); + cnt = 0; + while (sampleService != nullptr && cnt < WAIT_COUNT) { + OsalMSleep(MSLEEP_TIME); + sampleService = servmgr->GetService(TEST_SERVICE_NAME); + cnt++; + } + ASSERT_TRUE(sampleService == nullptr); +} } // namespace OHOS \ No newline at end of file diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi.h b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi.h index a654a3947..8ed8ab7df 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi.h +++ b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi.h @@ -47,6 +47,7 @@ enum { SAMPLE_UNREGISTER_DEVICE, SAMPLE_UPDATE_SERVIE, SAMPLE_TRANS_SMQ, + SAMPLE_END_HOST, }; struct SampleHdi { @@ -58,6 +59,7 @@ struct SampleHdi { int32_t (*updateService)(struct HdfDeviceObject *device, const char *info); int32_t (*tansSmq)(struct HdfDeviceObject *device, OHOS::HDI::Base::SharedMemQueueMeta *smqMeta, uint32_t element); + int32_t (*endHost)(const struct HdfDeviceObject *device); }; const struct SampleHdi *SampleHdiImplInstance(void); diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp index 35ccdf0b7..745e05774 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp +++ b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include #include @@ -179,6 +180,25 @@ static int32_t SampleServiceTansSmq( return HDF_SUCCESS; } +static int32_t SampleServiceEndHost(const struct HdfDeviceObject *device) +{ + (void)device; + struct IDevHostService *instance = DevHostServiceNewInstance(0, nullptr); + + if (instance == nullptr) { + HDF_LOGE("%{public}s parameter is null", __func__); + return HDF_FAILURE; + } + + struct DevHostServiceFull *fullService = reinterpret_cast(instance); + struct HdfMessageLooper *looper = &fullService->looper; + HDF_LOGW("%{public}s: host %{public}d stop", __func__, fullService->super.hostId); + if ((looper != nullptr) && (looper->Stop != nullptr)) { + looper->Stop(looper); + } + return HDF_SUCCESS; +} + static const struct SampleHdi g_sampleHdiImpl = { .ping = SampleServicePing, .sum = SampleServiceSum, @@ -187,6 +207,7 @@ static const struct SampleHdi g_sampleHdiImpl = { .unregisterDevice = SampleServiceUnregisterDevice, .updateService = SampleServiceUpdateDevice, .tansSmq = SampleServiceTansSmq, + .endHost = SampleServiceEndHost, }; const struct SampleHdi *SampleHdiImplInstance(void) diff --git a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp index d8f22d78d..e7edf4efa 100644 --- a/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp +++ b/adapter/uhdf2/host/test/unittest/sample_driver/sample_hdi_service_stub.cpp @@ -200,6 +200,15 @@ static int32_t SampleServiceSmqTrans(struct HdfDeviceIoClient *client, struct Hd return SampleHdiImplInstance()->tansSmq(client->device, smqMeta.get(), element); } +static int32_t SampleServiceEndHost(struct HdfDeviceIoClient *client, struct HdfSBuf *data) +{ + if (!HdfDeviceObjectCheckInterfaceDesc(client->device, data)) { + return HDF_ERR_INVALID_PARAM; + } + + return SampleHdiImplInstance()->endHost(client->device); +} + int32_t SampleServiceOnRemoteRequest( struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { @@ -223,6 +232,8 @@ int32_t SampleServiceOnRemoteRequest( return SampleServiceUpdateDevice(client, data); case SAMPLE_TRANS_SMQ: return SampleServiceSmqTrans(client, data); + case SAMPLE_END_HOST: + return SampleServiceEndHost(client, data); default: HDF_LOGE("SampleServiceDispatch: not support cmd %{public}d", cmdId); return HDF_ERR_INVALID_PARAM; diff --git a/framework/core/host/include/devhost_service.h b/framework/core/host/include/devhost_service.h index 8f513d34d..a7e20757f 100644 --- a/framework/core/host/include/devhost_service.h +++ b/framework/core/host/include/devhost_service.h @@ -14,6 +14,10 @@ #include "hdf_dlist.h" #include "osal_sysevent.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + struct DevHostService { struct IDevHostService super; uint16_t hostId; @@ -32,4 +36,8 @@ void DevHostServiceFreeInstance(struct IDevHostService *service); struct HdfObject *DevHostServiceCreate(void); void DevHostServiceRelease(struct HdfObject *object); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + #endif /* DEVICE_HOST_SERVICE_H */ -- Gitee From 8244ee27a85c699add5a5fe927f20d702797a206 Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Tue, 6 Dec 2022 10:56:52 +0800 Subject: [PATCH 27/60] fixed 49240e4 from https://gitee.com/xuxiaoqing16/drivers_hdf_core/pulls/1609 fix: add test cases of hdf_sbuf Signed-off-by: xuxiaoqing --- adapter/uhdf/test/unittest/manager/BUILD.gn | 10 +- adapter/uhdf2/ipc/BUILD.gn | 3 - adapter/uhdf2/test/unittest/manager/BUILD.gn | 6 +- .../test/unittest/common/hdf_sbuf_test.cpp | 91 ++++++++++++++++++- 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/adapter/uhdf/test/unittest/manager/BUILD.gn b/adapter/uhdf/test/unittest/manager/BUILD.gn index 9576dab4a..16c24bef4 100644 --- a/adapter/uhdf/test/unittest/manager/BUILD.gn +++ b/adapter/uhdf/test/unittest/manager/BUILD.gn @@ -89,7 +89,10 @@ unittest("hdf_adapter_uhdf_test_sbuf") { "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", ] - defines = [ "__USER__" ] + defines = [ + "__USER__", + "__LITEOS__", + ] sources = [ "//drivers/hdf_core/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp" ] deps = [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", @@ -119,7 +122,10 @@ unittest("hdf_adapter_uhdf_test_door") { "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", ] - defines = [ "__USER__" ] + defines = [ + "__USER__", + "__LITEOS__", + ] sources = [ "//drivers/hdf_core/framework/core/manager/test/unittest/common/hdf_ioservice_test.cpp", "//drivers/hdf_core/framework/core/manager/test/unittest/common/hdf_lite_manager_test.cpp", diff --git a/adapter/uhdf2/ipc/BUILD.gn b/adapter/uhdf2/ipc/BUILD.gn index e947d702b..5768d00c1 100644 --- a/adapter/uhdf2/ipc/BUILD.gn +++ b/adapter/uhdf2/ipc/BUILD.gn @@ -42,12 +42,9 @@ if (defined(ohos_lite)) { public_configs = [ ":libhdf_ipc_adapter_pub_config" ] sources = [ - # "src/hdf_parcel_adapter.cpp", "src/hdf_remote_adapter.cpp", "src/hdf_remote_service.c", "src/hdf_sbuf_impl_hipc.cpp", - - # "$hdf_uhdf_path/shared/src/hdf_parcel.c", ] deps = [ "$hdf_uhdf_path/utils:libhdf_utils" ] diff --git a/adapter/uhdf2/test/unittest/manager/BUILD.gn b/adapter/uhdf2/test/unittest/manager/BUILD.gn index 40a8cf04f..db0ac2e3c 100644 --- a/adapter/uhdf2/test/unittest/manager/BUILD.gn +++ b/adapter/uhdf2/test/unittest/manager/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") module_output_path = "hdf_core/manager" ohos_unittest("hdf_adapter_uhdf_test_manager") { @@ -86,7 +87,10 @@ ohos_unittest("hdf_adapter_uhdf_test_sbuf") { defines = [ "__USER__" ] sources = [ "//drivers/hdf_core/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp" ] - deps = [ "//drivers/hdf_core/adapter/uhdf2/utils:libhdf_utils" ] + deps = [ + "$hdf_uhdf_path/ipc:libhdf_ipc_adapter", + "$hdf_uhdf_path/utils:libhdf_utils", + ] if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp b/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp index 9a03072f3..91441a128 100644 --- a/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp +++ b/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp @@ -6,14 +6,18 @@ * See the LICENSE file in the root of this repository for complete details. */ - +#include +#include +#include +#include #include #include #include #include -#include -#include -#include + +#ifndef __LITEOS__ +#include "hdf_remote_adapter_if.h" +#endif namespace OHOS { using namespace testing::ext; @@ -810,4 +814,83 @@ HWTEST_F(HdfSBufTest, SbufTestSbufMoveHalf019, TestSize.Level1) HdfSbufRecycle(sBuf); HdfSbufRecycle(readBuf); } + +#ifndef __LITEOS__ +HWTEST_F(HdfSBufTest, SbufTestSbufString020, TestSize.Level1) +{ + const char16_t *str = u"test"; + std::u16string strStr(str); + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + bool ret = HdfSbufWriteString16(sBuf, str, strStr.size()); + ASSERT_EQ(ret, true); + const char16_t *readStr = HdfSbufReadString16(sBuf); + std::u16string readStrStr(readStr); + ASSERT_EQ(strStr.compare(readStrStr), 0); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufDouble021, TestSize.Level1) +{ + constexpr double EPS = 1e-6; + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + double data = 1; + bool ret = HdfSbufWriteDouble(sBuf, data); + ASSERT_EQ(ret, true); + double readData = 0; + ret = HdfSbufReadDouble(sBuf, &readData); + ASSERT_EQ(ret, true); + ASSERT_EQ(fabs(data - readData) < EPS, true); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufFloat022, TestSize.Level1) +{ + constexpr float EPS = 1e-6; + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + float data = 1; + bool ret = HdfSbufWriteFloat(sBuf, data); + ASSERT_EQ(ret, true); + float readData = 0; + ret = HdfSbufReadFloat(sBuf, &readData); + ASSERT_EQ(ret, true); + ASSERT_EQ(fabs(data - readData) < EPS, true); + HdfSbufRecycle(sBuf); + HdfRemoteAdapterAddService(nullptr, nullptr); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufFileDescriptor023, TestSize.Level1) +{ + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + int fd = 0; + bool ret = HdfSbufWriteFileDescriptor(sBuf, fd); + ASSERT_EQ(ret, true); + int readFd = HdfSbufReadFileDescriptor(sBuf); + ASSERT_TRUE(readFd >= 0); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufGetCapacity024, TestSize.Level1) +{ + constexpr int HDF_SBUF_DEFAULT_SIZE = 256; + HdfSBuf *sBuf = HdfSbufObtainDefaultSize(); + ASSERT_NE(sBuf, nullptr); + size_t capacity = HdfSbufGetCapacity(sBuf); + ASSERT_EQ(capacity, HDF_SBUF_DEFAULT_SIZE); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufSetDataSize025, TestSize.Level1) +{ + constexpr int HDF_SBUF_TEST_SIZE = 128; + HdfSBuf *sBuf = HdfSbufObtainDefaultSize(); + ASSERT_NE(sBuf, nullptr); + HdfSbufSetDataSize(sBuf, HDF_SBUF_TEST_SIZE); + ASSERT_EQ(HdfSbufGetDataSize(sBuf), HDF_SBUF_TEST_SIZE); + HdfSbufRecycle(sBuf); +} +#endif } // namespace OHOS -- Gitee From 0533abf776f26b50f98444759239200a25dff620 Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Wed, 7 Dec 2022 02:45:21 +0000 Subject: [PATCH 28/60] fixed b19bb60 from https://gitee.com/xuxiaoqing16/drivers_hdf_core/pulls/1614 fix: add ipc sbuf test cases Signed-off-by: xuxiaoqing --- .../test/unittest/common/hdf_sbuf_test.cpp | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp b/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp index 91441a128..57cf2c922 100644 --- a/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp +++ b/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp @@ -892,5 +892,67 @@ HWTEST_F(HdfSBufTest, SbufTestSbufSetDataSize025, TestSize.Level1) ASSERT_EQ(HdfSbufGetDataSize(sBuf), HDF_SBUF_TEST_SIZE); HdfSbufRecycle(sBuf); } + +HWTEST_F(HdfSBufTest, SbufTestSbufInt8026, TestSize.Level1) +{ + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + int8_t data = 1; + bool ret = HdfSbufWriteInt8(sBuf, data); + ASSERT_EQ(ret, true); + int8_t readData; + HdfSbufReadInt8(sBuf, &readData); + ASSERT_TRUE(readData == data); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufInt16027, TestSize.Level1) +{ + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + int16_t data = 1; + bool ret = HdfSbufWriteInt16(sBuf, data); + ASSERT_EQ(ret, true); + int16_t readData; + HdfSbufReadInt16(sBuf, &readData); + ASSERT_TRUE(readData == data); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufInt64028, TestSize.Level1) +{ + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + int64_t data = 1; + bool ret = HdfSbufWriteInt64(sBuf, data); + ASSERT_EQ(ret, true); + int64_t readData; + HdfSbufReadInt64(sBuf, &readData); + ASSERT_TRUE(readData == data); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufGetCapacity029, TestSize.Level1) +{ + constexpr size_t HDF_SBUF_TEST_SIZE = 64; + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + int64_t data = 1; + bool ret = HdfSbufWriteInt64(sBuf, data); + ASSERT_EQ(ret, true); + size_t capacity = HdfSbufGetCapacity(sBuf); + ASSERT_EQ(capacity, HDF_SBUF_TEST_SIZE); + HdfSbufRecycle(sBuf); +} + +HWTEST_F(HdfSBufTest, SbufTestSbufDataSize030, TestSize.Level1) +{ + constexpr size_t HDF_SBUF_TEST_SIZE = 0; + HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); + ASSERT_NE(sBuf, nullptr); + HdfSbufSetDataSize(sBuf, HDF_SBUF_TEST_SIZE); + ASSERT_EQ(HdfSbufGetDataSize(sBuf), HDF_SBUF_TEST_SIZE); + HdfSbufRecycle(sBuf); +} #endif } // namespace OHOS -- Gitee From 1e3a36c36088b08015fbca3279ca56b307c6d000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cguodongqi=E2=80=9D?= Date: Wed, 7 Dec 2022 16:02:39 +0800 Subject: [PATCH 29/60] fixed cdde499 from https://gitee.com/guo-dongqi/drivers_hdf_core/pulls/1616 fix: clear hdf alarms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “guodongqi” --- .../test/servmgr/service_manager_hdi_test.cpp | 30 +++++++++---------- .../test/unittest/common/hdf_sbuf_test.cpp | 28 ++++++++--------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index dfa0fc5b4..00fc0c868 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -308,8 +308,8 @@ void HdfServiceMangerHdiTest::TestServiceListenerStop(const sptr int ret = devmgr->LoadDevice(TEST_SERVICE_NAME); ASSERT_EQ(ret, HDF_SUCCESS); - constexpr int WAIT_COUNT = 300; - int count = WAIT_COUNT; + constexpr int waitCount = 300; + int count = waitCount; while (!callbacked && count > 0) { OsalMSleep(1); count--; @@ -323,7 +323,7 @@ void HdfServiceMangerHdiTest::TestServiceListenerStop(const sptr ret = devmgr->UnloadDevice(TEST_SERVICE_NAME); ASSERT_EQ(ret, HDF_SUCCESS); - count = WAIT_COUNT; + count = waitCount; while (!callbacked && count > 0) { OsalMSleep(1); count--; @@ -389,8 +389,8 @@ void HdfServiceMangerHdiTest::TestSampleService(sptr& sampleServi callbacked = false; status = sampleService->SendRequest(SAMPLE_UPDATE_SERVIE, data, reply, option); ASSERT_EQ(status, HDF_SUCCESS); - constexpr int WAIT_COUNT = 300; - int count = WAIT_COUNT; + constexpr int waitCount = 300; + int count = waitCount; while (!callbacked && count > 0) { OsalMSleep(1); count--; @@ -464,8 +464,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest010, TestSize.Level1) int ret = devmgr->LoadDevice(TEST_SERVICE_NAME); ASSERT_EQ(ret, HDF_SUCCESS); - constexpr int WAIT_COUNT = 300; - int count = WAIT_COUNT; + constexpr int waitCount = 300; + int count = waitCount; while (!callbacked && count > 0) { OsalMSleep(1); count--; @@ -639,8 +639,8 @@ HWTEST_F(HdfServiceMangerHdiTest, ServMgrTest014, TestSize.Level1) int status = servmgr->RegisterServiceStatusListener(listener, DEVICE_CLASS_DEFAULT); ASSERT_EQ(status, HDF_SUCCESS); - constexpr int WAIT_COUNT = 100; - int count = WAIT_COUNT; + constexpr int waitCount = 100; + int count = waitCount; while (!sampleServiceStarted && count > 0) { OsalMSleep(1); count--; @@ -685,12 +685,12 @@ HWTEST_F(HdfServiceMangerHdiTest, EndSampleHostTest, TestSize.Level1) int ret = devmgr->LoadDevice(TEST_SERVICE_NAME); ASSERT_TRUE(ret == HDF_SUCCESS); - constexpr int WAIT_COUNT = 1000; - constexpr int MSLEEP_TIME = 10; + constexpr int waitCount = 1000; + constexpr int msleepTime = 10; auto sampleService = servmgr->GetService(TEST_SERVICE_NAME); uint32_t cnt = 0; - while (sampleService == nullptr && cnt < WAIT_COUNT) { - OsalMSleep(MSLEEP_TIME); + while (sampleService == nullptr && cnt < waitCount) { + OsalMSleep(msleepTime); sampleService = servmgr->GetService(TEST_SERVICE_NAME); cnt++; } @@ -710,8 +710,8 @@ HWTEST_F(HdfServiceMangerHdiTest, EndSampleHostTest, TestSize.Level1) sampleService = servmgr->GetService(TEST_SERVICE_NAME); cnt = 0; - while (sampleService != nullptr && cnt < WAIT_COUNT) { - OsalMSleep(MSLEEP_TIME); + while (sampleService != nullptr && cnt < waitCount) { + OsalMSleep(msleepTime); sampleService = servmgr->GetService(TEST_SERVICE_NAME); cnt++; } diff --git a/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp b/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp index 57cf2c922..d850fa11b 100644 --- a/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp +++ b/framework/core/manager/test/unittest/common/hdf_sbuf_test.cpp @@ -832,7 +832,7 @@ HWTEST_F(HdfSBufTest, SbufTestSbufString020, TestSize.Level1) HWTEST_F(HdfSBufTest, SbufTestSbufDouble021, TestSize.Level1) { - constexpr double EPS = 1e-6; + constexpr double eps = 1e-6; HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); ASSERT_NE(sBuf, nullptr); double data = 1; @@ -841,13 +841,13 @@ HWTEST_F(HdfSBufTest, SbufTestSbufDouble021, TestSize.Level1) double readData = 0; ret = HdfSbufReadDouble(sBuf, &readData); ASSERT_EQ(ret, true); - ASSERT_EQ(fabs(data - readData) < EPS, true); + ASSERT_EQ(fabs(data - readData) < eps, true); HdfSbufRecycle(sBuf); } HWTEST_F(HdfSBufTest, SbufTestSbufFloat022, TestSize.Level1) { - constexpr float EPS = 1e-6; + constexpr float eps = 1e-6; HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); ASSERT_NE(sBuf, nullptr); float data = 1; @@ -856,7 +856,7 @@ HWTEST_F(HdfSBufTest, SbufTestSbufFloat022, TestSize.Level1) float readData = 0; ret = HdfSbufReadFloat(sBuf, &readData); ASSERT_EQ(ret, true); - ASSERT_EQ(fabs(data - readData) < EPS, true); + ASSERT_EQ(fabs(data - readData) < eps, true); HdfSbufRecycle(sBuf); HdfRemoteAdapterAddService(nullptr, nullptr); } @@ -875,21 +875,21 @@ HWTEST_F(HdfSBufTest, SbufTestSbufFileDescriptor023, TestSize.Level1) HWTEST_F(HdfSBufTest, SbufTestSbufGetCapacity024, TestSize.Level1) { - constexpr int HDF_SBUF_DEFAULT_SIZE = 256; + constexpr int hdfSbufDefaultSize = 256; HdfSBuf *sBuf = HdfSbufObtainDefaultSize(); ASSERT_NE(sBuf, nullptr); size_t capacity = HdfSbufGetCapacity(sBuf); - ASSERT_EQ(capacity, HDF_SBUF_DEFAULT_SIZE); + ASSERT_EQ(capacity, hdfSbufDefaultSize); HdfSbufRecycle(sBuf); } HWTEST_F(HdfSBufTest, SbufTestSbufSetDataSize025, TestSize.Level1) { - constexpr int HDF_SBUF_TEST_SIZE = 128; + constexpr int hdfSbufTestSize = 128; HdfSBuf *sBuf = HdfSbufObtainDefaultSize(); ASSERT_NE(sBuf, nullptr); - HdfSbufSetDataSize(sBuf, HDF_SBUF_TEST_SIZE); - ASSERT_EQ(HdfSbufGetDataSize(sBuf), HDF_SBUF_TEST_SIZE); + HdfSbufSetDataSize(sBuf, hdfSbufTestSize); + ASSERT_EQ(HdfSbufGetDataSize(sBuf), hdfSbufTestSize); HdfSbufRecycle(sBuf); } @@ -934,24 +934,24 @@ HWTEST_F(HdfSBufTest, SbufTestSbufInt64028, TestSize.Level1) HWTEST_F(HdfSBufTest, SbufTestSbufGetCapacity029, TestSize.Level1) { - constexpr size_t HDF_SBUF_TEST_SIZE = 64; + constexpr size_t hdfSbufTestSize = 64; HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); ASSERT_NE(sBuf, nullptr); int64_t data = 1; bool ret = HdfSbufWriteInt64(sBuf, data); ASSERT_EQ(ret, true); size_t capacity = HdfSbufGetCapacity(sBuf); - ASSERT_EQ(capacity, HDF_SBUF_TEST_SIZE); + ASSERT_EQ(capacity, hdfSbufTestSize); HdfSbufRecycle(sBuf); } HWTEST_F(HdfSBufTest, SbufTestSbufDataSize030, TestSize.Level1) { - constexpr size_t HDF_SBUF_TEST_SIZE = 0; + constexpr size_t hdfSbufTestSize = 0; HdfSBuf *sBuf = HdfSbufTypedObtain(SBUF_IPC); ASSERT_NE(sBuf, nullptr); - HdfSbufSetDataSize(sBuf, HDF_SBUF_TEST_SIZE); - ASSERT_EQ(HdfSbufGetDataSize(sBuf), HDF_SBUF_TEST_SIZE); + HdfSbufSetDataSize(sBuf, hdfSbufTestSize); + ASSERT_EQ(HdfSbufGetDataSize(sBuf), hdfSbufTestSize); HdfSbufRecycle(sBuf); } #endif -- Gitee From e51a97ba32f1d6f152e04402bbc701fc9302d252 Mon Sep 17 00:00:00 2001 From: yueyan Date: Fri, 9 Dec 2022 14:20:05 +0800 Subject: [PATCH 30/60] fixed ba68b9e from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1623 fix:modify the compilation configuration of hcs Signed-off-by: yueyan --- adapter/BUILD.gn | 14 +------------ adapter/uhdf2/hcs/BUILD.gn | 40 +++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 0a39db6e8..34ec8d12b 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -29,6 +29,7 @@ if (defined(ohos_lite)) { } else { group("uhdf_entry") { deps = [ + "//drivers/hdf_core/adapter/uhdf2/hcs:hcs_entry", "//drivers/hdf_core/adapter/uhdf2/hdi:libhdi", "//drivers/hdf_core/adapter/uhdf2/host:hdf_devhost", "//drivers/hdf_core/adapter/uhdf2/host:libhdf_host", @@ -42,19 +43,6 @@ if (defined(ohos_lite)) { "//drivers/hdf_core/framework/tools/hdf_dbg:hdf_dbg", "//drivers/peripheral/base:hdf_peripheral.cfg", ] - - import("//build/ohos.gni") - hcs_dir = - rebase_path("//vendor/$product_company/$product_name/hdf_config/uhdf/") - if (exec_script( - "//build/lite/run_shell_cmd.py", - [ "if [ -d ${hcs_dir} ]; then echo true; else echo false; fi" ], - "value")) { - deps += [ - "//drivers/hdf_core/adapter/uhdf2/hcs:hdf_default.hcb", - "//drivers/hdf_core/adapter/uhdf2/hcs:hdf_devhost.cfg", - ] - } } group("uhdf_test_entry") { testonly = true diff --git a/adapter/uhdf2/hcs/BUILD.gn b/adapter/uhdf2/hcs/BUILD.gn index abd7df17b..85c560936 100644 --- a/adapter/uhdf2/hcs/BUILD.gn +++ b/adapter/uhdf2/hcs/BUILD.gn @@ -15,15 +15,16 @@ import("//build/ohos.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") import("$hdf_framework_path/tools/hc-gen/hc_gen.gni") -hc_gen("build_hcs") { - hcs_source = "/hdf.hcs" +hcs_source = "hdf.hcs" +if (product_company == "openharmony") { + hcs_file = "default/$hcs_source" +} else { + hcs_file = + "//vendor/$product_company/$product_name/hdf_config/uhdf/$hcs_source" +} - if (product_company == "openharmony") { - hcs_config_path = "default" - } else { - hcs_config_path = "//vendor/$product_company/$product_name/hdf_config/uhdf/" - } - sources = [ rebase_path(hcs_config_path + hcs_source) ] +hc_gen("build_hcs") { + sources = [ rebase_path(hcs_file) ] outputs = [ "$target_gen_dir/hdf_default.hcb" ] } @@ -38,14 +39,7 @@ ohos_prebuilt_etc("hdf_default.hcb") { } hc_gen_start_cfg("gen_start_cfg") { - hcs_source = "/hdf.hcs" - - if (product_company == "openharmony") { - hcs_config_path = "default" - } else { - hcs_config_path = "//vendor/$product_company/$product_name/hdf_config/uhdf/" - } - sources = [ rebase_path(hcs_config_path + hcs_source) ] + sources = [ rebase_path(hcs_file) ] outputs = [ "$target_gen_dir/hdf_devhost.cfg" ] } @@ -58,3 +52,17 @@ ohos_prebuilt_etc("hdf_devhost.cfg") { subsystem_name = "hdf" part_name = "hdf_core" } + +group("hcs_entry") { + deps = [] + hcs_file_path = rebase_path("$hcs_file") + if (exec_script( + "//build/lite/run_shell_cmd.py", + [ "if [ -f ${hcs_file_path} ]; then echo true; else echo false; fi" ], + "value")) { + deps += [ + ":hdf_default.hcb", + ":hdf_devhost.cfg", + ] + } +} -- Gitee From fd594db7577ce3fa885cfde7ea2e3b32d0d16ebe Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 10 Dec 2022 10:11:39 +0800 Subject: [PATCH 31/60] fix:Optimize HDF service management mechanism Signed-off-by: zhang --- adapter/uhdf2/host/src/devsvc_manager_proxy.c | 4 +- .../uhdf2/manager/src/devsvc_manager_stub.c | 10 ++-- framework/core/host/src/devsvc_manager_clnt.c | 2 +- .../core/manager/include/devsvc_manager.h | 3 +- framework/core/manager/src/devsvc_manager.c | 49 +++++++++++++------ .../core/shared/include/devsvc_manager_if.h | 2 +- 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/adapter/uhdf2/host/src/devsvc_manager_proxy.c b/adapter/uhdf2/host/src/devsvc_manager_proxy.c index 9125fec5a..dedb85382 100644 --- a/adapter/uhdf2/host/src/devsvc_manager_proxy.c +++ b/adapter/uhdf2/host/src/devsvc_manager_proxy.c @@ -184,8 +184,10 @@ struct HdfObject *DevSvcManagerProxyGetService(struct IDevSvcManager *inst, cons return (remoteService == NULL) ? NULL : &remoteService->object_; } -void DevSvcManagerProxyRemoveService(struct IDevSvcManager *inst, const char *svcName) +void DevSvcManagerProxyRemoveService(struct IDevSvcManager *inst, const char *svcName, + const struct HdfDeviceObject *devObj) { + (void)devObj; if (inst == NULL || svcName == NULL) { return; } diff --git a/adapter/uhdf2/manager/src/devsvc_manager_stub.c b/adapter/uhdf2/manager/src/devsvc_manager_stub.c index 2db146d3b..1fdd15174 100644 --- a/adapter/uhdf2/manager/src/devsvc_manager_stub.c +++ b/adapter/uhdf2/manager/src/devsvc_manager_stub.c @@ -407,7 +407,7 @@ static int32_t DevSvcManagerStubRemoveService(struct IDevSvcManager *super, stru return HDF_ERR_INVALID_OBJECT; } OsalMutexUnlock(&stub->devSvcStubMutex); - super->RemoveService(super, name); + super->RemoveService(super, name, serviceObject); HDF_LOGI("service %{public}s removed", name); ReleaseServiceObject(stub, serviceObject); @@ -540,13 +540,9 @@ void DevSvcManagerOnServiceDied(struct HdfDeathRecipient *recipient, struct HdfR HDF_LOGI("%{public}s HdfStringCopy fail", __func__); return; } - struct HdfObject *service = iSvcMgr->GetService(iSvcMgr, serviceName); - HDF_LOGI("service %{public}s died", serviceName); - if ((uintptr_t)service == (uintptr_t)remote) { - HDF_LOGI("%{public}s: remove died service %{public}s", __func__, serviceName); - iSvcMgr->RemoveService(iSvcMgr, serviceName); - } + HDF_LOGI("service %{public}s died", serviceName); + iSvcMgr->RemoveService(iSvcMgr, serviceName, serviceObject); ReleaseServiceObject(stub, serviceObject); OsalMemFree(serviceName); diff --git a/framework/core/host/src/devsvc_manager_clnt.c b/framework/core/host/src/devsvc_manager_clnt.c index 4db623436..590823b07 100644 --- a/framework/core/host/src/devsvc_manager_clnt.c +++ b/framework/core/host/src/devsvc_manager_clnt.c @@ -135,7 +135,7 @@ void DevSvcManagerClntRemoveService(const char *svcName) if (serviceManager == NULL || serviceManager->RemoveService == NULL) { return; } - serviceManager->RemoveService(serviceManager, svcName); + serviceManager->RemoveService(serviceManager, svcName, NULL); } static void DevSvcManagerClntConstruct(struct DevSvcManagerClnt *inst) diff --git a/framework/core/manager/include/devsvc_manager.h b/framework/core/manager/include/devsvc_manager.h index 463351b88..2bc12a18f 100644 --- a/framework/core/manager/include/devsvc_manager.h +++ b/framework/core/manager/include/devsvc_manager.h @@ -32,7 +32,8 @@ int DevSvcManagerStartService(void); int DevSvcManagerAddService( struct IDevSvcManager *manager, struct HdfDeviceObject *service, const struct HdfServiceInfo *servInfo); struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *manager, const char *svcName); -void DevSvcManagerRemoveService(struct IDevSvcManager *manager, const char *svcName); +void DevSvcManagerRemoveService( + struct IDevSvcManager *manager, const char *svcName, const struct HdfDeviceObject *devObj); void DevSvcManagerListService(struct HdfSBuf *serviceNameSet, DeviceClass deviceClass); int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback); diff --git a/framework/core/manager/src/devsvc_manager.c b/framework/core/manager/src/devsvc_manager.c index 7a4f2de79..b72fc4664 100644 --- a/framework/core/manager/src/devsvc_manager.c +++ b/framework/core/manager/src/devsvc_manager.c @@ -18,7 +18,7 @@ #define HDF_LOG_TAG devsvc_manager -static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey) +static struct DevSvcRecord *DevSvcManagerSearchServiceLocked(struct IDevSvcManager *inst, uint32_t serviceKey) { struct DevSvcRecord *record = NULL; struct DevSvcRecord *searchResult = NULL; @@ -28,14 +28,12 @@ static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *in return NULL; } - OsalMutexLock(&devSvcManager->mutex); DLIST_FOR_EACH_ENTRY(record, &devSvcManager->services, struct DevSvcRecord, entry) { if (record->key == serviceKey) { searchResult = record; break; } } - OsalMutexUnlock(&devSvcManager->mutex); return searchResult; } @@ -91,13 +89,16 @@ int DevSvcManagerAddService(struct IDevSvcManager *inst, HDF_LOGE("failed to add service, input param is null"); return HDF_FAILURE; } - record = DevSvcManagerSearchService(inst, HdfStringMakeHashKey(servInfo->servName, 0)); + OsalMutexLock(&devSvcManager->mutex); + record = DevSvcManagerSearchServiceLocked(inst, HdfStringMakeHashKey(servInfo->servName, 0)); if (record != NULL) { - HDF_LOGI("%{public}s:add service %{public}s exist, only update value", __func__, servInfo->servName); // on service died will release old service object record->value = service; + OsalMutexUnlock(&devSvcManager->mutex); + HDF_LOGI("%{public}s:add service %{public}s exist, only update value", __func__, servInfo->servName); return HDF_SUCCESS; } + OsalMutexUnlock(&devSvcManager->mutex); record = DevSvcRecordNewInstance(); if (record == NULL) { HDF_LOGE("failed to add service , record is null"); @@ -131,15 +132,17 @@ int DevSvcManagerUpdateService(struct IDevSvcManager *inst, HDF_LOGE("failed to update service, invalid param"); return HDF_FAILURE; } - - record = DevSvcManagerSearchService(inst, HdfStringMakeHashKey(servInfo->servName, 0)); + OsalMutexLock(&devSvcManager->mutex); + record = DevSvcManagerSearchServiceLocked(inst, HdfStringMakeHashKey(servInfo->servName, 0)); if (record == NULL) { + OsalMutexUnlock(&devSvcManager->mutex); return HDF_DEV_ERR_NO_DEVICE; } if (servInfo->servInfo != NULL) { servInfoStr = HdfStringCopy(servInfo->servInfo); if (servInfoStr == NULL) { + OsalMutexUnlock(&devSvcManager->mutex); return HDF_ERR_MALLOC_FAIL; } OsalMemFree((char *)record->servInfo); @@ -149,7 +152,6 @@ int DevSvcManagerUpdateService(struct IDevSvcManager *inst, record->value = service; record->devClass = servInfo->devClass; record->devId = servInfo->devId; - OsalMutexLock(&devSvcManager->mutex); NotifyServiceStatusLocked(devSvcManager, record, SERVIE_STATUS_CHANGE); OsalMutexUnlock(&devSvcManager->mutex); return HDF_SUCCESS; @@ -174,39 +176,54 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa return devMgrSvc->super.LoadDevice(&devMgrSvc->super, svcName); } -void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName) +void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName, const struct HdfDeviceObject *devObj) { struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst; struct DevSvcRecord *serviceRecord = NULL; uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0); + bool removeFlag = false; if (svcName == NULL || devSvcManager == NULL) { return; } - serviceRecord = DevSvcManagerSearchService(inst, serviceKey); + OsalMutexLock(&devSvcManager->mutex); + serviceRecord = DevSvcManagerSearchServiceLocked(inst, serviceKey); if (serviceRecord == NULL) { + OsalMutexUnlock(&devSvcManager->mutex); return; } - OsalMutexLock(&devSvcManager->mutex); - NotifyServiceStatusLocked(devSvcManager, serviceRecord, SERVIE_STATUS_STOP); - DListRemove(&serviceRecord->entry); + if (devObj == NULL || (uintptr_t)devObj == (uintptr_t)serviceRecord->value) { + NotifyServiceStatusLocked(devSvcManager, serviceRecord, SERVIE_STATUS_STOP); + DListRemove(&serviceRecord->entry); + removeFlag = true; + } OsalMutexUnlock(&devSvcManager->mutex); - DevSvcRecordFreeInstance(serviceRecord); + if (removeFlag) { + DevSvcRecordFreeInstance(serviceRecord); + } else { + HDF_LOGI("%{public}s %{public}s device object is out of date", __func__, svcName); + } } struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, const char *svcName) { uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0); + struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst; struct DevSvcRecord *serviceRecord = NULL; + struct HdfDeviceObject *deviceObject = NULL; if (svcName == NULL) { HDF_LOGE("Get service failed, svcName is null"); return NULL; } - serviceRecord = DevSvcManagerSearchService(inst, serviceKey); + OsalMutexLock(&devSvcManager->mutex); + serviceRecord = DevSvcManagerSearchServiceLocked(inst, serviceKey); if (serviceRecord != NULL) { - return serviceRecord->value; + deviceObject = serviceRecord->value; + OsalMutexUnlock(&devSvcManager->mutex); + return deviceObject; } + OsalMutexUnlock(&devSvcManager->mutex); return NULL; } diff --git a/framework/core/shared/include/devsvc_manager_if.h b/framework/core/shared/include/devsvc_manager_if.h index 7a021778c..e844b00c1 100644 --- a/framework/core/shared/include/devsvc_manager_if.h +++ b/framework/core/shared/include/devsvc_manager_if.h @@ -23,7 +23,7 @@ struct IDevSvcManager { int (*UnsubscribeService)(struct IDevSvcManager *, const char *); struct HdfObject *(*GetService)(struct IDevSvcManager *, const char *); struct HdfDeviceObject *(*GetObject)(struct IDevSvcManager *, const char *); - void (*RemoveService)(struct IDevSvcManager *, const char *); + void (*RemoveService)(struct IDevSvcManager *, const char *, const struct HdfDeviceObject *); int (*RegsterServListener)(struct IDevSvcManager *, struct ServStatListenerHolder *); void (*UnregsterServListener)(struct IDevSvcManager *, struct ServStatListenerHolder *); void (*ListAllService)(struct IDevSvcManager *, struct HdfSBuf *); -- Gitee From 37f37fca454d0e703a1cc3c767786f23c4ccaf7d Mon Sep 17 00:00:00 2001 From: yueyan Date: Tue, 20 Dec 2022 17:54:54 +0800 Subject: [PATCH 32/60] fix:add feature that control hcs file compilation Signed-off-by: yueyan --- adapter/BUILD.gn | 9 ++++++++- bundle.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 34ec8d12b..f2f0a3362 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -27,9 +27,12 @@ if (defined(ohos_lite)) { ] } } else { + declare_args() { + hdf_core_feature_config = true + } + group("uhdf_entry") { deps = [ - "//drivers/hdf_core/adapter/uhdf2/hcs:hcs_entry", "//drivers/hdf_core/adapter/uhdf2/hdi:libhdi", "//drivers/hdf_core/adapter/uhdf2/host:hdf_devhost", "//drivers/hdf_core/adapter/uhdf2/host:libhdf_host", @@ -43,6 +46,10 @@ if (defined(ohos_lite)) { "//drivers/hdf_core/framework/tools/hdf_dbg:hdf_dbg", "//drivers/peripheral/base:hdf_peripheral.cfg", ] + + if (hdf_core_feature_config) { + deps += [ "//drivers/hdf_core/adapter/uhdf2/hcs:hcs_entry" ] + } } group("uhdf_test_entry") { testonly = true diff --git a/bundle.json b/bundle.json index 8898ce289..2b7c26451 100644 --- a/bundle.json +++ b/bundle.json @@ -13,7 +13,7 @@ "name": "hdf_core", "subsystem": "hdf", "syscap": [ "" ], - "features": [ "hdf_core_khdf_test_support" ], + "features": [ "hdf_core_khdf_test_support", "hdf_core_feature_config" ], "adapter_system_type": ["standard", "small"], "rom": "735KB", "ram": "8000KB", -- Gitee From 8d82a4d4914193a0ae1013940c521f5d4cfeb641 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Wed, 4 Jan 2023 11:32:35 +0800 Subject: [PATCH 33/60] fixed c536e3d from https://gitee.com/wangchaole/drivers_hdf_core/pulls/1664 fix: modify part name Signed-off-by: wangchaole --- adapter/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapter/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn b/adapter/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn index a2b6005ba..67a4b7f73 100644 --- a/adapter/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn +++ b/adapter/uhdf2/model/display/sequenceable/buffer_handle/BUILD.gn @@ -35,5 +35,5 @@ ohos_shared_library("libbuffer_handle_sequenceable_1.0") { install_images = [ system_base_dir ] relative_install_dir = "chipset-pub-sdk" subsystem_name = "hdf" - part_name = "drivers_peripheral_distributed_camera" + part_name = "drivers_interface_distributed_camera" } -- Gitee From 5075b9a0d29e777f62364f3ab4a0f44fa4c673ae Mon Sep 17 00:00:00 2001 From: yueyan Date: Tue, 10 Jan 2023 10:00:02 +0800 Subject: [PATCH 34/60] fix:fix bug about reading array type parameter failed Signed-off-by: yueyan --- .../tools/hdi-gen/ast/ast_array_type.cpp | 68 ++++++++------ .../tools/hdi-gen/ast/ast_boolean_type.cpp | 18 ++-- framework/tools/hdi-gen/ast/ast_byte_type.cpp | 19 ++-- .../tools/hdi-gen/ast/ast_double_type.cpp | 18 ++-- framework/tools/hdi-gen/ast/ast_enum_type.cpp | 91 ++++++++++++++----- framework/tools/hdi-gen/ast/ast_fd_type.cpp | 7 +- .../tools/hdi-gen/ast/ast_float_type.cpp | 18 ++-- .../tools/hdi-gen/ast/ast_integer_type.cpp | 18 ++-- framework/tools/hdi-gen/ast/ast_long_type.cpp | 18 ++-- framework/tools/hdi-gen/ast/ast_map_type.cpp | 17 ++-- .../tools/hdi-gen/ast/ast_short_type.cpp | 19 ++-- .../tools/hdi-gen/ast/ast_string_type.cpp | 4 +- .../tools/hdi-gen/ast/ast_uchar_type.cpp | 18 ++-- framework/tools/hdi-gen/ast/ast_uint_type.cpp | 18 ++-- .../tools/hdi-gen/ast/ast_ulong_type.cpp | 18 ++-- .../tools/hdi-gen/ast/ast_union_type.cpp | 7 +- .../tools/hdi-gen/ast/ast_ushort_type.cpp | 18 ++-- .../codegen/c_client_proxy_code_emitter.cpp | 8 +- .../codegen/c_service_impl_code_emitter.cpp | 8 +- .../codegen/c_service_stub_code_emitter.cpp | 18 ++-- .../codegen/cpp_custom_types_code_emitter.cpp | 15 +-- .../codegen/cpp_service_stub_code_emitter.cpp | 39 ++++++-- framework/tools/hdi-gen/util/common.h | 2 +- 23 files changed, 299 insertions(+), 185 deletions(-) diff --git a/framework/tools/hdi-gen/ast/ast_array_type.cpp b/framework/tools/hdi-gen/ast/ast_array_type.cpp index 5908e1135..60669ce14 100644 --- a/framework/tools/hdi-gen/ast/ast_array_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_array_type.cpp @@ -103,8 +103,6 @@ void ASTArrayType::EmitCWriteVar(const std::string &parcelName, const std::strin return; } - sb.Append(prefix).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, - lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix).AppendFormat("if (%s == NULL || %s == 0) {\n", name.c_str(), lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("if (!HdfSbufWriteUint32(%s, 0)) {\n", parcelName.c_str()); sb.Append(prefix + TAB + TAB) @@ -141,8 +139,6 @@ void ASTArrayType::EmitCProxyWriteOutVar(const std::string &parcelName, const st const std::string &ecName, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) const { std::string lenName = StringHelper::Format("*%sLen", name.c_str()); - sb.Append(prefix).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, - lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix).AppendFormat("if (!HdfSbufWriteUint32(%s, %s)) {\n", parcelName.c_str(), lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); @@ -178,8 +174,9 @@ void ASTArrayType::EmitCProxyReadVar(const std::string &parcelName, const std::s sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n\n"); - sb.Append(prefix).AppendFormat("%s(*%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, - lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); + sb.Append(prefix).AppendFormat("%s(*%s, >, %s / sizeof(%s), %s, HDF_ERR_INVALID_PARAM, %s);\n", + CHECK_VALUE_RET_GOTO_MACRO, lenName.c_str(), MAX_BUFF_SIZE_MACRO, elementType_->EmitCType().c_str(), + ecName.c_str(), gotoLabel.c_str()); if (Options::GetInstance().DoGenerateKernelCode()) { sb.Append(prefix).AppendFormat("for (i = 0; i < *%s; i++) {\n", lenName.c_str()); @@ -227,8 +224,9 @@ void ASTArrayType::EmitCStubReadVar(const std::string &parcelName, const std::st sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n\n"); - sb.Append(prefix).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, - lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); + sb.Append(prefix).AppendFormat("%s(%s, >, %s / sizeof(%s), %s, HDF_ERR_INVALID_PARAM, %s);\n", + CHECK_VALUE_RET_GOTO_MACRO, lenName.c_str(), MAX_BUFF_SIZE_MACRO, elementType_->EmitCType().c_str(), + ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix).AppendFormat("if (%s > 0) {\n", lenName.c_str()); EmitCMallocVar(name, lenName, false, ecName, gotoLabel, sb, prefix + TAB); @@ -266,8 +264,9 @@ void ASTArrayType::EmitCStubReadOutVar(const std::string &buffSizeName, const st sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix + TAB).Append("}\n\n"); - sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, - lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s / sizeof(%s), %s, HDF_ERR_INVALID_PARAM, %s);\n", + CHECK_VALUE_RET_GOTO_MACRO, lenName.c_str(), MAX_BUFF_SIZE_MACRO, elementType_->EmitCType().c_str(), + ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix + TAB).AppendFormat("if (%s > 0) {\n", lenName.c_str()); EmitCMallocVar(name, lenName, false, ecName, gotoLabel, sb, prefix + TAB + TAB); @@ -337,9 +336,13 @@ void ASTArrayType::EmitCppReadVar(const std::string &parcelName, const std::stri return; } - sb.Append(prefix).AppendFormat("uint32_t %sSize = %s.ReadUint32();\n", name.c_str(), parcelName.c_str()); - sb.Append(prefix).AppendFormat("%s(%sSize, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, - name.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("uint32_t %sSize = 0;\n", name.c_str()); + sb.Append(prefix).AppendFormat("if (!%s.ReadUint32(%sSize)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read size\", __func__);\n"); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("%s(%sSize, >, %s / sizeof(%s), HDF_ERR_INVALID_PARAM);\n", + CHECK_VALUE_RETURN_MACRO, name.c_str(), MAX_BUFF_SIZE_MACRO, elementType_->EmitCppType().c_str()); sb.Append(prefix).AppendFormat("%s.clear();\n", name.c_str()); sb.Append(prefix).AppendFormat("%s.reserve(%sSize);\n", name.c_str(), name.c_str()); sb.Append(prefix).AppendFormat( @@ -370,8 +373,8 @@ void ASTArrayType::EmitCMarshalling(const std::string &name, StringBuilder &sb, return; } - sb.Append(prefix).AppendFormat( - "if (%s > %s || !HdfSbufWriteUint32(data, %s)) {\n", lenName.c_str(), MAX_BUFF_SIZE_MACRO, lenName.c_str()); + sb.Append(prefix).AppendFormat("if (%s > %s / sizeof(%s) || !HdfSbufWriteUint32(data, %s)) {\n", lenName.c_str(), + MAX_BUFF_SIZE_MACRO, elementType_->EmitCType().c_str(), lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", lenName.c_str()); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n"); @@ -411,7 +414,8 @@ void ASTArrayType::EmitCUnMarshalling(const std::string &name, const std::string sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n"); - sb.Append(prefix).AppendFormat("if (%s > %s) {\n", lenName.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("if (%s > %s / sizeof(%s)) {\n", lenName.c_str(), MAX_BUFF_SIZE_MACRO, + elementType_->EmitCType().c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: %s is invalid data\", __func__);\n", lenName.c_str()); sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix).Append("}\n"); @@ -508,9 +512,13 @@ void ASTArrayType::EmitCppUnMarshalling(const std::string &parcelName, const std return; } - sb.Append(prefix).AppendFormat("uint32_t %s = %s.ReadUint32();\n", sizeName.c_str(), parcelName.c_str()); - sb.Append(prefix).AppendFormat( - "%s(%s, >, %s, false);\n", CHECK_VALUE_RETURN_MACRO, sizeName.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("uint32_t %s = 0;\n", sizeName.c_str()); + sb.Append(prefix).AppendFormat("if (!%s.ReadUint32(%s)) {\n", parcelName.c_str(), sizeName.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read size\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("%s(%s, >, %s / sizeof(%s), false);\n", CHECK_VALUE_RETURN_MACRO, sizeName.c_str(), + MAX_BUFF_SIZE_MACRO, elementType_->EmitCppType().c_str()); sb.Append(prefix).AppendFormat("%s.clear();\n", name.c_str()); sb.Append(prefix).AppendFormat("%s.reserve(%s);\n", name.c_str(), sizeName.c_str()); sb.Append(prefix).AppendFormat( @@ -537,7 +545,10 @@ void ASTArrayType::EmitMemoryRecycle( return false; } - return elementType_->IsStringType() ? true : false; + if (elementType_->IsStructType() || elementType_->IsStringType()) { + return true; + } + return false; }; if (elementTypeNeedFree()) { if (Options::GetInstance().DoGenerateKernelCode()) { @@ -847,7 +858,7 @@ void ASTArrayType::EmitCReadMethods( sb.Append(prefix + TAB + TAB).Append("return false;\n"); sb.Append(prefix + TAB).Append("}\n\n"); - sb.Append(prefix + TAB).AppendFormat("if (elementCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).AppendFormat("if (elementCount > %s / elementSize) {\n", MAX_BUFF_SIZE_MACRO); sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: invalid elementCount\", __func__);\n"); sb.Append(prefix + TAB + TAB).Append("return false;\n"); sb.Append(prefix + TAB).Append("}\n\n"); @@ -914,7 +925,7 @@ void ASTArrayType::EmitCStubReadMethodBody(StringBuilder &sb, const std::string sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); - sb.Append(prefix).AppendFormat("if (elementCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("if (elementCount > %s / elementSize) {\n", MAX_BUFF_SIZE_MACRO); sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid elementCount\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); @@ -966,7 +977,7 @@ void ASTArrayType::EmitCWriteStrArrayMethods( sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: invalid sbuf\", __func__);\n"); sb.Append(prefix + TAB + TAB).Append("return false;\n"); sb.Append(prefix + TAB).Append("}\n\n"); - sb.Append(prefix + TAB).AppendFormat("if (count > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix + TAB).AppendFormat("if (count > %s / sizeof(data[0])) {\n", MAX_BUFF_SIZE_MACRO); sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: invalid count\", __func__);\n"); sb.Append(prefix + TAB + TAB).Append("return false;\n"); sb.Append(prefix + TAB).Append("}\n\n"); @@ -1018,7 +1029,7 @@ void ASTArrayType::EmitCReadStrArrayMethodBody(StringBuilder &sb, const std::str sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read count of array\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); - sb.Append(prefix).AppendFormat("if (dataCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("if (dataCount > %s / sizeof(data[0])) {\n", MAX_BUFF_SIZE_MACRO); sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid dataCount\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); @@ -1099,7 +1110,7 @@ void ASTArrayType::EmitCStubReadStrArrayMethodBody(StringBuilder &sb, const std: sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read count of array\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); - sb.Append(prefix).AppendFormat("if (dataCount > %s) {\n", MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("if (dataCount > %s / sizeof(data[0])) {\n", MAX_BUFF_SIZE_MACRO); sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: invalid dataCount\", __func__);\n"); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n\n"); @@ -1205,7 +1216,12 @@ void ASTArrayType::EmitCppReadMethods( sb.Append(prefix).Append("{\n"); sb.Append(prefix + TAB).Append("data.clear();\n"); - sb.Append(prefix + TAB).Append("uint32_t size = parcel.ReadUint32();\n"); + sb.Append(prefix + TAB).Append("uint32_t size = 0;\n"); + sb.Append(prefix + TAB).Append("if (!parcel.ReadUint32(size)) {\n"); + sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: failed to read size\", __func__);\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).Append("if (size == 0) {\n"); sb.Append(prefix + TAB + TAB).Append("return true;\n"); sb.Append(prefix + TAB).Append("}\n"); diff --git a/framework/tools/hdi-gen/ast/ast_boolean_type.cpp b/framework/tools/hdi-gen/ast/ast_boolean_type.cpp index ae7937c05..a9787588b 100644 --- a/framework/tools/hdi-gen/ast/ast_boolean_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_boolean_type.cpp @@ -105,11 +105,12 @@ void ASTBooleanType::EmitCppReadVar(const std::string &parcelName, const std::st const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadBool();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadBool();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = false;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadBool(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTBooleanType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -143,11 +144,12 @@ void ASTBooleanType::EmitCppUnMarshalling(const std::string &parcelName, const s const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadBool();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadBool();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = false;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadBool(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTBooleanType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_byte_type.cpp b/framework/tools/hdi-gen/ast/ast_byte_type.cpp index 554228f87..f5ce347bc 100644 --- a/framework/tools/hdi-gen/ast/ast_byte_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_byte_type.cpp @@ -105,12 +105,12 @@ void ASTByteType::EmitCppReadVar(const std::string &parcelName, const std::strin const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat("%s %s = (%s)%s.ReadInt8();\n", EmitCppType().c_str(), name.c_str(), - EmitCppType().c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat( - "%s = (%s)%s.ReadInt8();\n", name.c_str(), EmitCppType().c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt8(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTByteType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -144,11 +144,12 @@ void ASTByteType::EmitCppUnMarshalling(const std::string &parcelName, const std: const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat("%s %s = (%s)%s.ReadInt8();\n", EmitCppType().c_str(), name.c_str(), - EmitCppType().c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadInt8();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt8(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTByteType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_double_type.cpp b/framework/tools/hdi-gen/ast/ast_double_type.cpp index cc255375e..45126258e 100644 --- a/framework/tools/hdi-gen/ast/ast_double_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_double_type.cpp @@ -105,11 +105,12 @@ void ASTDoubleType::EmitCppReadVar(const std::string &parcelName, const std::str const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadDouble();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadDouble();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadDouble(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTDoubleType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -143,11 +144,12 @@ void ASTDoubleType::EmitCppUnMarshalling(const std::string &parcelName, const st const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadDouble();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadDouble();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadDouble(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTDoubleType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_enum_type.cpp b/framework/tools/hdi-gen/ast/ast_enum_type.cpp index 30b51b46a..7f9066d18 100644 --- a/framework/tools/hdi-gen/ast/ast_enum_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_enum_type.cpp @@ -151,7 +151,7 @@ std::string ASTEnumType::EmitJavaTypeDecl() const void ASTEnumType::EmitCWriteVar(const std::string &parcelName, const std::string &name, const std::string &ecName, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("if (!HdfSbufWriteUint32(%s, (uint32_t)%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix).AppendFormat("if (!HdfSbufWriteUint64(%s, (uint64_t)%s)) {\n", parcelName.c_str(), name.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); @@ -161,27 +161,46 @@ void ASTEnumType::EmitCWriteVar(const std::string &parcelName, const std::string void ASTEnumType::EmitCProxyReadVar(const std::string &parcelName, const std::string &name, bool isInnerType, const std::string &ecName, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("if (!HdfSbufReadUint32(%s, (uint32_t*)%s)) {\n", parcelName.c_str(), name.c_str()); - sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); - sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); - sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + std::string tmpVarName = "enumTmp"; + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).AppendFormat("uint64_t %s = 0;\n", tmpVarName.c_str()); + sb.Append(prefix + TAB) + .AppendFormat("if (!HdfSbufReadUint64(%s, &%s)) {\n", parcelName.c_str(), tmpVarName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).AppendFormat("if (%s == NULL) {\n", name.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: invlid parameter %s\", __func__);\n", + name.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).AppendFormat("*%s = (%s)%s;\n", name.c_str(), EmitCType().c_str(), tmpVarName.c_str()); sb.Append(prefix).Append("}\n"); } void ASTEnumType::EmitCStubReadVar(const std::string &parcelName, const std::string &name, const std::string &ecName, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("if (!HdfSbufReadUint32(%s, (uint32_t*)%s)) {\n", parcelName.c_str(), name.c_str()); - sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); - sb.Append(prefix + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); - sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + std::string tmpVarName = "enumTmp"; + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).AppendFormat("uint64_t %s = 0;\n", tmpVarName.c_str()); + sb.Append(prefix + TAB) + .AppendFormat("if (!HdfSbufReadUint64(%s, &%s)) {\n", parcelName.c_str(), tmpVarName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).AppendFormat("%s = (%s)%s;\n", name.c_str(), EmitCType().c_str(), tmpVarName.c_str()); sb.Append(prefix).Append("}\n"); } void ASTEnumType::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, unsigned int innerLevel) const { - sb.Append(prefix).AppendFormat("if (!%s.WriteUint32((uint32_t)%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix).AppendFormat("if (!%s.WriteUint64(static_cast(%s))) {\n", parcelName.c_str(), + name.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); sb.Append(prefix).Append("}\n"); @@ -190,18 +209,26 @@ void ASTEnumType::EmitCppWriteVar(const std::string &parcelName, const std::stri void ASTEnumType::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, bool initVariable, unsigned int innerLevel) const { + std::string tmpVarName = "enumTmp"; if (initVariable) { - sb.Append(prefix).AppendFormat("%s %s = (%s)%s.ReadUint32();\n", EmitCppType().c_str(), name.c_str(), - EmitCppType().c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat( - "%s = (%s)%s.ReadUint32();\n", name.c_str(), EmitCppType().c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = static_cast<%s>(0);\n", EmitCppType().c_str(), name.c_str(), + EmitCType().c_str()); } + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).AppendFormat("uint64_t %s = 0;\n", tmpVarName.c_str()); + sb.Append(prefix + TAB).AppendFormat("if (!%s.ReadUint64(%s)) {\n", parcelName.c_str(), tmpVarName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", + name.c_str()); + sb.Append(prefix + TAB + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).AppendFormat("%s = static_cast<%s>(%s);\n", name.c_str(), EmitCType().c_str(), + tmpVarName.c_str()); + sb.Append(prefix).Append("}\n"); } void ASTEnumType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const { - sb.Append(prefix).AppendFormat("if (!HdfSbufWriteInt32(data, (int32_t)%s)) {\n", name.c_str()); + sb.Append(prefix).AppendFormat("if (!HdfSbufWriteUint64(data, (uint64_t)%s)) {\n", name.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n"); @@ -210,16 +237,22 @@ void ASTEnumType::EmitCMarshalling(const std::string &name, StringBuilder &sb, c void ASTEnumType::EmitCUnMarshalling(const std::string &name, const std::string &gotoLabel, StringBuilder &sb, const std::string &prefix, std::vector &freeObjStatements) const { - sb.Append(prefix).AppendFormat("if (!HdfSbufReadInt32(data, (int32_t*)&%s)) {\n", name.c_str()); - sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); - sb.Append(prefix + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + std::string tmpVarName = "enumTmp"; + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).AppendFormat("uint64_t %s = 0;\n", tmpVarName.c_str()); + sb.Append(prefix + TAB).AppendFormat("if (!HdfSbufReadUint64(data, &%s)) {\n", tmpVarName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).AppendFormat("%s = (%s)%s;\n", name.c_str(), EmitCType().c_str(), tmpVarName.c_str()); sb.Append(prefix).Append("}\n"); } void ASTEnumType::EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, unsigned int innerLevel) const { - sb.Append(prefix).AppendFormat("if (!%s.WriteUint32((uint32_t)%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix).AppendFormat( + "if (!%s.WriteUint64(static_cast(%s))) {\n", parcelName.c_str(), name.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).Append("return false;\n"); sb.Append(prefix).Append("}\n"); @@ -228,13 +261,21 @@ void ASTEnumType::EmitCppMarshalling(const std::string &parcelName, const std::s void ASTEnumType::EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, bool emitType, unsigned int innerLevel) const { + std::string tmpVarName = "enumTmp"; if (emitType) { - sb.Append(prefix).AppendFormat("%s %s = (%s)%s.ReadUint32();\n", EmitCppType().c_str(), name.c_str(), - EmitCppType().c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat( - "%s = (%s)%s.ReadUint32();\n", name.c_str(), EmitCppType().c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = static_cast<%s>(0);\n", EmitCppType().c_str(), name.c_str(), + EmitCType().c_str()); } + sb.Append(prefix).Append("{\n"); + sb.Append(prefix + TAB).AppendFormat("uint64_t %s = 0;\n", tmpVarName.c_str()); + sb.Append(prefix + TAB).AppendFormat("if (!%s.ReadUint64(%s)) {\n", parcelName.c_str(), tmpVarName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", + name.c_str()); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n"); + sb.Append(prefix + TAB).AppendFormat("%s = static_cast<%s>(%s);\n", name.c_str(), EmitCType().c_str(), + tmpVarName.c_str()); + sb.Append(prefix).Append("}\n"); } } // namespace HDI } // namespace OHOS diff --git a/framework/tools/hdi-gen/ast/ast_fd_type.cpp b/framework/tools/hdi-gen/ast/ast_fd_type.cpp index 1635db8d6..24f9f91eb 100644 --- a/framework/tools/hdi-gen/ast/ast_fd_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_fd_type.cpp @@ -314,7 +314,12 @@ void ASTFdType::EmitCppReadMethods( sb.Append(prefix).AppendFormat("static bool %s(MessageParcel &data, int &fd)\n", methodName.c_str()); sb.Append(prefix).Append("{\n"); sb.Append(prefix + TAB).Append("fd = -1;\n"); - sb.Append(prefix + TAB).Append("if (data.ReadBool()) {\n"); + sb.Append(prefix + TAB).Append("bool fdValid = false;\n"); + sb.Append(prefix + TAB).Append("if (!data.ReadBool(fdValid)) {\n"); + sb.Append(prefix + TAB + TAB).Append("HDF_LOGE(\"%{public}s: failed to read fdValid\", __func__);\n"); + sb.Append(prefix + TAB + TAB).Append("return false;\n"); + sb.Append(prefix + TAB).Append("}\n\n"); + sb.Append(prefix + TAB).Append("if (fdValid) {\n"); sb.Append(prefix + TAB + TAB).Append("fd = data.ReadFileDescriptor();\n"); sb.Append(prefix + TAB + TAB).Append("if (fd < 0) {\n"); sb.Append(prefix + TAB + TAB + TAB).Append("HDF_LOGE(\"%{public}s: failed to read fd\", __func__);\n"); diff --git a/framework/tools/hdi-gen/ast/ast_float_type.cpp b/framework/tools/hdi-gen/ast/ast_float_type.cpp index af750114b..9316f228c 100644 --- a/framework/tools/hdi-gen/ast/ast_float_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_float_type.cpp @@ -105,11 +105,12 @@ void ASTFloatType::EmitCppReadVar(const std::string &parcelName, const std::stri const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadFloat();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadFloat();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadFloat(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTFloatType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -143,11 +144,12 @@ void ASTFloatType::EmitCppUnMarshalling(const std::string &parcelName, const std const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadFloat();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadFloat();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadFloat(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTFloatType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_integer_type.cpp b/framework/tools/hdi-gen/ast/ast_integer_type.cpp index 19e7834e3..21977f972 100644 --- a/framework/tools/hdi-gen/ast/ast_integer_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_integer_type.cpp @@ -105,11 +105,12 @@ void ASTIntegerType::EmitCppReadVar(const std::string &parcelName, const std::st const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadInt32();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadInt32();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt32(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTIntegerType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -143,11 +144,12 @@ void ASTIntegerType::EmitCppUnMarshalling(const std::string &parcelName, const s const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadInt32();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadInt32();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt32(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTIntegerType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_long_type.cpp b/framework/tools/hdi-gen/ast/ast_long_type.cpp index 7e5b0a4a5..fdbe692e7 100644 --- a/framework/tools/hdi-gen/ast/ast_long_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_long_type.cpp @@ -105,11 +105,12 @@ void ASTLongType::EmitCppReadVar(const std::string &parcelName, const std::strin const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadInt64();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadInt64();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt64(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTLongType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -143,11 +144,12 @@ void ASTLongType::EmitCppUnMarshalling(const std::string &parcelName, const std: const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadInt64();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadInt64();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt64(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTLongType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_map_type.cpp b/framework/tools/hdi-gen/ast/ast_map_type.cpp index 465e0a2b0..37b5817bb 100644 --- a/framework/tools/hdi-gen/ast/ast_map_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_map_type.cpp @@ -105,9 +105,11 @@ void ASTMapType::EmitCppReadVar(const std::string &parcelName, const std::string if (initVariable) { sb.Append(prefix).AppendFormat("%s %s;\n", EmitCppType().c_str(), name.c_str()); } - sb.Append(prefix).AppendFormat("uint32_t %sSize = %s.ReadUint32();\n", name.c_str(), parcelName.c_str()); - sb.Append(prefix).AppendFormat("%s(%sSize, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, - name.c_str(), MAX_BUFF_SIZE_MACRO); + sb.Append(prefix).AppendFormat("uint32_t %sSize = 0;\n", name.c_str()); + sb.Append(prefix).AppendFormat("if (!%s.ReadUint32(%sSize)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read size\", __func__);\n"); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n\n"); sb.Append(prefix).AppendFormat("for (uint32_t i = 0; i < %sSize; ++i) {\n", name.c_str()); std::string KeyName = StringHelper::Format("key%d", innerLevel); std::string valueName = StringHelper::Format("value%d", innerLevel); @@ -143,10 +145,11 @@ void ASTMapType::EmitCppUnMarshalling(const std::string &parcelName, const std:: if (emitType) { sb.Append(prefix).AppendFormat("%s %s;\n", EmitCppType().c_str(), memberName.c_str()); } - sb.Append(prefix).AppendFormat("uint32_t %sSize = %s.ReadUint32();\n", memberName.c_str(), parcelName.c_str()); - sb.Append(prefix).AppendFormat("%s(%sSize, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, - memberName.c_str(), MAX_BUFF_SIZE_MACRO); - + sb.Append(prefix).AppendFormat("uint32_t %sSize = 0;\n", name.c_str()); + sb.Append(prefix).AppendFormat("if (!%s.ReadUint32(%sSize)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read size\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n\n"); sb.Append(prefix).AppendFormat("for (uint32_t i = 0; i < %sSize; ++i) {\n", memberName.c_str()); std::string KeyName = StringHelper::Format("key%d", innerLevel); std::string valueName = StringHelper::Format("value%d", innerLevel); diff --git a/framework/tools/hdi-gen/ast/ast_short_type.cpp b/framework/tools/hdi-gen/ast/ast_short_type.cpp index 70b63ed1c..65551cdbf 100644 --- a/framework/tools/hdi-gen/ast/ast_short_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_short_type.cpp @@ -105,12 +105,12 @@ void ASTShortType::EmitCppReadVar(const std::string &parcelName, const std::stri const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat("%s %s = (%s)%s.ReadInt16();\n", EmitCppType().c_str(), name.c_str(), - EmitCppType().c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat( - "%s = (%s)%s.ReadInt16();\n", name.c_str(), EmitCppType().c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt16(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTShortType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -144,11 +144,12 @@ void ASTShortType::EmitCppUnMarshalling(const std::string &parcelName, const std const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat("%s %s = (%s)%s.ReadInt16();\n", EmitCppType().c_str(), name.c_str(), - EmitCppType().c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadInt16();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadInt16(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } void ASTShortType::EmitJavaWriteVar( diff --git a/framework/tools/hdi-gen/ast/ast_string_type.cpp b/framework/tools/hdi-gen/ast/ast_string_type.cpp index a3dc9587e..c6afad6fe 100644 --- a/framework/tools/hdi-gen/ast/ast_string_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_string_type.cpp @@ -118,8 +118,8 @@ void ASTStringType::EmitCStubReadOutVar(const std::string &buffSizeName, const s sb.Append(prefix + TAB + TAB).AppendFormat("%s = HDF_ERR_INVALID_PARAM;\n", ecName.c_str()); sb.Append(prefix + TAB + TAB).AppendFormat("goto %s;\n", gotoLabel.c_str()); sb.Append(prefix + TAB).Append("}\n\n"); - sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s, %s, HDF_ERR_INVALID_PARAM, %s);\n", CHECK_VALUE_RET_GOTO_MACRO, - lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s / sizeof(char), %s, HDF_ERR_INVALID_PARAM, %s);\n", + CHECK_VALUE_RET_GOTO_MACRO, lenName.c_str(), MAX_BUFF_SIZE_MACRO, ecName.c_str(), gotoLabel.c_str()); sb.Append(prefix + TAB).AppendFormat("if (%s > 0) {\n", lenName.c_str()); sb.Append(prefix + TAB + TAB) diff --git a/framework/tools/hdi-gen/ast/ast_uchar_type.cpp b/framework/tools/hdi-gen/ast/ast_uchar_type.cpp index f013a3cb6..375a85f06 100644 --- a/framework/tools/hdi-gen/ast/ast_uchar_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_uchar_type.cpp @@ -106,11 +106,12 @@ void ASTUcharType::EmitCppReadVar(const std::string &parcelName, const std::stri const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint8();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint8();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint8(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTUcharType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -144,11 +145,12 @@ void ASTUcharType::EmitCppUnMarshalling(const std::string &parcelName, const std const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint8();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint8();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint8(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_uint_type.cpp b/framework/tools/hdi-gen/ast/ast_uint_type.cpp index 62155e7f9..143cdc9d3 100644 --- a/framework/tools/hdi-gen/ast/ast_uint_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_uint_type.cpp @@ -106,11 +106,12 @@ void ASTUintType::EmitCppReadVar(const std::string &parcelName, const std::strin const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint32();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint32();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint32(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTUintType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -144,11 +145,12 @@ void ASTUintType::EmitCppUnMarshalling(const std::string &parcelName, const std: const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint32();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint32();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint32(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_ulong_type.cpp b/framework/tools/hdi-gen/ast/ast_ulong_type.cpp index b53d55f43..2a1d0ba53 100644 --- a/framework/tools/hdi-gen/ast/ast_ulong_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_ulong_type.cpp @@ -106,11 +106,12 @@ void ASTUlongType::EmitCppReadVar(const std::string &parcelName, const std::stri const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint64();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint64();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint64(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTUlongType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -144,11 +145,12 @@ void ASTUlongType::EmitCppUnMarshalling(const std::string &parcelName, const std const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint64();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint64();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint64(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_union_type.cpp b/framework/tools/hdi-gen/ast/ast_union_type.cpp index dfa5bc2ee..03024fee5 100644 --- a/framework/tools/hdi-gen/ast/ast_union_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_union_type.cpp @@ -217,9 +217,12 @@ void ASTUnionType::EmitCppReadVar(const std::string &parcelName, const std::stri sb.Append(prefix).AppendFormat("if (%sCp == nullptr) {\n", name.c_str()); sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); - sb.Append(prefix).Append("}\n"); - sb.Append(prefix).AppendFormat("(void)memcpy_s(&%s, sizeof(%s), %sCp, sizeof(%s));\n", name.c_str(), + sb.Append(prefix).Append("}\n\n"); + sb.Append(prefix).AppendFormat("if (memcpy_s(&%s, sizeof(%s), %sCp, sizeof(%s)) != EOK) {\n", name.c_str(), EmitCppType().c_str(), name.c_str(), EmitCppType().c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to memcpy %s\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTUnionType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const diff --git a/framework/tools/hdi-gen/ast/ast_ushort_type.cpp b/framework/tools/hdi-gen/ast/ast_ushort_type.cpp index 1cb6b41ca..9b460ade3 100644 --- a/framework/tools/hdi-gen/ast/ast_ushort_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_ushort_type.cpp @@ -106,11 +106,12 @@ void ASTUshortType::EmitCppReadVar(const std::string &parcelName, const std::str const std::string &prefix, bool initVariable, unsigned int innerLevel) const { if (initVariable) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint16();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint16();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint16(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } void ASTUshortType::EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const @@ -144,11 +145,12 @@ void ASTUshortType::EmitCppUnMarshalling(const std::string &parcelName, const st const std::string &prefix, bool emitType, unsigned int innerLevel) const { if (emitType) { - sb.Append(prefix).AppendFormat( - "%s %s = %s.ReadUint16();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); - } else { - sb.Append(prefix).AppendFormat("%s = %s.ReadUint16();\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("%s %s = 0;\n", EmitCppType().c_str(), name.c_str()); } + sb.Append(prefix).AppendFormat("if (!%s.ReadUint16(%s)) {\n", parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: read %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); } } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp index bb5b9c46b..fdb4be41f 100644 --- a/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_client_proxy_code_emitter.cpp @@ -423,8 +423,12 @@ void CClientProxyCodeEmitter::EmitReadProxyMethodParameter(const AutoPtrGetTypeKind() == TypeKind::TYPE_UNION) { std::string cpName = StringHelper::Format("%sCp", param->GetName().c_str()); type->EmitCProxyReadVar(parcelName, cpName, false, errorCodeName_, gotoLabel, sb, prefix); - sb.Append(prefix).AppendFormat("(void)memcpy_s(%s, sizeof(%s), %s, sizeof(%s));\n", param->GetName().c_str(), - type->EmitCType().c_str(), cpName.c_str(), type->EmitCType().c_str()); + sb.Append(prefix).AppendFormat("if (memcpy_s(%s, sizeof(%s), %s, sizeof(%s)) != EOK) {\n", + param->GetName().c_str(), type->EmitCType().c_str(), cpName.c_str(), type->EmitCType().c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to memcpy %s\", __func__);\n", + param->GetName().c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } else { type->EmitCProxyReadVar(parcelName, param->GetName(), false, errorCodeName_, gotoLabel, sb, prefix); } diff --git a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp index 3f749f476..5b50d70d9 100644 --- a/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_impl_code_emitter.cpp @@ -284,11 +284,9 @@ void CServiceImplCodeEmitter::EmitServiceImplGetMethod(StringBuilder &sb) baseName_.c_str(), method->GetName().c_str()); } - if (Options::GetInstance().DoPassthrough()) { - AutoPtr method = interface_->GetVersionMethod(); - sb.Append(TAB).AppendFormat("%s->interface.%s = %s%s;\n", objName.c_str(), method->GetName().c_str(), - baseName_.c_str(), method->GetName().c_str()); - } + AutoPtr method = interface_->GetVersionMethod(); + sb.Append(TAB).AppendFormat("%s->interface.%s = %s%s;\n", objName.c_str(), method->GetName().c_str(), + baseName_.c_str(), method->GetName().c_str()); sb.Append(TAB).AppendFormat("return &%s->interface;\n", objName.c_str()); sb.Append("}\n"); diff --git a/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp b/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp index 9db085cb7..b66961a33 100644 --- a/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/c_service_stub_code_emitter.cpp @@ -354,8 +354,6 @@ void CServiceStubCodeEmitter::EmitReadStubMethodParameter(const AutoPtrGetTypeKind() == TypeKind::TYPE_STRING) { EmitReadCStringStubMethodParameter(param, parcelName, gotoLabel, sb, prefix, type); - } else if (type->GetTypeKind() == TypeKind::TYPE_INTERFACE) { - type->EmitCStubReadVar(parcelName, param->GetName(), errorCodeName_, gotoLabel, sb, prefix); } else if (type->GetTypeKind() == TypeKind::TYPE_STRUCT) { sb.Append(prefix).AppendFormat("%s = (%s*)OsalMemCalloc(sizeof(%s));\n", param->GetName().c_str(), type->EmitCType(TypeMode::NO_MODE).c_str(), type->EmitCType(TypeMode::NO_MODE).c_str()); @@ -377,11 +375,17 @@ void CServiceStubCodeEmitter::EmitReadStubMethodParameter(const AutoPtrGetName().c_str(), - type->EmitCType(TypeMode::NO_MODE).c_str(), cpName.c_str(), type->EmitCType(TypeMode::NO_MODE).c_str()); - } else if (type->GetTypeKind() == TypeKind::TYPE_ARRAY || type->GetTypeKind() == TypeKind::TYPE_LIST) { - type->EmitCStubReadVar(parcelName, param->GetName(), errorCodeName_, gotoLabel, sb, prefix); - } else if (type->GetTypeKind() == TypeKind::TYPE_FILEDESCRIPTOR) { + sb.Append(prefix).AppendFormat("if (memcpy_s(%s, sizeof(%s), %s, sizeof(%s)) != EOK) {\n", + param->GetName().c_str(), type->EmitCType(TypeMode::NO_MODE).c_str(), cpName.c_str(), + type->EmitCType(TypeMode::NO_MODE).c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to memcpy %s\", __func__);\n", + param->GetName().c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); + } else if (type->GetTypeKind() == TypeKind::TYPE_ARRAY || type->GetTypeKind() == TypeKind::TYPE_LIST || + type->GetTypeKind() == TypeKind::TYPE_FILEDESCRIPTOR || + type->GetTypeKind() == TypeKind::TYPE_ENUM || + type->GetTypeKind() == TypeKind::TYPE_INTERFACE) { type->EmitCStubReadVar(parcelName, param->GetName(), errorCodeName_, gotoLabel, sb, prefix); } else { std::string name = StringHelper::Format("&%s", param->GetName().c_str()); diff --git a/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp index 6348db16b..7737a2a12 100644 --- a/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_custom_types_code_emitter.cpp @@ -314,19 +314,20 @@ void CppCustomTypesCodeEmitter::EmitCustomTypeUnmarshallingImpl(StringBuilder &s AutoPtr memberType = type->GetMemberType(i); std::string memberName = type->GetMemberName(i); std::string name = StringHelper::Format("%s.%s", objName.c_str(), memberName.c_str()); - if (i > 0 && - (memberType->GetTypeKind() == TypeKind::TYPE_STRUCT || - memberType->GetTypeKind() == TypeKind::TYPE_UNION || - memberType->GetTypeKind() == TypeKind::TYPE_ARRAY || - memberType->GetTypeKind() == TypeKind::TYPE_LIST)) { + if (i > 0) { sb.Append("\n"); } if (memberType->GetTypeKind() == TypeKind::TYPE_UNION) { std::string cpName = StringHelper::Format("%sCp", memberName.c_str()); memberType->EmitCppUnMarshalling("data", cpName, sb, TAB, false); - sb.Append(TAB).AppendFormat("(void)memcpy_s(&%s, sizeof(%s), %s, sizeof(%s));\n", name.c_str(), - memberType->EmitCppType().c_str(), cpName.c_str(), memberType->EmitCppType().c_str()); + sb.Append(TAB).AppendFormat("if (memcpy_s(&%s, sizeof(%s), %s, sizeof(%s)) != EOK) {\n", + name.c_str(), memberType->EmitCppType().c_str(), cpName.c_str(), + memberType->EmitCppType().c_str()); + sb.Append(TAB).Append(TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to memcpy %s\", __func__);\n", + name.c_str()); + sb.Append(TAB).Append(TAB).Append("return false;\n"); + sb.Append(TAB).Append("}\n"); } else if (memberType->GetTypeKind() == TypeKind::TYPE_STRING) { std::string cpName = StringHelper::Format("%sCp", memberName.c_str()); memberType->EmitCppUnMarshalling("data", cpName, sb, TAB, false); diff --git a/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp b/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp index 16e2b336d..5d78f5424 100644 --- a/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp +++ b/framework/tools/hdi-gen/codegen/cpp_service_stub_code_emitter.cpp @@ -401,7 +401,12 @@ void CppServiceStubCodeEmitter::EmitStubReadMemFlag( const AutoPtr &method, const std::string &parcelName, StringBuilder &sb, const std::string &prefix) { if (NeedFlag(method)) { - sb.Append(prefix).AppendFormat("bool %s = %s.ReadBool();\n\n", flagOfSetMemName_.c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("bool %s = false;\n", flagOfSetMemName_.c_str()); + sb.Append(prefix).AppendFormat("if (!%s.ReadBool(%s)) {\n", parcelName.c_str(), flagOfSetMemName_.c_str()); + sb.Append(prefix + TAB) + .AppendFormat("HDF_LOGE(\"%%{public}s: failed to read %s\", __func__);\n", flagOfSetMemName_.c_str()); + sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix).Append("}\n"); } } @@ -410,16 +415,30 @@ void CppServiceStubCodeEmitter::EmitLocalVariable( { sb.Append(prefix).Append(param->EmitCppLocalVar()).Append("\n"); AutoPtr type = param->GetType(); - if (type->IsStringType() || type->IsArrayType() || type->IsListType()) { - sb.Append(prefix).AppendFormat("if (%s) {\n", flagOfSetMemName_.c_str()); - std::string capacityName = "capacity"; - sb.Append(prefix + TAB) - .AppendFormat("uint32_t %s = %s.ReadUint32();\n", capacityName.c_str(), parcelName.c_str()); - sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s, HDF_ERR_INVALID_PARAM);\n", CHECK_VALUE_RETURN_MACRO, - capacityName.c_str(), MAX_BUFF_SIZE_MACRO); - sb.Append(prefix + TAB).AppendFormat("%s.reserve(%s);\n", param->GetName().c_str(), capacityName.c_str()); - sb.Append(prefix).Append("}\n"); + if (!type->IsStringType() && !type->IsArrayType() && !type->IsListType()) { + return; + } + + sb.Append(prefix).AppendFormat("if (%s) {\n", flagOfSetMemName_.c_str()); + std::string capacityName = "capacity"; + sb.Append(prefix + TAB).AppendFormat("uint32_t %s = 0;\n", capacityName.c_str()); + sb.Append(prefix + TAB).AppendFormat("if (!%s.ReadUint32(%s)) {\n", parcelName.c_str(), capacityName.c_str()); + sb.Append(prefix + TAB + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to read %s\", __func__);\n", + capacityName.c_str()); + sb.Append(prefix + TAB + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); + sb.Append(prefix + TAB).Append("}\n"); + + if (type->IsStringType()) { + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s / sizeof(char), HDF_ERR_INVALID_PARAM);\n", + CHECK_VALUE_RETURN_MACRO, capacityName.c_str(), MAX_BUFF_SIZE_MACRO); + } else { + AutoPtr arrayType = dynamic_cast(type.Get()); + sb.Append(prefix + TAB).AppendFormat("%s(%s, >, %s / sizeof(%s), HDF_ERR_INVALID_PARAM);\n", + CHECK_VALUE_RETURN_MACRO, capacityName.c_str(), MAX_BUFF_SIZE_MACRO, + arrayType->GetElementType()->EmitCppType().c_str()); } + sb.Append(prefix + TAB).AppendFormat("%s.reserve(%s);\n", param->GetName().c_str(), capacityName.c_str()); + sb.Append(prefix).Append("}\n"); } void CppServiceStubCodeEmitter::GetUtilMethods(UtilMethodMap &methods) diff --git a/framework/tools/hdi-gen/util/common.h b/framework/tools/hdi-gen/util/common.h index 64a52eb57..6c1593c2d 100644 --- a/framework/tools/hdi-gen/util/common.h +++ b/framework/tools/hdi-gen/util/common.h @@ -21,7 +21,7 @@ namespace HDI { #endif constexpr const char *MAX_BUFF_SIZE_MACRO = "HDI_BUFF_MAX_SIZE"; - constexpr const char *MAX_BUFF_SIZE_VALUE = "1024 * 4"; + constexpr const char *MAX_BUFF_SIZE_VALUE = "1024 * 200"; // 200KB constexpr const char *CHECK_VALUE_RETURN_MACRO = "HDI_CHECK_VALUE_RETURN"; constexpr const char *CHECK_VALUE_RET_GOTO_MACRO = "HDI_CHECK_VALUE_RET_GOTO"; } -- Gitee From cde257918593cdca3429f459b8d1a183bcd92a12 Mon Sep 17 00:00:00 2001 From: jiaziyangnewer Date: Tue, 10 Jan 2023 11:31:40 +0800 Subject: [PATCH 35/60] fix:Replace Sensitive Words. Signed-off-by: jiaziyangnewer --- adapter/khdf/linux/platform/spi/spi_adapter.c | 2 +- adapter/platform/i2c/i2c_bes.h | 2 +- adapter/platform/i2c/i2c_wm.c | 2 +- framework/include/platform/i2s_if.h | 18 +++++++++--------- framework/include/platform/i3c_if.h | 4 ++-- .../model/storage/include/mmc/mmc_protocol.h | 4 ++-- framework/model/storage/src/mmc/mmc_protocol.c | 2 +- .../test/unittest/platform/common/i3c_test.c | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/adapter/khdf/linux/platform/spi/spi_adapter.c b/adapter/khdf/linux/platform/spi/spi_adapter.c index 26f16032a..595e9a2be 100644 --- a/adapter/khdf/linux/platform/spi/spi_adapter.c +++ b/adapter/khdf/linux/platform/spi/spi_adapter.c @@ -293,7 +293,7 @@ static int32_t SpiFindDeviceFromBus(struct device *dev, void *para) if (spidev->master == NULL) { put_device(&spidev->dev); - HDF_LOGE("%s: spi_device %s -> master is NULL", __func__, GetSpiDevName(&spidev->dev)); + HDF_LOGE("%s: spi_device %s is invalid", __func__, GetSpiDevName(&spidev->dev)); return HDF_ERR_INVALID_PARAM; } HDF_LOGI("%s: spi_device %s, find success", __func__, GetSpiDevName(&spidev->dev)); diff --git a/adapter/platform/i2c/i2c_bes.h b/adapter/platform/i2c/i2c_bes.h index 404e8ff60..21d0db554 100644 --- a/adapter/platform/i2c/i2c_bes.h +++ b/adapter/platform/i2c/i2c_bes.h @@ -34,7 +34,7 @@ struct I2cResource { }; struct I2cDevice { - uint16_t devAddr; /**< slave device addr */ + uint16_t devAddr; /**< device addr */ uint32_t addressWidth; /**< Addressing mode: 7 bit or 10 bit */ struct OsalMutex mutex; uint32_t port; diff --git a/adapter/platform/i2c/i2c_wm.c b/adapter/platform/i2c/i2c_wm.c index fa090df8e..a51a87b47 100755 --- a/adapter/platform/i2c/i2c_wm.c +++ b/adapter/platform/i2c/i2c_wm.c @@ -28,7 +28,7 @@ struct I2cResource { }; struct I2cDevice { - uint16_t devAddr; /**< slave device addr */ + uint16_t devAddr; /**< device addr */ uint32_t addressWidth; /**< Addressing mode: 7 bit or 10 bit */ struct OsalMutex mutex; uint32_t port; diff --git a/framework/include/platform/i2s_if.h b/framework/include/platform/i2s_if.h index 8bb838bf7..3dd78096e 100644 --- a/framework/include/platform/i2s_if.h +++ b/framework/include/platform/i2s_if.h @@ -72,8 +72,8 @@ enum I2sWordWidth { }; enum I2sMode { - I2S_MODE_MASTER_TX_MODE, - I2S_MODE_MASTER_RX_MODE, + I2S_MODE_HOST_TX_MODE, + I2S_MODE_HOST_RX_MODE, I2S_MODE_STANDBY_TX_MODE, I2S_MODE_STANDBY_RX_MODE, }; @@ -141,16 +141,16 @@ enum I2slFsSel { struct I2sCfg { enum I2sSampleRate sampleRate; /**< I2S sample rate, 8k,16k,32k... */ - enum I2sWordWidth width; /**< I2S word width, 8bit,16bit,20bit,24bit... */ - enum I2sMode mode; /**< I2S mode, master/standby, tx/rx */ + enum I2sWordWidth width; /**< I2S word width, 8bit,16bit,20bit,24bit... */ + enum I2sMode mode; /**< I2S mode, host/standby, tx/rx */ enum I2sPcmFscDelay syncMode; /**< pcm mode, FSC starts location */ - enum I2sLoopMode loopMode; /**< is loopback */ + enum I2sLoopMode loopMode; /**< is loopback */ enum I2sProtocolType type; /**< I2S protocol type */ - enum I2sChannel channel; - enum I2sFrameLen frameLen; - enum I2sDataSel dataSel; + enum I2sChannel channel; + enum I2sFrameLen frameLen; + enum I2sDataSel dataSel; enum I2sChannelMode channelMode; /**< I2S mode,data channel */ - uint8_t samplePrecision; /**< bit */ + uint8_t samplePrecision; /**< bit */ enum I2sChannelIfMode channelIfMode; uint32_t mclk; /**< KHZ */ uint32_t bclk; /**< KHZ */ diff --git a/framework/include/platform/i3c_if.h b/framework/include/platform/i3c_if.h index bfe076e55..780ea45e6 100644 --- a/framework/include/platform/i3c_if.h +++ b/framework/include/platform/i3c_if.h @@ -126,8 +126,8 @@ enum I3cBusMode { struct I3cConfig { /** I3C bus mode */ enum I3cBusMode busMode; - /** Current master object, its NULL when the controller is the master */ - struct I3cDevice *curMaster; + /** Current host object, its NULL when the controller is the host */ + struct I3cDevice *curHost; }; /** diff --git a/framework/model/storage/include/mmc/mmc_protocol.h b/framework/model/storage/include/mmc/mmc_protocol.h index 92503749f..221986c99 100644 --- a/framework/model/storage/include/mmc/mmc_protocol.h +++ b/framework/model/storage/include/mmc/mmc_protocol.h @@ -955,8 +955,8 @@ enum SdioCccrCapbility { /* POWER_CONTROL-->bit0: SMPC, bit1: EMPC */ enum SdioCccrPower { - SDIO_CCCR_POWER_SMPC = 0x01, /* Support Master Power Control. */ - SDIO_CCCR_POWER_EMPC = 0x02, /* Enable Master Power Control. */ + SDIO_CCCR_POWER_SMPC = 0x01, /* Support Power Control. */ + SDIO_CCCR_POWER_EMPC = 0x02, /* Enable Power Control. */ }; /* BUS_SPEED_SELECT-->bit0: SHS. Support High-Speed. */ diff --git a/framework/model/storage/src/mmc/mmc_protocol.c b/framework/model/storage/src/mmc/mmc_protocol.c index 38166cc6d..833289e61 100644 --- a/framework/model/storage/src/mmc/mmc_protocol.c +++ b/framework/model/storage/src/mmc/mmc_protocol.c @@ -3269,7 +3269,7 @@ int32_t SdioCccrIntEnable(struct MmcCntlr *cntlr) return err; } /* - * [0]IENM: Interrupt Enable Master. + * [0]IENM: Interrupt Enable Host. * If this bit is cleared to 0, no interrupts from this card shall be sent to the host. * If this bit is set to 1, then any function's interrupt shall be sent to the host. */ diff --git a/framework/test/unittest/platform/common/i3c_test.c b/framework/test/unittest/platform/common/i3c_test.c index 4a6559bb6..a758dddeb 100644 --- a/framework/test/unittest/platform/common/i3c_test.c +++ b/framework/test/unittest/platform/common/i3c_test.c @@ -254,7 +254,7 @@ static int32_t I3cTestSetConfig(void *param) } config->busMode = I3C_BUS_HDR_MODE; - config->curMaster = NULL; + config->curHost = NULL; ret = I3cSetConfig(tester->handle, config); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: Set config failed!, busId = %hu", __func__, tester->config.busId); @@ -487,7 +487,7 @@ static int32_t I3cTestReliability(void *param) return HDF_ERR_MALLOC_FAIL; } config->busMode = I3C_BUS_HDR_MODE; - config->curMaster = NULL; + config->curHost = NULL; // invalid handle (void)I3cTransfer(NULL, g_msgs, 1, I3C_MODE); (void)I3cSetConfig(NULL, config); -- Gitee From 8e67a86a0519afb916e345b31a0910f19e4b6a6e Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Tue, 10 Jan 2023 16:39:52 +0800 Subject: [PATCH 36/60] fix:python 'open' to create file need set permission modify Signed-off-by: chenpan0560 --- framework/tools/hc-gen/test/update_case.py | 6 +++++- framework/tools/hcs-view/hcsWebView/build.py | 8 ++++++-- framework/tools/hcs-view/hcsWebView/build_plugin.py | 8 ++++++-- .../command_line/hdf_defconfig_patch.py | 4 +++- .../command_line/hdf_device_info_hcs.py | 5 +++-- .../command_line/hdf_model_enable_operation.py | 6 ++++-- .../command_line/hdf_vendor_build_file.py | 5 ++++- .../command_line/hdi_add_handler.py | 6 +++++- .../tools/hdf_dev_eco_tool/hdf_tool_settings.py | 5 +++++ framework/tools/hdf_dev_eco_tool/hdf_utils.py | 13 ++++++++++--- .../hdf_dev_eco_tool/resources/create_driver.config | 3 +-- .../tools/hdf_dev_eco_tool/resources/settings.json | 4 ++++ framework/tools/idl-gen/_header_parser.py | 8 ++++++-- framework/tools/idl-gen/idl_generator.py | 6 +++++- .../tools/idl-gen/testcase/test_header_parser.py | 9 +++++++-- 15 files changed, 74 insertions(+), 22 deletions(-) diff --git a/framework/tools/hc-gen/test/update_case.py b/framework/tools/hc-gen/test/update_case.py index b444ca1c3..d7491ea65 100755 --- a/framework/tools/hc-gen/test/update_case.py +++ b/framework/tools/hc-gen/test/update_case.py @@ -32,6 +32,7 @@ import os import platform import shutil +import stat import subprocess import sys import base64 @@ -81,7 +82,10 @@ def index_case(case_path): def save_compile_result(mode, case_name, status, output): result_file_name = os.path.join(TestConfig.WORK_DIR, case_name, 'golden_%s_compile_result.txt' % mode) - with open(result_file_name, 'w') as result_output: + flags = os.O_RDWR | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IWGRP | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + write_fd = os.open(result_file_name, flags, modes) + with os.fdopen(write_fd, "w", encoding="utf-8") as result_output: status_str = "[compile exit status]:" + str(status) output_str = "\n[compile console output]:\n" + output result_output.write(status_str) diff --git a/framework/tools/hcs-view/hcsWebView/build.py b/framework/tools/hcs-view/hcsWebView/build.py index 64a5c6004..447f4c1e4 100644 --- a/framework/tools/hcs-view/hcsWebView/build.py +++ b/framework/tools/hcs-view/hcsWebView/build.py @@ -6,7 +6,8 @@ # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. # See the LICENSE file in the root of this repository for complete details. - +import os +import stat from asyncio import subprocess if __name__ == "__main__": @@ -19,6 +20,9 @@ if __name__ == "__main__": with open(r".\dist\main.js", "r", encoding="utf8") as file: destss = file.read() ss = ss[:i1] + destss + ss[i2:] - with open(r".\..\hcsVSCode\editor.html", "w", encoding="utf8") as file: + flags = os.O_RDWR | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IWGRP | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + write_fd = os.open(r".\..\hcsVSCode\editor.html", flags, modes) + with os.fdopen(write_fd, "w", encoding="utf-8") as file: file.write(ss) print("replaced") diff --git a/framework/tools/hcs-view/hcsWebView/build_plugin.py b/framework/tools/hcs-view/hcsWebView/build_plugin.py index db06974bb..545dd2277 100644 --- a/framework/tools/hcs-view/hcsWebView/build_plugin.py +++ b/framework/tools/hcs-view/hcsWebView/build_plugin.py @@ -6,7 +6,8 @@ # HDF is dual licensed: you can use it either under the terms of # the GPL, or the BSD license, at your option. # See the LICENSE file in the root of this repository for complete details. - +import os +import stat from asyncio import subprocess if __name__ == "__main__": @@ -19,6 +20,9 @@ if __name__ == "__main__": with open(r".\dist\main.js", "r", encoding="utf8") as file: destss = file.read() ss = ss[:i1] + destss + ss[i2:] - with open(r".\..\hcs_config_plugin\editor.html", "w", encoding="utf8") as file: + flags = os.O_RDWR | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IWGRP | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + write_fd = os.open(r".\..\hcs_config_plugin\editor.html", flags, modes) + with os.fdopen(write_fd, "w", encoding="utf-8") as file: file.write(ss) print("replace success") diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py index e28755bbe..8b8053128 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py @@ -52,7 +52,9 @@ class HdfDefconfigAndPatch(object): lines.remove(self.new_demo_config.encode("utf-8")) else: lines.remove(("+" + self.new_demo_config).encode("utf-8")) - with open(path, "wb") as f_write: + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "wb") as f_write: f_write.writelines(lines) def rename_vendor(self): diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py index 9e41a724c..cff8db154 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_device_info_hcs.py @@ -53,8 +53,9 @@ class HdfDeviceInfoHcsFile(object): def _save(self): if self.lines: - codetype = "utf-8" - with open(self.hcspath, "w+", encoding=codetype) as lwrite: + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(self.hcspath, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "w+", encoding="utf-8") as lwrite: for line in self.lines: lwrite.write(line) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py index 3ebe462ee..857d32408 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py @@ -16,6 +16,7 @@ import hdf_utils from hdf_tool_exception import HdfToolException from .hdf_liteos_scann import HdfLiteScan from .hdf_command_error_code import CommandErrorCode +from hdf_tool_settings import HdfToolSettings class EnableOperation(object): @@ -227,8 +228,9 @@ class EnableOperation(object): for index, line in enumerate(file_lines): if old_demo_config.encode('utf-8') == line.strip(): file_lines[index] = new_demo_config.encode('utf-8') - - with open(file_path, 'wb') as f_write: + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(file_path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "wb") as f_write: f_write.writelines(file_lines) return True diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py index cb746b679..eddd8a585 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py @@ -14,6 +14,7 @@ import re import hdf_utils from hdf_tool_exception import HdfToolException from .hdf_command_error_code import CommandErrorCode +from hdf_tool_settings import HdfToolSettings class HdfVendorBuildFile(object): @@ -38,7 +39,9 @@ class HdfVendorBuildFile(object): new_line["value"] = line new_line["value"] = new_line.get("value").replace("input", module) data.insert(new_line.get("index"), new_line.get("value")) - with open(self.file_path, 'w') as write_file: + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(self.file_path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "w") as write_file: for i in data: write_file.write(i) return self.file_path diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py b/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py index 37fc52e3a..6369eaea9 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py @@ -17,11 +17,13 @@ import string import hdf_tool_settings import hdf_utils +import hdf_tool_settings from command_line.hdf_command_error_code import CommandErrorCode from command_line.hdf_command_handler_base import HdfCommandHandlerBase from hdf_tool_exception import HdfToolException + class HdiAddHandler(HdfCommandHandlerBase): def __init__(self, args): super(HdiAddHandler, self).__init__() @@ -396,7 +398,9 @@ class HdiAddHandler(HdfCommandHandlerBase): file_info = "".join(selinux_temp.get(key_name)) temp_file_info = string.Template(file_info).safe_substitute(replace_data) file_path = os.path.join(temp_peripheral_path, temp_file_name) - with open(file_path, "wb")as f_write: + config_info = hdf_tool_settings.HdfToolSettings().get_file_config_info() + write_fd = os.open(file_path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "wb") as f_write: f_write.write(temp_file_info.encode("utf-8")) temp_create = self.format_file_path(file_path, root_path) self.result_json["create_file"].append(temp_create) diff --git a/framework/tools/hdf_dev_eco_tool/hdf_tool_settings.py b/framework/tools/hdf_dev_eco_tool/hdf_tool_settings.py index d574a51fe..ab0007f7a 100644 --- a/framework/tools/hdf_dev_eco_tool/hdf_tool_settings.py +++ b/framework/tools/hdf_dev_eco_tool/hdf_tool_settings.py @@ -60,6 +60,7 @@ class HdfToolSettings(object): self.hdi_config_key = "hdi_config" self.passwd_group_key = "passwd_group_config" self.config_setting_info = "config_setting_file_info" + self.create_file_config_info = "create_file_config" def get_supported_boards(self): key = self.supported_boards_key @@ -148,6 +149,10 @@ class HdfToolSettings(object): key = self.config_setting_info return self.settings.get(key, 'hdf') + def get_file_config_info(self): + key = self.create_file_config_info + return self.settings.get(key, 'hdf') + @singleton class HdiToolConfig(object): diff --git a/framework/tools/hdf_dev_eco_tool/hdf_utils.py b/framework/tools/hdf_dev_eco_tool/hdf_utils.py index 00968745f..1de420010 100644 --- a/framework/tools/hdf_dev_eco_tool/hdf_utils.py +++ b/framework/tools/hdf_dev_eco_tool/hdf_utils.py @@ -108,7 +108,9 @@ def _write_one_section(file_obj, section_content): def add_before_and_save(file_content, file_path, pos_range, new_section): if not file_content or not file_path or not pos_range or not new_section: return - with open(file_path, 'w', newline='\n') as file_write: + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(file_path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "w", newline='\n') as file_write: file_write.write(file_content[:pos_range.start_pos]) _write_one_section(file_write, new_section) file_write.write(file_content[pos_range.start_pos:]) @@ -194,7 +196,9 @@ def write_file(file_path, content): def write_file_lines(file_path, content, code_type="utf-8"): - with open(file_path, 'w', encoding=code_type) as file_write: + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(file_path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "w", encoding=code_type) as file_write: file_write.writelines(content) @@ -450,7 +454,10 @@ def ini_file_read_operation(section_name, node_name, path=""): def ini_file_write_operation(model, operation_object, model_child_dir_list): json_format_list = json.dumps(model_child_dir_list) operation_object.set(model, "file_dir", json_format_list) - with open(os.path.join("resources", "config.ini"), "w") as write_ini_file: + ini_file_path = os.path.join("resources", "config.ini") + config_info = HdfToolSettings().get_file_config_info() + write_fd = os.open(ini_file_path, config_info["flags"], config_info["modes"]) + with os.fdopen(write_fd, "w") as write_ini_file: operation_object.write(write_ini_file) diff --git a/framework/tools/hdf_dev_eco_tool/resources/create_driver.config b/framework/tools/hdf_dev_eco_tool/resources/create_driver.config index 7a73a41bf..0967ef424 100644 --- a/framework/tools/hdf_dev_eco_tool/resources/create_driver.config +++ b/framework/tools/hdf_dev_eco_tool/resources/create_driver.config @@ -1,2 +1 @@ -{ -} \ No newline at end of file +{} diff --git a/framework/tools/hdf_dev_eco_tool/resources/settings.json b/framework/tools/hdf_dev_eco_tool/resources/settings.json index e9f889720..d7daf29c4 100644 --- a/framework/tools/hdf_dev_eco_tool/resources/settings.json +++ b/framework/tools/hdf_dev_eco_tool/resources/settings.json @@ -69,5 +69,9 @@ ], "config_path": "resources/templates/lite/hdi_template/create_idl_hdi.json", "out_config_name": "create_idl_hdi.config" + }, + "create_file_config": { + "flags": 258, + "modes": 436 } } diff --git a/framework/tools/idl-gen/_header_parser.py b/framework/tools/idl-gen/_header_parser.py index d46ee1528..99a372042 100644 --- a/framework/tools/idl-gen/_header_parser.py +++ b/framework/tools/idl-gen/_header_parser.py @@ -10,6 +10,7 @@ import json import os import re +import stat from shutil import copyfile, move import CppHeaderParser @@ -79,8 +80,11 @@ class HeaderParser: continue else: new_lines += line - with open(header_file, 'w') as f: - f.writelines(new_lines) + flags = os.O_RDWR | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IWGRP | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + write_fd = os.open(header_file, flags, modes) + with os.fdopen(write_fd, "w", encoding="utf-8") as file: + file.write(new_lines) return back_file @staticmethod diff --git a/framework/tools/idl-gen/idl_generator.py b/framework/tools/idl-gen/idl_generator.py index 0cb3308bd..34df35bd2 100644 --- a/framework/tools/idl-gen/idl_generator.py +++ b/framework/tools/idl-gen/idl_generator.py @@ -10,6 +10,7 @@ import argparse import os import re +import stat import pip @@ -293,7 +294,10 @@ class IDLGenerator: def _write_file(self, file_path, file_name): file = os.path.join(self._make_output_dir(file_path), file_name).replace('\\', '/') - with open(file, "w", encoding="utf8") as fp: + flags = os.O_RDWR | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IWGRP | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + write_fd = os.open(file, flags, modes) + with os.fdopen(write_fd, "w", encoding="utf-8") as fp: fp.write("".join(self._idl)) print("Generate: --------------------- %s ---------------------\n" % os.path.normpath(file)) self._idl = [] diff --git a/framework/tools/idl-gen/testcase/test_header_parser.py b/framework/tools/idl-gen/testcase/test_header_parser.py index ee8b10d32..95474135e 100644 --- a/framework/tools/idl-gen/testcase/test_header_parser.py +++ b/framework/tools/idl-gen/testcase/test_header_parser.py @@ -8,6 +8,8 @@ # See the LICENSE file in the root of this repository for complete details. import json +import os +import stat import sys import unittest from os import remove @@ -268,8 +270,11 @@ class HeaderParserTestCase(unittest.TestCase): } DevAbility; """ file_name = "header_file.h" - with open(file_name, 'w') as f: - f.write(header_file) + flags = os.O_RDWR | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IWGRP | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH + write_fd = os.open(file_name, flags, modes) + with os.fdopen(write_fd, "w", encoding="utf-8") as file: + file.write(header_file) parser = HeaderParser() back_file = parser._pre_handle(file_name) -- Gitee From 3926d8b9ad881d2abe1f417a087cd284678e154b Mon Sep 17 00:00:00 2001 From: YOUR_NAME Date: Fri, 13 Jan 2023 10:58:45 +0800 Subject: [PATCH 37/60] fix:Alarm cleanup Signed-off-by: chenpan0560 --- .../hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py | 2 +- .../hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py index 857d32408..3fc688373 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py @@ -14,9 +14,9 @@ from string import Template import hdf_utils from hdf_tool_exception import HdfToolException +from hdf_tool_settings import HdfToolSettings from .hdf_liteos_scann import HdfLiteScan from .hdf_command_error_code import CommandErrorCode -from hdf_tool_settings import HdfToolSettings class EnableOperation(object): diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py index eddd8a585..a94ebe7bf 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_vendor_build_file.py @@ -13,8 +13,8 @@ import re import hdf_utils from hdf_tool_exception import HdfToolException -from .hdf_command_error_code import CommandErrorCode from hdf_tool_settings import HdfToolSettings +from .hdf_command_error_code import CommandErrorCode class HdfVendorBuildFile(object): -- Gitee From 1b75a5ec6cb2c55e27710480c97fed2463e74ccc Mon Sep 17 00:00:00 2001 From: yueyan Date: Thu, 12 Jan 2023 16:40:15 +0800 Subject: [PATCH 38/60] fixed 1277dce from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1688 fix:fix blocking time calculation error of smq Signed-off-by: yueyan --- adapter/uhdf2/include/hdi/base/hdi_smq.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/adapter/uhdf2/include/hdi/base/hdi_smq.h b/adapter/uhdf2/include/hdi/base/hdi_smq.h index 9092207cf..7972516d0 100644 --- a/adapter/uhdf2/include/hdi/base/hdi_smq.h +++ b/adapter/uhdf2/include/hdi/base/hdi_smq.h @@ -277,11 +277,12 @@ int SharedMemQueue::Write(const T *data, size_t count, int64_t waitTimeNanoSe while (true) { if (waitTimeNanoSec != 0) { currentTime = GetNanoTime(); - if (GetNanoTime() - startTime >= waitTimeNanoSec) { + waitTimeNanoSec -= (currentTime - startTime); + startTime = currentTime; + if (waitTimeNanoSec <= 0) { ret = WriteNonBlocking(data, count); break; } - waitTimeNanoSec -= currentTime - startTime; } ret = syncer_->Wait(SharedMemQueueSyncer::SYNC_WORD_WRITE, waitTimeNanoSec); if (ret != 0 && ret != -ETIMEDOUT) { @@ -322,11 +323,12 @@ int SharedMemQueue::Read(T *data, size_t count, int64_t waitTimeNanoSec) while (true) { if (waitTimeNanoSec != 0) { currentTime = GetNanoTime(); - if (currentTime - startTime >= waitTimeNanoSec) { + waitTimeNanoSec -= (currentTime - startTime); + startTime = currentTime; + if (waitTimeNanoSec <= 0) { ret = ReadNonBlocking(data, count); break; } - waitTimeNanoSec -= currentTime - startTime; } ret = syncer_->Wait(SharedMemQueueSyncer::SYNC_WORD_READ, waitTimeNanoSec); if (ret != 0 && ret != -ETIMEDOUT) { -- Gitee From 7b799b15662c0062b8729e666c2067355efac9c4 Mon Sep 17 00:00:00 2001 From: JanierVan Date: Tue, 10 Jan 2023 12:31:48 +0000 Subject: [PATCH 39/60] fixed 68a9216 from https://gitee.com/janiervan/drivers_hdf_core/pulls/1684 fix: hifi/codec watchdog notice fail Signed-off-by: JanierVan --- adapter/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index f2f0a3362..6efb02024 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -44,6 +44,8 @@ if (defined(ohos_lite)) { "//drivers/hdf_core/adapter/uhdf2/platform:libhdf_platform", "//drivers/hdf_core/adapter/uhdf2/utils:libhdf_utils", "//drivers/hdf_core/framework/tools/hdf_dbg:hdf_dbg", + "//drivers/peripheral/base:audio_hifi_watchdog.para", + "//drivers/peripheral/base:audio_hifi_watchdog.para.dac", "//drivers/peripheral/base:hdf_peripheral.cfg", ] -- Gitee From b66e7f852089c1b0521b25f6908cba51356fb71b Mon Sep 17 00:00:00 2001 From: BanYG Date: Fri, 20 Jan 2023 07:26:52 +0000 Subject: [PATCH 40/60] Ensure that the maximum page size is 4096 and the load section is aligned Signed-off-by: BanYG --- adapter/uhdf2/host/BUILD.gn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adapter/uhdf2/host/BUILD.gn b/adapter/uhdf2/host/BUILD.gn index 5232da34f..dba6af873 100644 --- a/adapter/uhdf2/host/BUILD.gn +++ b/adapter/uhdf2/host/BUILD.gn @@ -130,6 +130,12 @@ if (defined(ohos_lite)) { external_deps = [ "hilog:libhilog" ] } + # Ensure that the maximum page size is 4096 and the load section is aligned + ldflags = [ + "-Wl,-z,max-page-size=4096", + "-Wl,-z,separate-code", + ] + install_enable = true install_images = [ chipset_base_dir ] subsystem_name = "hdf" -- Gitee From bc30a4b7f4f14939270480a4641cdc7ad9c8e378 Mon Sep 17 00:00:00 2001 From: BanYG Date: Sun, 29 Jan 2023 02:39:52 +0000 Subject: [PATCH 41/60] The musl version uses this compilation option Signed-off-by: BanYG --- adapter/uhdf2/host/BUILD.gn | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/adapter/uhdf2/host/BUILD.gn b/adapter/uhdf2/host/BUILD.gn index dba6af873..f76894379 100644 --- a/adapter/uhdf2/host/BUILD.gn +++ b/adapter/uhdf2/host/BUILD.gn @@ -131,10 +131,12 @@ if (defined(ohos_lite)) { } # Ensure that the maximum page size is 4096 and the load section is aligned - ldflags = [ - "-Wl,-z,max-page-size=4096", - "-Wl,-z,separate-code", - ] + if (use_musl) { + ldflags = [ + "-Wl,-z,max-page-size=4096", + "-Wl,-z,separate-code", + ] + } install_enable = true install_images = [ chipset_base_dir ] -- Gitee From 5f9d3b04afe348c5d28eb55b2142a2d1c6b94403 Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Wed, 1 Feb 2023 17:00:08 +0800 Subject: [PATCH 42/60] fix:clear tools warning Signed-off-by: chenpan0560 --- .../command_line/driver_add/hdf_add_driver.py | 6 ++++-- .../tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py | 7 +++---- .../tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py | 6 ++++-- .../hdf_dev_eco_tool/command_line/hdf_liteos_scann.py | 6 ++++-- .../tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py | 4 ++-- framework/tools/hdi-gen/util/string_builder.cpp | 3 ++- framework/tools/hdi-gen/util/string_helper.cpp | 3 ++- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py index 69c9a4c24..68e8be43b 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/driver_add/hdf_add_driver.py @@ -386,6 +386,7 @@ class HdfAddDriver(object): return result_path_source, result_path_head def __get_enable_config(self): + device_enable_config = None templates_dir = hdf_utils.get_templates_lite_dir() templates_model_dir = [] for path, dir_name, _ in os.walk(templates_dir): @@ -418,9 +419,10 @@ class HdfAddDriver(object): else: device_enable_config = [ "LOSCFG_DRIVERS_HDF_SENSOR_ACCEL=y\n"] + if device_enable_config: + return device_enable_config[0] else: - device_enable_config = [""] - return device_enable_config[0] + return "" def get_model_template_list(self, module, board): templates_dir = hdf_utils.get_templates_lite_dir() diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index 2d213603b..6444f918e 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -166,8 +166,8 @@ class HdfAddHandler(HdfCommandHandlerBase): framework_hdf, adapter_model_path, data_model, *args_tuple) else: - file_path = {} - model_level_config = {} + file_path = "" + model_level_config = "" base_config = { 'module_name': module, 'module_path': file_path, @@ -391,6 +391,7 @@ class HdfAddHandler(HdfCommandHandlerBase): add_driver = HdfAddDriver(args=args_tuple) # create driver Source File (.c 、.h) state, file_list, head_list = add_driver.add_driver(*args_tuple) + file_path = [] if board == "hispark_taurus": file_path = add_driver.add_liteos(file_list, head_list) elif board.endswith("linux"): @@ -399,8 +400,6 @@ class HdfAddHandler(HdfCommandHandlerBase): file_path = add_driver.add_kernel(file_list, head_list) elif board.startswith("hispark_taurus_standard_kernel"): file_path = add_driver.add_kernel(file_list, head_list) - else: - file_path = [] config_item = { 'module_name': module, 'module_path': file_path, diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py index 14aad9ef0..fa764e63d 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py @@ -385,6 +385,8 @@ class HdfLinuxScan(object): re_split_list[-1].strip()]) def name_split_func(self, result, config_enable_lines): + enable_list_temp = [] + name_split_dict_temp = {} enable_list = [] name_split_dict = {} for enable_key, enable_value in result.items(): @@ -392,8 +394,8 @@ class HdfLinuxScan(object): if key in config_enable_lines: if isinstance(enable_value, dict): enable_list, name_split_dict = self.operate_dict( - enable_key, name_split_dict, enable_value, - config_enable_lines, enable_list) + enable_key, name_split_dict_temp, enable_value, + config_enable_lines, enable_list_temp) elif isinstance(enable_value, list): if enable_key.find("HDF") != -1: k2 = ''.join( diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py index a0cb59a86..70bb309dd 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py @@ -234,6 +234,8 @@ class HdfLiteScan(object): return replace_path def get_need_result(self, model_path_dict): + return_dict_temp = {} + need_replace_temp = {} return_dict = {} need_replace = {} import_gni_path = [] @@ -247,13 +249,13 @@ class HdfLiteScan(object): enable_path_dict, import_gni_path = \ self.get_need_result_only( model_path_dict, name, import_replace_name, - import_gni_path, return_dict, need_replace) + import_gni_path, return_dict_temp, need_replace_temp) else: need_replace, return_dict, \ enable_path_dict, import_gni_path = \ self.get_need_result_list( model_path_dict, name, import_replace_name, - import_gni_path, return_dict, need_replace) + import_gni_path, return_dict_temp, need_replace_temp) for k_name in list(return_dict.keys()): for model_detail in list(return_dict.get(k_name).keys()): diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py b/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py index 6369eaea9..270d62de4 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdi_add_handler.py @@ -495,8 +495,8 @@ class HdiAddHandler(HdfCommandHandlerBase): temp_replace_list = [] new_line = "" if not set(temp_replace_list) < set(temp_lines): - new_line = new_line.encode('utf-8') - temp_lines.append(new_line) + new_line_temp = new_line.encode('utf-8') + temp_lines.append(new_line_temp) self.writer_lines_binary(target_config_file_path, temp_lines) return target_config_file_path diff --git a/framework/tools/hdi-gen/util/string_builder.cpp b/framework/tools/hdi-gen/util/string_builder.cpp index bd14c7fd3..b72c62f1b 100644 --- a/framework/tools/hdi-gen/util/string_builder.cpp +++ b/framework/tools/hdi-gen/util/string_builder.cpp @@ -76,7 +76,8 @@ StringBuilder &StringBuilder::Append(const std::string &string) StringBuilder &StringBuilder::AppendFormat(const char *format, ...) { - va_list args, argsCopy; + va_list args; + va_list argsCopy; va_start(args, format); va_copy(argsCopy, args); diff --git a/framework/tools/hdi-gen/util/string_helper.cpp b/framework/tools/hdi-gen/util/string_helper.cpp index 00eefaa23..f0f688c04 100644 --- a/framework/tools/hdi-gen/util/string_helper.cpp +++ b/framework/tools/hdi-gen/util/string_helper.cpp @@ -154,7 +154,8 @@ std::string StringHelper::StrToUpper(const std::string &value) std::string StringHelper::Format(const char *format, ...) { - va_list args, argsCopy; + va_list args; + va_list argsCopy; va_start(args, format); va_copy(argsCopy, args); -- Gitee From f936aab8e8dc8f3bc5f0761b0dfaf7c8d4ef78a0 Mon Sep 17 00:00:00 2001 From: luo-wei246 Date: Wed, 1 Feb 2023 17:05:52 +0800 Subject: [PATCH 43/60] fixed 27a9155 from https://gitee.com/luo-wei246/drivers_framework/pulls/1716 fix USB alarm cleanup Signed-off-by: luo-wei246 --- adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c | 5 +++-- .../test/unittest/model/usb/device/src/hdf_usb_device_test.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c b/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c index 2d74f89e8..9cff365fb 100644 --- a/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c +++ b/adapter/khdf/liteos/model/usb/host/src/usb_pnp_notify.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -264,7 +264,8 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo infoTable->interfaceInfo[0].interfaceProtocol = infoData.infoData->interfaceProtocol; infoTable->interfaceInfo[0].interfaceNumber = infoData.infoData->interfaceNumber; } else { - uint8_t i, j; + uint8_t i; + uint8_t j; for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) { if (deviceInfo->interfaceRemoveStatus[i] == true) { HDF_LOGI("%s:%d j = %hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i); diff --git a/framework/test/unittest/model/usb/device/src/hdf_usb_device_test.c b/framework/test/unittest/model/usb/device/src/hdf_usb_device_test.c index a157110c8..cd8ad1b1e 100644 --- a/framework/test/unittest/model/usb/device/src/hdf_usb_device_test.c +++ b/framework/test/unittest/model/usb/device/src/hdf_usb_device_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -139,7 +139,8 @@ static HdfTestCaseList g_hdfUsbDeviceTestCaseList[] = { int32_t HdfUsbDeviceEntry(HdfTestMsg *msg) { - int32_t result, i; + int32_t result; + int32_t i; if (msg == NULL) { HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); -- Gitee From 813470a5626411d1e0e2f6f5026337dd28fc3078 Mon Sep 17 00:00:00 2001 From: zhangyu Date: Wed, 1 Feb 2023 15:51:19 +0800 Subject: [PATCH 44/60] fixed 41286ec from https://gitee.com/zyshg/drivers_hdf_core/pulls/1715 fix:Modify wlan codex Signed-off-by: zhangyu --- .../liteos_m/network/src/net_device_adapter.c | 6 +++-- .../model/network/ethernet/src/hdf_eth_core.c | 6 +++-- .../wifi/platform/src/hdf_wlan_utils.c | 5 ++-- .../wifi/platform/src/qos/flow_control.c | 8 +++--- .../wifi/unittest/net/hdf_netbuf_test.c | 25 +++++++++++-------- framework/test/unittest/wifi/hdf_wifi_test.c | 5 ++-- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/adapter/khdf/liteos_m/network/src/net_device_adapter.c b/adapter/khdf/liteos_m/network/src/net_device_adapter.c index 36ad810c0..2d3756b71 100644 --- a/adapter/khdf/liteos_m/network/src/net_device_adapter.c +++ b/adapter/khdf/liteos_m/network/src/net_device_adapter.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -256,7 +256,9 @@ static int32_t LiteNetDevAdd(struct NetDeviceImpl *netDeviceImpl) struct NetDeviceAdapterLite *liteNdPri = (struct NetDeviceAdapterLite *)netDeviceImpl->osPrivate; struct NetDevice *lwipNd = netDeviceImpl->netDevice; struct netif *lwipNf = NULL; - ip4_addr_t gw, ipaddr, netmask; + ip4_addr_t gw; + ip4_addr_t ipaddr; + ip4_addr_t netmask; IP4_ADDR(&gw, 0, 0, 0, 0); IP4_ADDR(&ipaddr, 0, 0, 0, 0); IP4_ADDR(&netmask, 0, 0, 0, 0); diff --git a/framework/model/network/ethernet/src/hdf_eth_core.c b/framework/model/network/ethernet/src/hdf_eth_core.c index cd026d2da..a7927dcac 100644 --- a/framework/model/network/ethernet/src/hdf_eth_core.c +++ b/framework/model/network/ethernet/src/hdf_eth_core.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -52,7 +52,9 @@ static int32_t DeinitEth(struct EthDevice *ethDevice) #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) static int32_t SetEthNetworkAddr(struct NetDevice *netDev) { - IpV4Addr ip, netmask, gw; + IpV4Addr ip; + IpV4Addr netmask; + IpV4Addr gw; ip.addr = 0x0A01a8c0UL; /* 192, 168, 1. 10 */ netmask.addr = 0x00ffffffUL; /* 255, 255, 255, 0 */ diff --git a/framework/model/network/wifi/platform/src/hdf_wlan_utils.c b/framework/model/network/wifi/platform/src/hdf_wlan_utils.c index fcac4d7a5..d2d956aa9 100644 --- a/framework/model/network/wifi/platform/src/hdf_wlan_utils.c +++ b/framework/model/network/wifi/platform/src/hdf_wlan_utils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -231,7 +231,8 @@ char *HdfWlanGetIfNames(const uint8_t chipId, uint8_t *ifNameCount) uint32_t netIfMapTemp; char *ifNames = NULL; uint32_t bufferSize; - uint8_t i, j; + uint8_t i; + uint8_t j; int32_t ret; if (ifNameCount == NULL) { HDF_LOGE("%s: para is NULL", __func__); diff --git a/framework/model/network/wifi/platform/src/qos/flow_control.c b/framework/model/network/wifi/platform/src/qos/flow_control.c index 4eb59b47b..b0e06377c 100644 --- a/framework/model/network/wifi/platform/src/qos/flow_control.c +++ b/framework/model/network/wifi/platform/src/qos/flow_control.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2022 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -136,7 +136,8 @@ static FlowControlQueueID IpProcessFunc(const void *buff, uint32_t len) static void FlowControlQueueInit(struct FlowControlModule *fcm) { - int32_t i, j; + int32_t i; + int32_t j; if (fcm == NULL) { HDF_LOGE("%s fail: fcm = null!", __func__); return; @@ -151,7 +152,8 @@ static void FlowControlQueueInit(struct FlowControlModule *fcm) static void FlowControlQueueDeinit(struct FlowControlModule *fcm) { - int32_t i, j; + int32_t i; + int32_t j; if (fcm == NULL) { HDF_LOGE("%s fcm already free!", __func__); return; diff --git a/framework/test/unittest/model/network/wifi/unittest/net/hdf_netbuf_test.c b/framework/test/unittest/model/network/wifi/unittest/net/hdf_netbuf_test.c index 2676bc890..28c99dd0a 100644 --- a/framework/test/unittest/model/network/wifi/unittest/net/hdf_netbuf_test.c +++ b/framework/test/unittest/model/network/wifi/unittest/net/hdf_netbuf_test.c @@ -1,10 +1,10 @@ -/* - * Copyright (c) 2020-2022 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ +/* + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ #include "hdf_netbuf.h" #include "hdf_log.h" @@ -17,7 +17,7 @@ #define DEFAULT_MAPPING_QUEUE 10 #define DEFAULT_TRIM_SIZE 3 #define DEFAULT_SECTION_SIZE 10 - + #define MAX_MEM_ALLOC_SIZE 0x7fffffff typedef int32_t (*pTestCaseFunc)(void); @@ -360,7 +360,8 @@ static int32_t HdfNetBufTest010(void) */ static int32_t HdfNetBufTest011(void) { - uint32_t ret, dstDataLen; + uint32_t ret; + uint32_t dstDataLen; NetBuf *dst = NetBufAlloc(DEFAULT_NETBUF_SIZE); NetBuf *src = NetBufAlloc(DEFAULT_NETBUF_SIZE); if (dst == NULL || src == NULL) { @@ -863,7 +864,8 @@ pTestCaseFunc g_hdfNetBufQueueTestCaseLists[] = { // HDFNetBuf test case Entry int32_t HdfNetBufTest(void) { - int32_t ret, i; + int32_t ret; + int32_t i; for (i = 0; i < sizeof(g_hdfNetBufTestCaseLists) / sizeof(g_hdfNetBufTestCaseLists[0]); ++i) { if (g_hdfNetBufTestCaseLists[i] != NULL) { @@ -882,7 +884,8 @@ int32_t HdfNetBufTest(void) // HdfNetBufQueue test case Entry int32_t HdfNetBufQueueTest(void) { - int32_t ret, i; + int32_t ret; + int32_t i; for (i = 0; i < sizeof(g_hdfNetBufQueueTestCaseLists) / sizeof(g_hdfNetBufQueueTestCaseLists[0]); ++i) { if (g_hdfNetBufQueueTestCaseLists[i] != NULL) { diff --git a/framework/test/unittest/wifi/hdf_wifi_test.c b/framework/test/unittest/wifi/hdf_wifi_test.c index 4132c8fa9..6d975c2ec 100644 --- a/framework/test/unittest/wifi/hdf_wifi_test.c +++ b/framework/test/unittest/wifi/hdf_wifi_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -52,7 +52,8 @@ static HdfTestCaseList g_hdfWiFiTestCaseList[] = { int32_t HdfWifiEntry(HdfTestMsg *msg) { - int32_t result, i; + int32_t result; + int32_t i; if (msg == NULL) { HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); -- Gitee From 781706c48dcdaf6580779a2bf15ced8c691dfecc Mon Sep 17 00:00:00 2001 From: chenhaifan Date: Thu, 2 Feb 2023 14:24:35 +0800 Subject: [PATCH 45/60] fixed bc4d9fa from https://gitee.com/chengmai_1_0/drivers_hdf_core/pulls/1726 fix:Write only one sentence per line Signed-off-by: chenhaifan --- framework/model/audio/common/src/audio_codec_base.c | 5 +++-- framework/test/unittest/model/audio/src/hdf_audio_test.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/model/audio/common/src/audio_codec_base.c b/framework/model/audio/common/src/audio_codec_base.c index 234df6b38..3267e2cb4 100644 --- a/framework/model/audio/common/src/audio_codec_base.c +++ b/framework/model/audio/common/src/audio_codec_base.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -313,7 +313,8 @@ static int32_t CodecSetSapmConfigInfo(struct CodecData *codeData, struct AudioRe static int32_t CodecSetKcontrolInfo(struct CodecData *codeData, struct AudioRegCfgGroupNode **regCfgGroup) { - uint16_t index, enumIndex = 0; + uint16_t index = 0; + uint16_t enumIndex = 0; struct AudioControlConfig *compItem = NULL; struct AudioMixerControl *ctlRegCfgItem = NULL; struct AudioEnumCtrlConfig *enumCtlRegCfgItem = NULL; diff --git a/framework/test/unittest/model/audio/src/hdf_audio_test.c b/framework/test/unittest/model/audio/src/hdf_audio_test.c index 9c9a83635..048391234 100644 --- a/framework/test/unittest/model/audio/src/hdf_audio_test.c +++ b/framework/test/unittest/model/audio/src/hdf_audio_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -114,7 +114,8 @@ static HdfTestCaseList g_hdfAudioTestCaseList[] = { int32_t HdfAudioEntry(HdfTestMsg *msg) { - int32_t result, i; + int32_t result = 0; + int32_t i = 0; if (msg == NULL) { HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); -- Gitee From e9dea49f67e98f74805aabb28796f32bf4a6e0d6 Mon Sep 17 00:00:00 2001 From: zhusiyuan Date: Wed, 1 Feb 2023 17:38:08 +0800 Subject: [PATCH 46/60] fixed 209581f from https://gitee.com/zhusiyuan2/drivers_hdf_core/pulls/1719 Fix: Clean input codecheck alarm (one line should have only one statement) Signed-off-by: zhusiyuan --- .../input/driver/touchscreen/touch_ft5x06.c | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/framework/model/input/driver/touchscreen/touch_ft5x06.c b/framework/model/input/driver/touchscreen/touch_ft5x06.c index 82610a044..c5c5df029 100644 --- a/framework/model/input/driver/touchscreen/touch_ft5x06.c +++ b/framework/model/input/driver/touchscreen/touch_ft5x06.c @@ -196,36 +196,49 @@ static void SetAbility(ChipDevice *device) device->driver->inputDev->attrSet.axisInfo[ABS_MT_TRACKING_ID].max = MAX_POINT; } -static int32_t ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, uint8_t pointNum, int32_t version) +static int32_t SelectDataPin(int32_t version, int32_t *offset, int32_t *tpLen, int32_t *crcLen) { - int32_t i = NUM_0, x = NUM_0, y = NUM_0; - int32_t offset = NUM_0, tplen = NUM_0, crclen = NUM_0, type = NUM_0; switch (version) { case EDT_M06: - offset = NUM_5; /* where the actual touch data starts */ - tplen = NUM_4; /* data comes in so called frames */ - crclen = NUM_1; /* length of the crc data */ - break; + *offset = NUM_5; /* where the actual touch data starts */ + *tpLen = NUM_4; /* data comes in so called frames */ + *crcLen = NUM_1; /* length of the crc data */ + return HDF_SUCCESS; case EDT_M09: case EDT_M12: case EV_FT: case GENERIC_FT: - offset = NUM_3; - tplen = NUM_6; - crclen = NUM_0; - break; + *offset = NUM_3; + *tpLen = NUM_6; + *crcLen = NUM_0; + return HDF_SUCCESS; default: return HDF_FAILURE; } +} + +static int32_t ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf, uint8_t pointNum, int32_t version) +{ + int32_t i = 0; + int32_t x = 0; + int32_t y = 0; + int32_t offset = 0; + int32_t tpLen = 0; + int32_t crcLen = 0; + int32_t type = 0; + + if (SelectDataPin(version, &offset, &tpLen, &crcLen) != HDF_SUCCESS) { + HDF_LOGE("%s: SelectDataPin version %d not support", __func__, version); + return HDF_FAILURE; + } - for (i = NUM_0; i < pointNum; i++) { - u8 *rdbuf = &buf[i * tplen + offset]; + for (i = 0; i < pointNum; i++) { + u8 *rdbuf = &buf[i * tpLen + offset]; type = rdbuf[NUM_0] >> NUM_6; /* ignore Reserved events */ if (type == TOUCH_EVENT_RESERVED) { return HDF_FAILURE; - continue; } /* M06 sometimes sends bogus coordinates in TOUCH_DOWN */ if (version == EDT_M06 && type == TOUCH_EVENT_DOWN) { @@ -250,7 +263,7 @@ static int32_t ParsePointData(ChipDevice *device, FrameData *frame, uint8_t *buf frame->definedEvent = frame->fingers[i].status; if ((frame->fingers[i].status == TOUCH_DOWN || frame->fingers[i].status == TOUCH_CONTACT) - && (pointNum == NUM_0)) { + && (pointNum == 0)) { return HDF_FAILURE; } } -- Gitee From 827c3a8fa0ead625b5bbafb465cf8098f5211cf2 Mon Sep 17 00:00:00 2001 From: jiaziyangnewer Date: Thu, 2 Feb 2023 10:42:39 +0800 Subject: [PATCH 47/60] fix:clear platform drivers tool scan problems Signed-off-by: jiaziyangnewer --- .../khdf/linux/model/storage/sdio_adapter.c | 5 +- .../khdf/linux/platform/gpio/gpio_adapter.c | 5 +- .../linux/platform/mipi_dsi/mipi_tx_hi35xx.c | 8 +- adapter/platform/i2c/i2c_wm.c | 6 +- .../model/storage/src/mmc/mmc_protocol.c | 53 ++++-- .../support/platform/src/hdmi/hdmi_cec.c | 18 +- .../support/platform/src/hdmi/hdmi_common.c | 20 ++- .../support/platform/src/hdmi/hdmi_dfm.c | 5 +- .../support/platform/src/hdmi/hdmi_dispatch.c | 5 +- .../support/platform/src/hdmi/hdmi_edid.c | 21 ++- .../support/platform/src/hdmi/hdmi_hdcp.c | 8 +- .../platform/src/hdmi/hdmi_infoframe.c | 5 +- .../support/platform/src/hdmi/hdmi_scdc.c | 5 +- framework/support/platform/src/i3c/i3c_core.c | 5 +- .../support/platform/src/pcie/pcie_dispatch.c | 8 +- .../test/unittest/platform/common/adc_test.c | 87 +++++---- .../test/unittest/platform/common/dac_test.c | 75 ++++---- .../test/unittest/platform/common/emmc_test.c | 5 +- .../test/unittest/platform/common/i2c_test.c | 84 +++++---- .../test/unittest/platform/common/i3c_test.c | 35 ++-- .../platform/common/platform_dumper_test.c | 75 ++++---- .../unittest/platform/common/regulator_test.c | 76 ++++---- .../unittest/platform/common/timer_test.c | 170 +++++++++++------- 23 files changed, 472 insertions(+), 312 deletions(-) diff --git a/adapter/khdf/linux/model/storage/sdio_adapter.c b/adapter/khdf/linux/model/storage/sdio_adapter.c index cf84a871a..dcd63a4f8 100644 --- a/adapter/khdf/linux/model/storage/sdio_adapter.c +++ b/adapter/khdf/linux/model/storage/sdio_adapter.c @@ -3,7 +3,7 @@ * * linux sdio driver implement. * - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -367,7 +367,8 @@ static struct sdio_func *LinuxSdioSearchFunc(uint32_t funcNum, uint16_t vendorId struct mmc_card *card = NULL; struct mmc_host *host = NULL; struct sdio_func *func = NULL; - uint32_t i, j; + uint32_t i; + uint32_t j; for (i = 0; i < MMC_SLOT_NUM; i++) { host = GetMmcHost(i); diff --git a/adapter/khdf/linux/platform/gpio/gpio_adapter.c b/adapter/khdf/linux/platform/gpio/gpio_adapter.c index ff1442c08..3754dfb8d 100644 --- a/adapter/khdf/linux/platform/gpio/gpio_adapter.c +++ b/adapter/khdf/linux/platform/gpio/gpio_adapter.c @@ -3,7 +3,7 @@ * * gpio driver adapter of linux * - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -123,7 +123,8 @@ static irqreturn_t LinuxGpioIrqBridge(int irq, void *data) static int32_t LinuxGpioSetIrq(struct GpioCntlr *cntlr, uint16_t local, uint16_t mode) { - int ret, irq; + int ret; + int irq; unsigned long flags = 0; uint16_t gpio; diff --git a/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c b/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c index e2f587960..566e02cb9 100644 --- a/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c +++ b/adapter/khdf/linux/platform/mipi_dsi/mipi_tx_hi35xx.c @@ -3,7 +3,7 @@ * * hi35xx mipi_tx driver implement * - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -664,7 +664,8 @@ static void MipiTxDrvSetPayloadData(const unsigned char *cmd, unsigned short cmd { int32_t ret; U_GEN_PLD_DATA genPldData; - int i, j; + int i; + int j; genPldData.u32 = g_mipiTxRegsVa->GEN_PLD_DATA.u32; @@ -846,7 +847,8 @@ static int MipiTxSendShortPacket(unsigned char virtualChannel, static int MipiTxGetReadFifoData(unsigned int getDataSize, unsigned char *dataBuf) { U_GEN_PLD_DATA pldData; - unsigned int i, j; + unsigned int i; + unsigned int j; for (i = 0; i < getDataSize / 4; i++) { /* 4byte once */ if (MipiTxWaitReadFifoNotEmpty() != HDF_SUCCESS) { diff --git a/adapter/platform/i2c/i2c_wm.c b/adapter/platform/i2c/i2c_wm.c index a51a87b47..fb4e03908 100755 --- a/adapter/platform/i2c/i2c_wm.c +++ b/adapter/platform/i2c/i2c_wm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Jiangsu Hoperun Software Co., Ltd. + * Copyright (c) 2022-2023 Jiangsu Hoperun Software Co., Ltd. * * This file is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -271,7 +271,9 @@ static void i2cDriverRelease(struct HdfDeviceObject *device) static int32_t i2c_send(struct I2cMsg *msg) { uint16_t len; - uint8_t ifack, ifstop, ifstart; + uint8_t ifack; + uint8_t ifstop; + uint8_t ifstart; len = msg->len; ifstop = 0; diff --git a/framework/model/storage/src/mmc/mmc_protocol.c b/framework/model/storage/src/mmc/mmc_protocol.c index 833289e61..77a4fb82c 100644 --- a/framework/model/storage/src/mmc/mmc_protocol.c +++ b/framework/model/storage/src/mmc/mmc_protocol.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -678,7 +678,8 @@ int32_t MmcSendReadWriteBlocks(struct MmcCntlr *cntlr, struct MmcRwData *info) static int32_t EmmcDecodeCsd(struct MmcCntlr *cntlr) { struct MmcCsd *csd = NULL; - uint32_t unit, factor; + uint32_t unit; + uint32_t factor; uint32_t *rawCsd = NULL; if (cntlr == NULL || cntlr->curDev == NULL) { @@ -751,7 +752,8 @@ static int32_t EmmcDecodeCid(struct MmcCntlr *cntlr) uint32_t i; struct MmcCid *cid = NULL; uint32_t *rawCid = NULL; - uint8_t specVers, cbx; + uint8_t specVers; + uint8_t cbx; if (cntlr == NULL || cntlr->curDev == NULL) { return HDF_ERR_INVALID_PARAM; @@ -1231,7 +1233,9 @@ static int32_t EmmcSelectHs200(struct MmcCntlr *cntlr, struct EmmcDevice *emmcDe static uint32_t EmmcGetPowerClassValue(struct MmcCntlr *cntlr, struct EmmcExtCsd *extCsd) { uint32_t val = 0; - uint32_t vdd, busWidthBit, clock; + uint32_t vdd; + uint32_t busWidthBit; + uint32_t clock; busWidthBit = (cntlr->curDev->workPara.width == BUS_WIDTH8) ? EMMC_EXT_CSD_BUS_WIDTH_8 : EMMC_EXT_CSD_BUS_WIDTH_4; @@ -1415,7 +1419,8 @@ static int32_t EmmcSelectSwitchDdrMode(struct MmcCntlr *cntlr, struct EmmcDevice struct EmmcExtCsd *extCsd) { int32_t error; - uint32_t index, ddrMode; + uint32_t index; + uint32_t ddrMode; enum MmcBusWidth width; const enum MmcBusWidth busWidths[] = { BUS_WIDTH8, BUS_WIDTH4, BUS_WIDTH1 }; uint32_t busWidthBit[][2] = { @@ -1948,7 +1953,8 @@ static int32_t SdDecodeSSr(struct MmcCntlr *cntlr, uint32_t *rawSsr, uint32_t le struct SdSsr *ssr = NULL; struct SdScr *scr = NULL; struct SdDevice *sdDev = NULL; - uint32_t eraseSize, eraseTimeout; + uint32_t eraseSize; + uint32_t eraseTimeout; if (cntlr == NULL || cntlr->curDev == NULL || rawSsr == NULL || len == 0) { return HDF_ERR_INVALID_PARAM; @@ -2029,7 +2035,8 @@ static void SdDecodeCid(struct MmcCntlr *cntlr) static void SdSetBlockCapacity(struct MmcCntlr *cntlr) { struct SdDevice *sdDev = (struct SdDevice *)cntlr->curDev; - uint32_t gibVal, mibVal; + uint32_t gibVal; + uint32_t mibVal; sdDev->mmc.eraseSize = sdDev->mmc.reg.csd.eraseSize; sdDev->mmc.capacity = sdDev->mmc.reg.csd.capacity << @@ -2042,7 +2049,8 @@ static void SdSetBlockCapacity(struct MmcCntlr *cntlr) static void SdDecodeCsdRev1Field(struct MmcCntlr *cntlr, struct MmcCsd *csd, uint32_t *rawCsd) { - uint32_t unit, factor; + uint32_t unit; + uint32_t factor; /* TAAC: [119:112]; TAAC bit position-->Time unit: [2:0], Multiplier factor: [6:3]. */ factor = MmcParseBits(rawCsd, CSD_BITS, 115, 4); @@ -2096,7 +2104,8 @@ static void SdDecodeCsdRev1Field(struct MmcCntlr *cntlr, struct MmcCsd *csd, uin static void SdDecodeCsdRev2Field(struct MmcCntlr *cntlr, struct MmcCsd *csd, uint32_t *rawCsd) { - uint32_t unit, factor; + uint32_t unit; + uint32_t factor; cntlr->curDev->state.bits.blockAddr = 1; /* TRAN_SPEED: [103:96]; TRAN_SPEED bit-->Frequency unit: [2:0], Multiplier factor: [6:3]. */ @@ -2915,7 +2924,8 @@ int32_t SdioReadWriteByte(struct MmcCntlr *cntlr, bool writeFlag, static int32_t SdioReadWriteRemainBytes(struct MmcCntlr *cntlr, struct SdioCmdParam *param, uint8_t *data, uint32_t size, uint32_t addr) { - uint32_t maxBlkSize, curSize; + uint32_t maxBlkSize; + uint32_t curSize; struct SdioDevice *dev = (struct SdioDevice *)cntlr->curDev; uint32_t remLen = size; uint32_t curAddr = addr; @@ -2961,11 +2971,12 @@ static void SdioFillRwExtendedCmdParam(struct SdioCmdParam *param, int32_t SdioReadWriteBlock(struct MmcCntlr *cntlr, struct SdioRwBlockInfo *info) { - uint32_t maxBlkNum, maxBlkSize, curblkNum, curSize, curAddr, remLen; + uint32_t maxBlkNum; + uint32_t curblkNum; + uint32_t curSize; int32_t err; struct SdioCmdParam param = {0}; struct SdioDevice *dev = NULL; - uint8_t *buffer = NULL; if (cntlr == NULL || info == NULL) { return HDF_ERR_INVALID_PARAM; @@ -2975,7 +2986,7 @@ int32_t SdioReadWriteBlock(struct MmcCntlr *cntlr, struct SdioRwBlockInfo *info) return HDF_ERR_INVALID_OBJECT; } - maxBlkSize = MMC_MIN(cntlr->maxBlkSize, dev->curFunction->maxBlkSize); + uint32_t maxBlkSize = MMC_MIN(cntlr->maxBlkSize, dev->curFunction->maxBlkSize); maxBlkSize = MMC_MIN(maxBlkSize, BYTES_PER_BLOCK); if (maxBlkSize == 0) { return HDF_ERR_INVALID_PARAM; @@ -2984,9 +2995,9 @@ int32_t SdioReadWriteBlock(struct MmcCntlr *cntlr, struct SdioRwBlockInfo *info) return HDF_ERR_INVALID_PARAM; } - remLen = info->size; - curAddr = info->addr; - buffer = info->buf; + uint32_t remLen = info->size; + uint32_t curAddr = info->addr; + uint8_t *buffer = info->buf; SdioFillRwExtendedCmdParam(¶m, dev, info); if (info->scatterFlag == true) { return SdioRwExtended(cntlr, ¶m, buffer, MMC_MAX(1, remLen / maxBlkSize), MMC_MIN(remLen, maxBlkSize)); @@ -3490,7 +3501,8 @@ static int32_t SdioReadCisTplField(struct MmcCntlr *cntlr, uint32_t addr, uint8_ static void SdioDecodeCisTplManfId(struct MmcCntlr *cntlr, struct SdioFunction *function, struct SdioCisTuple *tuple) { - uint16_t vendorId, deviceId; + uint16_t vendorId; + uint16_t deviceId; struct SdioDevice *dev = NULL; if (tuple->tplLink < SDIO_CIS_TPL_MANFID_MIN_SIZE) { @@ -3644,7 +3656,8 @@ static int32_t SdioFillTplInfo(struct MmcCntlr *cntlr, struct SdioCisTuple *tupl static int32_t SdioDecodeCis(struct MmcCntlr *cntlr, struct SdioFunction *function, uint32_t cisStartAddr) { int32_t ret = HDF_SUCCESS; - uint8_t tplCode, tplLink; + uint8_t tplCode; + uint8_t tplLink; struct SdioCisTuple *tuple = NULL; uint32_t addr = cisStartAddr; @@ -3695,7 +3708,9 @@ static int32_t SdioDecodeCis(struct MmcCntlr *cntlr, struct SdioFunction *functi static int32_t SdioReadCis(struct MmcCntlr *cntlr, struct SdioFunction *function) { - uint32_t funcNum, i, cisStartAddr; + uint32_t funcNum; + uint32_t i; + uint32_t cisStartAddr; uint8_t data; int32_t ret; struct SdioCmdParam param = {0}; diff --git a/framework/support/platform/src/hdmi/hdmi_cec.c b/framework/support/platform/src/hdmi/hdmi_cec.c index 33f5742a6..fcc83b766 100644 --- a/framework/support/platform/src/hdmi/hdmi_cec.c +++ b/framework/support/platform/src/hdmi/hdmi_cec.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -134,7 +134,8 @@ struct HdmiCecMsgLenInfo g_cecMsg[] = { static struct HdmiCecMsgLenInfo *HdmiCecGetMsgLenInfo(uint8_t opcode) { - uint32_t i, len; + uint32_t i; + uint32_t len; len = sizeof(g_cecMsg) / sizeof(g_cecMsg[0]); for (i = 0; i < len; i++) { @@ -1096,7 +1097,8 @@ void HdmiCecEncodingReportAudioStatusMsg(struct HdmiCecMsg *msg, uint8_t audioMu void HdmiCecEncodingRequestShortAudioDescriptorMsg(struct HdmiCecMsg *msg, const uint8_t *id, const uint8_t *code, uint32_t len, bool response) { - uint32_t num, i; + uint32_t num; + uint32_t i; if (id == NULL || code == NULL || len == 0) { HDF_LOGE("encoding request short audio descriptor, input param invalid."); @@ -1116,7 +1118,8 @@ void HdmiCecEncodingRequestShortAudioDescriptorMsg(struct HdmiCecMsg *msg, void HdmiCecEncodingReportShortAudioDescriptorMsg(struct HdmiCecMsg *msg, const uint32_t *descriptor, uint32_t len) { - uint32_t num, i; + uint32_t num; + uint32_t i; if (descriptor == NULL || len == 0) { HDF_LOGE("encoding report short audio descriptor, input param invalid."); @@ -1620,7 +1623,8 @@ static void HdmiCecMsgDefaultHandle(struct HdmiCntlr *cntlr, static void HdmiCecMsgHandle(struct HdmiCntlr *cntlr, struct HdmiCecMsg *msg, struct HdmiCecMsg *txMsg, uint8_t opcode) { - uint32_t i, len; + uint32_t i; + uint32_t len; struct HdmiCecHandleMsgFuncMap funcMap[] = { { HDMI_CEC_OPCODE_GET_CEC_VERSION, HdmiCecHandleGetCecVersionMsg }, @@ -1673,7 +1677,9 @@ static void HdmiCecReceivedMsgHandle(struct HdmiCntlr *cntlr, struct HdmiCecMsg int32_t HdmiCecReceivedMsg(struct HdmiCec *cec, struct HdmiCecMsg *msg) { struct HdmiCntlr *cntlr = NULL; - uint8_t opcode, initiator, destination; + uint8_t opcode; + uint8_t initiator; + uint8_t destination; if (cec == NULL || cec->priv == NULL || msg == NULL) { HDF_LOGE("cec receive msg, input param invalid."); diff --git a/framework/support/platform/src/hdmi/hdmi_common.c b/framework/support/platform/src/hdmi/hdmi_common.c index 2cfac6c80..d53116c0d 100644 --- a/framework/support/platform/src/hdmi/hdmi_common.c +++ b/framework/support/platform/src/hdmi/hdmi_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -237,7 +237,8 @@ enum HdmiDeepColor HdmiCommonColorDepthConvertToDeepClolor(enum HdmiVideoBitDept enum HdmiVic HdmiCommonGetVic(enum HdmiVideoTiming timing, enum HdmiPictureAspectRatio aspect, bool enable3d) { - uint32_t i, len; + uint32_t i; + uint32_t len; enum HdmiVic vic = 0; len = sizeof(g_ceaVideoDefInfoMap) / sizeof(g_ceaVideoDefInfoMap[0]); @@ -261,7 +262,8 @@ enum HdmiVic HdmiCommonGetVic(enum HdmiVideoTiming timing, static struct HdmiVideoDefInfo *HdmiCommonGetCommFormatInfo(enum HdmiVic vic) { - uint32_t i, len; + uint32_t i; + uint32_t len; len = sizeof(g_ceaVideoDefInfoMap) / sizeof(g_ceaVideoDefInfoMap[0]); for (i = 0; i < len; i++) { @@ -274,7 +276,8 @@ static struct HdmiVideoDefInfo *HdmiCommonGetCommFormatInfo(enum HdmiVic vic) static struct HdmiVideoDefInfo *HdmiCommonGetVesaFormatInfo(enum HdmiVideoTiming timing) { - uint32_t i, len; + uint32_t i; + uint32_t len; len = sizeof(g_vesaVideoDefInfoMap) / sizeof(g_vesaVideoDefInfoMap[0]); for (i = 0; i < len; i++) { @@ -302,7 +305,8 @@ struct HdmiVideoDefInfo *HdmiCommonGetVideoDefInfo(enum HdmiVideoTiming timing, enum HdmiVideoTiming HdmiCommonGetVideoTiming(enum HdmiVic vic, enum HdmiPictureAspectRatio aspect) { - uint32_t i, len; + uint32_t i; + uint32_t len; enum HdmiVideoTiming timing = HDMI_VIDEO_TIMING_NONE; len = sizeof(g_ceaVideoDefInfoMap) / sizeof(g_ceaVideoDefInfoMap[0]); @@ -317,7 +321,8 @@ enum HdmiVideoTiming HdmiCommonGetVideoTiming(enum HdmiVic vic, enum HdmiPicture struct HdmiVideo4kInfo *HdmiCommonGetVideo4kInfo(uint32_t _4kVic) { - uint32_t i, len; + uint32_t i; + uint32_t len; len = sizeof(g_video4kInfoMap) / sizeof(g_video4kInfoMap[0]); for (i = 0; i < len; i++) { @@ -331,7 +336,8 @@ struct HdmiVideo4kInfo *HdmiCommonGetVideo4kInfo(uint32_t _4kVic) enum HdmiVideoTiming HdmiCommonGetVideo4kTiming(uint32_t _4kVic) { - uint32_t i, len; + uint32_t i; + uint32_t len; enum HdmiVideoTiming timing = HDMI_VIDEO_TIMING_NONE; len = sizeof(g_video4kInfoMap) / sizeof(g_video4kInfoMap[0]); diff --git a/framework/support/platform/src/hdmi/hdmi_dfm.c b/framework/support/platform/src/hdmi/hdmi_dfm.c index 937d85841..981ddc8e2 100644 --- a/framework/support/platform/src/hdmi/hdmi_dfm.c +++ b/framework/support/platform/src/hdmi/hdmi_dfm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -179,7 +179,8 @@ static void HdmiDfmCaculateVideoBorrowInfo(struct HdmiDfmInfo *info) static void HdmiDfmCaculateVideoInfo(struct HdmiDfmInfo *info, const struct HdmiDfmParam *param) { - uint32_t kcd, k420; + uint32_t kcd; + uint32_t k420; /* * 1. if 4:2:2 pixels, kcd is 1. Otherwise, kcd is CD / 8. diff --git a/framework/support/platform/src/hdmi/hdmi_dispatch.c b/framework/support/platform/src/hdmi/hdmi_dispatch.c index 690f04ab6..6d90c635e 100644 --- a/framework/support/platform/src/hdmi/hdmi_dispatch.c +++ b/framework/support/platform/src/hdmi/hdmi_dispatch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -249,7 +249,8 @@ static int32_t HdmiCmdUnregisterHpdCallbackFunc(struct HdmiCntlr *cntlr, struct int32_t HdmiIoDispatch(struct HdfDeviceIoClient *client, int32_t cmd, struct HdfSBuf *data, struct HdfSBuf *reply) { struct HdmiCntlr *cntlr = NULL; - uint32_t i, len; + uint32_t i; + uint32_t len; struct HdmiDispatchFunc dispatchFunc[] = { { HDMI_CMD_OPEN, HdmiCmdOpen }, { HDMI_CMD_CLOSE, HdmiCmdClose }, diff --git a/framework/support/platform/src/hdmi/hdmi_edid.c b/framework/support/platform/src/hdmi/hdmi_edid.c index 5d33bbf17..e3d56d3e7 100644 --- a/framework/support/platform/src/hdmi/hdmi_edid.c +++ b/framework/support/platform/src/hdmi/hdmi_edid.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -82,7 +82,9 @@ static int32_t HdmiEdidBlockCheckSum(uint8_t *data) static int32_t HdmiEdidVendorInfoPhase(struct HdmiEdid *edid) { - uint16_t data, i, tmpData; + uint16_t data; + uint16_t i; + uint16_t tmpData; struct HdmiSinkDeviceCapability *sinkCap = &(edid->sinkCap); struct HdmiEdidFirstBlockInfo *block = (struct HdmiEdidFirstBlockInfo *)edid->raw; @@ -221,7 +223,8 @@ static uint32_t HdmiEdidGetStandardTimingVertPixel(uint32_t aspectRatio, uint32_ static int32_t HdmiEdidStandardTimingPhase(struct HdmiEdid *edid) { - uint32_t i, aspectRatio; + uint32_t i; + uint32_t aspectRatio; struct HdmiSinkDeviceCapability *sinkCap = &(edid->sinkCap); struct HdmiEdidFirstBlockInfo *block = (struct HdmiEdidFirstBlockInfo *)edid->raw; uint8_t *data = block->stdTiming; @@ -506,7 +509,8 @@ static void HdmiEdidExtAdbDepthAndMaxRatePhase(struct HdmiEdidAudioInfo *audio, static int32_t HdmiEdidExtAudioDataBlockPhase(struct HdmiSinkDeviceCapability *sinkCap, uint8_t *data, uint8_t len) { - uint8_t i, formatCode; + uint8_t i; + uint8_t formatCode; /* * Each Short Audio Descriptor is 3-bytes long. There can be up to 31 bytes following any tag, @@ -546,7 +550,8 @@ static int32_t HdmiEdidExtVideoDataBlockPhase(struct HdmiSinkDeviceCapability *s uint8_t len) { uint8_t i; - uint32_t vicAll, vicLower; + uint32_t vicAll; + uint32_t vicLower; uint32_t implicitNative = 0; for (i = 0; i < len; i++) { @@ -660,7 +665,8 @@ static void HdmiEdidVsdbSinkLatencyPhase(struct HdmiSinkDeviceCapability *sinkCa static void HdmiEdidVsdbVicInfoPhase(struct HdmiSinkDeviceCapability *sinkCap, const uint8_t *data, uint8_t vicLen, uint8_t *offset) { - uint8_t i, index; + uint8_t i; + uint8_t index; /* see hdmi spec 1.4 table 8-13. */ uint32_t hdmi4kVic[] = { 0, @@ -967,7 +973,8 @@ static void HdmiEdidExtUseExtDataBlockY420VdbPhase(struct HdmiSinkDeviceCapabili static void HdmiEdidExtUseExtDataBlockY420CmdbPhase(struct HdmiSinkDeviceCapability *sinkCap, uint8_t *data, uint8_t len) { - uint32_t i, loop; + uint32_t i; + uint32_t loop; /* * When the Length field is set to 1, the Y420CMDB does not include a YCBCR 4:2:0 Capability Bit Map and diff --git a/framework/support/platform/src/hdmi/hdmi_hdcp.c b/framework/support/platform/src/hdmi/hdmi_hdcp.c index 41ad2035e..087483093 100644 --- a/framework/support/platform/src/hdmi/hdmi_hdcp.c +++ b/framework/support/platform/src/hdmi/hdmi_hdcp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -53,7 +53,8 @@ static int32_t HdmiHdcpWrite(struct HdmiHdcp *hdcp, enum HdmiHdcpPortOffset offs static bool HdmiHdcpCheckKvs(const uint8_t *ksv, uint32_t len) { - uint32_t i, j; + uint32_t i; + uint32_t j; uint32_t cnt = 0; for (i = 0; i < len; i++) { @@ -123,7 +124,8 @@ static int32_t HdmiHdcpWriteMsgAn(struct HdmiHdcp *hdcp) static int32_t HdmiHdcpReadMsgHv(struct HdmiHdcp *hdcp) { - uint8_t offset, i; + uint8_t offset; + uint8_t i; uint8_t vhNum = HDMI_HDCP_MSG_ALL_VH_LEN / HDMI_HDCP_MSG_PER_VH_LEN; int32_t ret; diff --git a/framework/support/platform/src/hdmi/hdmi_infoframe.c b/framework/support/platform/src/hdmi/hdmi_infoframe.c index 5627da881..351e2452d 100644 --- a/framework/support/platform/src/hdmi/hdmi_infoframe.c +++ b/framework/support/platform/src/hdmi/hdmi_infoframe.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -729,7 +729,8 @@ static void HdmiFillSpdInfoFrame(struct HdmiSpdInfoFrame *spd, const char *vendorName, const char *productName, enum HdmiSpdSdi sdi) { - uint32_t len, length; + uint32_t len; + uint32_t length; if (memset_s(spd, sizeof(struct HdmiSpdInfoFrame), 0, sizeof(struct HdmiSpdInfoFrame)) != EOK) { HDF_LOGE("fill spd infoFrame, memset_s fail."); diff --git a/framework/support/platform/src/hdmi/hdmi_scdc.c b/framework/support/platform/src/hdmi/hdmi_scdc.c index 7e080e1ff..d5d242bd5 100644 --- a/framework/support/platform/src/hdmi/hdmi_scdc.c +++ b/framework/support/platform/src/hdmi/hdmi_scdc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -270,7 +270,8 @@ int32_t HdmiScdcScrambleGet(struct HdmiScdc *scdc, struct HdmiScdcScrambleCap *s bool HdmiScdcSinkSupport(struct HdmiScdc *scdc) { - uint8_t srcVer, i; + uint8_t srcVer; + uint8_t i; int32_t ret; if (scdc == NULL) { diff --git a/framework/support/platform/src/i3c/i3c_core.c b/framework/support/platform/src/i3c/i3c_core.c index a0d948c41..46e257bac 100644 --- a/framework/support/platform/src/i3c/i3c_core.c +++ b/framework/support/platform/src/i3c/i3c_core.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -245,7 +245,8 @@ struct I3cDevice *I3cGetDeviceByAddr(const struct I3cCntlr *cntlr, uint16_t addr static int32_t I3cDeviceDefineI3cDevices(struct I3cDevice *device) { - int32_t ret, addr; + int32_t ret; + int32_t addr; ret = SetAddrStatus(device->cntlr, device->addr, I3C_ADDR_I3C_DEVICE); if (ret != HDF_SUCCESS) { diff --git a/framework/support/platform/src/pcie/pcie_dispatch.c b/framework/support/platform/src/pcie/pcie_dispatch.c index 88fe74933..b3fb79069 100644 --- a/framework/support/platform/src/pcie/pcie_dispatch.c +++ b/framework/support/platform/src/pcie/pcie_dispatch.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -27,7 +27,8 @@ struct PcieDispatchFunc { static int32_t PcieCmdRead(struct PcieCntlr *cntlr, struct HdfSBuf *data, struct HdfSBuf *reply) { - uint32_t len, pos; + uint32_t len; + uint32_t pos; uint8_t *buf = NULL; int32_t ret; @@ -67,7 +68,8 @@ EXIT: static int32_t PcieCmdWrite(struct PcieCntlr *cntlr, struct HdfSBuf *data, struct HdfSBuf *reply) { - uint32_t size, pos; + uint32_t size; + uint32_t pos; uint8_t *buf = NULL; (void)reply; diff --git a/framework/test/unittest/platform/common/adc_test.c b/framework/test/unittest/platform/common/adc_test.c index 2c0e1466a..c8c4c9fce 100644 --- a/framework/test/unittest/platform/common/adc_test.c +++ b/framework/test/unittest/platform/common/adc_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -19,9 +19,10 @@ #define HDF_LOG_TAG adc_test_c -#define TEST_ADC_VAL_NUM 50 +#define TEST_ADC_VAL_NUM 50 #define ADC_TEST_WAIT_TIMES 100 -#define ADC_TEST_STACK_SIZE (1024 * 64) +#define ADC_TEST_WAIT_TIMEOUT 20 +#define ADC_TEST_STACK_SIZE (1024 * 64) static int32_t AdcTestGetConfig(struct AdcTestConfig *config) { @@ -157,58 +158,76 @@ static int AdcTestThreadFunc(void *param) return val; } -static int32_t AdcTestMultiThread(void) +static int32_t AdcTestStartThread(struct OsalThread *thread1, struct OsalThread *thread2, + const int32_t *count1, const int32_t *count2) { int32_t ret; - struct OsalThread thread1, thread2; - struct OsalThreadParam cfg1, cfg2; - int32_t count1 = 0; - int32_t count2 = 0; + uint32_t time = 0; + struct OsalThreadParam cfg1; + struct OsalThreadParam cfg2; + + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s failed.", __func__); + return HDF_ERR_IO; + } - HDF_LOGI("%s: enter", __func__); - ret = OsalThreadCreate(&thread1, (OsalThreadEntry)AdcTestThreadFunc, (void *)&count1); + cfg1.name = "AdcTestThread-1"; + cfg2.name = "AdcTestThread-2"; + cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; + cfg1.stackSize = cfg2.stackSize = ADC_TEST_STACK_SIZE; + + ret = OsalThreadStart(thread1, &cfg1); if (ret != HDF_SUCCESS) { - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; + HDF_LOGE("start test thread1 failed:%d", ret); + return ret; } - ret = OsalThreadCreate(&thread2, (OsalThreadEntry)AdcTestThreadFunc, (void *)&count2); + ret = OsalThreadStart(thread2, &cfg2); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; + HDF_LOGE("start test thread2 failed:%d", ret); } - cfg1.name = "AdcTestThread-1"; - cfg2.name = "AdcTestThread-2"; - cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; - cfg1.stackSize = cfg2.stackSize = ADC_TEST_STACK_SIZE; + while (*count1 == 0 || *count2 == 0) { + HDF_LOGV("waitting testing thread finish..."); + OsalMSleep(ADC_TEST_WAIT_TIMES); + time++; + if (time > ADC_TEST_WAIT_TIMEOUT) { + break; + } + } + return ret; +} + +static int32_t AdcTestMultiThread(void) +{ + int32_t ret; + struct OsalThread thread1; + struct OsalThread thread2; + int32_t count1 = 0; + int32_t count2 = 0; - ret = OsalThreadStart(&thread1, &cfg1); + ret = OsalThreadCreate(&thread1, (OsalThreadEntry)AdcTestThreadFunc, (void *)&count1); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); - HDF_LOGE("start test thread1 fail:%d", ret); - return HDF_FAILURE; + HDF_LOGE("create test thread1 failed:%d", ret); + return ret; } - ret = OsalThreadStart(&thread2, &cfg2); + ret = OsalThreadCreate(&thread2, (OsalThreadEntry)AdcTestThreadFunc, (void *)&count2); if (ret != HDF_SUCCESS) { (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); - HDF_LOGE("start test thread2 fail:%d", ret); - return HDF_FAILURE; + HDF_LOGE("create test thread1 failed:%d", ret); + return ret; } - while (count1 == 0 || count2 == 0) { - HDF_LOGE("waitting testing thread finish..."); - OsalMSleep(ADC_TEST_WAIT_TIMES); + ret = AdcTestStartThread(&thread1, &thread2, &count1, &count2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("test start thread failed:%d", ret); } (void)OsalThreadDestroy(&thread1); (void)OsalThreadDestroy(&thread2); - HDF_LOGI("%s: done", __func__); - return HDF_SUCCESS; + return ret; } static int32_t AdcTestReliability(void) diff --git a/framework/test/unittest/platform/common/dac_test.c b/framework/test/unittest/platform/common/dac_test.c index d87c47086..b54a29a43 100644 --- a/framework/test/unittest/platform/common/dac_test.c +++ b/framework/test/unittest/platform/common/dac_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -145,26 +145,18 @@ static int DacTestThreadFunc(void *param) return val; } -static int32_t DacTestMultiThread(void) +static int32_t DacTestStartThread(struct OsalThread *thread1, struct OsalThread *thread2, + const int32_t *count1, const int32_t *count2) { int32_t ret; uint32_t time = 0; - struct OsalThread thread1, thread2; - struct OsalThreadParam cfg1, cfg2; - int32_t count1 = 0; - int32_t count2 = 0; - - ret = OsalThreadCreate(&thread1, (OsalThreadEntry)DacTestThreadFunc, (void *)&count1); - if (ret != HDF_SUCCESS) { - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; - } + struct OsalThreadParam cfg1; + struct OsalThreadParam cfg2; - ret = OsalThreadCreate(&thread2, (OsalThreadEntry)DacTestThreadFunc, (void *)&count2); - if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s failed.", __func__); + return HDF_ERR_IO; } cfg1.name = "DacTestThread-1"; @@ -172,34 +164,57 @@ static int32_t DacTestMultiThread(void) cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; cfg1.stackSize = cfg2.stackSize = DAC_TEST_STACK_SIZE; - ret = OsalThreadStart(&thread1, &cfg1); + ret = OsalThreadStart(thread1, &cfg1); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); - HDF_LOGE("start test thread1 fail:%d", ret); - return HDF_FAILURE; + HDF_LOGE("start test thread1 failed:%d", ret); + return ret; } - ret = OsalThreadStart(&thread2, &cfg2); + ret = OsalThreadStart(thread2, &cfg2); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); - HDF_LOGE("start test thread2 fail:%d", ret); - return HDF_FAILURE; + HDF_LOGE("start test thread2 failed:%d", ret); } - while (count1 == 0 || count2 == 0) { - HDF_LOGE("waitting testing thread finish..."); + while (*count1 == 0 || *count2 == 0) { + HDF_LOGV("waitting testing thread finish..."); OsalMSleep(DAC_TEST_WAIT_TIMES); time++; if (time > DAC_TEST_WAIT_TIMEOUT) { break; } } + return ret; +} + +static int32_t DacTestMultiThread(void) +{ + int32_t ret; + struct OsalThread thread1; + struct OsalThread thread2; + int32_t count1 = 0; + int32_t count2 = 0; + + ret = OsalThreadCreate(&thread1, (OsalThreadEntry)DacTestThreadFunc, (void *)&count1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread1 failed:%d", ret); + return ret; + } + + ret = OsalThreadCreate(&thread2, (OsalThreadEntry)DacTestThreadFunc, (void *)&count2); + if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); + HDF_LOGE("create test thread1 failed:%d", ret); + return ret; + } + + ret = DacTestStartThread(&thread1, &thread2, &count1, &count2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("test start thread failed:%d", ret); + } (void)OsalThreadDestroy(&thread1); (void)OsalThreadDestroy(&thread2); - return HDF_SUCCESS; + return ret; } static int32_t DacTestReliability(void) diff --git a/framework/test/unittest/platform/common/emmc_test.c b/framework/test/unittest/platform/common/emmc_test.c index cad6269bd..6d9e69fea 100644 --- a/framework/test/unittest/platform/common/emmc_test.c +++ b/framework/test/unittest/platform/common/emmc_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -41,7 +41,8 @@ static void EmmcTestReleaseHandle(DevHandle handle) static int32_t TestEmmcGetCid(struct EmmcTester *tester) { - int32_t ret, i; + int32_t ret; + int32_t i; uint8_t cid[EMMC_CID_LEN] = {0}; ret = EmmcGetCid(tester->handle, cid, EMMC_CID_LEN); diff --git a/framework/test/unittest/platform/common/i2c_test.c b/framework/test/unittest/platform/common/i2c_test.c index 87e03a7cc..82e9fae06 100644 --- a/framework/test/unittest/platform/common/i2c_test.c +++ b/framework/test/unittest/platform/common/i2c_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -25,6 +25,7 @@ #define I2C_TEST_MLTTHD_TIMES 1000 #define I2C_TEST_STACK_SIZE (1024 * 100) #define I2C_TEST_WAIT_TIMES 200 +#define I2C_TEST_WAIT_TIMEOUT 40 static struct I2cMsg g_msgs[I2C_TEST_MSG_NUM]; static uint8_t *g_buf; @@ -247,61 +248,76 @@ static int I2cTestThreadFunc(void *param) return HDF_SUCCESS; } -static int32_t I2cTestMultiThread(void) +static int32_t I2cTestStartThread(struct OsalThread *thread1, struct OsalThread *thread2, + const int32_t *count1, const int32_t *count2) { int32_t ret; - struct OsalThread thread1, thread2; - struct OsalThreadParam cfg1, cfg2; - int32_t count1, count2; - - count1 = count2 = 0; - - ret = OsalThreadCreate(&thread1, (OsalThreadEntry)I2cTestThreadFunc, (void *)&count1); - if (ret != HDF_SUCCESS) { - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; - } - - ret = OsalThreadCreate(&thread2, (OsalThreadEntry)I2cTestThreadFunc, (void *)&count2); - if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; + uint32_t time = 0; + struct OsalThreadParam cfg1; + struct OsalThreadParam cfg2; + + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s fail.", __func__); + return HDF_ERR_IO; } - cfg1.name = "I2cTestThread-1"; cfg2.name = "I2cTestThread-2"; cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; cfg1.stackSize = cfg2.stackSize = I2C_TEST_STACK_SIZE; - ret = OsalThreadStart(&thread1, &cfg1); + ret = OsalThreadStart(thread1, &cfg1); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread1 fail:%d", ret); - return HDF_FAILURE; + return ret; } - ret = OsalThreadStart(&thread2, &cfg2); + ret = OsalThreadStart(thread2, &cfg2); if (ret != HDF_SUCCESS) { - while (count1 == 0) { - HDF_LOGD("waitting testing thread finish..."); - OsalMSleep(I2C_TEST_WAIT_TIMES); - } - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread2 fail:%d", ret); - return HDF_FAILURE; } - while (count1 == 0 || count2 == 0) { + while (*count1 == 0 || *count2 == 0) { HDF_LOGD("waitting testing thread finish..."); OsalMSleep(I2C_TEST_WAIT_TIMES); + time++; + if (time > I2C_TEST_WAIT_TIMEOUT) { + break; + } + } + + return ret; +} + +static int32_t I2cTestMultiThread(void) +{ + int32_t ret; + struct OsalThread thread1; + struct OsalThread thread2; + int32_t count1 = 0; + int32_t count2 = 0; + + ret = OsalThreadCreate(&thread1, (OsalThreadEntry)I2cTestThreadFunc, (void *)&count1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread1 fail:%d", ret); + return ret; + } + + ret = OsalThreadCreate(&thread2, (OsalThreadEntry)I2cTestThreadFunc, (void *)&count2); + if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); + HDF_LOGE("create test thread1 fail:%d", ret); + return ret; + } + + ret = I2cTestStartThread(&thread1, &thread2, &count1, &count2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("test start thread fail:%d", ret); } (void)OsalThreadDestroy(&thread1); (void)OsalThreadDestroy(&thread2); - return HDF_SUCCESS; + return ret; } static int32_t I2cTestReliability(void) diff --git a/framework/test/unittest/platform/common/i3c_test.c b/framework/test/unittest/platform/common/i3c_test.c index a758dddeb..fadf6cea7 100644 --- a/framework/test/unittest/platform/common/i3c_test.c +++ b/framework/test/unittest/platform/common/i3c_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -367,11 +367,15 @@ static int32_t I3cTestStartThread(struct OsalThread *thread1, struct OsalThread const int32_t *count1, const int32_t *count2) { int32_t ret; - uint32_t time; + uint32_t time = 0; struct OsalThreadParam cfg1; struct OsalThreadParam cfg2; - time = 0; + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s fail.", __func__); + return HDF_ERR_IO; + } cfg1.name = "I3cTestThread-1"; cfg2.name = "I3cTestThread-2"; cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; @@ -386,15 +390,6 @@ static int32_t I3cTestStartThread(struct OsalThread *thread1, struct OsalThread ret = OsalThreadStart(thread2, &cfg2); if (ret != HDF_SUCCESS) { HDF_LOGE("start test thread2 fail:%d", ret); - while (*count1 == 0) { - HDF_LOGE("waitting testing thread1 finish..."); - OsalMSleep(I3C_TEST_WAIT_TIMES); - time++; - if (time > I3C_TEST_WAIT_TIMEOUT) { - break; - } - } - return ret; } while (*count1 == 0 || *count2 == 0) { @@ -405,16 +400,17 @@ static int32_t I3cTestStartThread(struct OsalThread *thread1, struct OsalThread break; } } - return HDF_SUCCESS; + return ret; } static int32_t I3cTestThreadFunc(OsalThreadEntry func) { int32_t ret; - struct OsalThread thread1, thread2; - int32_t count1, count2; + struct OsalThread thread1; + struct OsalThread thread2; + int32_t count1 = 0; + int32_t count2 = 0; - count1 = count2 = 0; ret = OsalThreadCreate(&thread1, func, (void *)&count1); if (ret != HDF_SUCCESS) { HDF_LOGE("create test thread1 fail:%d", ret); @@ -423,7 +419,7 @@ static int32_t I3cTestThreadFunc(OsalThreadEntry func) ret = OsalThreadCreate(&thread2, func, (void *)&count2); if (ret != HDF_SUCCESS) { - HDF_LOGE("create test thread1 fail:%d", ret); + HDF_LOGE("create test thread2 fail:%d", ret); (void)OsalThreadDestroy(&thread1); return ret; } @@ -431,14 +427,11 @@ static int32_t I3cTestThreadFunc(OsalThreadEntry func) ret = I3cTestStartThread(&thread1, &thread2, &count1, &count2); if (ret != HDF_SUCCESS) { HDF_LOGE("test start thread fail:%d", ret); - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); - return ret; } (void)OsalThreadDestroy(&thread1); (void)OsalThreadDestroy(&thread2); - return HDF_SUCCESS; + return ret; } static struct I3cTestEntry g_multiThreadEntry[] = { diff --git a/framework/test/unittest/platform/common/platform_dumper_test.c b/framework/test/unittest/platform/common/platform_dumper_test.c index f4fbd8a32..326a913ed 100644 --- a/framework/test/unittest/platform/common/platform_dumper_test.c +++ b/framework/test/unittest/platform/common/platform_dumper_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -334,62 +334,75 @@ static int PlatformDumperTestThreadFunc(void *param) return HDF_SUCCESS; } -static int32_t PlatformDumperTestMultiThread(void) +static int32_t PlatformDumperTestStartThread(struct OsalThread *thread1, struct OsalThread *thread2, + const int32_t *count1, const int32_t *count2) { int32_t ret; - uint32_t time; - struct OsalThread thread1, thread2; - struct OsalThreadParam cfg1, cfg2; - int32_t count1, count2; - - count1 = count2 = 0; - time = 0; - ret = OsalThreadCreate(&thread1, (OsalThreadEntry)PlatformDumperTestThreadFunc, (void *)&count1); - if (ret != HDF_SUCCESS) { - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; - } + uint32_t time = 0; + struct OsalThreadParam cfg1; + struct OsalThreadParam cfg2; - ret = OsalThreadCreate(&thread2, (OsalThreadEntry)PlatformDumperTestThreadFunc, (void *)&count2); - if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s fail.", __func__); + return HDF_ERR_IO; } - cfg1.name = "DumperTestThread-1"; cfg2.name = "DumperTestThread-2"; cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; cfg1.stackSize = cfg2.stackSize = PLAT_DUMPER_TEST_STACK_SIZE; - ret = OsalThreadStart(&thread1, &cfg1); + ret = OsalThreadStart(thread1, &cfg1); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread1 fail:%d", ret); - return HDF_FAILURE; + return ret; } - ret = OsalThreadStart(&thread2, &cfg2); + ret = OsalThreadStart(thread2, &cfg2); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread2 fail:%d", ret); - return HDF_FAILURE; } - while (count1 == 0 || count2 == 0) { - HDF_LOGE("waitting testing Regulator thread finish..."); + while (*count1 == 0 || *count2 == 0) { + HDF_LOGV("waitting testing dumper thread finish..."); OsalMSleep(PLAT_DUMPER_TEST_WAIT_TIMES); time++; if (time > PLAT_DUMPER_TEST_WAIT_TIMEOUT) { break; } } + return ret; +} + +static int32_t PlatformDumperTestMultiThread(void) +{ + int32_t ret; + struct OsalThread thread1; + struct OsalThread thread2; + int32_t count1 = 0; + int32_t count2 = 0; + + ret = OsalThreadCreate(&thread1, (OsalThreadEntry)PlatformDumperTestThreadFunc, (void *)&count1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread1 fail:%d", ret); + return ret; + } + ret = OsalThreadCreate(&thread2, (OsalThreadEntry)PlatformDumperTestThreadFunc, (void *)&count2); + if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); + HDF_LOGE("create test thread2 fail:%d", ret); + return ret; + } + + ret = PlatformDumperTestStartThread(&thread1, &thread2, &count1, &count2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("test start thread fail:%d", ret); + } + (void)OsalThreadDestroy(&thread1); (void)OsalThreadDestroy(&thread2); - return HDF_SUCCESS; + return ret; } static int32_t PlatformDumperTestDelData(void) diff --git a/framework/test/unittest/platform/common/regulator_test.c b/framework/test/unittest/platform/common/regulator_test.c index 7ae558359..b35aba98b 100644 --- a/framework/test/unittest/platform/common/regulator_test.c +++ b/framework/test/unittest/platform/common/regulator_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -12,6 +12,7 @@ #include "osal_thread.h" #include "osal_time.h" #include "regulator_if.h" +#include "securec.h" #if defined(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR) #include "virtual/regulator_linux_voltage_virtual_driver.h" #include "virtual/regulator_linux_current_virtual_driver.h" @@ -178,52 +179,36 @@ static int RegulatorTestThreadFunc(void *param) return HDF_SUCCESS; } -static int32_t RegulatorTestMultiThread(struct RegulatorTest *test) +static int32_t RegulatorTestStartThread(struct OsalThread *thread1, struct OsalThread *thread2, + const int32_t *count1, const int32_t *count2) { int32_t ret; - uint32_t time; - struct OsalThread thread1, thread2; - struct OsalThreadParam cfg1, cfg2; - int32_t count1, count2; - - (void)test; - count1 = count2 = 0; - time = 0; - ret = OsalThreadCreate(&thread1, (OsalThreadEntry)RegulatorTestThreadFunc, (void *)&count1); - if (ret != HDF_SUCCESS) { - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; - } + uint32_t time = 0; + struct OsalThreadParam cfg1; + struct OsalThreadParam cfg2; - ret = OsalThreadCreate(&thread2, (OsalThreadEntry)RegulatorTestThreadFunc, (void *)&count2); - if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - HDF_LOGE("create test thread1 fail:%d", ret); - return HDF_FAILURE; + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s fail.", __func__); + return HDF_ERR_IO; } - cfg1.name = "RegulatorTestThread-1"; cfg2.name = "RegulatorTestThread-2"; cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; cfg1.stackSize = cfg2.stackSize = REGULATOR_TEST_STACK_SIZE; - ret = OsalThreadStart(&thread1, &cfg1); + ret = OsalThreadStart(thread1, &cfg1); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread1 fail:%d", ret); - return HDF_FAILURE; + return ret; } - ret = OsalThreadStart(&thread2, &cfg2); + ret = OsalThreadStart(thread2, &cfg2); if (ret != HDF_SUCCESS) { - (void)OsalThreadDestroy(&thread1); - (void)OsalThreadDestroy(&thread2); HDF_LOGE("start test thread2 fail:%d", ret); - return HDF_FAILURE; } - while (count1 == 0 || count2 == 0) { + while (*count1 == 0 || *count2 == 0) { HDF_LOGE("waitting testing Regulator thread finish..."); OsalMSleep(REGULATOR_TEST_WAIT_TIMES); time++; @@ -231,10 +216,39 @@ static int32_t RegulatorTestMultiThread(struct RegulatorTest *test) break; } } + return ret; +} + +static int32_t RegulatorTestMultiThread(struct RegulatorTest *test) +{ + int32_t ret; + struct OsalThread thread1; + struct OsalThread thread2; + int32_t count1 = 0; + int32_t count2 = 0; + + (void)test; + ret = OsalThreadCreate(&thread1, (OsalThreadEntry)RegulatorTestThreadFunc, (void *)&count1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread1 fail:%d", ret); + return ret; + } + + ret = OsalThreadCreate(&thread2, (OsalThreadEntry)RegulatorTestThreadFunc, (void *)&count2); + if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(&thread1); + HDF_LOGE("create test thread2 fail:%d", ret); + return ret; + } + + ret = RegulatorTestStartThread(&thread1, &thread2, &count1, &count2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("test start thread fail:%d", ret); + } (void)OsalThreadDestroy(&thread1); (void)OsalThreadDestroy(&thread2); - return HDF_SUCCESS; + return ret; } static int32_t RegulatorTestReliability(struct RegulatorTest *test) diff --git a/framework/test/unittest/platform/common/timer_test.c b/framework/test/unittest/platform/common/timer_test.c index 9fe0abe64..d401da8bd 100644 --- a/framework/test/unittest/platform/common/timer_test.c +++ b/framework/test/unittest/platform/common/timer_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -152,96 +152,136 @@ static int TimerPeriodTestThreadFunc(void *param) return HDF_SUCCESS; } -static int32_t TimerTestMultiThread(const struct TimerTest *test) +static int32_t TimerTestStartThread(struct OsalThread *thread1, struct OsalThread *thread2) { int32_t ret; uint32_t time = 0; - struct OsalThread thread1, thread2; - struct OsalThreadParam cfg1, cfg2; - DevHandle handle1 = NULL; - DevHandle handle2 = NULL; - if (test == NULL) { - HDF_LOGE("%s: timer test NULL", __func__); - return HDF_FAILURE; + struct OsalThreadParam cfg1; + struct OsalThreadParam cfg2; + + if (memset_s(&cfg1, sizeof(cfg1), 0, sizeof(cfg1)) != EOK || + memset_s(&cfg2, sizeof(cfg2), 0, sizeof(cfg2)) != EOK) { + HDF_LOGE("%s:memset_s fail.", __func__); + return HDF_ERR_IO; } - thread1.realThread = NULL; - thread2.realThread = NULL; - do { - handle1 = HwTimerOpen(TIMER_TEST_TIME_ID_THREAD1); - if (handle1 == NULL) { - HDF_LOGE("%s: timer test get handle1 fail", __func__); - ret = HDF_FAILURE; - break; - } - handle2 = HwTimerOpen(TIMER_TEST_TIME_ID_THREAD2); - if (handle2 == NULL) { - HDF_LOGE("%s: timer test get handle2 fail", __func__); - ret = HDF_FAILURE; - break; - } + cfg1.name = "TimerTestThread-once"; + cfg2.name = "TimerTestThread-period"; + cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; + cfg1.stackSize = cfg2.stackSize = TIMER_TEST_STACK_SIZE; - ret = OsalThreadCreate(&thread1, (OsalThreadEntry)TimerOnceTestThreadFunc, (void *)handle1); - if (ret != HDF_SUCCESS) { - HDF_LOGE("create test once timer fail:%d", ret); - ret = HDF_FAILURE; - break; - } + ret = OsalThreadStart(thread1, &cfg1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("testing start timer thread1 failed:%d", ret); + return ret; + } - ret = OsalThreadCreate(&thread2, (OsalThreadEntry)TimerPeriodTestThreadFunc, (void *)handle2); - if (ret != HDF_SUCCESS) { - HDF_LOGE("create test period timer fail:%d", ret); - ret = HDF_FAILURE; + ret = OsalThreadStart(thread2, &cfg2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("testing start timer thread2 failed:%d", ret); + } + + while (g_theard1Flag == false || g_theard2Flag == false) { + HDF_LOGD("[%d]waitting testing timer thread finish...", time); + OsalSleep(TIMER_TEST_WAIT_TIMEOUT); + time++; + if (time > TIMER_TEST_WAIT_TIMES) { break; } + } + return ret; +} - cfg1.name = "TimerTestThread-once"; - cfg2.name = "TimerTestThread-period"; - cfg1.priority = cfg2.priority = OSAL_THREAD_PRI_DEFAULT; - cfg1.stackSize = cfg2.stackSize = TIMER_TEST_STACK_SIZE; +static int32_t TimerTestCreateThread(struct OsalThread *thread1, struct OsalThread *thread2, + DevHandle handle1, DevHandle handle2) +{ + int32_t ret; - ret = OsalThreadStart(&thread1, &cfg1); - if (ret != HDF_SUCCESS) { - HDF_LOGE("start test thread1 fail:%d", ret); - ret = HDF_FAILURE; - break; - } + ret = OsalThreadCreate(thread1, (OsalThreadEntry)TimerOnceTestThreadFunc, (void *)handle1); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test once timer failed:%d", ret); + return ret; + } - ret = OsalThreadStart(&thread2, &cfg2); - if (ret != HDF_SUCCESS) { - HDF_LOGE("start test thread2 fail:%d", ret); - ret = HDF_FAILURE; - break; - } + ret = OsalThreadCreate(thread2, (OsalThreadEntry)TimerPeriodTestThreadFunc, (void *)handle2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test period timer failed:%d", ret); + return ret; + } - while (g_theard1Flag == false || g_theard2Flag == false) { - HDF_LOGD("[%d]waitting testing timer thread finish...", time); - OsalSleep(TIMER_TEST_WAIT_TIMEOUT); - time++; - if (time > TIMER_TEST_WAIT_TIMES) { - break; - } - } - ret = HDF_SUCCESS; - } while (0); + return HDF_SUCCESS; +} +static void MultiThreadSourceRecycle(struct OsalThread *thread1, struct OsalThread *thread2, + DevHandle handle1, DevHandle handle2) +{ if (handle1 != NULL) { HwTimerClose(handle1); handle1 = NULL; } + if (handle2 != NULL) { HwTimerClose(handle2); handle2 = NULL; } - if (thread1.realThread != NULL) { - (void)OsalThreadDestroy(&thread1); + + if (thread1->realThread != NULL) { + (void)OsalThreadDestroy(thread1); } - if (thread2.realThread != NULL) { - (void)OsalThreadDestroy(&thread2); + + if (thread2->realThread != NULL) { + (void)OsalThreadDestroy(thread2); } + g_theard1Flag = false; g_theard2Flag = false; - return ret; +} + +static int32_t TimerTestMultiThread(const struct TimerTest *test) +{ + int32_t ret; + struct OsalThread thread1; + struct OsalThread thread2; + DevHandle handle1 = NULL; + DevHandle handle2 = NULL; + thread1.realThread = NULL; + thread2.realThread = NULL; + + if (test == NULL) { + HDF_LOGE("%s: timer test NULL", __func__); + return HDF_FAILURE; + } + + handle1 = HwTimerOpen(TIMER_TEST_TIME_ID_THREAD1); + if (handle1 == NULL) { + HDF_LOGE("%s: timer test get handle1 failed", __func__); + MultiThreadSourceRecycle(&thread1, &thread2, handle1, handle2); + return HDF_FAILURE; + } + + handle2 = HwTimerOpen(TIMER_TEST_TIME_ID_THREAD2); + if (handle2 == NULL) { + HDF_LOGE("%s: timer test get handle2 failed", __func__); + MultiThreadSourceRecycle(&thread1, &thread2, handle1, handle2); + return HDF_FAILURE; + } + + ret = TimerTestCreateThread(&thread1, &thread2, handle1, handle2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: timer test create thread failed", __func__); + MultiThreadSourceRecycle(&thread1, &thread2, handle1, handle2); + return ret; + } + + ret = TimerTestStartThread(&thread1, &thread2); + if (ret != HDF_SUCCESS) { + HDF_LOGE("timer test start thread failed:%d", ret); + MultiThreadSourceRecycle(&thread1, &thread2, handle1, handle2); + return ret; + } + + MultiThreadSourceRecycle(&thread1, &thread2, handle1, handle2); + return HDF_SUCCESS; } static int32_t TimerTestReliability(const struct TimerTest *test) -- Gitee From 647b4cd397c8a493d6c31591037b6acf4e9390ba Mon Sep 17 00:00:00 2001 From: luo-wei246 Date: Fri, 3 Feb 2023 09:56:12 +0800 Subject: [PATCH 48/60] fixed db6b30c from https://gitee.com/luo-wei246/drivers_framework/pulls/1729 fix:USB alarm cleanup Signed-off-by: luo-wei246 --- adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c b/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c index e56e56c10..0c44151f3 100644 --- a/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c +++ b/adapter/khdf/linux/model/usb/host/src/usb_pnp_notify.c @@ -3,7 +3,7 @@ * * usb pnp notify adapter of linux * - * Copyright (c) 2020-2022 Huawei Device Co., Ltd. + * Copyright (c) 2020-2023 Huawei Device Co., Ltd. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -236,7 +236,8 @@ static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo infoTable->interfaceInfo[0].interfaceProtocol = infoData.infoData->interfaceProtocol; infoTable->interfaceInfo[0].interfaceNumber = infoData.infoData->interfaceNumber; } else { - uint8_t i, j; + uint8_t i; + uint8_t j; for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) { if (deviceInfo->interfaceRemoveStatus[i] == true) { HDF_LOGI("%s:%d j=%hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i); -- Gitee From 5aa9285795ba3b6a0c58006eb4654963efecc11a Mon Sep 17 00:00:00 2001 From: chenhaifan Date: Fri, 3 Feb 2023 16:03:43 +0800 Subject: [PATCH 49/60] fix:Remove initialization of variables Signed-off-by: chenhaifan --- framework/test/unittest/model/audio/src/hdf_audio_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/test/unittest/model/audio/src/hdf_audio_test.c b/framework/test/unittest/model/audio/src/hdf_audio_test.c index 048391234..ff3630036 100644 --- a/framework/test/unittest/model/audio/src/hdf_audio_test.c +++ b/framework/test/unittest/model/audio/src/hdf_audio_test.c @@ -114,8 +114,8 @@ static HdfTestCaseList g_hdfAudioTestCaseList[] = { int32_t HdfAudioEntry(HdfTestMsg *msg) { - int32_t result = 0; - int32_t i = 0; + int32_t result; + int32_t i; if (msg == NULL) { HDF_LOGE("%s is fail: HdfTestMsg is NULL!", __func__); -- Gitee From df43f231226bf4b2941e24bc63e347a2d7768e8c Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Fri, 3 Feb 2023 16:15:45 +0800 Subject: [PATCH 50/60] fix:target_cpu add new judgment cpu x86_64 Signed-off-by: chenpan0560 --- adapter/uhdf2/hdi/BUILD.gn | 2 +- adapter/uhdf2/host/BUILD.gn | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adapter/uhdf2/hdi/BUILD.gn b/adapter/uhdf2/hdi/BUILD.gn index 5795f6bae..5b2be8b53 100644 --- a/adapter/uhdf2/hdi/BUILD.gn +++ b/adapter/uhdf2/hdi/BUILD.gn @@ -41,7 +41,7 @@ if (defined(ohos_lite)) { } } else { ohos_shared_library("libhdi") { - if (target_cpu == "arm64") { + if (target_cpu == "arm64" || target_cpu == "x86_64") { defines = [ "__ARM64__" ] } diff --git a/adapter/uhdf2/host/BUILD.gn b/adapter/uhdf2/host/BUILD.gn index f76894379..64129f6c2 100644 --- a/adapter/uhdf2/host/BUILD.gn +++ b/adapter/uhdf2/host/BUILD.gn @@ -33,7 +33,7 @@ if (defined(ohos_lite)) { } } else { ohos_shared_library("libhdf_host") { - if (target_cpu == "arm64") { + if (target_cpu == "arm64" || target_cpu == "x86_64") { defines = [ "__ARM64__" ] } -- Gitee From 824480f609031504f39027048582653b211021dd Mon Sep 17 00:00:00 2001 From: jiaziyangnewer Date: Wed, 8 Feb 2023 17:53:23 +0800 Subject: [PATCH 51/60] fix:clear platform drivers tool scan problems Signed-off-by: jiaziyangnewer --- framework/test/unittest/platform/common/i2c_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/test/unittest/platform/common/i2c_test.c b/framework/test/unittest/platform/common/i2c_test.c index 82e9fae06..491eb0553 100644 --- a/framework/test/unittest/platform/common/i2c_test.c +++ b/framework/test/unittest/platform/common/i2c_test.c @@ -224,7 +224,8 @@ static int32_t I2cTestWriteRead(void) static int I2cTestThreadFunc(void *param) { - int32_t i, ret; + int32_t i; + int32_t ret; struct I2cTester *tester = NULL; tester = I2cTesterGet(); -- Gitee From 04b3534f9124c2c17e2f20f0ac29919a84bfd143 Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Wed, 8 Feb 2023 18:48:09 +0800 Subject: [PATCH 52/60] fix:tools/hdf_core alarm cleanup Signed-off-by: chenpan0560 --- adapter/uhdf2/include/hdi/base/hdi_smq.h | 2 +- .../tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/adapter/uhdf2/include/hdi/base/hdi_smq.h b/adapter/uhdf2/include/hdi/base/hdi_smq.h index 7972516d0..6279fd210 100644 --- a/adapter/uhdf2/include/hdi/base/hdi_smq.h +++ b/adapter/uhdf2/include/hdi/base/hdi_smq.h @@ -273,7 +273,7 @@ int SharedMemQueue::Write(const T *data, size_t count, int64_t waitTimeNanoSe int ret = 0; auto startTime = GetNanoTime(); - uint64_t currentTime = startTime; + int64_t currentTime = startTime; while (true) { if (waitTimeNanoSec != 0) { currentTime = GetNanoTime(); diff --git a/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index 6444f918e..1531d7680 100644 --- a/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/framework/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -391,7 +391,6 @@ class HdfAddHandler(HdfCommandHandlerBase): add_driver = HdfAddDriver(args=args_tuple) # create driver Source File (.c 、.h) state, file_list, head_list = add_driver.add_driver(*args_tuple) - file_path = [] if board == "hispark_taurus": file_path = add_driver.add_liteos(file_list, head_list) elif board.endswith("linux"): -- Gitee From b1ccc3c29558cbae82a162cb39fb9a0a15fcafa3 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 30 Nov 2022 15:07:20 +0000 Subject: [PATCH 53/60] fixed fe85e0e from https://gitee.com/ohos_frank/drivers_hdf_core/pulls/1598 update adapter/khdf/linux/model/audio/Makefile. Signed-off-by: kevin --- adapter/khdf/linux/model/audio/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/adapter/khdf/linux/model/audio/Makefile b/adapter/khdf/linux/model/audio/Makefile index 8f9cbc5bb..1317797a0 100644 --- a/adapter/khdf/linux/model/audio/Makefile +++ b/adapter/khdf/linux/model/audio/Makefile @@ -40,9 +40,6 @@ obj-$(CONFIG_DRIVERS_HDF_AUDIO_HI3516CODEC) += \ obj-$(CONFIG_DRIVERS_HDF_AUDIO_RK3568) += \ $(KHDF_AUDIO_BASE_ROOT_DIR)/device/board/hihope/rk3568/audio_drivers/ -obj-$(CONFIG_DRIVERS_HDF_AUDIO_RK3566) += \ - $(KHDF_AUDIO_BASE_ROOT_DIR)/device/board/kaihong/khdvk_3566b/kernel/audio/ - obj-$(CONFIG_DRIVERS_HDF_AUDIO_A311D) += \ $(KHDF_AUDIO_A311D_DIR)/codec/soc_codec/a311d_codec_adapter.o \ $(KHDF_AUDIO_A311D_DIR)/codec/soc_codec/a311d_codec_ops.o \ -- Gitee From 955099bde9b2f41a14c5e6fcbe232b5bfc4bb4be Mon Sep 17 00:00:00 2001 From: yueyan Date: Wed, 15 Feb 2023 17:34:29 +0800 Subject: [PATCH 54/60] fixed 42c3617 from https://gitee.com/yueyan233/drivers_hdf_core/pulls/1756 fix:add serialize function of ashmem and smq Signed-off-by: yueyan --- framework/tools/hdi-gen/ast/ast_smq_type.cpp | 67 +++++++++++++++++++- framework/tools/hdi-gen/ast/ast_smq_type.h | 12 ++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/framework/tools/hdi-gen/ast/ast_smq_type.cpp b/framework/tools/hdi-gen/ast/ast_smq_type.cpp index 9e1772f47..b9fe39102 100644 --- a/framework/tools/hdi-gen/ast/ast_smq_type.cpp +++ b/framework/tools/hdi-gen/ast/ast_smq_type.cpp @@ -89,6 +89,43 @@ void ASTSmqType::EmitCppReadVar(const std::string &parcelName, const std::string "std::make_shared>(*%s);\n", innerType_->EmitCppType().c_str(), metaVarName.c_str()); } +void ASTSmqType::EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, unsigned int innerLevel) const +{ + sb.Append(prefix).AppendFormat( + "if (%s == nullptr || !%s->IsGood() || %s->GetMeta() == nullptr || ", name.c_str(), name.c_str(), name.c_str()); + sb.AppendFormat("!%s->GetMeta()->Marshalling(%s)) {\n", name.c_str(), parcelName.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); +} + +void ASTSmqType::EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType, unsigned int innerLevel) const +{ + size_t index = name.find('.'); + std::string memberName = (index == std::string::npos) ? name : StringHelper::SubStr(name, index + 1); + std::string metaVarName = StringHelper::Format("%sMeta_", memberName.c_str()); + + sb.Append(prefix).AppendFormat( + "std::shared_ptr> %s = ", innerType_->EmitCppType().c_str(), metaVarName.c_str()); + sb.AppendFormat( + "SharedMemQueueMeta<%s>::UnMarshalling(%s);\n", innerType_->EmitCppType().c_str(), parcelName.c_str()); + sb.Append(prefix).AppendFormat("if (%s == nullptr) {\n", metaVarName.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: SharedMemQueueMeta is nullptr\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n\n"); + + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = ", EmitCppType(TypeMode::LOCAL_VAR).c_str(), memberName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = ", name.c_str()); + } + + sb.AppendFormat( + "std::make_shared>(*%s);\n", innerType_->EmitCppType().c_str(), metaVarName.c_str()); +} + bool ASTAshmemType::IsAshmemType() { return true; @@ -125,7 +162,7 @@ void ASTAshmemType::EmitCppWriteVar(const std::string &parcelName, const std::st { sb.Append(prefix).AppendFormat( "if (%s == nullptr || !%s.WriteAshmem(%s)) {\n", name.c_str(), parcelName.c_str(), name.c_str()); - sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: write %s failed!\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to write %s\", __func__);\n", name.c_str()); sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); sb.Append(prefix).Append("}\n"); } @@ -141,9 +178,35 @@ void ASTAshmemType::EmitCppReadVar(const std::string &parcelName, const std::str } sb.Append(prefix).AppendFormat("if (%s == nullptr) {\n", name.c_str()); - sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: read an invalid ashmem object\", __func__);\n"); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read ashmem object\", __func__);\n"); sb.Append(prefix + TAB).Append("return HDF_ERR_INVALID_PARAM;\n"); sb.Append(prefix).Append("}\n"); } + +void ASTAshmemType::EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, unsigned int innerLevel) const +{ + sb.Append(prefix).AppendFormat( + "if (%s == nullptr || !%s.WriteAshmem(%s)) {\n", name.c_str(), parcelName.c_str(), name.c_str()); + sb.Append(prefix + TAB).AppendFormat("HDF_LOGE(\"%%{public}s: failed to write %s\", __func__);\n", name.c_str()); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); +} + +void ASTAshmemType::EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType, unsigned int innerLevel) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat( + "%s %s = %s.ReadAshmem();\n", EmitCppType().c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %s.ReadAshmem();\n", name.c_str(), parcelName.c_str()); + } + + sb.Append(prefix).AppendFormat("if (%s == nullptr) {\n", name.c_str()); + sb.Append(prefix + TAB).Append("HDF_LOGE(\"%{public}s: failed to read ashmem object\", __func__);\n"); + sb.Append(prefix + TAB).Append("return false;\n"); + sb.Append(prefix).Append("}\n"); +} } // namespace HDI } // namespace OHOS \ No newline at end of file diff --git a/framework/tools/hdi-gen/ast/ast_smq_type.h b/framework/tools/hdi-gen/ast/ast_smq_type.h index 133f31476..d09025f5b 100644 --- a/framework/tools/hdi-gen/ast/ast_smq_type.h +++ b/framework/tools/hdi-gen/ast/ast_smq_type.h @@ -38,6 +38,12 @@ public: void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, bool initVariable, unsigned int innerLevel = 0) const override; + void EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, unsigned int innerLevel = 0) const override; + + void EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType, unsigned int innerLevel = 0) const override; + private: AutoPtr innerType_; }; @@ -59,6 +65,12 @@ public: void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, const std::string &prefix, bool initVariable, unsigned int innerLevel = 0) const override; + + void EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, unsigned int innerLevel = 0) const override; + + void EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType, unsigned int innerLevel = 0) const override; }; } // namespace HDI } // namespace OHOS -- Gitee From e4ef5eb1462f0d61add5e80c14d1c1c173ac9662 Mon Sep 17 00:00:00 2001 From: mn_manan Date: Tue, 17 Jan 2023 03:33:36 +0000 Subject: [PATCH 55/60] fixed 4007725 from https://gitee.com/mn_manan/drivers_hdf_core/pulls/1699 feat: add HDI interfaces of vibrator Signed-off-by: mn_manan --- .../misc/vibrator/driver/include/vibrator_driver.h | 4 ++-- .../vibrator/driver/include/vibrator_driver_type.h | 14 +++++++------- .../misc/vibrator/driver/src/vibrator_driver.c | 10 +++++----- .../misc/vibrator/driver/src/vibrator_parser.c | 14 +++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/framework/model/misc/vibrator/driver/include/vibrator_driver.h b/framework/model/misc/vibrator/driver/include/vibrator_driver.h index 536308253..b4199d083 100644 --- a/framework/model/misc/vibrator/driver/include/vibrator_driver.h +++ b/framework/model/misc/vibrator/driver/include/vibrator_driver.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -19,7 +19,7 @@ struct VibratorOps { int32_t (*Start)(void); int32_t (*Stop)(void); int32_t (*StartEffect)(uint32_t effectType); - int32_t (*SetParameter)(int32_t intensity, int32_t frequency); + int32_t (*SetParameter)(uint16_t intensity, int16_t frequency); }; typedef int32_t (*VibratorCmdHandle)(struct HdfSBuf *reqData, struct HdfSBuf *reply); diff --git a/framework/model/misc/vibrator/driver/include/vibrator_driver_type.h b/framework/model/misc/vibrator/driver/include/vibrator_driver_type.h index ef3943a0b..da6ac7c5b 100644 --- a/framework/model/misc/vibrator/driver/include/vibrator_driver_type.h +++ b/framework/model/misc/vibrator/driver/include/vibrator_driver_type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -83,12 +83,12 @@ struct VibratorBus { }; struct VibratorInfo { - int32_t isSupportIntensity; /**< setting intensity capability */ - int32_t isSupportFrequency; /**< setting frequency capability */ - int32_t intensityMaxValue; /**< Max intensity */ - int32_t intensityMinValue; /**< Min intensity */ - int32_t frequencyMaxValue; /**< Max frequency */ - int32_t frequencyMinValue; /**< Min frequency */ + bool isSupportIntensity; /**< setting intensity capability */ + bool isSupportFrequency; /**< setting frequency capability */ + uint16_t intensityMaxValue; /**< Max intensity */ + uint16_t intensityMinValue; /**< Min intensity */ + int16_t frequencyMaxValue; /**< Max frequency */ + int16_t frequencyMinValue; /**< Min frequency */ }; diff --git a/framework/model/misc/vibrator/driver/src/vibrator_driver.c b/framework/model/misc/vibrator/driver/src/vibrator_driver.c index 21f8451e3..a5b3d85be 100644 --- a/framework/model/misc/vibrator/driver/src/vibrator_driver.c +++ b/framework/model/misc/vibrator/driver/src/vibrator_driver.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -262,8 +262,8 @@ static int32_t EnableModulationParameter(struct HdfSBuf *data, struct HdfSBuf *r struct VibratorEffectCfg config; struct VibratorDriverData *drvData; uint32_t duration; - int32_t intensity; - int32_t frequency; + uint16_t intensity; + int16_t frequency; int32_t ret; drvData = GetVibratorDrvData(); @@ -281,12 +281,12 @@ static int32_t EnableModulationParameter(struct HdfSBuf *data, struct HdfSBuf *r return HDF_FAILURE; } - if (!HdfSbufReadInt32(data, &intensity)) { + if (!HdfSbufReadUint16(data, &intensity)) { HDF_LOGE("%s: sbuf read intensity failed!", __func__); return HDF_FAILURE; } - if (!HdfSbufReadInt32(data, &frequency)) { + if (!HdfSbufReadInt16(data, &frequency)) { HDF_LOGE("%s: sbuf read frequency failed!", __func__); return HDF_FAILURE; } diff --git a/framework/model/misc/vibrator/driver/src/vibrator_parser.c b/framework/model/misc/vibrator/driver/src/vibrator_parser.c index 7886c4b7e..c233e15c5 100755 --- a/framework/model/misc/vibrator/driver/src/vibrator_parser.c +++ b/framework/model/misc/vibrator/driver/src/vibrator_parser.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * * HDF is dual licensed: you can use it either under the terms of * the GPL, or the BSD license, at your option. @@ -40,17 +40,17 @@ static int32_t ParseVibratorInfo(struct DeviceResourceIface *parser, const struc CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(infoNode, HDF_ERR_INVALID_PARAM); CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); - ret = parser->GetUint32(infoNode, "isSupportIntensity", (uint32_t *)&config->vibratorInfo.isSupportIntensity, 0); + ret = parser->GetBool(infoNode, "isSupportIntensity"); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "isSupportIntensity"); - ret = parser->GetUint32(infoNode, "isSupportFrequency", (uint32_t *)&config->vibratorInfo.isSupportFrequency, 0); + ret = parser->GetBool(infoNode, "isSupportFrequency"); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "isSupportFrequency"); - ret = parser->GetUint32(infoNode, "intensityMaxValue", (uint32_t *)&config->vibratorInfo.intensityMaxValue, 0); + ret = parser->GetUint16(infoNode, "intensityMaxValue", (uint16_t *)&config->vibratorInfo.intensityMaxValue, 0); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "intensityMaxValue"); - ret = parser->GetUint32(infoNode, "intensityMinValue", (uint32_t *)&config->vibratorInfo.intensityMinValue, 0); + ret = parser->GetUint16(infoNode, "intensityMinValue", (uint16_t *)&config->vibratorInfo.intensityMinValue, 0); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "intensityMinValue"); - ret = parser->GetUint32(infoNode, "frequencyMaxValue", (uint32_t *)&config->vibratorInfo.frequencyMaxValue, 0); + ret = parser->GetUint16(infoNode, "frequencyMaxValue", (uint16_t *)&config->vibratorInfo.frequencyMaxValue, 0); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "frequencyMaxValue"); - ret = parser->GetUint32(infoNode, "frequencyMinValue", (uint32_t *)&config->vibratorInfo.frequencyMinValue, 0); + ret = parser->GetUint16(infoNode, "frequencyMinValue", (uint16_t *)&config->vibratorInfo.frequencyMinValue, 0); CHECK_VIBRATOR_PARSER_RESULT_RETURN_VALUE(ret, "frequencyMinValue"); return ret; -- Gitee From 16db0fa4c12fc8d48d3baa76648524020597f17c Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Wed, 4 Jan 2023 07:06:04 +0000 Subject: [PATCH 56/60] fixed 639679d from https://gitee.com/xuxiaoqing16/drivers_hdf_core/pulls/1662 fix: fix the loadDevice failed problem Signed-off-by: xuxiaoqing --- .../uhdf2/host/test/unittest/devmgr_test.cpp | 32 +++++++++++++++++++ .../uhdf2/manager/src/devmgr_service_full.c | 7 ++-- framework/core/manager/src/devmgr_service.c | 25 +++++++++++---- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp index 2b592a90b..549546066 100644 --- a/adapter/uhdf2/host/test/unittest/devmgr_test.cpp +++ b/adapter/uhdf2/host/test/unittest/devmgr_test.cpp @@ -108,4 +108,36 @@ HWTEST_F(DevMgrTest, DriverUnLoaderTest, TestSize.Level1) ASSERT_TRUE(sampleService == nullptr); } + +HWTEST_F(DevMgrTest, DriverTest, TestSize.Level1) +{ + ASSERT_TRUE(servmgr != nullptr); + ASSERT_TRUE(devmgr != nullptr); + int ret; + constexpr int loop = 100; + + for (int i = 0; i < loop; i++) { + ret = devmgr->LoadDevice(devmgr, TEST_SERVICE_NAME); + ASSERT_EQ(ret, HDF_SUCCESS); + uint32_t cnt = 0; + struct HdfRemoteService *sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + while (sampleService == nullptr && cnt < timeout) { + OsalMSleep(waitTime); + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + cnt++; + } + ASSERT_TRUE(sampleService != nullptr); + + ret = devmgr->UnloadDevice(devmgr, TEST_SERVICE_NAME); + ASSERT_EQ(ret, HDF_SUCCESS); + cnt = 0; + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + while (sampleService != nullptr && cnt < timeout) { + OsalMSleep(waitTime); + sampleService = servmgr->GetService(servmgr, TEST_SERVICE_NAME); + cnt++; + } + ASSERT_TRUE(sampleService == nullptr); + } +} } // namespace OHOS diff --git a/adapter/uhdf2/manager/src/devmgr_service_full.c b/adapter/uhdf2/manager/src/devmgr_service_full.c index 628c277b5..25daa8633 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_full.c +++ b/adapter/uhdf2/manager/src/devmgr_service_full.c @@ -33,11 +33,11 @@ static Map g_hostMap = {0}; static void CleanupDiedHostResources(struct DevHostServiceClnt *hostClnt, struct HdfRemoteService *service) { OsalMutexLock(&hostClnt->hostLock); - hostClnt->hostPid = INVALID_PID; struct DevHostServiceProxy *hostProxy = (struct DevHostServiceProxy *)hostClnt->hostService; if (hostProxy != NULL) { if ((hostProxy->remote != NULL) && ((uintptr_t)hostProxy->remote == (uintptr_t)service)) { HDF_LOGI("%{public}s hostId: %{public}u remove current hostService", __func__, hostClnt->hostId); + hostClnt->hostPid = INVALID_PID; DevHostServiceProxyRecycle(hostProxy); hostClnt->hostService = NULL; HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete); @@ -90,7 +90,10 @@ static int32_t DevmgrServiceFullHandleDeviceHostDied(struct DevHostServiceClnt * struct IDriverInstaller *installer = DriverInstallerGetInstance(); if (installer != NULL && installer->StartDeviceHost != NULL) { HDF_LOGI("%{public}s:%{public}d", __func__, __LINE__); - hostClnt->hostPid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName, true); + int pid = installer->StartDeviceHost(hostClnt->hostId, hostClnt->hostName, true); + OsalMutexLock(&hostClnt->hostLock); + hostClnt->hostPid = pid; + OsalMutexUnlock(&hostClnt->hostLock); return hostClnt->hostPid; } return INVALID_PID; diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 54c1fee31..ac221dbb3 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -19,6 +19,7 @@ #include "osal_time.h" #define HDF_LOG_TAG devmgr_service +#define INVALID_PID (-1) static bool DevmgrServiceDynamicDevInfoFound( const char *svcName, struct DevHostServiceClnt **targetHostClnt, struct HdfDeviceInfo **targetDeviceInfo) @@ -104,11 +105,16 @@ static int DevmgrServiceLoadDevice(struct IDevmgrService *devMgrSvc, const char } dynamic = HdfSListIsEmpty(&hostClnt->unloadDevInfos) && !HdfSListIsEmpty(&hostClnt->dynamicDevInfos); - if (hostClnt->hostPid < 0 && DevmgrServiceStartHostProcess(hostClnt, true, dynamic) != HDF_SUCCESS) { - HDF_LOGW("failed to start device host(%{public}s, %{public}u)", hostClnt->hostName, hostClnt->hostId); - return HDF_FAILURE; - } OsalMutexLock(&hostClnt->hostLock); + if (hostClnt->hostPid < 0) { + OsalMutexUnlock(&hostClnt->hostLock); + if (DevmgrServiceStartHostProcess(hostClnt, true, dynamic) != HDF_SUCCESS) { + HDF_LOGW("failed to start device host(%{public}s, %{public}u)", hostClnt->hostName, hostClnt->hostId); + return HDF_FAILURE; + } + OsalMutexLock(&hostClnt->hostLock); + } + if (hostClnt->hostService == NULL || hostClnt->hostService->AddDevice == NULL) { OsalMutexUnlock(&hostClnt->hostLock); HDF_LOGE("%{public}s load %{public}s failed, hostService is null", __func__, serviceName); @@ -157,17 +163,24 @@ static int DevmgrServiceUnloadDevice(struct IDevmgrService *devMgrSvc, const cha return HDF_FAILURE; } ret = hostClnt->hostService->DelDevice(hostClnt->hostService, deviceInfo->deviceId); - OsalMutexUnlock(&hostClnt->hostLock); if (ret != HDF_SUCCESS) { + OsalMutexUnlock(&hostClnt->hostLock); HDF_LOGI("%{public}s:unload service %{public}s delDevice failed", __func__, serviceName); return ret; } deviceInfo->status = HDF_SERVICE_UNUSABLE; if (!HdfSListIsEmpty(&hostClnt->devices)) { + OsalMutexUnlock(&hostClnt->hostLock); HDF_LOGD("%{public}s host %{public}s devices is not empty", __func__, hostClnt->hostName); return HDF_SUCCESS; } - return DevmgrServiceStopHost(hostClnt); + hostClnt->hostPid = INVALID_PID; + hostClnt->hostService = NULL; // old hostService will be recycled in CleanupDiedHostResources + HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete); + OsalMutexUnlock(&hostClnt->hostLock); + ret = DevmgrServiceStopHost(hostClnt); + + return ret; } int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc) -- Gitee From cf11a68253db190aebb373895f8de84a7e5eddd6 Mon Sep 17 00:00:00 2001 From: yueyan Date: Tue, 28 Mar 2023 11:13:11 +0800 Subject: [PATCH 57/60] fix:devmgr return 305 error code when receive invalid code Signed-off-by: yueyan --- .../test/servmgr/service_manager_hdi_test.cpp | 37 +++++++++++++++++++ .../uhdf2/ipc/include/hdf_remote_adapter_if.h | 3 ++ adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 37 +++++++++++++++++++ adapter/uhdf2/ipc/src/hdf_remote_service.c | 5 +++ .../uhdf2/manager/src/devmgr_service_stub.c | 3 +- .../uhdf2/manager/src/devsvc_manager_stub.c | 4 +- .../uhdf2/shared/include/hdf_remote_service.h | 3 ++ 7 files changed, 88 insertions(+), 4 deletions(-) diff --git a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp index 00fc0c868..f1d5e3287 100644 --- a/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp +++ b/adapter/uhdf2/hdi/test/servmgr/service_manager_hdi_test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -49,6 +50,9 @@ static constexpr int PAYLOAD_NUM = 1234; static constexpr int SMQ_TEST_QUEUE_SIZE = 10; static constexpr int SMQ_TEST_WAIT_TIME = 100; static constexpr int WAIT_LOAD_UNLOAD_TIME = 300; +static constexpr int DEVICE_SERVICE_MANAGER_SA_ID = 5100; +static constexpr int INVALID_CODE = 100; +static constexpr int ERROR_CODE_WITH_INVALID_CODE = 305; class HdfServiceMangerHdiTest : public testing::Test { public: @@ -717,4 +721,37 @@ HWTEST_F(HdfServiceMangerHdiTest, EndSampleHostTest, TestSize.Level1) } ASSERT_TRUE(sampleService == nullptr); } + +HWTEST_F(HdfServiceMangerHdiTest, InvalidCodeTest001, TestSize.Level1) +{ + auto servmgr = OHOS::HDI::ServiceManager::V1_0::IServiceManager::Get(); + ASSERT_NE(servmgr, nullptr); + + sptr remote = servmgr->GetService("hdf_device_manager"); + ASSERT_NE(remote, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + ASSERT_TRUE(data.WriteInterfaceToken(IDeviceManager::GetDescriptor())); + int ret = remote->SendRequest(INVALID_CODE, data, reply, option); + EXPECT_EQ(ret, ERROR_CODE_WITH_INVALID_CODE); +} + +HWTEST_F(HdfServiceMangerHdiTest, InvalidCodeTest002, TestSize.Level1) +{ + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + ASSERT_NE(saManager, nullptr); + sptr remote = saManager->GetSystemAbility(DEVICE_SERVICE_MANAGER_SA_ID); + ASSERT_NE(remote, nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + ASSERT_TRUE(data.WriteInterfaceToken(OHOS::HDI::ServiceManager::V1_0::IServiceManager::GetDescriptor())); + int ret = remote->SendRequest(INVALID_CODE, data, reply, option); + ASSERT_EQ(ret, ERROR_CODE_WITH_INVALID_CODE); +} } // namespace OHOS \ No newline at end of file diff --git a/adapter/uhdf2/ipc/include/hdf_remote_adapter_if.h b/adapter/uhdf2/ipc/include/hdf_remote_adapter_if.h index 14e2d7aaa..d2dd42640 100644 --- a/adapter/uhdf2/ipc/include/hdf_remote_adapter_if.h +++ b/adapter/uhdf2/ipc/include/hdf_remote_adapter_if.h @@ -49,6 +49,9 @@ pid_t HdfRemoteGetCallingPid(void); pid_t HdfRemoteGetCallingUid(void); +int HdfRemoteAdapterDefaultDispatch( + struct HdfRemoteService *service, int code, struct HdfSBuf *data, struct HdfSBuf *reply); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index 8cb5e5d3f..c36c0d46d 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -378,3 +378,40 @@ pid_t HdfRemoteGetCallingUid(void) { return OHOS::IPCSkeleton::GetCallingUid(); } + +int HdfRemoteAdapterDefaultDispatch(struct HdfRemoteService *service, + int code, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); + if (holder == nullptr) { + HDF_LOGE("%{public}s: failed to converts remote to holder", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (holder->remote_ == nullptr) { + HDF_LOGE("%{public}s: invaild holder, holder->remote is nullptr", __func__); + return HDF_ERR_INVALID_PARAM; + } + + OHOS::IPCObjectStub *stub = reinterpret_cast(holder->remote_.GetRefPtr()); + if (stub == nullptr) { + HDF_LOGE("%{public}s: failed to converts holder->remote to IPCObjectStub object", __func__); + return HDF_ERR_INVALID_PARAM; + } + + OHOS::MessageParcel *dataParcel = nullptr; + OHOS::MessageParcel *replyParcel = nullptr; + OHOS::MessageOption option; + + if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (SbufToParcel(data, &replyParcel) != HDF_SUCCESS) { + HDF_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__); + return HDF_ERR_INVALID_PARAM; + } + + return stub->IPCObjectStub::OnRemoteRequest(code, *dataParcel, *replyParcel, option); +} \ No newline at end of file diff --git a/adapter/uhdf2/ipc/src/hdf_remote_service.c b/adapter/uhdf2/ipc/src/hdf_remote_service.c index 952eec775..a9ceac49c 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_service.c +++ b/adapter/uhdf2/ipc/src/hdf_remote_service.c @@ -68,3 +68,8 @@ bool HdfRemoteServiceCheckInterfaceToken(struct HdfRemoteService *service, struc return HdfRemoteAdapterCheckInterfaceToken(service, data); } +int HdfRemoteServiceDefaultDispatch( + struct HdfRemoteService *service, int code, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + return HdfRemoteAdapterDefaultDispatch(service, code, data, reply); +} diff --git a/adapter/uhdf2/manager/src/devmgr_service_stub.c b/adapter/uhdf2/manager/src/devmgr_service_stub.c index 151992403..302d61ef6 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_stub.c +++ b/adapter/uhdf2/manager/src/devmgr_service_stub.c @@ -139,14 +139,13 @@ int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struc ret = DevmgrServiceStubDispatchListAllDevice(super, reply); break; default: - break; + return HdfRemoteServiceDefaultDispatch(serviceStub->remote, code, data, reply); } if (ret != HDF_SUCCESS) { HDF_LOGE("%{public}s devmgr service stub dispach failed, cmd id is %{public}d, ret = %{public}d", __func__, code, ret); HdfSbufWriteInt32(reply, ret); } - return ret; } diff --git a/adapter/uhdf2/manager/src/devsvc_manager_stub.c b/adapter/uhdf2/manager/src/devsvc_manager_stub.c index 1fdd15174..7c2491a29 100644 --- a/adapter/uhdf2/manager/src/devsvc_manager_stub.c +++ b/adapter/uhdf2/manager/src/devsvc_manager_stub.c @@ -502,8 +502,8 @@ int DevSvcManagerStubDispatch(struct HdfRemoteService *service, int code, struct ret = DevSvcManagerStubListAllService(super, data, reply); break; default: - HDF_LOGE("Unknown code : %{public}d", code); - ret = HDF_FAILURE; + ret = HdfRemoteServiceDefaultDispatch(stub->remote, code, data, reply); + break; } return ret; } diff --git a/adapter/uhdf2/shared/include/hdf_remote_service.h b/adapter/uhdf2/shared/include/hdf_remote_service.h index ae71b25da..0440e6e14 100644 --- a/adapter/uhdf2/shared/include/hdf_remote_service.h +++ b/adapter/uhdf2/shared/include/hdf_remote_service.h @@ -58,6 +58,9 @@ bool HdfRemoteServiceWriteInterfaceToken(struct HdfRemoteService *service, struc bool HdfRemoteServiceCheckInterfaceToken(struct HdfRemoteService *service, struct HdfSBuf *data); +int HdfRemoteServiceDefaultDispatch( + struct HdfRemoteService *service, int code, struct HdfSBuf *data, struct HdfSBuf *reply); + #ifdef __cplusplus } #endif /* __cplusplus */ -- Gitee From ddf4fb8ea00cf5419817f1b21d84c02de773d574 Mon Sep 17 00:00:00 2001 From: yueyan Date: Mon, 17 Apr 2023 10:31:40 +0800 Subject: [PATCH 58/60] fix:lock when getting remote object Signed-off-by: yueyan --- adapter/uhdf2/hdi/src/idevmgr_client.cpp | 12 ++++++++++++ adapter/uhdf2/hdi/src/iservmgr_client.cpp | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index 6ae3e4fc9..baee55826 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include + #include #include #include @@ -28,6 +30,8 @@ namespace OHOS { namespace HDI { namespace DeviceManager { namespace V1_0 { +std::mutex g_remoteMutex; + enum DevmgrCmdId : uint32_t { DEVMGR_SERVICE_ATTACH_DEVICE_HOST = 1, DEVMGR_SERVICE_ATTACH_DEVICE, @@ -63,7 +67,9 @@ int32_t DeviceManagerProxy::LoadDevice(const std::string &serviceName) return HDF_FAILURE; } + std::unique_lock lock(g_remoteMutex); int status = Remote()->SendRequest(DEVMGR_SERVICE_LOAD_DEVICE, data, reply, option); + lock.unlock(); if (status != HDF_SUCCESS) { HDF_LOGE("load device failed, %{public}d", status); } @@ -83,7 +89,9 @@ int32_t DeviceManagerProxy::UnloadDevice(const std::string &serviceName) return HDF_FAILURE; } + std::unique_lock lock(g_remoteMutex); int status = Remote()->SendRequest(DEVMGR_SERVICE_UNLOAD_DEVICE, data, reply, option); + lock.unlock(); if (status != HDF_SUCCESS) { HDF_LOGE("unload device failed, %{public}d", status); } @@ -126,7 +134,9 @@ int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInf } MessageOption option; + std::unique_lock lock(g_remoteMutex); int status = Remote()->SendRequest(DEVMGR_SERVICE_LIST_ALL_DEVICE, data, reply, option); + lock.unlock(); if (status != HDF_SUCCESS) { HDF_LOGE("list all device info failed, %{public}d", status); } else { @@ -142,6 +152,8 @@ sptr IDeviceManager::Get() HDF_LOGE("failed to get hdi service manager"); return nullptr; } + + std::unique_lock lock(g_remoteMutex); sptr remote = servmgr->GetService("hdf_device_manager"); if (remote != nullptr) { return hdi_facecast(remote); diff --git a/adapter/uhdf2/hdi/src/iservmgr_client.cpp b/adapter/uhdf2/hdi/src/iservmgr_client.cpp index 0d80a5fc4..a343b2578 100644 --- a/adapter/uhdf2/hdi/src/iservmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/iservmgr_client.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include + #include #include #include @@ -33,6 +35,7 @@ constexpr int DEVSVC_MANAGER_GET_SERVICE = 3; constexpr int DEVSVC_MANAGER_REGISTER_SVCLISTENER = 4; constexpr int DEVSVC_MANAGER_UNREGISTER_SVCLISTENER = 5; constexpr int DEVSVC_MANAGER_LIST_ALL_SERVICE = 6; +std::mutex g_remoteMutex; class ServiceManagerProxy : public IProxyBroker { public: @@ -55,6 +58,8 @@ sptr IServiceManager::Get() HDF_LOGE("failed to get sa manager"); return nullptr; } + + std::unique_lock lock(g_remoteMutex); sptr remote = saManager->GetSystemAbility(DEVICE_SERVICE_MANAGER_SA_ID); if (remote != nullptr) { return new ServiceManagerProxy(remote); @@ -76,7 +81,9 @@ int32_t ServiceManagerProxy::RegisterServiceStatusListener( return HDF_FAILURE; } + std::unique_lock lock(g_remoteMutex); int status = Remote()->SendRequest(DEVSVC_MANAGER_REGISTER_SVCLISTENER, data, reply, option); + lock.unlock(); if (status) { HDF_LOGE("failed to register servstat listener, %{public}d", status); } @@ -93,7 +100,9 @@ int32_t ServiceManagerProxy::UnregisterServiceStatusListener(::OHOS::sptr lock(g_remoteMutex); int status = Remote()->SendRequest(DEVSVC_MANAGER_UNREGISTER_SVCLISTENER, data, reply, option); + lock.unlock(); if (status) { HDF_LOGE("failed to unregister servstat listener, %{public}d", status); } @@ -109,7 +118,9 @@ sptr ServiceManagerProxy::GetService(const char *serviceName) } MessageOption option; + std::unique_lock lock(g_remoteMutex); int status = Remote()->SendRequest(DEVSVC_MANAGER_GET_SERVICE, data, reply, option); + lock.unlock(); if (status) { HDF_LOGE("get hdi service %{public}s failed, %{public}d", serviceName, status); return nullptr; @@ -143,7 +154,9 @@ int32_t ServiceManagerProxy::ListAllService(std::vector &service } MessageOption option; + std::unique_lock lock(g_remoteMutex); int status = Remote()->SendRequest(DEVSVC_MANAGER_LIST_ALL_SERVICE, data, reply, option); + lock.unlock(); if (status != HDF_SUCCESS) { HDF_LOGE("list all service info failed, %{public}d", status); return status; -- Gitee From 9088b4a2d9c34dd843416d859ed3414ebff903b6 Mon Sep 17 00:00:00 2001 From: guowen666 Date: Thu, 25 May 2023 09:47:46 +0800 Subject: [PATCH 59/60] fixed befc2df from https://gitee.com/guowen666/drivers_hdf_core/pulls/1896 fix input event report bug Signed-off-by: guowen666 --- framework/model/input/driver/event_hub.c | 31 +++++++++++-- framework/model/input/driver/event_hub.h | 1 + .../model/input/driver/hdf_hid_adapter.c | 23 ++++++---- .../input/driver/hdf_input_device_manager.c | 45 ++++++++++++++++++- .../input/driver/hdf_input_device_manager.h | 7 +++ 5 files changed, 94 insertions(+), 13 deletions(-) diff --git a/framework/model/input/driver/event_hub.c b/framework/model/input/driver/event_hub.c index dc2f52a6d..6ffc3b554 100644 --- a/framework/model/input/driver/event_hub.c +++ b/framework/model/input/driver/event_hub.c @@ -12,6 +12,7 @@ #define SEC_TO_USEC 1000000 +#ifdef __LITEOS_M__ static void SendFramePackages(InputDevice *inputDev) { struct HdfDeviceObject *hdfDev = inputDev->hdfDevObj; @@ -21,18 +22,32 @@ static void SendFramePackages(InputDevice *inputDev) } HdfDeviceSendEvent(hdfDev, 0, inputDev->pkgBuf); } +#else +void EventQueueWorkEntry(void *arg) +{ + InputDevice *inputDev = (InputDevice *)arg; + if (inputDev == NULL) { + HDF_LOGE("%s: inputDev is NULL", __func__); + return; + } + + HdfDeviceSendEvent(inputDev->hdfDevObj, 0, inputDev->pkgBuf); + HdfSbufFlush(inputDev->pkgBuf); +} +#endif // __LITEOS_M__ void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t value) { OsalTimespec time; EventPackage package = {0}; + uint32_t flag; InputManager *inputManager = GetInputManager(); if (inputDev == NULL) { HDF_LOGE("%s: parm is null", __func__); return; } - OsalMutexLock(&inputManager->mutex); + OsalSpinLockIrqSave(&inputManager->lock, &flag); package.type = type; package.code = code; package.value = value; @@ -59,12 +74,22 @@ void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t } if (!inputDev->errFrameFlag) { +#ifdef __LITEOS_M__ SendFramePackages(inputDev); +#else + if (!HdfAddWork(&inputDev->eventWorkQueue, &inputDev->eventWork)) { + HDF_LOGE("%s: Add event work queue failed", __func__); + OsalSpinUnlockIrqRestore(&inputManager->lock, &flag); + return; + } +#endif // __LITEOS_M__ } inputDev->pkgCount = 0; - HdfSbufFlush(inputDev->pkgBuf); inputDev->errFrameFlag = false; +#ifdef __LITEOS_M__ + HdfSbufFlush(inputDev->pkgBuf); +#endif // __LITEOS_M__ } - OsalMutexUnlock(&inputManager->mutex); + OsalSpinUnlockIrqRestore(&inputManager->lock, &flag); } \ No newline at end of file diff --git a/framework/model/input/driver/event_hub.h b/framework/model/input/driver/event_hub.h index 97dec781d..f7ed1a1aa 100644 --- a/framework/model/input/driver/event_hub.h +++ b/framework/model/input/driver/event_hub.h @@ -27,6 +27,7 @@ typedef struct { } EventPackage; void PushOnePackage(InputDevice *inputDev, uint32_t type, uint32_t code, int32_t value); +void EventQueueWorkEntry(void *arg); static inline void ReportAbs(InputDevice *inputDev, uint32_t code, int32_t value) { diff --git a/framework/model/input/driver/hdf_hid_adapter.c b/framework/model/input/driver/hdf_hid_adapter.c index a54cdb5ee..a5f714c62 100644 --- a/framework/model/input/driver/hdf_hid_adapter.c +++ b/framework/model/input/driver/hdf_hid_adapter.c @@ -33,6 +33,15 @@ HidInfo *g_cachedInfo[MAX_INPUT_DEV_NUM]; uint32_t g_kbdcode = 0; OsalTimer g_timer; +static bool InputDriverLoaded(void) +{ + InputManager* g_inputManager = GetInputManager(); + if ((g_inputManager != NULL) && (g_inputManager->initialized != false)) { + return true; + } + return false; +} + static bool HaveHidCache(void) { if (cachedHid[0] == NULL) { @@ -224,15 +233,6 @@ static void CacheHid(InputDevice* inputDev) } } -static bool InputDriverLoaded(void) -{ - InputManager* g_inputManager = GetInputManager(); - if ((g_inputManager != NULL) && (g_inputManager->initialized != false)) { - return true; - } - return false; -} - void* HidRegisterHdfInputDev(HidInfo *info) { InputDevice* inputDev = HidConstructInputDev(info); @@ -288,6 +288,11 @@ static void RepateEvent(const InputDevice *device) void HidReportEvent(const void *inputDev, uint32_t type, uint32_t code, int32_t value) { + bool loaded = InputDriverLoaded(); + if (!loaded) { + HDF_LOGD("%s: device not loaded", __func__); + return; + } #ifdef CONFIG_DFX_ZEROHUNG if (type == EV_KEY && code == KEY_POWER) hung_wp_screen_powerkey_ncb(value); diff --git a/framework/model/input/driver/hdf_input_device_manager.c b/framework/model/input/driver/hdf_input_device_manager.c index 9a4f60ebd..e63a66a32 100644 --- a/framework/model/input/driver/hdf_input_device_manager.c +++ b/framework/model/input/driver/hdf_input_device_manager.c @@ -16,6 +16,7 @@ #define NODE_MODE 0660 #define SERVICE_NAME_LEN 24 +#define QUEUE_NAME_LEN 18 #define INPUT_DEV_EXIST 1 #define INPUT_DEV_NOT_EXIST 0 #define INPUTDEV_FIRST_ID 2 @@ -286,6 +287,30 @@ static int32_t AllocDeviceID(InputDevice *inputDev) return HDF_FAILURE; } +#ifndef __LITEOS_M__ +static int32_t InitEventWorkQueue(InputDevice *inputDev) +{ + char queueName[QUEUE_NAME_LEN] = {0}; + + int32_t len = (inputDev->devId < PLACEHOLDER_LIMIT) ? 1 : PLACEHOLDER_LENGTH; + int32_t ret = snprintf_s(queueName, QUEUE_NAME_LEN, strlen("hdf_event") + len + strlen("_queue"), "%s%u%s", + "hdf_event", inputDev->devId, "_queue"); + if (ret < 0) { + HDF_LOGE("%s: snprintf_s failed", __func__); + return HDF_FAILURE; + } + if (HdfWorkQueueInit(&inputDev->eventWorkQueue, queueName) != HDF_SUCCESS) { + HDF_LOGE("%s: device %s init work queue failed", __func__, inputDev->devName); + return HDF_FAILURE; + } + if (HdfWorkInit(&inputDev->eventWork, EventQueueWorkEntry, inputDev) != HDF_SUCCESS) { + HDF_LOGE("%s: gwgw create event thread failed", __func__); + return HDF_FAILURE; + } + return HDF_SUCCESS; +} +#endif // __LITEOS_M__ + int32_t RegisterInputDevice(InputDevice *inputDev) { int32_t ret; @@ -315,7 +340,12 @@ int32_t RegisterInputDevice(InputDevice *inputDev) if (ret != HDF_SUCCESS) { goto EXIT1; } - +#ifndef __LITEOS_M__ + ret = InitEventWorkQueue(inputDev); + if (ret != HDF_SUCCESS) { + goto EXIT1; + } +#endif // __LITEOS_M__ AddInputDevice(inputDev); OsalMutexUnlock(&g_inputManager->mutex); HDF_LOGI("%s: exit succ, devCount is %d", __func__, g_inputManager->devCount); @@ -357,7 +387,12 @@ void UnregisterInputDevice(InputDevice *inputDev) } HdfSbufRecycle(inputDev->eventBuf); inputDev->eventBuf = NULL; +#ifndef __LITEOS_M__ + HdfWorkQueueDestroy(&inputDev->eventWorkQueue); + HdfWorkDestroy(&inputDev->eventWork); +#endif // __LITEOS_M__ OsalMemFree(inputDev); + inputDev = NULL; OsalMutexUnlock(&g_inputManager->mutex); HDF_LOGI("%s: exit succ, devCount is %d", __func__, g_inputManager->devCount); return; @@ -453,6 +488,13 @@ static int32_t HdfInputManagerInit(struct HdfDeviceObject *device) g_inputManager = NULL; return HDF_FAILURE; } + + if (OsalSpinInit(&g_inputManager->lock) != HDF_SUCCESS) { + HDF_LOGE("%s: spin lock init failed", __func__); + OsalMemFree(g_inputManager); + g_inputManager = NULL; + return HDF_FAILURE; + } g_inputManager->initialized = true; g_inputManager->hdfDevObj = device; HDF_LOGI("%s: exit succ", __func__); @@ -467,6 +509,7 @@ static void HdfInputManagerRelease(struct HdfDeviceObject *device) } if (g_inputManager != NULL) { OsalMutexDestroy(&g_inputManager->mutex); + OsalSpinDestroy(&g_inputManager->lock); OsalMemFree(g_inputManager); g_inputManager = NULL; } diff --git a/framework/model/input/driver/hdf_input_device_manager.h b/framework/model/input/driver/hdf_input_device_manager.h index 00d5e1655..74ecd6cab 100644 --- a/framework/model/input/driver/hdf_input_device_manager.h +++ b/framework/model/input/driver/hdf_input_device_manager.h @@ -11,8 +11,10 @@ #include "input-event-codes.h" #include "osal_mutex.h" +#include "osal_spinlock.h" #include "hdf_types.h" #include "hdf_device_desc.h" +#include "hdf_workqueue.h" #ifdef HDF_LOG_TAG #undef HDF_LOG_TAG @@ -103,6 +105,10 @@ typedef struct { typedef struct InputDeviceInfo { struct HdfDeviceObject *hdfDevObj; +#ifndef __LITEOS_M__ + HdfWorkQueue eventWorkQueue; + HdfWork eventWork; +#endif // __LITEOS_M__ uint32_t devId; uint32_t devType; const char *devName; @@ -121,6 +127,7 @@ typedef struct { struct HdfDeviceObject *hdfDevObj; uint32_t devCount; struct OsalMutex mutex; + OsalSpinlock lock; bool initialized; InputDevice *inputDevList; } InputManager; -- Gitee From f9115eb185e688c99683cef697a11245f7ffb731 Mon Sep 17 00:00:00 2001 From: guowen Date: Mon, 29 May 2023 01:41:37 +0000 Subject: [PATCH 60/60] update framework/model/input/driver/hdf_input_device_manager.c. Signed-off-by: guowen --- framework/model/input/driver/hdf_input_device_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/model/input/driver/hdf_input_device_manager.c b/framework/model/input/driver/hdf_input_device_manager.c index e63a66a32..175a74d78 100644 --- a/framework/model/input/driver/hdf_input_device_manager.c +++ b/framework/model/input/driver/hdf_input_device_manager.c @@ -304,7 +304,7 @@ static int32_t InitEventWorkQueue(InputDevice *inputDev) return HDF_FAILURE; } if (HdfWorkInit(&inputDev->eventWork, EventQueueWorkEntry, inputDev) != HDF_SUCCESS) { - HDF_LOGE("%s: gwgw create event thread failed", __func__); + HDF_LOGE("%s: create event thread failed", __func__); return HDF_FAILURE; } return HDF_SUCCESS; -- Gitee