core: Add provisions for per-context private backend data
authorChris Dickens <christopher.a.dickens@gmail.com>
Wed, 5 Jul 2017 22:01:58 +0000 (15:01 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Thu, 6 Jul 2017 21:26:46 +0000 (14:26 -0700)
This functionality will be useful for backends that need to maintain
data specific to a context.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/core.c
libusb/libusbi.h
libusb/os/haiku_usb_raw.cpp
libusb/os/netbsd_usb.c
libusb/os/openbsd_usb.c
libusb/os/wince_usb.c
libusb/os/windows_usbdk.c
libusb/os/windows_winusb.c
libusb/version_nano.h

index 38dea8e..06da8d0 100644 (file)
@@ -2050,6 +2050,7 @@ int API_EXPORTED libusb_init(libusb_context **context)
 {
        struct libusb_device *dev, *next;
        char *dbg = getenv("LIBUSB_DEBUG");
+       size_t priv_size = usbi_backend.context_priv_size;
        struct libusb_context *ctx;
        static int first_init = 1;
        int r = 0;
@@ -2067,7 +2068,7 @@ int API_EXPORTED libusb_init(libusb_context **context)
                return 0;
        }
 
-       ctx = calloc(1, sizeof(*ctx));
+       ctx = calloc(1, sizeof(*ctx) + priv_size);
        if (!ctx) {
                r = LIBUSB_ERROR_NO_MEM;
                goto err_unlock;
index bd76111..c820b89 100644 (file)
@@ -358,6 +358,8 @@ struct libusb_context {
 #endif
 
        struct list_head list;
+
+       PTR_ALIGNED unsigned char os_priv[ZERO_SIZED_ARRAY];
 };
 
 enum usbi_event_flags {
@@ -1112,6 +1114,11 @@ struct usbi_os_backend {
        clockid_t (*get_timerfd_clockid)(void);
 #endif
 
+       /* Number of bytes to reserve for per-context private backend data.
+        * This private data area is accessible through the "os_priv" field of
+        * struct libusb_context. */
+       size_t context_priv_size;
+
        /* Number of bytes to reserve for per-device private backend data.
         * This private data area is accessible through the "os_priv" field of
         * struct libusb_device. */
index a84bd59..f480b2d 100644 (file)
@@ -244,6 +244,7 @@ const struct usbi_os_backend usbi_backend = {
        /*.get_timerfd_clockid =*/ NULL,
 #endif
 
+       /*.context_priv_size=*/ 0,
        /*.device_priv_size =*/ sizeof(USBDevice *),
        /*.device_handle_priv_size =*/ sizeof(USBDeviceHandle *),
        /*.transfer_priv_size =*/ sizeof(USBTransfer *),
index 26163c0..93a1e22 100644 (file)
@@ -131,6 +131,7 @@ const struct usbi_os_backend usbi_backend = {
        netbsd_handle_transfer_completion,
 
        netbsd_clock_gettime,
+       0,                              /* context_priv_size */
        sizeof(struct device_priv),
        sizeof(struct handle_priv),
        0,                              /* transfer_priv_size */
index bb75db7..4afa262 100644 (file)
@@ -134,6 +134,7 @@ const struct usbi_os_backend usbi_backend = {
        obsd_handle_transfer_completion,
 
        obsd_clock_gettime,
+       0,                              /* context_priv_size */
        sizeof(struct device_priv),
        sizeof(struct handle_priv),
        0,                              /* transfer_priv_size */
index 39c2da1..a691c9e 100644 (file)
@@ -893,6 +893,7 @@ const struct usbi_os_backend usbi_backend = {
        NULL,                           /* handle_transfer_completion() */
 
        wince_clock_gettime,
+       0,
        sizeof(struct wince_device_priv),
        0,
        sizeof(struct wince_transfer_priv),
index 6aa7cad..047ce51 100644 (file)
@@ -893,6 +893,7 @@ const struct usbi_os_backend usbi_backend = {
 #if defined(USBI_TIMERFD_AVAILABLE)
        NULL,
 #endif
+       0,
        sizeof(struct usbdk_device_priv),
        0,
        sizeof(struct usbdk_transfer_priv),
index c2559c7..ac360d2 100644 (file)
@@ -2095,6 +2095,7 @@ const struct usbi_os_backend usbi_backend = {
 #if defined(USBI_TIMERFD_AVAILABLE)
        NULL,
 #endif
+       0,
        sizeof(struct windows_device_priv),
        sizeof(struct windows_device_handle_priv),
        sizeof(struct windows_transfer_priv),
index 9821993..d60e39e 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11206
+#define LIBUSB_NANO 11207