aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Langlois <pierre.langlois@arm.com>2016-03-04 18:07:22 +0000
committerPierre Langlois <pierre.langlois@arm.com>2016-03-04 18:23:15 +0000
commit999315a51efd81ab42ae5a81ddb9d3719732252a (patch)
tree18fe04dd82aca20a780e791f45d595a500aefcc5
parent80f5f70119a92b8b9e250c41c9862c84c371a443 (diff)
downloadkdbinder-999315a51efd81ab42ae5a81ddb9d3719732252a.tar.gz
libkdbinder: Support the latest version of KDBUS
KDBinder no longer worked with the latest version of KDBUS. The breaking changes were: - `struct kdbus_cmd_make` no longer exists. Use the generic `struct kdbus_cmd` instead. - `struct kdbus_cmd_name_list` no longer exists. Use `struct kdbus_cmd_list` instead. - `struct kdbus_name_list` was replaced by `kdbus_info`. - When receiving a payload with the KDBUS_ITEM_PAYLOAD_OFF item, the offset is no longer relative to the start of the pool. It is now relative to the start of the slice, which corresponds to the address of the message in the pool. - We can no longer expect the first connection on a bus to have the ID `1`. Do not expect this in the test-suite.
-rw-r--r--libs/kdbinder/kdbus/command.h36
-rw-r--r--libs/kdbinder/kdbus/connection.cpp28
-rw-r--r--libs/kdbinder/kdbus/iterable.cpp12
-rw-r--r--libs/kdbinder/kdbus/iterable.h4
-rw-r--r--libs/kdbinder/tests/kdbus/connection.cpp4
5 files changed, 40 insertions, 44 deletions
diff --git a/libs/kdbinder/kdbus/command.h b/libs/kdbinder/kdbus/command.h
index 894d744..d94a1ec 100644
--- a/libs/kdbinder/kdbus/command.h
+++ b/libs/kdbinder/kdbus/command.h
@@ -78,11 +78,11 @@ const Reply send_command(FILE *file, uint64_t flags, int ioctl_cmd,
template<typename... ITEMS>
inline const Reply send_command_make(FILE *file, ITEMS...item) {
- return send_command<struct kdbus_cmd_make>(file, KDBUS_MAKE_ACCESS_WORLD,
- KDBUS_CMD_BUS_MAKE,
- [](struct kdbus_cmd_make *){},
- [](const kdbus_cmd_make&){},
- item...);
+ return send_command<struct kdbus_cmd>(file, KDBUS_MAKE_ACCESS_WORLD,
+ KDBUS_CMD_BUS_MAKE,
+ [](struct kdbus_cmd *){},
+ [](const kdbus_cmd&){},
+ item...);
}
struct ReplyHello : Reply {
@@ -114,21 +114,19 @@ inline const ReplyHello send_command_hello(FILE *file, uint64_t pool_size,
template<typename... ITEMS>
inline const Reply send_command_name_acquire(FILE *file, uint64_t flags,
ITEMS... item) {
- return send_command<struct kdbus_cmd_name>(file, flags,
- KDBUS_CMD_NAME_ACQUIRE,
- [](struct kdbus_cmd_name *){},
- [](const struct kdbus_cmd_name&){},
- item...);
+ return send_command<struct kdbus_cmd>(file, flags, KDBUS_CMD_NAME_ACQUIRE,
+ [](struct kdbus_cmd *){},
+ [](const struct kdbus_cmd&){},
+ item...);
}
// Tell the current connection to release its well-known name.
template<typename... ITEMS>
inline const Reply send_command_name_release(FILE *file, ITEMS... item) {
- return send_command<struct kdbus_cmd_name>(file, 0,
- KDBUS_CMD_NAME_RELEASE,
- [](struct kdbus_cmd_name *){},
- [](const struct kdbus_cmd_name&){},
- item...);
+ return send_command<struct kdbus_cmd>(file, 0, KDBUS_CMD_NAME_RELEASE,
+ [](struct kdbus_cmd *){},
+ [](const struct kdbus_cmd&){},
+ item...);
}
struct ReplyNameList : Reply {
@@ -145,10 +143,10 @@ inline const ReplyNameList send_command_name_list(FILE *file, uint64_t flags,
ITEMS... item) {
uint64_t offset = 0;
uint64_t list_size = 0;
- auto reply = send_command<struct kdbus_cmd_name_list>(
- file, flags, KDBUS_CMD_NAME_LIST,
- [](struct kdbus_cmd_name_list *){},
- [&offset, &list_size](const struct kdbus_cmd_name_list& cmd){
+ auto reply = send_command<struct kdbus_cmd_list>(
+ file, flags, KDBUS_CMD_LIST,
+ [](struct kdbus_cmd_list *){},
+ [&offset, &list_size](const struct kdbus_cmd_list& cmd){
offset = cmd.offset;
list_size = cmd.list_size;
}, item...);
diff --git a/libs/kdbinder/kdbus/connection.cpp b/libs/kdbinder/kdbus/connection.cpp
index 94354fd..71a829f 100644
--- a/libs/kdbinder/kdbus/connection.cpp
+++ b/libs/kdbinder/kdbus/connection.cpp
@@ -115,7 +115,7 @@ const Reply Connection::release_name(const std::string& name) const {
}
std::vector<NameInfo> Connection::name_list(uint64_t flags) const {
- struct kdbus_name_list *list;
+ struct kdbus_info *list;
std::vector<NameInfo> names = {};
auto reply = send_command_name_list(bus_file_.get(), flags);
@@ -128,27 +128,22 @@ std::vector<NameInfo> Connection::name_list(uint64_t flags) const {
// The list of names will be stored in our mapped memory region and
// the kernel will have written the offset at which to read the data.
- list = reinterpret_cast<struct kdbus_name_list *>(
+ list = reinterpret_cast<struct kdbus_info *>(
reinterpret_cast<uint8_t *>(buf_.get()) + reply.offset);
- if (list->size != reply.list_size) {
- ALOGE("The size of the received list does not match the reply.");
- return {};
- }
-
- for_each_name_info(list,
- [&names, &flags](struct kdbus_name_info *name) {
+ for_each_info(list, reply.list_size,
+ [&names, &flags](struct kdbus_info *info) {
// Include IDs.
if ((flags & Unique) == Unique) {
- names.emplace_back("", 0, name->conn_flags, name->owner_id);
+ names.emplace_back("", 0, info->flags, info->id);
}
// Include well-known names.
if ((flags & Names) == Names) {
- for_each_item(name, [&names, &name](struct kdbus_item *item) {
+ for_each_item(info, [&names, &info](struct kdbus_item *item) {
if (item->type == KDBUS_ITEM_OWNED_NAME) {
names.emplace_back(item->name.name, item->name.flags,
- name->conn_flags, name->owner_id);
+ info->flags, info->id);
}
});
}
@@ -195,11 +190,10 @@ const DataReply Connection::dequeue_message() const {
reinterpret_cast<uint8_t *>(buf_.get()) + reply.offset);
std::vector<DataReply::Data> vecs;
- for_each_item(msg, [&vecs, this](struct kdbus_item *item) {
+ for_each_item(msg, [&vecs, msg](struct kdbus_item *item) {
switch (item->type) {
case KDBUS_ITEM_PAYLOAD_OFF: {
- uint8_t *data = reinterpret_cast<uint8_t *>(buf_.get()) +
- item->vec.offset;
+ uint8_t *data = reinterpret_cast<uint8_t *>(msg) + item->vec.offset;
vecs.emplace_back(data, item->vec.size);
break;
@@ -264,10 +258,10 @@ const DataReply Connection::transact(const MessageSync& message) const {
KDBUS_CHECK(message.cookie() == msg->cookie_reply);
// TODO: parse the rest of the items for extra information.
- for_each_item(msg, [&vecs, address = buf_.get()](struct kdbus_item *item) {
+ for_each_item(msg, [&vecs, msg](struct kdbus_item *item) {
switch (item->type) {
case KDBUS_ITEM_PAYLOAD_OFF: {
- uint8_t *data = reinterpret_cast<uint8_t *>(address) + item->vec.offset;
+ uint8_t *data = reinterpret_cast<uint8_t *>(msg) + item->vec.offset;
vecs.emplace_back(data, item->vec.size);
break;
diff --git a/libs/kdbinder/kdbus/iterable.cpp b/libs/kdbinder/kdbus/iterable.cpp
index d45221a..b7093ec 100644
--- a/libs/kdbinder/kdbus/iterable.cpp
+++ b/libs/kdbinder/kdbus/iterable.cpp
@@ -19,9 +19,15 @@
namespace android {
namespace kdbus {
-void for_each_name_info(struct kdbus_name_list *list,
- std::function<void(struct kdbus_name_info *)> f) {
- for_each(list->names, list, f);
+void for_each_info(struct kdbus_info *list, uint64_t size,
+ std::function<void(struct kdbus_info *)> f) {
+ struct kdbus_info *info = list;
+ while (reinterpret_cast<uint8_t *>(info)
+ < reinterpret_cast<uint8_t *>(list) + size) {
+ f(info);
+ info = reinterpret_cast<struct kdbus_info *>(
+ reinterpret_cast<uint8_t *>(info) + kAlignTo8Bit(info->size));
+ }
}
} // namespace kdbus
diff --git a/libs/kdbinder/kdbus/iterable.h b/libs/kdbinder/kdbus/iterable.h
index 6b87a97..1a80d00 100644
--- a/libs/kdbinder/kdbus/iterable.h
+++ b/libs/kdbinder/kdbus/iterable.h
@@ -44,8 +44,8 @@ void for_each_item(CONTAINER *container,
}
// Iterate over the given list name names in `list`.
-void for_each_name_info(struct kdbus_name_list *list,
- std::function<void(struct kdbus_name_info *)> f);
+void for_each_info(struct kdbus_info *list, uint64_t size,
+ std::function<void(struct kdbus_info *)> f);
} // namespace kdbus
} // namespace android
diff --git a/libs/kdbinder/tests/kdbus/connection.cpp b/libs/kdbinder/tests/kdbus/connection.cpp
index 54bd113..68bb65f 100644
--- a/libs/kdbinder/tests/kdbus/connection.cpp
+++ b/libs/kdbinder/tests/kdbus/connection.cpp
@@ -57,10 +57,8 @@ TEST_F(ConnectionTest, hello) {
auto c1 = Connection::hello(*bus_, "test-conn");
auto c2 = Connection::hello(*bus_, "test-conn");
+ ASSERT_TRUE(c1 != nullptr);
ASSERT_TRUE(c2 != nullptr);
- ASSERT_TRUE(c1->id == 1);
- ASSERT_TRUE(c2 != nullptr);
- ASSERT_TRUE(c2->id == 2);
}
TEST_F(ConnectionTest, acquire_name) {