immunant / IA2-Phase2

5 stars 0 forks source link

rewriter: `struct __va_list_tag *` used instead of `va_list` #429

Open kkysen opened 1 month ago

kkysen commented 1 month ago

When the IA2_TYPE_* for a variadic function is generated, struct __va_list_tag * is used. However, this type is, IIUC, supposed to be private, resulting in errors like this:

/home/kkysen/work/rust/dav1d-ia2/callgate_wrapper.h:31:86: warning: ‘struct __va_list_tag’ declared inside parameter list will not be visible outside of this definition or declaration
   31 | #define IA2_TYPE__ZTSPFvPvPKcP13__va_list_tagE void (*)(void *, const char *, struct __va_list_tag *)
      |                                                                                      ^~~~~~~~~~~~~
../../ia2/runtime/libia2/include/ia2_internal.h:42:6: note: in expansion of macro ‘IA2_TYPE__ZTSPFvPvPKcP13__va_list_tagE’
   42 |     (IA2_TYPE_##id) & __ia2_indirect_callgate_##id##_pkey_##pkey;              \
      |      ^~~~~~~~~
../../ia2/runtime/libia2/include/ia2_internal.h:44:37: note: in expansion of macro ‘__IA2_CALL’
   44 | #define _IA2_CALL(opaque, id, pkey) __IA2_CALL(opaque, id, pkey)
      |                                     ^~~~~~~~~~
../../ia2/runtime/libia2/include/ia2.h:136:30: note: in expansion of macro ‘_IA2_CALL’
  136 | #define IA2_CALL(opaque, id) _IA2_CALL(opaque, id, PKEY)
      |                              ^~~~~~~~~
../src/log.c:54:5: note: in expansion of macro ‘IA2_CALL’
   54 |     IA2_CALL(c->logger.callback, _ZTSPFvPvPKcP13__va_list_tagE)(c->logger.cookie, format, ap);
      |     ^~~~~~~~
../src/log.c:54:91: error: passing argument 3 of ‘(({...}))’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   54 |     IA2_CALL(c->logger.callback, _ZTSPFvPvPKcP13__va_list_tagE)(c->logger.cookie, format, ap);
      |                                                                                           ^~
      |                                                                                           |
      |                                                                                           __va_list_tag *
../src/log.c:54:91: note: expected ‘struct __va_list_tag *’ but argument is of type ‘__va_list_tag *’

That is, the struct __va_list_tag * creates some new anonymous struct __va_list_tag type that's different from the private struct __va_list_tag type from stdarg.h, which publically exposes it through va_list, which is typedef'd/macro'd to struct __va_list_tag *. Thus, I'm pretty sure that we should be using va_list here instead, and changing the code in callgate_wrapper.h to use va_list instead fixes this error.

ayrtonm commented 1 month ago

We can't have variadic functions at compartment boundaries. Is it possible to move the boundary up or down one function in the call stack?

kkysen commented 1 month ago

We can't have variadic functions at compartment boundaries. Is it possible to move the boundary up or down one function in the call stack?

I thought @rinon said this is okay, just that it'll just run the fn ptr in compartment 0 instead, which should be fine for just logging things (hopefully).