1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LOOP_SYSTEST_H 17 #define LOOP_SYSTEST_H 18 19 #include <stdlib.h> 20 #include <string.h> 21 #include <fcntl.h> 22 23 #include "loop_event.h" 24 #include "le_socket.h" 25 #include "le_task.h" 26 #include "list.h" 27 28 #ifndef BASE_DIR 29 #define BASE_DIR "" 30 #endif 31 32 #define SOCKET_NAME "looptest" 33 #if defined(__MUSL__) 34 #define SOCKET_DIR BASEDIR "/dev/unix/socket" 35 #else 36 #define SOCKET_DIR BASEDIR "/dev/socket" 37 #endif 38 39 #define MIN_TIME 0 40 #define MAX_TIME INT_MAX 41 #define INVALID_OFFSET 0xffffffff 42 #define MAX_MSG_LEN 128 43 #define MAX_FD_COUNT 16 44 #define DIR_MODE 0711 45 46 #define TLV_NAME_LEN 32 47 #define MAX_MSG_BLOCK_LEN (4 * 1024) 48 #define RECV_BLOCK_LEN 1024 49 #define MAX_MSG_TOTAL_LENGTH (64 * 1024) 50 #define EXTRAINFO_TOTAL_LENGTH_MAX (32 * 1024) 51 #define MAX_TLV_COUNT 128 52 #define MSG_MAGIC 0xEF201234 53 54 typedef enum { 55 OK = 0, 56 SYSTEM_ERROR = 0xD000000, 57 ARG_INVALID, 58 MSG_INVALID, 59 MSG_TOO_LONG, 60 TLV_NOT_SUPPORT, 61 TLV_NONE, 62 SANDBOX_NONE, 63 SANDBOX_LOAD_FAIL, 64 SANDBOX_INVALID, 65 SANDBOX_MOUNT_FAIL, 66 TIMEOUT, 67 CHILD_CRASH, 68 NATIVE_NOT_SUPPORT, 69 ACCESS_TOKEN_INVALID, 70 PERMISSION_NOT_SUPPORT, 71 BUFFER_NOT_ENOUGH, 72 FORK_FAIL, 73 DEBUG_MODE_NOT_SUPPORT, 74 ERROR_UTILS_MEM_FAIL, 75 ERROR_FILE_RMDIR_FAIL, 76 NODE_EXIST, 77 } ErrorCode; 78 79 typedef enum { 80 TLV_BUNDLE_INFO = 0, 81 TLV_MSG_FLAGS, 82 TLV_DAC_INFO, 83 TLV_DOMAIN_INFO, 84 TLV_OWNER_INFO, 85 TLV_ACCESS_TOKEN_INFO, 86 TLV_PERMISSION, 87 TLV_INTERNET_INFO, 88 TLV_RENDER_TERMINATION_INFO, 89 TLV_MAX 90 } MsgTlvType; 91 92 typedef enum { 93 MSG_NORMAL = 0, 94 MSG_GET_RENDER_TERMINATION_STATUS, 95 MSG_NATIVE_PROCESS, 96 MSG_DUMP, 97 MSG_BEGET, 98 MSG_BEGET_TIME, 99 MSG_UPDATE_MOUNT_POINTS, 100 MSG_RESTART, 101 MAX_TYPE_INVALID 102 } MsgType; 103 104 typedef Result_ { 105 int result; 106 pid_t pid; 107 } Result; 108 109 typedef struct Message_ { 110 uint32_t magic; 111 uint32_t msgType; 112 uint32_t msgLen; 113 uint32_t msgId; 114 uint32_t tlvCount; 115 char buffer[MAX_MSG_LEN]; 116 } Message; 117 118 typedef struct { 119 Message msgHdr; 120 Result result; 121 } ResponseMsg; 122 123 typedef struct { 124 uint32_t count; 125 uint32_t flags[0]; 126 } MsgFlags; 127 128 typedef struct { 129 struct ListNode node; 130 uint32_t reqId; 131 uint32_t retryCount; 132 int fdCount; 133 int fds[MAX_FD_COUNT]; 134 MsgFlags *msgFlags; 135 MsgFlags *permissionFlags; 136 Message *msg; 137 struct ListNode msgBlocks; // 保存实际的消息数据 138 } ReqMsgNode; 139 140 #endif