Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libspdm: simplify extern fn type checking #91

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Commits on Jul 18, 2024

  1. libspdm: Check the libspdm_write_certificate_to_nvm arguments

    The libspdm version of libspdm_write_certificate_to_nvm() has changed,
    the C header is different as is the bindgen Rust code.
    
    The problem is, we don't get an error that our function no longer
    matches. For now this is ok, as libspdm only appended arguments, but in
    the future this could cause breakages.
    
    There doesn't appear to be any reasonable way to assert that our
    function matches the bindgen version. Moving
    libspdm_write_certificate_to_nvm() to libspdm_rs.rs for example causes
    errors as there are two copies, but that doesn't help us.
    
    The best solution I can think of is to use a test function to check that
    the two functions at least have the same function pointer. This is the
    equivilent checks that a C compiler would do using function pointers.
    
    This adds the checks for libspdm_write_certificate_to_nvm(), we also
    need to do the check for all other functions next.
    
    Signed-off-by: Alistair Francis <[email protected]>
    alistair23 committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    24f9a13 View commit details
    Browse the repository at this point in the history

Commits on Jul 19, 2024

  1. libspdm: Check all extern function arguments

    We don't generate errors or warnings if the function signatures we implement
    don't match the version in libspdm. So far this has been ok as libspdm only
    appended arguments, but in the future this could cause breakages.
    
    There doesn't appear to be any reasonable way to assert that our
    function matches the bindgen version.
    
    The best solution I can think of is to use a test function to check that
    the two functions at least have the same function pointer. This is the
    equivilent checks that a C compiler would do using function pointers.
    
    This patch adds a macro that can generate that function (somewhat manually)
    and then uses that macro for all of the `extern "C"` functions.
    
    Signed-off-by: Alistair Francis <[email protected]>
    alistair23 committed Jul 19, 2024
    Configuration menu
    Copy the full SHA
    9a01062 View commit details
    Browse the repository at this point in the history

Commits on Jul 24, 2024

  1. libspdm: add extern fn type checking

    We don't generate errors or warnings if the function signatures we implement
    don't match the version in libspdm. So far this has been ok as libspdm only
    appended arguments, but in the future this could cause breakages.
    
    There doesn't appear to be any reasonable way to assert that our
    function matches the bindgen version.
    
    This patch adds a macro that can compare a provided function type, to
    it's bindgen generated type upon expansion. When using this macro, the
    first argument shall specify the local type, that is, the type of the
    function as defined within `spdm-utils`. Upon expansion, the macro will
    type check bindgen generated function against the provided type.
    
    All of this shall run only in a `test` context, with no runtime
    overhead. CI should catch any future failures if `libspdm` has changed.
    
    Signed-off-by: Alistair Francis <[email protected]>
    Signed-off-by: Wilfred Mallawa <[email protected]>
    twilfredo committed Jul 24, 2024
    Configuration menu
    Copy the full SHA
    c8c3142 View commit details
    Browse the repository at this point in the history