core: Optimize the memory layout of the transfer structure
authorChris Dickens <christopher.a.dickens@gmail.com>
Wed, 26 Feb 2020 23:14:56 +0000 (15:14 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Wed, 26 Feb 2020 23:14:56 +0000 (15:14 -0800)
commit0e8f3997bd7b11390e9ec7b7de7eb31f403c1c83
tree82d76c8514da3ee274364963950dfc056a099d6c
parent136346391677455b9259e446c8445e7fbb1ad36e
core: Optimize the memory layout of the transfer structure

Prior to this commit, the memory layout of the transfer structure was as
follows:

         ------------------------------------------------------
        | usbi_transfer | libusb_transfer [variable] | os_priv |
         ------------------------------------------------------

With this layout, accessing the os_priv area requires calculating the
size of the area used by the libusb_transfer, which varies based on the
number of iso packets allocated for the transfer.

This commit changes the memory layout of the transfer structure to the
following:

         ------------------------------------------------------
        | os_priv | usbi_transfer | libusb_transfer [variable] |
         ------------------------------------------------------

Having the os_priv in a fixed position relative to the usbi_transfer
allows for constant-time access with the added benefit of not allowing
the user to corrupt the data by accessing elements of the
libusb_transfer structure that are out-of-bounds.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/io.c
libusb/libusbi.h
libusb/version_nano.h