info struct add padding pool
authorAndy Green <andy.green@linaro.org>
Fri, 25 Dec 2015 01:17:15 +0000 (09:17 +0800)
committerAndy Green <andy.green@linaro.org>
Fri, 25 Dec 2015 01:23:25 +0000 (09:23 +0800)
The info struct is too fragile against additions being able to keep soname.

Because if we add something, the library can't count on the user code being
built against latest headers with largest info struct size.  Then the user
code may not have zeroed down enough of the struct and give us junk in the
new members.

Add a pool at the end of the info struct that exists so it will be zeroed
down even though no current use for those future members, then later
library versions can compatibly use them without breaking soname if it is
understood 0 means default.

Because keeping sizeof info straight if you add something is now a thing,
also add an lwsl_info letting you confirm it easily.

It's fine if the size of info differs on different platforms.  But when
we add things to the struct we need to balance the padding using a scheme
like

       short  new_member;
       unsigned char _padding1[sizeof(void *) - sizeof(short)];

which is immune to differences in platform differences in sizeof void *.

Signed-off-by: Andy Green <andy.green@linaro.org>
lib/context.c
lib/libwebsockets.h

index cb0fbbf..757fdd3 100644 (file)
@@ -100,6 +100,7 @@ lws_create_context(struct lws_context_creation_info *info)
 
        lwsl_info(" SPEC_LATEST_SUPPORTED: %u\n", SPEC_LATEST_SUPPORTED);
        lwsl_info(" AWAITING_TIMEOUT: %u\n", AWAITING_TIMEOUT);
+       lwsl_info(" sizeof (*info): %u\n", sizeof(*info));
 #if LWS_POSIX
        lwsl_info(" SYSTEM_RANDOM_FILEPATH: '%s'\n", SYSTEM_RANDOM_FILEPATH);
        lwsl_info(" LWS_MAX_ZLIB_CONN_BUFFER: %u\n", LWS_MAX_ZLIB_CONN_BUFFER);
index 3536125..4855cd9 100644 (file)
@@ -1278,7 +1278,14 @@ struct lws_context_creation_info {
 #endif
 
        /* Add new things just above here ---^
-        * This is part of the ABI, don't needlessly break compatibilty */
+        * This is part of the ABI, don't needlessly break compatibility
+        *
+        * The below is to ensure later library versions with new
+        * members added above will see 0 (default) even if the app
+        * was not built against the newer headers.
+        */
+
+       void *_unused[9];
 };
 
 LWS_VISIBLE LWS_EXTERN void