diff options
author | Kay Sievers <kay@vrfy.org> | 2013-05-21 19:18:10 +0200 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2013-05-21 19:18:10 +0200 |
commit | 9b1830e5146b5165486d8c2443b526241d37388f (patch) | |
tree | 91820a927e9dc9eeddf6d7f7d18ba45eeeaf1451 | |
parent | d0097b8c4a36c27ec34cf38c0dcc0b3b89461f63 (diff) | |
download | kdbus-bus-9b1830e5146b5165486d8c2443b526241d37388f.tar.gz kdbus-bus-9b1830e5146b5165486d8c2443b526241d37388f.tar.bz2 kdbus-bus-9b1830e5146b5165486d8c2443b526241d37388f.zip |
names: add KDBUS_ITEM_NEXT, pad to alignment
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | names.c | 13 | ||||
-rw-r--r-- | test/kdbus-util.c | 9 | ||||
-rw-r--r-- | test/kdbus-util.h | 9 |
5 files changed, 23 insertions, 12 deletions
@@ -1,7 +1,9 @@ External API: - _IOWR() vs. _IOR()/_IOW()? + - convert kdbus_cmd_names to items? Internal: + - use hash_for_each() instead of list to iterate over connections? - if we expect larger amounts of memory to copy around from the sender to the receiver's pool, we should chunk get_user_pages(), replace vmap() - update/rethink kdbus_conn_accounting_sub_size() use, we don't allocate diff --git a/internal.h b/internal.h index 901f2545989..98c3383b1f9 100644 --- a/internal.h +++ b/internal.h @@ -43,7 +43,7 @@ #define KDBUS_IS_ALIGNED8(s) (IS_ALIGNED(s, 8)) #define KDBUS_ITEM_HEADER_SIZE offsetof(struct kdbus_item, data) -#define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE) +#define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8(KDBUS_ITEM_HEADER_SIZE + (s)) #define KDBUS_ITEM_NEXT(item) \ (struct kdbus_item *)((u8 *)item + KDBUS_ALIGN8((item)->size)) #define KDBUS_ITEM_FOREACH(item, head) \ @@ -409,6 +409,11 @@ int kdbus_cmd_name_release(struct kdbus_name_registry *reg, return ret; } +#define KDBUS_NAME_SIZE(s) \ + KDBUS_ALIGN8(sizeof(struct kdbus_cmd_name) + strlen(s) + 1) +#define KDBUS_NAME_NEXT(n) \ + (struct kdbus_cmd_name *)((u8 *)n + KDBUS_ALIGN8(n->size)) + int kdbus_cmd_name_list(struct kdbus_name_registry *reg, struct kdbus_conn *conn, void __user *buf) @@ -427,7 +432,7 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg, size = sizeof(struct kdbus_cmd_names); hash_for_each(reg->entries_hash, tmp, e, hentry) - size += sizeof(struct kdbus_cmd_name) + strlen(e->name) + 1; + size += KDBUS_NAME_SIZE(e->name); if (size > user_size) { kdbus_size_set_user(&size, buf, struct kdbus_cmd_names); @@ -445,12 +450,12 @@ int kdbus_cmd_name_list(struct kdbus_name_registry *reg, cmd_name = cmd_names->names; hash_for_each(reg->entries_hash, tmp, e, hentry) { - cmd_name->size = sizeof(struct kdbus_cmd_name) + strlen(e->name) + 1; + cmd_name->size = sizeof(struct kdbus_cmd_name) + + strlen(e->name) + 1; cmd_name->name_flags = e->flags; cmd_name->id = e->conn->id; strcpy(cmd_name->name, e->name); - //FIXME: alignment for next record? convert records to items maybe? - cmd_name = (struct kdbus_cmd_name *) ((u8 *) cmd_name + cmd_name->size); + cmd_name = KDBUS_NAME_NEXT(cmd_name); } if (copy_to_user(buf, cmd_names, size)) { diff --git a/test/kdbus-util.c b/test/kdbus-util.c index 7f15d23fbe7..693aff6bc8b 100644 --- a/test/kdbus-util.c +++ b/test/kdbus-util.c @@ -462,15 +462,10 @@ int name_list(struct conn *conn) return EXIT_FAILURE; } - size = names->size - sizeof(*names); - name = names->names; - printf("REGISTRY:\n"); - - while (size > 0) { + KDBUS_NAME_FOREACH(name, names) { printf(" '%s' is acquired by id %llx\n", name->name, name->id); - size -= name->size; - name = (struct kdbus_cmd_name *) ((char *) name + name->size); + name = KDBUS_NAME_NEXT(name); } printf("\n"); diff --git a/test/kdbus-util.h b/test/kdbus-util.h index 69fbe4a0c51..34776262c48 100644 --- a/test/kdbus-util.h +++ b/test/kdbus-util.h @@ -26,6 +26,15 @@ item = KDBUS_ITEM_NEXT(item)) #define KDBUS_ITEM_SIZE(s) KDBUS_ALIGN8((s) + KDBUS_ITEM_HEADER_SIZE) +#define KDBUS_NAME_SIZE(s) \ + KDBUS_ALIGN8(sizeof(struct kdbus_cmd_name) + strlen(s) + 1) +#define KDBUS_NAME_NEXT(n) \ + (struct kdbus_cmd_name *)((char *)n + KDBUS_ALIGN8(n->size)) +#define KDBUS_NAME_FOREACH(name, names) \ + for (name = names->names; \ + (char *)name < (char *)names + name->size; \ + name = KDBUS_NAME_NEXT(name)) + struct conn { int fd; uint64_t id; |