tpm2-software/tpm2-tss

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

Closed this issue · 3 comments

Akuli commented

#else
typedef void FAPI_POLL_HANDLE;
#ifndef FAPI_SUPPRESS_POLL_WARNINGS
#pragma message "Info: Platform not supported for FAPI_POLL_HANDLES"
#endif

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:

struct pollfd fds;
fds.events = io->pollevents;
fds.fd = fileno(io->stream);
LOG_TRACE("Waiting for fd %i with event %i", fds.fd, fds.events);
rc = poll(&fds, 1, -1);

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 commented

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:

(*handles)->events = io->pollevents;
(*handles)->fd = fileno(io->stream);

@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?

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