From 105f4cc6d1c9d2f227d1e5ea08d9adf04001eace Mon Sep 17 00:00:00 2001 From: h60047265 Date: Wed, 26 Feb 2025 19:13:25 +0800 Subject: [PATCH] =?UTF-8?q?samgr=5Flite=E5=91=8A=E8=AD=A6=E6=B8=85?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h60047265 --- .../broadcast/source/pub_sub_implement.c | 2 +- samgr/adapter/posix/lock_free_queue.c | 4 +-- samgr/source/task_manager.c | 2 +- samgr_endpoint/source/default_client_rpc.c | 7 ++-- samgr_endpoint/source/endpoint_rpc.c | 20 ++++++++--- samgr_endpoint/source/sa_store.c | 2 +- .../source/samgr_small_ipc_adapter.c | 20 +++++++---- samgr_endpoint/source/token_bucket.c | 4 +-- samgr_server/source/samgr_server_rpc.c | 34 +++++++++---------- 9 files changed, 59 insertions(+), 36 deletions(-) diff --git a/communication/broadcast/source/pub_sub_implement.c b/communication/broadcast/source/pub_sub_implement.c index 0718d2a..3b3e05d 100644 --- a/communication/broadcast/source/pub_sub_implement.c +++ b/communication/broadcast/source/pub_sub_implement.c @@ -228,7 +228,7 @@ static BOOL ImmediatelyPublish(PubSubFeature *feature, const Topic *topic, const continue; } - Response response = {item->consumer, 0}; + Response response = {item->consumer, 0, NULL}; int ret = SAMGR_SendSharedDirectRequest(item->consumer->identity, request, &response, &token, DefaultHandle); if (ret != EC_SUCCESS) { needAync = FALSE; diff --git a/samgr/adapter/posix/lock_free_queue.c b/samgr/adapter/posix/lock_free_queue.c index 91de561..ce49550 100644 --- a/samgr/adapter/posix/lock_free_queue.c +++ b/samgr/adapter/posix/lock_free_queue.c @@ -34,8 +34,8 @@ LockFreeQueue *LFQUE_Create(int size, int count) } queue->write = 0; queue->read = 0; - queue->itemSize = size; - queue->totalSize = total; + queue->itemSize = (uint32)size; + queue->totalSize = (uint32)total; return queue; } diff --git a/samgr/source/task_manager.c b/samgr/source/task_manager.c index 4128bfc..0949b23 100644 --- a/samgr/source/task_manager.c +++ b/samgr/source/task_manager.c @@ -126,7 +126,7 @@ static void *TaskEntry(void *argv) THREAD_SetThreadLocal(argv); while (TRUE) { Exchange exchange; - uint32 msgRcvRet = SAMGR_MsgRecv((MQueueId)argv, (uint8 *)&exchange, sizeof(Exchange)); + uint32 msgRcvRet = (uint32)SAMGR_MsgRecv((MQueueId)argv, (uint8 *)&exchange, sizeof(Exchange)); if (msgRcvRet != EC_SUCCESS) { continue; } diff --git a/samgr_endpoint/source/default_client_rpc.c b/samgr_endpoint/source/default_client_rpc.c index d7cc4b7..3017c9b 100644 --- a/samgr_endpoint/source/default_client_rpc.c +++ b/samgr_endpoint/source/default_client_rpc.c @@ -207,13 +207,14 @@ static void OnServiceExit(void *argv) header->target.handle = INVALID_INDEX; header->target.token = INVALID_INDEX; header->target.cookie = INVALID_INDEX; - HILOG_ERROR(HILOG_MODULE_SAMGR, "Miss the remote service<%u, %u>!", header->target.handle, header->target.token); + HILOG_ERROR(HILOG_MODULE_SAMGR, "Miss the remote service<%d>!", header->target.handle); } static SvcIdentity QueryIdentity(const char *service, const char *feature) { IpcIo req; uint8 data[MAX_DATA_LEN]; + SvcIdentity target = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX}; IpcIoInit(&req, data, MAX_DATA_LEN, 0); WriteInt32(&req, 0); WriteUint32(&req, RES_FEATURE); @@ -226,12 +227,14 @@ static SvcIdentity QueryIdentity(const char *service, const char *feature) IpcIo reply; void *replyBuf = NULL; const SvcIdentity *samgr = GetContextObject(); + if (samgr == NULL) { + return target; + } MessageOption flag; MessageOptionInit(&flag); int ret = SendRequest(*samgr, INVALID_INDEX, &req, &reply, flag, (uintptr_t *)&replyBuf); int32_t saRet = EC_FAILURE; ret = (ret != EC_SUCCESS) ? EC_FAILURE : ReadInt32(&reply, &saRet); - SvcIdentity target = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX}; if (saRet == EC_SUCCESS) { ReadRemoteObject(&reply, &target); uint32_t token; diff --git a/samgr_endpoint/source/endpoint_rpc.c b/samgr_endpoint/source/endpoint_rpc.c index 9a40af6..f3048b7 100644 --- a/samgr_endpoint/source/endpoint_rpc.c +++ b/samgr_endpoint/source/endpoint_rpc.c @@ -48,7 +48,7 @@ Endpoint *SAMGR_CreateEndpoint(const char *name, RegisterEndpoint registry) endpoint->routers = VECTOR_Make((VECTOR_Key)GetIServerProxy, (VECTOR_Compare)CompareIServerProxy); endpoint->name = name; endpoint->running = FALSE; - endpoint->identity.handle = (uint32_t)INVALID_INDEX; + endpoint->identity.handle = (int32_t)INVALID_INDEX; endpoint->identity.token = (uint32_t)INVALID_INDEX; endpoint->identity.cookie = (uint32_t)INVALID_INDEX; endpoint->registerEP = (registry == NULL) ? RegisterRemoteEndpoint : registry; @@ -116,6 +116,9 @@ int32 SAMGR_AddSysCap(const Endpoint *endpoint, const char *sysCap, BOOL isReg) IpcIo reply; void *replyBuf = NULL; SvcIdentity *samgr = GetContextObject(); + if (samgr == NULL) { + return EC_INVALID; + } MessageOption option; MessageOptionInit(&option); int ret = SendRequest(*samgr, INVALID_INDEX, &req, &reply, @@ -151,6 +154,9 @@ int32 SAMGR_GetSysCap(const Endpoint *endpoint, const char *sysCap, BOOL *isReg) IpcIo reply; void *replyBuf = NULL; SvcIdentity *samgr = GetContextObject(); + if (samgr == NULL) { + return EC_INVALID; + } MessageOption option; MessageOptionInit(&option); int ret = SendRequest(*samgr, INVALID_INDEX, &req, &reply, @@ -181,6 +187,9 @@ static int SendGetAllSysCapsRequest(const Endpoint *endpoint, uint32 startIdx, I WriteUint32(&req, OP_ALL); WriteUint32(&req, startIdx); SvcIdentity *samgr = GetContextObject(); + if (samgr == NULL) { + return EC_INVALID; + } MessageOption option; MessageOptionInit(&option); int ret = SendRequest(*samgr, INVALID_INDEX, &req, reply, @@ -192,6 +201,9 @@ static int SendGetAllSysCapsRequest(const Endpoint *endpoint, uint32 startIdx, I static int32 ParseGetAllSysCapsReply(IpcIo *reply, char sysCaps[MAX_SYSCAP_NUM][MAX_SYSCAP_NAME_LEN], int32 *sysCapNum, BOOL *isEnd, uint32 *nextRequestIdx) { + if (isEnd == NULL) { + return EC_INVALID; + } int32_t ret; if (ReadInt32(reply, &ret)) { if (ret != EC_SUCCESS) { @@ -272,8 +284,8 @@ int SAMGR_ProcPolicy(const Endpoint *endpoint, const SaName *saName, int token) SAMGR_Free(policy); continue; } - HILOG_INFO(HILOG_MODULE_SAMGR, "Register server sa<%s, %s> id<%lu, %u> retry:%d ret:%d!", - saName->service, saName->feature, saInfo.handle, saInfo.token, retry, ret); + HILOG_INFO(HILOG_MODULE_SAMGR, "Register server sa<%s, %s> id<%d> retry:%d ret:%d!", + saName->service, saName->feature, saInfo.handle, retry, ret); ret = AddPolicyToRouter(endpoint, &saInfo, policy, policyNum); SAMGR_Free(policy); if (ret == EC_SUCCESS) { @@ -293,7 +305,7 @@ static int AddPolicyToRouter(const Endpoint *endpoint, const SvcIdentity *saInfo Router *router = VECTOR_At((Vector *)&endpoint->routers, saInfo->token); if (router == NULL) { - HILOG_ERROR(HILOG_MODULE_SAMGR, "Router <%s, %u> is NULL", endpoint->name, saInfo->token); + HILOG_ERROR(HILOG_MODULE_SAMGR, "Router <%s> is NULL", endpoint->name); return EC_INVALID; } diff --git a/samgr_endpoint/source/sa_store.c b/samgr_endpoint/source/sa_store.c index 016c777..7dfc868 100644 --- a/samgr_endpoint/source/sa_store.c +++ b/samgr_endpoint/source/sa_store.c @@ -216,7 +216,7 @@ SvcIdentity SASTORA_Find(SAStore *saStore, const char *service, const char *feat return identity; } - identity.handle = curNode->info.handle; + identity.handle = (int32_t)curNode->info.handle; identity.cookie = curNode->info.cookie; FeatureNode *featureNode = FindFeatureByName(curNode->info.head, feature); if (featureNode != NULL) { diff --git a/samgr_endpoint/source/samgr_small_ipc_adapter.c b/samgr_endpoint/source/samgr_small_ipc_adapter.c index 2749f88..ad287df 100644 --- a/samgr_endpoint/source/samgr_small_ipc_adapter.c +++ b/samgr_endpoint/source/samgr_small_ipc_adapter.c @@ -50,7 +50,9 @@ int ClientRegisterRemoteEndpoint(SvcIdentity *identity, int token, const char *s MessageOption option; MessageOptionInit(&option); SvcIdentity *samgr = GetContextObject(); - + if (samgr == NULL) { + continue; + } int err = SendRequest(*samgr, INVALID_INDEX, &req, &reply, option, (uintptr_t *)&replyBuf); if (err == EC_SUCCESS) { ret = ReadInt32(&reply, &identity->handle); @@ -112,6 +114,9 @@ static void *Receive(void *argv) registerEpArg->token, registerEpArg->service, registerEpArg->feature); if (ret == EC_SUCCESS) { SvcIdentity *samgr = GetContextObject(); + if (samgr == NULL) { + continue; + } (void)RemoveDeathRecipient(*samgr, registerEpArg->endpoint->deadId); (void)AddDeathRecipient(*samgr, OnSamgrServerExit, registerEpArg->endpoint, ®isterEpArg->endpoint->deadId); @@ -149,7 +154,7 @@ static int RegisterRemoteFeatures(Endpoint *endpoint) continue; } identity.handle = endpoint->identity.handle; - identity.token = i; + identity.token = (uintptr_t)i; int ret = RegisterIdentity(&(router->saName), &identity, &(router->policy), &(router->policyNum)); if (ret == EC_SUCCESS) { @@ -178,6 +183,9 @@ int RegisterIdentity(const SaName *saName, SvcIdentity *saInfo, PolicyTrans **po IpcIo reply; void *replyBuf = NULL; SvcIdentity *samgr = GetContextObject(); + if (samgr == NULL) { + return EC_INVALID; + } MessageOption option; MessageOptionInit(&option); int ret = SendRequest(*samgr, INVALID_INDEX, &req, &reply, option, @@ -205,12 +213,12 @@ static int Dispatch(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption opti goto ERROR; } if (TB_CheckMessage(&endpoint->bucket) == BUCKET_BUSY) { - HILOG_WARN(HILOG_MODULE_SAMGR, "Flow Control <%u> is NULL", token); + HILOG_WARN(HILOG_MODULE_SAMGR, "Flow Control token is NULL"); goto ERROR; } Router *router = VECTOR_At(&endpoint->routers, token); if (router == NULL) { - HILOG_ERROR(HILOG_MODULE_SAMGR, "Router <%s, %u> is NULL", endpoint->name, token); + HILOG_ERROR(HILOG_MODULE_SAMGR, "Router <%s> is NULL", endpoint->name); goto ERROR; } @@ -236,7 +244,7 @@ static void HandleIpc(const Request *request, const Response *response) HILOG_ERROR(HILOG_MODULE_SAMGR, "Invalid IPC router!"); return; } - uid_t uid = GetCallingUid(); + uid_t uid = (uid_t)GetCallingUid(); if ((strcmp(router->saName.service, SAMGR_SERVICE) != 0) && !JudgePolicy(uid, (const PolicyTrans *)(router->policy), router->policyNum)) { HILOG_ERROR(HILOG_MODULE_SAMGR, "Consumer uid<%d> has no permission to access<%s, %d, %d>!", @@ -267,7 +275,7 @@ static boolean SearchFixedPolicy(uid_t callingUid, PolicyTrans policy) { int i; for (i = 0; i < UID_SIZE; i++) { - if (callingUid == policy.fixedUid[i]) { + if (callingUid == (uid_t)policy.fixedUid[i]) { return TRUE; } } diff --git a/samgr_endpoint/source/token_bucket.c b/samgr_endpoint/source/token_bucket.c index 858b65b..670d333 100644 --- a/samgr_endpoint/source/token_bucket.c +++ b/samgr_endpoint/source/token_bucket.c @@ -22,9 +22,9 @@ int TB_CheckMessage(TokenBucket *bucket) return BUCKET_INVALID; } uint64 now = SAMGR_GetProcessTime(); - uint64 generated = (now > bucket->last) ? ((now - bucket->last) * bucket->rate) : 0; + uint64 generated = (now > bucket->last) ? ((now - bucket->last) * (uint64)bucket->rate) : 0; int used = bucket->used + TOKEN_PRE_MSG; - used = (generated > used) ? 0 : (used - (int)generated); + used = (generated > (uint64)used) ? 0 : (used - (int)generated); if (used >= bucket->burst * TOKEN_PRE_MSG) { return BUCKET_BUSY; } diff --git a/samgr_server/source/samgr_server_rpc.c b/samgr_server/source/samgr_server_rpc.c index 1c024cc..6970ae6 100644 --- a/samgr_server/source/samgr_server_rpc.c +++ b/samgr_server/source/samgr_server_rpc.c @@ -282,9 +282,9 @@ static int ProcEndpoint(SamgrServer *server, int32 option, void *origin, IpcIo * return EC_FAILURE; } #endif - handle.uid = GetCallingUid(); + handle.uid = (uid_t)GetCallingUid(); handle.pid = pid; - handle.handle = identity.handle; + handle.handle = (uint32)identity.handle; handle.cookie = identity.cookie; handle.deadId = INVALID_INDEX; (void)SASTORA_SaveHandleByPid(&server->store, handle); @@ -305,8 +305,8 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req, WriteInt32(reply, EC_INVALID); return EC_INVALID; } - pid_t pid = GetCallingPid(); - uid_t uid = GetCallingUid(); + pid_t pid = (pid_t)GetCallingPid(); + uid_t uid = (uid_t)GetCallingUid(); bool isFeature; ReadBool(req, &isFeature); char *feature = NULL; @@ -323,7 +323,7 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req, return EC_NOSERVICE; } *identity = SASTORA_Find(&server->store, service, feature); - if (identity->handle != INVALID_INDEX && identity->handle != handle.handle) { + if (identity->handle != INVALID_INDEX && (uint32)identity->handle != handle.handle) { MUTEX_Unlock(server->mtx); WriteInt32(reply, EC_INVALID); return EC_INVALID; @@ -349,8 +349,8 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req, } ret = SASTORA_Save(&server->store, service, feature, identity); MUTEX_Unlock(server->mtx); - HILOG_DEBUG(HILOG_MODULE_SAMGR, "Register Feature<%s, %s> pid<%d>, id<%d, %d> ret:%d", - service, feature, pid, identity->handle, identity->token, ret); + HILOG_DEBUG(HILOG_MODULE_SAMGR, "Register Feature<%s, %s> pid<%d>, id<%d> ret:%d", + service, feature, pid, identity->handle, ret); TransmitPolicy(ret, identity, reply, policy, policyNum); SAMGR_Free(policy); return ret; @@ -419,15 +419,15 @@ static int32 ProcGetFeature(SamgrServer *server, const void *origin, IpcIo *req, *identity = SASTORA_Find(&server->store, service, feature); if (identity->handle == INVALID_INDEX) { MUTEX_Unlock(server->mtx); - HILOG_DEBUG(HILOG_MODULE_SAMGR, "Cannot Find Feature<%s, %s> id<%d, %d> ret:%d", - service, feature, identity->handle, identity->token, EC_NOSERVICE); + HILOG_DEBUG(HILOG_MODULE_SAMGR, "Cannot Find Feature<%s, %s> id<%d> ret:%d", + service, feature, identity->handle, EC_NOSERVICE); return EC_NOSERVICE; } PidHandle providerPid = SASTORA_FindPidHandleByIpcHandle(&server->store, identity->handle); MUTEX_Unlock(server->mtx); if (providerPid.pid == INVALID_INDEX || providerPid.uid == INVALID_INDEX) { - HILOG_DEBUG(HILOG_MODULE_SAMGR, "Cannot Find PidHandle<%s, %s> id<%d, %d> ret:%d", - service, feature, identity->handle, identity->token, EC_FAILURE); + HILOG_DEBUG(HILOG_MODULE_SAMGR, "Cannot Find PidHandle<%s, %s> id<%d> ret:%d", + service, feature, identity->handle, EC_FAILURE); return EC_FAILURE; } AuthParams authParams = { @@ -561,7 +561,7 @@ void ProcGetAllSysCap(SamgrServer *server, IpcIo *req, IpcIo *reply) MUTEX_Unlock(server->sysCapMtx); return; } - int32 nextRequestIdx = startIdx; + int32 nextRequestIdx = (int32)startIdx; int32 replyNum = GetReplyNumAndNextReqIdx(sysCapablitys, startIdx, &nextRequestIdx); HILOG_DEBUG(HILOG_MODULE_SAMGR, "ProcGetAllSysCap replyNum: %d, size: %d, startIdx: %u, nextRequestIdx: %d", replyNum, size, startIdx, nextRequestIdx); @@ -572,7 +572,7 @@ void ProcGetAllSysCap(SamgrServer *server, IpcIo *req, IpcIo *reply) WriteUint32(reply, nextRequestIdx); WriteUint32(reply, replyNum); int32 cnt = 0; - int32 i = startIdx; + int32 i = (int32)startIdx; for (; i < size && cnt < replyNum; i++) { SysCapImpl *serviceImpl = (SysCapImpl *)VECTOR_At(sysCapablitys, i); if (serviceImpl->isRegister == FALSE) { @@ -634,7 +634,7 @@ static void OnEndpointExit(void* argv) pid_t pid = (pid_t)((uintptr_t)argv); Request request = {0}; request.msgId = MSG_CLEAN; - request.msgValue = pid; + request.msgValue = (uint32)pid; int retry = RETRY_TIMES; int ret = EC_INVALID; while (retry > 0) { @@ -650,7 +650,7 @@ static void OnEndpointExit(void* argv) int err = SASTORA_FindHandleByPid(&g_server.store, pid, &handle); if (err != INVALID_INDEX) { SvcIdentity target = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX}; - target.handle = handle.handle; + target.handle = (int32_t)handle.handle; ReleaseSvc(target); } HILOG_ERROR(HILOG_MODULE_SAMGR, "IPC pid<%d> exit! send clean request retry(%d), ret(%d)!", pid, retry, ret); @@ -743,10 +743,10 @@ static void ParseSysCap(void) SAMGR_Free(impl); continue; } - impl->isRegister = cJSON_IsTrue(isRegister); + impl->isRegister = (uint32)cJSON_IsTrue(isRegister); if (VECTOR_Add(&(g_server.sysCapabilitys), impl) == INVALID_INDEX) { - SAMGR_Free(impl); HILOG_ERROR(HILOG_MODULE_SAMGR, "system capability %s register failed!", impl->name); + SAMGR_Free(impl); continue; } sysCapNum++; -- Gitee