未验证 提交 fe48697b 编写于 作者: O openharmony_ci 提交者: Gitee

!704 修改dbinderService传递stub指针

Merge pull request !704 from Yippo/master
......@@ -325,6 +325,8 @@ private:
bool SendEntryToRemote(const sptr<DBinderServiceStub> stub, uint32_t seqNumber, uint32_t pid, uint32_t uid);
uint16_t AllocFreeSocketPort();
std::string GetLocalDeviceID();
binder_uintptr_t AddStubByTag(binder_uintptr_t stub);
binder_uintptr_t QueryStubPtr(binder_uintptr_t stub);
bool CheckBinderObject(const sptr<DBinderServiceStub> &stub, binder_uintptr_t binderObject);
bool HasDBinderStub(binder_uintptr_t binderObject);
bool IsSameStubObject(const sptr<DBinderServiceStub> &stub, const std::u16string &service,
......@@ -380,6 +382,10 @@ private:
std::mutex threadPoolMutex_;
uint32_t seqNumber_ = 0; /* indicate make remote binder message sequence number, and can be overflow */
/* indicate the stub flag used for negotiation with the peer end, and can be overflow */
binder_uintptr_t stubTagNum_ = 1;
std::map<binder_uintptr_t, binder_uintptr_t> mapDBinderStubRegisters_;
std::list<sptr<DBinderServiceStub>> DBinderStubRegisted_;
std::map<std::u16string, binder_uintptr_t> mapRemoteBinderObjects_;
std::map<uint32_t, std::shared_ptr<struct ThreadLockInfo>> threadLockInfo_;
......
......@@ -49,6 +49,7 @@ DBinderService::~DBinderService()
StopRemoteListener();
DBinderStubRegisted_.clear();
mapDBinderStubRegisters_.clear();
mapRemoteBinderObjects_.clear();
threadLockInfo_.clear();
proxyObject_.clear();
......@@ -177,6 +178,38 @@ bool DBinderService::IsDeviceIdIllegal(const std::string &deviceID)
return false;
}
binder_uintptr_t DBinderService::AddStubByTag(binder_uintptr_t stub)
{
std::lock_guard<std::mutex> lockGuard(handleEntryMutex_);
// the same stub needs add stubNum to mapDBinderStubRegisters_, the previous corresponding stubNum will be returned.
for (auto iter = mapDBinderStubRegisters_.begin(); iter != mapDBinderStubRegisters_.end(); iter++) {
if (iter->second == stub) {
return iter->first;
}
}
binder_uintptr_t stubTag = stubTagNum_++;
auto result = mapDBinderStubRegisters_.insert(
std::pair<binder_uintptr_t, binder_uintptr_t>(stubTag, stub));
if (result.second) {
return stubTag;
} else {
return 0;
}
}
binder_uintptr_t DBinderService::QueryStubPtr(binder_uintptr_t stubTag)
{
std::lock_guard<std::mutex> lockGuard(handleEntryMutex_);
auto iter = mapDBinderStubRegisters_.find(stubTag);
if (iter != mapDBinderStubRegisters_.end()) {
return iter->second;
}
return 0;
}
bool DBinderService::CheckBinderObject(const sptr<DBinderServiceStub> &stub, binder_uintptr_t stubPtr)
{
if (stub == nullptr) {
......@@ -241,6 +274,12 @@ bool DBinderService::DeleteDBinderStub(const std::u16string &service, const std:
if (it == DBinderStubRegisted_.end()) {
return false;
}
for (auto mapIt = mapDBinderStubRegisters_.begin(); mapIt != mapDBinderStubRegisters_.end(); mapIt++) {
if (mapIt->second == reinterpret_cast<binder_uintptr_t>((*it).GetRefPtr())) {
mapDBinderStubRegisters_.erase(mapIt);
}
}
DBinderStubRegisted_.erase(it);
return true;
}
......@@ -328,7 +367,7 @@ bool DBinderService::SendEntryToRemote(const sptr<DBinderServiceStub> stub, uint
message->stubIndex = static_cast<uint64_t>(std::atoi(stub->GetServiceName().c_str()));
message->seqNumber = seqNumber;
message->binderObject = stub->GetBinderObject();
message->stub = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
message->stub = AddStubByTag(reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr()));
message->deviceIdInfo.tokenId = IPCSkeleton::GetCallingTokenID();
message->pid = pid;
message->uid = uid;
......@@ -785,7 +824,7 @@ bool DBinderService::IsSameSession(std::shared_ptr<struct SessionInfo> oldSessio
void DBinderService::MakeSessionByReplyMessage(const struct DHandleEntryTxRx *replyMessage)
{
if (HasDBinderStub(replyMessage->stub) == false) {
if (HasDBinderStub(QueryStubPtr(replyMessage->stub)) == false) {
DBINDER_LOGE(LOG_LABEL, "invalid stub object");
return;
}
......@@ -820,7 +859,7 @@ void DBinderService::MakeSessionByReplyMessage(const struct DHandleEntryTxRx *re
return;
}
// check whether need to update session
std::shared_ptr<struct SessionInfo> oldSession = QuerySessionObject(replyMessage->stub);
std::shared_ptr<struct SessionInfo> oldSession = QuerySessionObject(QueryStubPtr(replyMessage->stub));
if (oldSession != nullptr) {
if (IsSameSession(oldSession, session) == true) {
DBINDER_LOGI(LOG_LABEL, "invoker remote session already, do nothing");
......@@ -829,7 +868,7 @@ void DBinderService::MakeSessionByReplyMessage(const struct DHandleEntryTxRx *re
// ignore seqNumber overflow here, greater seqNumber means later request
if (oldSession->seqNumber < session->seqNumber) {
// remote old session
if (!DetachSessionObject(replyMessage->stub)) {
if (!DetachSessionObject(QueryStubPtr(replyMessage->stub))) {
DBINDER_LOGE(LOG_LABEL, "failed to detach session object");
}
} else {
......@@ -839,7 +878,7 @@ void DBinderService::MakeSessionByReplyMessage(const struct DHandleEntryTxRx *re
}
}
if (!AttachSessionObject(session, replyMessage->stub)) {
if (!AttachSessionObject(session, QueryStubPtr(replyMessage->stub))) {
DBINDER_LOGE(LOG_LABEL, "attach SessionInfo fail");
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册