From 8f4ce8d1484730799d89c68da5da4006ffe93dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E6=99=93=E5=BA=86?= Date: Wed, 27 Apr 2022 18:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0PID=E3=80=81UID=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=E6=9C=BA=E5=88=B6=EF=BC=8C=E4=BF=AE=E6=94=B9SetRegist?= =?UTF-8?q?ryObject=EF=BC=8C=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 13759949570 --- ipc/native/c/ipc/src/linux/ipc_invoker.c | 5 +- .../c/ipc/src/liteos_a/include/lite_ipc.h | 7 +- ipc/native/c/ipc/src/liteos_a/ipc_invoker.c | 208 ++++++++++-------- .../c/ipc/src/liteos_a/serializer_inner.c | 90 ++++---- .../c/manager/include/iremote_invoker.h | 2 +- .../c/manager/src/ipc_process_skeleton.c | 6 +- ipc/native/c/manager/src/serializer.c | 17 +- ipc/native/c/rpc/src/dbinder_invoker.c | 3 +- ipc/test/ipc/client/client.c | 8 +- ipc/test/ipc/server/Ability.cpp | 14 +- .../unittest/ipc/client/IpcClientTest.cpp | 6 +- ipc/test/unittest/ipc/include/ipc_proxy.h | 6 - ipc/test/unittest/ipc/samgr/IpcSamgrTest.cpp | 1 + .../unittest/ipc/server/IpcServerTest.cpp | 16 +- 14 files changed, 204 insertions(+), 185 deletions(-) diff --git a/ipc/native/c/ipc/src/linux/ipc_invoker.c b/ipc/native/c/ipc/src/linux/ipc_invoker.c index ffe5555..2e32197 100644 --- a/ipc/native/c/ipc/src/linux/ipc_invoker.c +++ b/ipc/native/c/ipc/src/linux/ipc_invoker.c @@ -391,15 +391,16 @@ static int32_t IpcSetMaxWorkThread(int32_t maxThreadNum) return ret; } -static int32_t IpcSetRegistryObject(SvcIdentity target) +static int32_t IpcSetRegistryObject(SvcIdentity target, SvcIdentity *samgr) { - (void)target; if (g_connector == NULL) { RPC_LOG_ERROR("ipc driver not init"); return ERR_FAILED; } int32_t ret = ioctl(g_connector->fd, BINDER_SET_CONTEXT_MGR, 0); if (ret == ERR_NONE) { + samgr->handle = -1; + samgr->cookie = target.cookie; RPC_LOG_INFO("set samgr success!!"); return ERR_NONE; } diff --git a/ipc/native/c/ipc/src/liteos_a/include/lite_ipc.h b/ipc/native/c/ipc/src/liteos_a/include/lite_ipc.h index dc0d156..7eeade5 100644 --- a/ipc/native/c/ipc/src/liteos_a/include/lite_ipc.h +++ b/ipc/native/c/ipc/src/liteos_a/include/lite_ipc.h @@ -111,9 +111,9 @@ typedef struct { typedef struct { uint32_t num; - void* msg; + void *msg; IpcIo io; - IpcObjectStub* cbs; + IpcObjectStub *cbs; bool useFlag; } HdlerArg; @@ -124,6 +124,9 @@ typedef struct { } AnonymousApi; int32_t StartCallbackDispatch(void); +IpcCallback *GetIpcCb(void); +uint32_t GetThreadId(void); +uintptr_t GetObjectStub(uintptr_t cookie); #ifdef __cplusplus #if __cplusplus diff --git a/ipc/native/c/ipc/src/liteos_a/ipc_invoker.c b/ipc/native/c/ipc/src/liteos_a/ipc_invoker.c index e82d0e3..c0fd102 100644 --- a/ipc/native/c/ipc/src/liteos_a/ipc_invoker.c +++ b/ipc/native/c/ipc/src/liteos_a/ipc_invoker.c @@ -31,11 +31,8 @@ #include "ipc_types.h" #include "ipc_process_skeleton.h" -// #define TEST_NORMAL_SERVICE_DEATH -// #define TEST_ANONYMOUS_SERVICE_DEATH #define MAX_SA_SIZE (0x100) #define LITEIPC_VERSION_MIN_REQUIRE (2) -extern thread_local uintptr_t g_objectStub_; uint32_t g_threadId = 0; static RemoteInvoker g_ipcInvoker; @@ -54,7 +51,7 @@ IpcCallback g_ipcCallback = { .threadWorking = false }; -static inline void InitIpcCallback() +static inline void InitIpcCallback(void) { UtilsListInit(&g_ipcCallback.apis); } @@ -101,6 +98,19 @@ OPEN_ERR: return NULL; } +static void CloseDriver(void) +{ + if (g_connector == NULL) { + return; + } + pthread_mutex_lock(&g_connectorMutex); + munmap(g_connector->mmapAddr, g_connector->mmapSize); + close(g_connector->fd); + free(g_connector); + g_connector = NULL; + pthread_mutex_unlock(&g_connectorMutex); +} + static int32_t AcquireHandle(int32_t handle) { return ERR_NONE; @@ -129,16 +139,15 @@ static int32_t IpcFreeBuffer(void *buffer) return ioctl(g_connector->fd, IPC_SEND_RECV_MSG, &content); } -static void IpcIoInitFromMsg(IpcIo *io, const void *msg) +static void IpcIoInitFromMsg(IpcIo *io, const IpcMsg *msg) { if ((io == NULL) || (msg == NULL)) { return; } - IpcMsg *local = (IpcMsg *)msg; - io->bufferCur = io->bufferBase = (char *)(intptr_t)local->data; - io->offsetsCur = io->offsetsBase = (size_t *)(intptr_t)(local->offsets); - io->bufferLeft = local->dataSz; - io->offsetsLeft = local->spObjNum; + io->bufferCur = io->bufferBase = (char *)(intptr_t)msg->data; + io->offsetsCur = io->offsetsBase = (size_t *)(intptr_t)(msg->offsets); + io->bufferLeft = msg->dataSz; + io->offsetsLeft = msg->spObjNum; io->flag = IPC_IO_INITIALIZED; } @@ -252,14 +261,6 @@ static void SendFailedReply(IpcMsg *ipcMsg) } } -static void FreeData(UTILS_DL_LIST *apis) -{ - AnonymousApi *node = NULL; - UTILS_DL_LIST_FOR_EACH_ENTRY(node, apis, AnonymousApi, list) - { - free(node); - } -} static void CallDeathCallback(IpcMsg *ipcMsg) { @@ -280,37 +281,53 @@ static void CallDeathCallback(IpcMsg *ipcMsg) } } -static void *CallbackBatchHandler(void *arg) +static void CallIpcCallback(IpcMsg *ipcMsg, HdlerArg *hdlerArg) +{ + for (uint32_t i = 0; i < hdlerArg->num; i++) { + if (hdlerArg->useFlag == false) { + continue; + } + ThreadContext *threadContext = GetCurrentThreadContext(); + const pid_t oldPid = threadContext->callerPid; + const pid_t oldUid = threadContext->callerUid; + threadContext->callerPid = ipcMsg->processID; + threadContext->callerUid = (pid_t)ipcMsg->userID; + MessageOption option = { + .flags = ipcMsg->flag, + .args = hdlerArg->cbs[i].args + }; + IpcIo reply; + uint8 tempData[MAX_IO_SIZE]; + IpcIoInit(&reply, tempData, MAX_IO_SIZE, MAX_OBJ_NUM); + int32_t error = OnRemoteRequestInner(ipcMsg->code, &hdlerArg->io, &reply, option, &hdlerArg->cbs[i]); + if (error < 0) { + RPC_LOG_ERROR("OnRemoteRequestInner failed, error = %d", error); + } + if (!(ipcMsg->flag & TF_OP_ASYNC)) { + SendReply(ipcMsg, &reply); + } else { + IpcFreeBuffer((void *)ipcMsg); + } + threadContext->callerPid = oldPid; + threadContext->callerUid = oldUid; + } + free(hdlerArg); +} + +static void *CallbackBatchHandler(HdlerArg *hdlerArg) { pthread_detach(pthread_self()); - HdlerArg *hdlerArg = (HdlerArg *)arg; IpcMsg *ipcMsg = (IpcMsg *)hdlerArg->msg; - if (ipcMsg->type == MT_DEATH_NOTIFY) { - CallDeathCallback(ipcMsg); - } else if (ipcMsg->type == MT_REQUEST) { - uint32_t i; - for (i = 0; i < hdlerArg->num; i++) { - if (hdlerArg->useFlag == true) { - MessageOption option = { - .flags = ipcMsg->flag, - .args = hdlerArg->cbs[i].args - }; - IpcIo reply; - uint8 tempData[MAX_IO_SIZE]; - IpcIoInit(&reply, tempData, MAX_IO_SIZE, MAX_OBJ_NUM); - int32_t error = OnRemoteRequestInner(ipcMsg->code, &hdlerArg->io, &reply, option, &hdlerArg->cbs[i]); - if (error < 0) { - RPC_LOG_ERROR("OnRemoteRequestInner failed, error = %d", error); - } - if (!(ipcMsg->flag & TF_OP_ASYNC)) { - SendReply(ipcMsg, &reply); - } else { - IpcFreeBuffer((void *)ipcMsg); - } - } - } - free(arg); - FreeData(&g_ipcCallback.apis); + switch (ipcMsg->type) { + case MT_DEATH_NOTIFY: + CallDeathCallback(ipcMsg); + break; + case MT_REQUEST: + CallIpcCallback(ipcMsg, hdlerArg); + break; + default: + RPC_LOG_ERROR("ipcMsg type unknow."); + break; } return NULL; } @@ -351,21 +368,12 @@ static void GetIpcCallback(IpcMsg* msg, HdlerArg* arg) (void)pthread_mutex_unlock(&g_ipcCallback.mutex); } -static void *CallbackDispatch(void *arg) +static void CallbackDispatchLoop(void) { - if (g_connector == NULL) { - RPC_LOG_ERROR("liteipc driver not init"); - return NULL; - } - - int32_t ret = ioctl(g_connector->fd, IPC_SET_IPC_THREAD, 0); - g_threadId = syscall(SYS_gettid); - g_ipcCallback.handleId = ret; - g_ipcCallback.threadWorking = true; while (1) { IpcContent content = {.flag = RECV}; sched_yield(); - ret = ioctl(g_connector->fd, IPC_SEND_RECV_MSG, &content); + int32_t ret = ioctl(g_connector->fd, IPC_SEND_RECV_MSG, &content); if (ret < 0) { continue; } @@ -391,12 +399,6 @@ static void *CallbackDispatch(void *arg) goto ERROR_MSG; } -#ifdef TEST_ANONYMOUS_SERVICE_DEATH - if (ipcMsg->code == 3) { - RPC_LOG_INFO("Test Anonymous DeathCallback: thread exit!"); - return NULL; - } -#endif pthread_t tid; ret = pthread_create(&tid, NULL, CallbackBatchHandler, tArg); if (ret == 0) { @@ -406,7 +408,6 @@ static void *CallbackDispatch(void *arg) ERROR_MSG: free(tArg); - FreeData(&g_ipcCallback.apis); ERROR_MALLOC: if ((ipcMsg->type == MT_REQUEST) && (ipcMsg->flag == TF_OP_SYNC)) { SendFailedReply(ipcMsg); @@ -414,20 +415,43 @@ ERROR_MALLOC: IpcFreeBuffer((void *)ipcMsg); } } +} + +static void *CallbackDispatch(void) +{ + if (g_connector == NULL) { + RPC_LOG_ERROR("liteipc driver not init"); + return NULL; + } + + int32_t ret = ioctl(g_connector->fd, IPC_SET_IPC_THREAD, 0); + g_threadId = syscall(SYS_gettid); + g_ipcCallback.handleId = ret; + g_ipcCallback.threadWorking = true; + CallbackDispatchLoop(); g_ipcCallback.threadWorking = false; - return arg; + return NULL; +} + +IpcCallback *GetIpcCb(void) +{ + return &g_ipcCallback; +} + +uint32_t GetThreadId(void) +{ + return g_threadId; } int32_t StartCallbackDispatch(void) { - if(!g_ipcCallback.threadWorking) { + if (!g_ipcCallback.threadWorking) { pthread_attr_t threadAttr; pthread_attr_init(&threadAttr); pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED); pthread_t tid; int32_t ret = pthread_create(&tid, &threadAttr, CallbackDispatch, NULL); - if (ret != 0) { RPC_LOG_ERROR("Create callback dispatch thread failed."); return ERR_FAILED; @@ -448,14 +472,9 @@ int32_t StartCallbackDispatch(void) } } -static void IpcJoinThread(bool initiative) +static void IpcJoinThreadLoop(void) { - if (g_connector == NULL) { - RPC_LOG_ERROR("liteipc driver not init"); - return; - } - - IpcObjectStub *objectStub = (IpcObjectStub *)g_objectStub_; + IpcObjectStub *objectStub = (IpcObjectStub *)GetObjectStub(0); if (objectStub == NULL) { RPC_LOG_INFO("objectStub is NULL."); return; @@ -468,23 +487,12 @@ static void IpcJoinThread(bool initiative) continue; } IpcMsg *ipcMsg = content.inMsg; + ThreadContext *threadContext = GetCurrentThreadContext(); + const pid_t oldPid = threadContext->callerPid; + const pid_t oldUid = threadContext->callerUid; + threadContext->callerPid = ipcMsg->processID; + threadContext->callerUid = (pid_t)ipcMsg->userID; -#ifdef TEST_NORMAL_SERVICE_DEATH - static int msg_count = 0; - static int server_handle = 0; - RPC_LOG_INFO("ipcMsg->code = %d\n", ipcMsg->code); - if (ipcMsg->code == 10) { - server_handle = ipcMsg->target.handle; - } - RPC_LOG_INFO("recv msg count:%d, type:%d, target.handle:%d, server_handle:%d", msg_count, ipcMsg->type, ipcMsg->target.handle, server_handle); - msg_count++; - if(server_handle != 0) { - if((msg_count > 201) && (ipcMsg->target.handle == server_handle)) { - RPC_LOG_INFO("Test DeathCallback: thread exit!"); - return; - } - } -#endif IpcIo data, reply; IpcIoInitFromMsg(&data, ipcMsg); uint8 tempData[MAX_IO_SIZE]; @@ -502,7 +510,18 @@ static void IpcJoinThread(bool initiative) } else { IpcFreeBuffer((void *)ipcMsg); } + threadContext->callerPid = oldPid; + threadContext->callerUid = oldUid; + } +} + +static void IpcJoinThread(bool initiative) +{ + if (g_connector == NULL) { + RPC_LOG_ERROR("liteipc driver not init"); + return; } + IpcJoinThreadLoop(); } static int32_t IpcSetMaxWorkThread(int32_t maxThreadNum) @@ -510,16 +529,17 @@ static int32_t IpcSetMaxWorkThread(int32_t maxThreadNum) return ERR_NONE; } -static int32_t IpcSetRegistryObject(SvcIdentity target) +static int32_t IpcSetRegistryObject(SvcIdentity target, SvcIdentity *samgr) { - (void)target; + (void)samgr; if (g_connector == NULL) { RPC_LOG_ERROR("liteipc driver not init"); return ERR_IPC_SKELETON_NOT_INIT; } int32_t ret = ioctl(g_connector->fd, IPC_SET_CMS, MAX_SA_SIZE); if (ret == ERR_NONE) { - g_objectStub_ = target.cookie; + GetObjectStub(target.cookie); + // samgr->cookie = target.cookie; RPC_LOG_INFO("set samgr success!!"); return ERR_NONE; } @@ -581,7 +601,7 @@ static int32_t IpcSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, Ip static int32_t IpcAddDeathRecipient(int32_t handle, void *cookie) { - if(!g_ipcCallback.threadWorking) { + if (!g_ipcCallback.threadWorking) { pthread_mutex_lock(&g_ipcCallback.mutex); int32_t ret = StartCallbackDispatch(); if (ret < 0) { diff --git a/ipc/native/c/ipc/src/liteos_a/serializer_inner.c b/ipc/native/c/ipc/src/liteos_a/serializer_inner.c index a19f656..a3cf720 100644 --- a/ipc/native/c/ipc/src/liteos_a/serializer_inner.c +++ b/ipc/native/c/ipc/src/liteos_a/serializer_inner.c @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include #include "ipc_skeleton.h" -#include "serializer_inner.h" #include "rpc_log.h" #include "lite_ipc.h" -#include -#include +#include "serializer_inner.h" #define ALIGN_SZ 4 #define IPC_IO_ALIGN(sz) (((sz) + ALIGN_SZ - 1) & (~(ALIGN_SZ - 1))) @@ -79,31 +79,37 @@ ERROR: } thread_local uintptr_t g_objectStub_ = 0; -extern IpcCallback g_ipcCallback; -extern uint32_t g_threadId; -static int32_t AddList(IpcObjectStub *stub, uint32_t *token) +uintptr_t GetObjectStub(uintptr_t cookie) +{ + if (cookie != NULL) { + g_objectStub_ = cookie; + } + return g_objectStub_; +} + +static int32_t AddList(IpcObjectStub *stub, uint32_t *token, IpcCallback *ipcCallback) { int32_t ret = -1; - pthread_mutex_lock(&g_ipcCallback.mutex); + pthread_mutex_lock(&ipcCallback->mutex); static uint32_t index = 0; AnonymousApi *anonymousApi = (AnonymousApi *)malloc(sizeof(AnonymousApi)); if (anonymousApi == NULL) { RPC_LOG_ERROR("anonymousApi malloc failed"); - pthread_mutex_unlock(&g_ipcCallback.mutex); + pthread_mutex_unlock(&ipcCallback->mutex); return ret; } *token = index++; anonymousApi->token = *token; ret = memcpy_s((char *)&anonymousApi->hdlerPair, sizeof(IpcObjectStub), stub, sizeof(IpcObjectStub)); if (ret == 0) { - UtilsListAdd(&(g_ipcCallback.apis), &anonymousApi->list); - pthread_mutex_unlock(&g_ipcCallback.mutex); + UtilsListAdd(&ipcCallback->apis, &anonymousApi->list); + pthread_mutex_unlock(&ipcCallback->mutex); return ret; } RPC_LOG_ERROR("anonymousApi memcpy_s failed"); free(anonymousApi); - pthread_mutex_unlock(&g_ipcCallback.mutex); + pthread_mutex_unlock(&ipcCallback->mutex); return ret; } @@ -117,39 +123,41 @@ bool WriteRemoteObject(IpcIo *io, const SvcIdentity *svc) return false; } SpecialObj* ptr = IoPushSpecObj(io); - if (ptr != NULL) { - ptr->type = OBJ_SVC; - ptr->content.svc.handle = svc->handle; - ptr->content.svc.token = svc->token; - ptr->content.svc.cookie = svc->cookie; - if (ptr->content.svc.handle == IPC_INVALID_HANDLE) { - IpcObjectStub *stub = (IpcObjectStub *)ptr->content.svc.cookie; - if (ptr->content.svc.token == SERVICE_TYPE_NORMAL) { - g_objectStub_ = stub; - } else if (ptr->content.svc.token == SERVICE_TYPE_ANONYMOUS) { - uint32_t token; - int32_t ret = AddList(stub, &token); - if(ret != 0) { - RPC_LOG_ERROR("Add list failed."); - return false; - } - ptr->content.svc.token = token; - if(!g_ipcCallback.threadWorking) { - pthread_mutex_lock(&g_ipcCallback.mutex); - ret = StartCallbackDispatch(); - if (ret < 0) { - RPC_LOG_ERROR("WriteRemoteObject StartCallbackDispatch failed."); - pthread_mutex_unlock(&g_ipcCallback.mutex); - return false; - } - pthread_mutex_unlock(&g_ipcCallback.mutex); - } - ptr->content.svc.handle = g_threadId; + if (ptr == NULL) { + return false; + } + ptr->type = OBJ_SVC; + ptr->content.svc.handle = svc->handle; + ptr->content.svc.token = svc->token; + ptr->content.svc.cookie = svc->cookie; + if (ptr->content.svc.handle != IPC_INVALID_HANDLE) { + return true; + } + IpcObjectStub *stub = (IpcObjectStub *)ptr->content.svc.cookie; + if (ptr->content.svc.token == SERVICE_TYPE_NORMAL) { + g_objectStub_ = stub; + } else if (ptr->content.svc.token == SERVICE_TYPE_ANONYMOUS) { + IpcCallback *ipcCallback = GetIpcCb(); + uint32_t token; + int32_t ret = AddList(stub, &token, ipcCallback); + if (ret != 0) { + RPC_LOG_ERROR("Add list failed."); + return false; + } + ptr->content.svc.token = token; + if (!ipcCallback->threadWorking) { + pthread_mutex_lock(&ipcCallback->mutex); + ret = StartCallbackDispatch(); + if (ret < 0) { + RPC_LOG_ERROR("WriteRemoteObject StartCallbackDispatch failed."); + pthread_mutex_unlock(&ipcCallback->mutex); + return false; } + pthread_mutex_unlock(&ipcCallback->mutex); } - return true; + ptr->content.svc.handle = GetThreadId(); } - return false; + return true; } bool ReadRemoteObject(IpcIo *io, SvcIdentity *svc) diff --git a/ipc/native/c/manager/include/iremote_invoker.h b/ipc/native/c/manager/include/iremote_invoker.h index 2900479..8b2afdd 100644 --- a/ipc/native/c/manager/include/iremote_invoker.h +++ b/ipc/native/c/manager/include/iremote_invoker.h @@ -37,7 +37,7 @@ typedef struct { void (*JoinThread)(bool initiative); void (*ExitCurrentThread)(void); void (*JoinProcessThread)(bool initiative); - int32_t (*SetRegistryObject)(SvcIdentity target); + int32_t (*SetRegistryObject)(SvcIdentity target, SvcIdentity *samgr); int32_t (*AddDeathRecipient)(int32_t handle, void *cookie); int32_t (*RemoveDeathRecipient)(int32_t handle, void *cookie); void (*InvokerResetIpc)(void); diff --git a/ipc/native/c/manager/src/ipc_process_skeleton.c b/ipc/native/c/manager/src/ipc_process_skeleton.c index 4c23750..52b1fff 100644 --- a/ipc/native/c/manager/src/ipc_process_skeleton.c +++ b/ipc/native/c/manager/src/ipc_process_skeleton.c @@ -158,11 +158,7 @@ int32_t SetRegistryObject(SvcIdentity target) int32_t ret = ERR_THREAD_INVOKER_NOT_INIT; RemoteInvoker *invoker = GetRemoteInvoker(); if (invoker != NULL) { - ret = (invoker->SetRegistryObject)(target); - } - if (ret == ERR_NONE) { - g_samgrSvc.handle = -1; - g_samgrSvc.cookie = target.cookie; + ret = (invoker->SetRegistryObject)(target, &g_samgrSvc); } return ret; } diff --git a/ipc/native/c/manager/src/serializer.c b/ipc/native/c/manager/src/serializer.c index 9ecd7a5..6120ecc 100644 --- a/ipc/native/c/manager/src/serializer.c +++ b/ipc/native/c/manager/src/serializer.c @@ -658,16 +658,21 @@ bool ReadDouble(IpcIo *io, double *value) uint8_t *ReadString(IpcIo *io, size_t *len) { - if (io == NULL || len == NULL) { - RPC_LOG_ERROR("IPC io == NULL || len == NULL failed: %s:%d\n", __FUNCTION__, __LINE__); - return false; + if (io == NULL) { + RPC_LOG_ERROR("IPC io == NULL failed: %s:%d\n", __FUNCTION__, __LINE__); + return NULL; } uint32_t value; bool ret = ReadUint32(io, &value); if (ret) { - *len = value; - } - if (value > MAX_IO_SIZE) { + if (value > MAX_IO_SIZE) { + return NULL; + } + if (len != NULL) { + *len = value; + } + } else { + RPC_LOG_ERROR("IPC ReadUint32 failed: %s:%d\n", __FUNCTION__, __LINE__); return NULL; } return (uint8_t *)IoPop(io, value + 1); diff --git a/ipc/native/c/rpc/src/dbinder_invoker.c b/ipc/native/c/rpc/src/dbinder_invoker.c index 07ca4b6..2a4a00f 100644 --- a/ipc/native/c/rpc/src/dbinder_invoker.c +++ b/ipc/native/c/rpc/src/dbinder_invoker.c @@ -772,9 +772,10 @@ void RpcStopWorkThread(void) threadContext->stopWorkThread = true; } -int32_t RpcSetRegistryObject(SvcIdentity target) +int32_t RpcSetRegistryObject(SvcIdentity target, SvcIdentity *samgr) { (void)target; + (void)samgr; return ERR_NONE; } diff --git a/ipc/test/ipc/client/client.c b/ipc/test/ipc/client/client.c index 49307e0..9b541b8 100644 --- a/ipc/test/ipc/client/client.c +++ b/ipc/test/ipc/client/client.c @@ -23,6 +23,7 @@ static SvcIdentity g_serverSid; static MessageOption g_option; +static SvcIdentity *g_samgr = NULL; int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option) { @@ -71,10 +72,6 @@ void ServerDead3(void) RPC_LOG_INFO("#### server dead callback33 called ... "); } -static SvcIdentity g_samgr = { - .handle = 0 -}; - static void GetServerOne(void) { IpcIo data1; @@ -83,7 +80,7 @@ static void GetServerOne(void) WriteInt32(&data1, SERVER_SA_ID1); IpcIo reply1; uintptr_t ptr = 0; - int ret = SendRequest(g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply1, g_option, &ptr); + int ret = SendRequest(*g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply1, g_option, &ptr); ReadRemoteObject(&reply1, &g_serverSid); FreeBuffer((void *)ptr); EXPECT_EQ(ret, ERR_NONE); @@ -203,6 +200,7 @@ static void DeathCallbackTest(void) int main(int argc, char *argv[]) { RPC_LOG_INFO("Enter System Ability Client .... "); + g_samgr = GetContextObject(); MessageOptionInit(&g_option); GetServerOne(); CallServerAdd(); diff --git a/ipc/test/ipc/server/Ability.cpp b/ipc/test/ipc/server/Ability.cpp index 6412f12..ad90b44 100644 --- a/ipc/test/ipc/server/Ability.cpp +++ b/ipc/test/ipc/server/Ability.cpp @@ -24,10 +24,7 @@ #include "serializer.h" static SvcIdentity *sid = nullptr; - -static SvcIdentity g_samgr = { - .handle = 0 -}; +static const SvcIdentity *g_samgr; static void CallAnonymosFunc(const char *str) { @@ -49,7 +46,7 @@ static void CallAnonymosFunc(const char *str) RPC_LOG_INFO("server Async call res = %d", ret); } -void ServerDead1(void) +static void ServerDead1(void) { RPC_LOG_INFO("#### server dead callback11 called ... "); } @@ -113,7 +110,7 @@ public: const char *str = "server call anonymos service one."; WriteInt32(reply, ERR_NONE); uint32_t cbId1 = -1; - int ret = AddDeathRecipient(*sid, (OnRemoteDead)ServerDead1, (void *)NULL,(uint32_t *)&cbId1); + int ret = AddDeathRecipient(*sid, (OnRemoteDead)ServerDead1, (void *)NULL, (uint32_t *)&cbId1); break; } default: @@ -143,7 +140,7 @@ static void AddSaOne(void) IpcIo reply; uintptr_t ptr = 0; RPC_LOG_INFO("====== add ability one to samgr ======"); - int ret = SendRequest(g_samgr, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr); + int ret = SendRequest(*g_samgr, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr); int res = -1; ReadInt32(&reply, &res); FreeBuffer((void *)ptr); @@ -155,6 +152,7 @@ static void AddSaOne(void) int main(int argc, char *argv[]) { RPC_LOG_INFO("Enter System Ability Server .... "); + g_samgr = GetContextObject(); MessageOptionInit(&g_option); AddSaOne(); @@ -165,7 +163,7 @@ int main(int argc, char *argv[]) uint8_t dataGet[IPC_MAX_SIZE]; IpcIoInit(&data1, dataGet, IPC_MAX_SIZE, 0); WriteInt32(&data1, SERVER_SA_ID1); - int ret = SendRequest(g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply, g_option, &ptr); + int ret = SendRequest(*g_samgr, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply, g_option, &ptr); SvcIdentity sidOne; ReadRemoteObject(&reply, &sidOne); FreeBuffer((void *)ptr); diff --git a/ipc/test/unittest/ipc/client/IpcClientTest.cpp b/ipc/test/unittest/ipc/client/IpcClientTest.cpp index 1e0ec5d..c3da6c6 100644 --- a/ipc/test/unittest/ipc/client/IpcClientTest.cpp +++ b/ipc/test/unittest/ipc/client/IpcClientTest.cpp @@ -110,12 +110,10 @@ HWTEST_F(IpcClientTest, IpcClientTest001, TestSize.Level1) uint8_t tmpData1[IPC_MAX_SIZE]; IpcIoInit(&data1, tmpData1, IPC_MAX_SIZE, 0); WriteInt32(&data1, SERVER_SA_ID1); - SvcIdentity target = { - .handle = 0 - }; + const SvcIdentity *target = GetContextObject(); IpcIo reply1; uintptr_t ptr = 0; - int ret = SendRequest(target, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply1, g_option, &ptr); + int ret = SendRequest(*target, GET_SYSTEM_ABILITY_TRANSACTION, &data1, &reply1, g_option, &ptr); ReadRemoteObject(&reply1, &sidServer); FreeBuffer((void *)ptr); EXPECT_EQ(ret, ERR_NONE); diff --git a/ipc/test/unittest/ipc/include/ipc_proxy.h b/ipc/test/unittest/ipc/include/ipc_proxy.h index 91f87ae..05f9e5a 100644 --- a/ipc/test/unittest/ipc/include/ipc_proxy.h +++ b/ipc/test/unittest/ipc/include/ipc_proxy.h @@ -16,8 +16,6 @@ #ifndef OHOS_IPC_PROXY_H #define OHOS_IPC_PROXY_H -// #define TEST_NORMAL_SERVICE_DEATH - enum { GET_SYSTEM_ABILITY_TRANSACTION = 1, ADD_SYSTEM_ABILITY_TRANSACTION = 2, @@ -30,11 +28,7 @@ enum { }; enum { -#ifdef TEST_NORMAL_SERVICE_DEATH - SERVER_OP_ADD = 10, -#else SERVER_OP_ADD = 1, -#endif SERVER_OP_SUB = 2, SERVER_OP_MULTI = 3, SERVER_OP_ADD_SERVICE = 4, diff --git a/ipc/test/unittest/ipc/samgr/IpcSamgrTest.cpp b/ipc/test/unittest/ipc/samgr/IpcSamgrTest.cpp index 5988ed7..0a26e76 100644 --- a/ipc/test/unittest/ipc/samgr/IpcSamgrTest.cpp +++ b/ipc/test/unittest/ipc/samgr/IpcSamgrTest.cpp @@ -70,6 +70,7 @@ int32_t RemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption op { int32_t result = ERR_NONE; RPC_LOG_INFO("OnRemoteRequest called.... code = %u", code); + RPC_LOG_INFO("calling pid = %d, uid = %d", GetCallingPid(), GetCallingUid()); switch (code) { case ADD_SYSTEM_ABILITY_TRANSACTION: { int32_t saId; diff --git a/ipc/test/unittest/ipc/server/IpcServerTest.cpp b/ipc/test/unittest/ipc/server/IpcServerTest.cpp index 283ae72..570f206 100644 --- a/ipc/test/unittest/ipc/server/IpcServerTest.cpp +++ b/ipc/test/unittest/ipc/server/IpcServerTest.cpp @@ -24,7 +24,7 @@ #include "serializer.h" namespace { -constexpr uint32_t IPC_TEST_TIME_INTERVAL = 120; +constexpr uint32_t IPC_TEST_TIME_INTERVAL = 30; SvcIdentity *sid = nullptr; MessageOption g_option = { .flags = TF_OP_SYNC @@ -88,7 +88,7 @@ int32_t RemoteRequestOne(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption const char *str = "server call anonymos service one."; WriteInt32(reply, ERR_NONE); uint32_t cbId1 = -1; - int ret = AddDeathRecipient(*sid, (OnRemoteDead)ServerDead1, (void *)NULL,(uint32_t *)&cbId1); + int ret = AddDeathRecipient(*sid, (OnRemoteDead)ServerDead1, (void *)NULL, (uint32_t *)&cbId1); break; } default: @@ -174,10 +174,8 @@ HWTEST_F(IpcServerTest, IpcServerTest003, TestSize.Level0) IpcIo reply; uintptr_t ptr = 0; RPC_LOG_INFO("====== add ability one to samgr ======"); - SvcIdentity target = { - .handle = 0 - }; - int ret = SendRequest(target, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr); + const SvcIdentity *target = GetContextObject(); + int ret = SendRequest(*target, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr); int res = -1; ReadInt32(&reply, &res); FreeBuffer((void *)ptr); @@ -196,10 +194,8 @@ HWTEST_F(IpcServerTest, IpcServerTest004, TestSize.Level0) RPC_LOG_INFO("====== add ability two to samgr ======"); uintptr_t ptr = 0; IpcIo reply; - SvcIdentity target = { - .handle = 0 - }; - int ret = SendRequest(target, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr); + const SvcIdentity *target = GetContextObject(); + int ret = SendRequest(*target, ADD_SYSTEM_ABILITY_TRANSACTION, &data, &reply, g_option, &ptr); int res; ReadInt32(&reply, &res); FreeBuffer((void *)ptr); -- Gitee