tpm2-tss icon indicating copy to clipboard operation
tpm2-tss copied to clipboard

Should FAPI work out of the box without poll()?

Open Akuli opened this issue 1 year ago • 2 comments

https://github.com/tpm2-software/tpm2-tss/blob/74e8294ca7b0280957a518c1bab0266510962870/include/tss2/tss2_fapi.h#L61-L65

If I understand this code correctly, it is saying that FAPI can be used on systems without poll(). I would imagine it will just wait for the TPM chip to respond, making the async functions kinda useless but still being useful as a sync library.

But it's not really possible, because FAPI also calls poll() unconditionally:

https://github.com/tpm2-software/tpm2-tss/blob/74e8294ca7b0280957a518c1bab0266510962870/src/tss2-fapi/ifapi_io.c#L706-L710

This code is not inside an #ifdef. It is also in a file that is needed for fapi to work at all. So it seems to me that there's no way to disable this, apart from resorting to #define poll(...) 0 and the like.

Is FAPI supposed to "just work" on systems that don't have poll()?

Akuli avatar Jul 13 '23 18:07 Akuli

Also, it seems that the typedef to void doesn't work at all. For example, this does not compile because handles has type void ** and cannot be dereferenced twice:

https://github.com/tpm2-software/tpm2-tss/blob/74e8294ca7b0280957a518c1bab0266510962870/src/tss2-fapi/ifapi_io.c#L745-L746

Akuli avatar Jul 13 '23 18:07 Akuli

@Akuli No FAPI should not work out of the box without poll. Also some tctis should not compile in the case :

#else
typedef void TSS2_TCTI_POLL_HANDLE;
#ifndef TSS2_TCTI_SUPPRESS_POLL_WARNINGS
#pragma message "Info: Platform not supported for TCTI_POLL_HANDLES"

In this case compilation is possible after: ./configure --disable-tcti-device --disable-tcti-mssim --disable-tcti-cmd --disable-fapi

@AndreasFuchsTPM @joholl Wouldn't it be better to create an error in this case at least for fapi?

JuergenReppSIT avatar Jul 15 '23 07:07 JuergenReppSIT

The FAPI API (i.e. include/tss2/tss2-fapi.h) is designed to work on multiple systems, those with poll() being one of such. The implementation of ifapi-io.c is specific to systems that have poll(). In order to get FAPI working on e.g. Windows, ifapi-io.c would need to be made more flexible, or maybe we would even want to have an ifapi-io-linux.c and an ifapi-io-windows.c

AndreasFuchsTPM avatar May 08 '24 15:05 AndreasFuchsTPM