Implementation doc: tpmd

Threads

There are two threads: the dbus thread and the tpm thread. The dbus thread is responsible for handling incoming DBus method calls and posting them onto the TPM thread; it also handles the GetStatus API call and reads of TPM properties. We use dbus-c++ to generate adaptors and handle method calls. The flow when a method is called is this:

  • DBus method call arrives
  • Adaptor invoked on dbus thread
  • Adaptor posts task into tpm thread
  • The tpm thread eventually runs the function, which might block for a while
  • The tpm thread sends a reply to the method call over DBus

To do this, we have to use dbus-c++ in its special ‘async adaptor’ mode, which makes it generate wrappers that can defer returning their results; we hand the required continuation (called a ‘tag’) to the tpm thread to use in its reply.