summaryrefslogtreecommitdiff
path: root/libs/binder/RpcAddress.cpp
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2021-06-15 18:02:40 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2021-06-15 18:02:40 +0000
commit58fb61efef5da8d60f2ce89152b7cc2ed00d5f12 (patch)
tree64b06f1bb2d93dab0799077cf613044e67951741 /libs/binder/RpcAddress.cpp
parentc6f1ee8027ebfe45e3e278ec5590e68a7541cd75 (diff)
parent2ce034f75bf2262af4fc751f087adcfe0c6919e1 (diff)
Merge changes I881f63b8,I4c5edd2d,I8ff0d29c,I6578c3a4,Iea286ab0, ... am: 2ce034f75b
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1735011 Change-Id: I29254913a0b0ac090b42839d007ad6142077eb9f
Diffstat (limited to 'libs/binder/RpcAddress.cpp')
-rw-r--r--libs/binder/RpcAddress.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/libs/binder/RpcAddress.cpp b/libs/binder/RpcAddress.cpp
index 5c3232045e..98dee9a039 100644
--- a/libs/binder/RpcAddress.cpp
+++ b/libs/binder/RpcAddress.cpp
@@ -29,7 +29,7 @@ RpcAddress RpcAddress::zero() {
}
bool RpcAddress::isZero() const {
- RpcWireAddress ZERO{0};
+ RpcWireAddress ZERO{.options = 0};
return memcmp(mRawAddr.get(), &ZERO, sizeof(RpcWireAddress)) == 0;
}
@@ -51,13 +51,34 @@ static void ReadRandomBytes(uint8_t* buf, size_t len) {
close(fd);
}
-RpcAddress RpcAddress::unique() {
+RpcAddress RpcAddress::random(bool forServer) {
+ // The remainder of this header acts as reserved space for different kinds
+ // of binder objects.
+ uint64_t options = RPC_WIRE_ADDRESS_OPTION_CREATED;
+
+ // servers and clients allocate addresses independently, so this bit can
+ // tell you where an address originates
+ if (forServer) options |= RPC_WIRE_ADDRESS_OPTION_FOR_SERVER;
+
RpcAddress ret;
- ReadRandomBytes((uint8_t*)ret.mRawAddr.get(), sizeof(RpcWireAddress));
+ RpcWireAddress* raw = ret.mRawAddr.get();
+
+ raw->options = options;
+ ReadRandomBytes(raw->address, sizeof(raw->address));
+
LOG_RPC_DETAIL("Creating new address: %s", ret.toString().c_str());
return ret;
}
+bool RpcAddress::isForServer() const {
+ return mRawAddr.get()->options & RPC_WIRE_ADDRESS_OPTION_FOR_SERVER;
+}
+
+bool RpcAddress::isRecognizedType() const {
+ uint64_t allKnownOptions = RPC_WIRE_ADDRESS_OPTION_CREATED | RPC_WIRE_ADDRESS_OPTION_FOR_SERVER;
+ return (mRawAddr.get()->options & ~allKnownOptions) == 0;
+}
+
RpcAddress RpcAddress::fromRawEmbedded(const RpcWireAddress* raw) {
RpcAddress addr;
memcpy(addr.mRawAddr.get(), raw, sizeof(RpcWireAddress));