]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: introduce new SD_BUS_VTABLE_ABSOLUTE_OFFSET vtable flag
authorLennart Poettering <lennart@poettering.net>
Tue, 28 Apr 2020 15:04:08 +0000 (17:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 May 2020 14:57:44 +0000 (16:57 +0200)
When set, the offset specified for the vtable entry is passed to the
handler as-is, and is not added to the userdata pointer. This is useful
in case methods/properties are mixed on the same vtable, that expect to
operate relative to some object in memory and that expect pointers to
absolute memory, or that just want a number passed.

src/libsystemd/sd-bus/bus-objects.c
src/systemd/sd-bus-vtable.h

index ad66d634d7ebfd1c03fb7f40b4bbd2250af97f68..6abac8822c6eed5792529f5ca7cb09b67af58f7d 100644 (file)
@@ -56,7 +56,7 @@ static int node_vtable_get_userdata(
 static void *vtable_method_convert_userdata(const sd_bus_vtable *p, void *u) {
         assert(p);
 
-        if (!u)
+        if (!u || FLAGS_SET(p->flags, SD_BUS_VTABLE_ABSOLUTE_OFFSET))
                 return SIZE_TO_PTR(p->x.method.offset); /* don't add offset on NULL, to make ubsan happy */
 
         return (uint8_t*) u + p->x.method.offset;
@@ -65,7 +65,7 @@ static void *vtable_method_convert_userdata(const sd_bus_vtable *p, void *u) {
 static void *vtable_property_convert_userdata(const sd_bus_vtable *p, void *u) {
         assert(p);
 
-        if (!u)
+        if (!u || FLAGS_SET(p->flags, SD_BUS_VTABLE_ABSOLUTE_OFFSET))
                 return SIZE_TO_PTR(p->x.property.offset); /* as above */
 
         return (uint8_t*) u + p->x.property.offset;
index f2423ba456a3bbc4128645f4173811bfc3ec9679..b10a3e04bc3490cb7d50987126433f1fb095138c 100644 (file)
@@ -44,6 +44,7 @@ enum {
         SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION  = 1ULL << 6,
         SD_BUS_VTABLE_PROPERTY_EXPLICIT            = 1ULL << 7,
         SD_BUS_VTABLE_SENSITIVE                    = 1ULL << 8, /* covers both directions: method call + reply */
+        SD_BUS_VTABLE_ABSOLUTE_OFFSET              = 1ULL << 9,
         _SD_BUS_VTABLE_CAPABILITY_MASK             = 0xFFFFULL << 40
 };