From 80c6e2c84aac7eec76f17dc28f0e3a257798373a Mon Sep 17 00:00:00 2001 From: zhangyuhang72 Date: Mon, 9 Sep 2024 11:43:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0StartNative=E5=AD=90=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyuhang72 Change-Id: Iba8a1be3e1842d6594b6c326759228ce4ca9fe87 --- .../child_process/libchild_process.ndk.json | 9 +- .../child_process/native_child_process.h | 105 ++++++++++++++++++ .../coreImpl/check/rules/perssion_rule.json | 9 ++ 3 files changed, 122 insertions(+), 1 deletion(-) diff --git a/ability/ability_runtime/child_process/libchild_process.ndk.json b/ability/ability_runtime/child_process/libchild_process.ndk.json index 6206b6310..b00d0d189 100644 --- a/ability/ability_runtime/child_process/libchild_process.ndk.json +++ b/ability/ability_runtime/child_process/libchild_process.ndk.json @@ -1,3 +1,10 @@ [ - { "name": "OH_Ability_CreateNativeChildProcess" } + { + "first_introduced": "12", + "name": "OH_Ability_CreateNativeChildProcess" + }, + { + "first_introduced": "13", + "name": "OH_Ability_StartNativeChildProcess" + } ] \ No newline at end of file diff --git a/ability/ability_runtime/child_process/native_child_process.h b/ability/ability_runtime/child_process/native_child_process.h index 5cce2512a..af736450b 100644 --- a/ability/ability_runtime/child_process/native_child_process.h +++ b/ability/ability_runtime/child_process/native_child_process.h @@ -173,6 +173,111 @@ typedef void (*OH_Ability_OnNativeChildProcessStarted)(int errCode, OHIPCRemoteP int OH_Ability_CreateNativeChildProcess(const char* libName, OH_Ability_OnNativeChildProcessStarted onProcessStarted); +/** + * @brief The info of the file descriptors passed to child process. + * @since 13 + */ +typedef struct NativeChildProcess_Fd { + /** the key of the file descriptor. */ + char* fdName; + + /** the value of the file descriptor. */ + int32_t fd; + + /** the next pointer of the linked list. */ + struct NativeChildProcess_Fd* next; +} NativeChildProcess_Fd; + +/** + * @brief The list of the info of the file descriptors passed to child process. + * @since 13 + */ +typedef struct NativeChildProcess_FdList { + /** the head of the list. + * For details, see {@link NativeChildProcess_Fd}. + */ + struct NativeChildProcess_Fd* head; +} NativeChildProcess_FdList; + +/** + * @brief Enumerates the isolation modes used by the native child process module. + * @since 13 + */ +typedef enum NativeChildProcess_IsolationMode { + /** + * Normal isolation mode, parent process shares the same sandbox or internet with the child process. + */ + NCP_ISOLATION_MODE_NORMAL = 0, + + /** + * Isolated mode, parent process does not share the same sandbox or internet with the child process. + */ + NCP_ISOLATION_MODE_ISOLATED = 1, +} NativeChildProcess_IsolationMode; + +/** + * @brief The options used by the child process. + * @since 13 + */ +typedef struct NativeChildProcess_Options { + /** the isolation mode used by the child process. + * For details, see {@link NativeChildProcess_IsolationMode}. + */ + NativeChildProcess_IsolationMode isolationMode; + + /** reserved field for future extension purposes */ + int64_t reserved; +} NativeChildProcess_Options; + +/** + * @brief The arguments passed to the child process. + * @since 13 + */ +typedef struct NativeChildProcess_Args { + /** the entry parameter. */ + char* entryParams; + + /** the list of the info of the file descriptors passed to child process. + * For details, see {@link NativeChildProcess_FdList}. + */ + struct NativeChildProcess_FdList fdList; +} NativeChildProcess_Args; + +/** + * @brief Starts a child process, loads the specified dynamic library file. + * + * The dynamic library specified must implement a function with NativeChildProcess_Args as a + * pamameter(function name can be customized), and export the function, such as:\n + * 1. void Main(NativeChildProcess_Args args); + * + * The processing logic sequence is shown in the following pseudocode: \n + * Main process: \n + * 1. OH_Ability_StartNativeChildProcess(entryPoint, args, options)\n + * Child process: \n + * 2. dlopen(libName)\n + * 3. dlsym("Main")\n + * 4. Main(args)\n + * 5. The child process exits after the Main(args) function is returned \n + * + * @param entry Dynamic library and entry function loaded in child process, such as "libEntry.so:Main". + * The value cannot be nullptr. + * @param args The arguments passed to the child process. + * For details, see {@link NativeChildProcess_Args}. + * @param options The child process options. + * For details, see {@link NativeChildProcess_Options}. + * @param pid The started child process id. + * @return Returns {@link NCP_NO_ERROR} if the call is successful.\n + * Returns {@link NCP_ERR_INVALID_PARAM} if the dynamic library name or callback function pointer is invalid.\n + * Returns {@link NCP_ERR_NOT_SUPPORTED} if the device does not support the creation of native child processes.\n + * Returns {@link NCP_ERR_ALREADY_IN_CHILD} if it is not allowed to create another child process in the child process.\n + * Returns {@link NCP_ERR_MAX_CHILD_PROCESSES_REACHED} if the maximum number of native child processes is reached.\n + * For details, see {@link Ability_NativeChildProcess_ErrCode}. + * @see OH_Ability_OnNativeChildProcessStarted + * @since 13 + */ +Ability_NativeChildProcess_ErrCode OH_Ability_StartNativeChildProcess( + const char* entry, NativeChildProcess_Args args, + NativeChildProcess_Options options, int32_t *pid); #ifdef __cplusplus } // extern "C" diff --git a/build-tools/capi_parser/src/coreImpl/check/rules/perssion_rule.json b/build-tools/capi_parser/src/coreImpl/check/rules/perssion_rule.json index 86ddddeac..1f24bce79 100644 --- a/build-tools/capi_parser/src/coreImpl/check/rules/perssion_rule.json +++ b/build-tools/capi_parser/src/coreImpl/check/rules/perssion_rule.json @@ -2581,6 +2581,15 @@ "availableLevel": "system_basic", "provisionEnable": true, "distributedSceneEnable": false + }, + { + "name": "ohos.permission.START_NATIVE_CHILD_PROCESS", + "grantMode": "system_grant", + "since": 12, + "deprecated": "", + "availableLevel": "system_basic", + "provisionEnable": true, + "distributedSceneEnable": false } ] } -- Gitee