Thunks: Use libclang-based code generation for libxcb-present

This commit is contained in:
Tony Wasserka 2021-12-10 11:24:59 +01:00
parent c8b2d714a8
commit e735281b2c
7 changed files with 170 additions and 187 deletions

View File

@ -1,38 +0,0 @@
#!/usr/bin/python3
from ThunkHelpers import *
lib_with_filename("libxcb_present", "0", "libxcb-present")
# FEX
fn("void FEX_xcb_present_init_extension(xcb_connection_t *, xcb_extension_t *)"); no_unpack()
fn("size_t FEX_usable_size(void*)"); no_unpack()
fn("void FEX_free_on_host(void*)"); no_unpack()
fn("void xcb_present_notify_next(xcb_present_notify_iterator_t *)")
fn("xcb_generic_iterator_t xcb_present_notify_end(xcb_present_notify_iterator_t)")
fn("xcb_present_query_version_cookie_t xcb_present_query_version(xcb_connection_t *, uint32_t, uint32_t)"); no_pack()
fn("xcb_present_query_version_cookie_t xcb_present_query_version_unchecked(xcb_connection_t *, uint32_t, uint32_t)"); no_pack()
fn("xcb_present_query_version_reply_t * xcb_present_query_version_reply(xcb_connection_t *, xcb_present_query_version_cookie_t, xcb_generic_error_t **)"); no_pack()
fn("int xcb_present_pixmap_sizeof(const void *, uint32_t)")
fn("xcb_void_cookie_t xcb_present_pixmap_checked(xcb_connection_t *, xcb_window_t, xcb_pixmap_t, uint32_t, xcb_xfixes_region_t, xcb_xfixes_region_t, int16_t, int16_t, xcb_randr_crtc_t, xcb_sync_fence_t, xcb_sync_fence_t, uint32_t, uint64_t, uint64_t, uint64_t, uint32_t, const xcb_present_notify_t *)")
fn("xcb_void_cookie_t xcb_present_pixmap(xcb_connection_t *, xcb_window_t, xcb_pixmap_t, uint32_t, xcb_xfixes_region_t, xcb_xfixes_region_t, int16_t, int16_t, xcb_randr_crtc_t, xcb_sync_fence_t, xcb_sync_fence_t, uint32_t, uint64_t, uint64_t, uint64_t, uint32_t, const xcb_present_notify_t *)")
# ::Iterator::
fn("xcb_present_notify_t * xcb_present_pixmap_notifies(const xcb_present_pixmap_request_t *)")
fn("int xcb_present_pixmap_notifies_length(const xcb_present_pixmap_request_t *)")
fn("xcb_present_notify_iterator_t xcb_present_pixmap_notifies_iterator(const xcb_present_pixmap_request_t *)")
fn("xcb_void_cookie_t xcb_present_notify_msc_checked(xcb_connection_t *, xcb_window_t, uint32_t, uint64_t, uint64_t, uint64_t)")
fn("xcb_void_cookie_t xcb_present_notify_msc(xcb_connection_t *, xcb_window_t, uint32_t, uint64_t, uint64_t, uint64_t)")
fn("void xcb_present_event_next(xcb_present_event_iterator_t *)")
fn("xcb_generic_iterator_t xcb_present_event_end(xcb_present_event_iterator_t)")
fn("xcb_void_cookie_t xcb_present_select_input_checked(xcb_connection_t *, xcb_present_event_t, xcb_window_t, uint32_t)")
fn("xcb_void_cookie_t xcb_present_select_input(xcb_connection_t *, xcb_present_event_t, xcb_window_t, uint32_t)")
fn("xcb_present_query_capabilities_cookie_t xcb_present_query_capabilities(xcb_connection_t *, uint32_t)")
fn("xcb_present_query_capabilities_cookie_t xcb_present_query_capabilities_unchecked(xcb_connection_t *, uint32_t)")
fn("xcb_present_query_capabilities_reply_t * xcb_present_query_capabilities_reply(xcb_connection_t *, xcb_present_query_capabilities_cookie_t, xcb_generic_error_t **)"); no_pack();
fn("int xcb_present_redirect_notify_sizeof(const void *, uint32_t)")
# ::Iterator::
fn("xcb_present_notify_t * xcb_present_redirect_notify_notifies(const xcb_present_redirect_notify_event_t *)")
fn("int xcb_present_redirect_notify_notifies_length(const xcb_present_redirect_notify_event_t *)")
fn("xcb_present_notify_iterator_t xcb_present_redirect_notify_notifies_iterator(const xcb_present_redirect_notify_event_t *)")
Generate()

View File

@ -258,8 +258,8 @@ add_guest_lib(xcb_shm)
generate(libxcb_sync thunks function_packs function_packs_public)
add_guest_lib(xcb_sync)
generate(libxcb_present thunks function_packs function_packs_public)
add_guest_lib(xcb_present)
generate_new(libxcb-present ${CMAKE_CURRENT_SOURCE_DIR}/../libxcb-present/libxcb-present_interface.cpp thunks function_packs function_packs_public)
add_guest_lib(xcb-present)
generate(libxcb_randr thunks function_packs function_packs_public)
add_guest_lib(xcb_randr)

View File

@ -179,8 +179,8 @@ add_host_lib(xcb_shm)
generate(libxcb_sync function_unpacks tab_function_unpacks ldr ldr_ptrs)
add_host_lib(xcb_sync)
generate(libxcb_present function_unpacks tab_function_unpacks ldr ldr_ptrs)
add_host_lib(xcb_present)
generate_new(libxcb-present ${CMAKE_CURRENT_SOURCE_DIR}/../libxcb-present/libxcb-present_interface.cpp function_unpacks tab_function_unpacks ldr ldr_ptrs)
add_host_lib(xcb-present)
generate(libxcb_randr function_unpacks tab_function_unpacks ldr ldr_ptrs)
add_host_lib(xcb_randr)

View File

@ -0,0 +1,110 @@
/*
$info$
tags: thunklibs|xcb-present
$end_info$
*/
#include <xcb/present.h>
#include <xcb/xcbext.h>
#include <stdio.h>
#include <cstring>
#include <map>
#include <string>
#include "common/Guest.h"
#include <stdarg.h>
#include "thunks.inl"
#include "function_packs.inl"
#include "function_packs_public.inl"
extern "C" {
xcb_extension_t xcb_present_id = {
.name = "Present",
.global_id = 0,
};
void FEX_malloc_free_on_host(void *Ptr) {
struct {void *p;} args;
args.p = Ptr;
fexthunks_libxcb_present_FEX_free_on_host(&args);
}
size_t FEX_malloc_usable_size(void *Ptr) {
struct {void *p; size_t rv;} args;
args.p = Ptr;
fexthunks_libxcb_present_FEX_usable_size(&args);
return args.rv;
}
static void InitializeExtensions(xcb_connection_t *c) {
FEX_xcb_present_init_extension(c, &xcb_present_id);
}
xcb_present_query_version_cookie_t xcb_present_query_version(xcb_connection_t * a_0,uint32_t a_1,uint32_t a_2){
auto ret = fexfn_pack_xcb_present_query_version(a_0, a_1, a_2);
InitializeExtensions(a_0);
return ret;
}
xcb_present_query_version_cookie_t xcb_present_query_version_unchecked(xcb_connection_t * a_0,uint32_t a_1,uint32_t a_2){
auto ret = fexfn_pack_xcb_present_query_version_unchecked(a_0, a_1, a_2);
InitializeExtensions(a_0);
return ret;
}
xcb_present_query_version_reply_t * xcb_present_query_version_reply(xcb_connection_t * a_0,xcb_present_query_version_cookie_t a_1,xcb_generic_error_t ** a_2){
auto ret = fexfn_pack_xcb_present_query_version_reply(a_0, a_1, a_2);
// We now need to do some fixups here
if (a_2 && *a_2) {
// If the error code pointer exists then we need to copy the contents and free the host facing pointer
xcb_generic_error_t *NewError = (xcb_generic_error_t *)malloc(sizeof(xcb_generic_error_t));
memcpy(NewError, *a_2, sizeof(xcb_generic_error_t));
FEX_malloc_free_on_host(*a_2);
// User is expected to free this
*a_2 = NewError;
}
if (ret) {
constexpr size_t ResultSize = sizeof(std::remove_pointer<decltype(ret)>::type);
void *NewPtr = malloc(ResultSize);
memcpy(NewPtr, ret, ResultSize);
FEX_malloc_free_on_host(ret);
ret = (decltype(ret))NewPtr;
}
return ret;
}
xcb_present_query_capabilities_reply_t * xcb_present_query_capabilities_reply(xcb_connection_t * a_0,xcb_present_query_capabilities_cookie_t a_1,xcb_generic_error_t ** a_2){
auto ret = fexfn_pack_xcb_present_query_capabilities_reply(a_0, a_1, a_2);
// We now need to do some fixups here
if (a_2 && *a_2) {
// If the error code pointer exists then we need to copy the contents and free the host facing pointer
xcb_generic_error_t *NewError = (xcb_generic_error_t *)malloc(sizeof(xcb_generic_error_t));
memcpy(NewError, *a_2, sizeof(xcb_generic_error_t));
FEX_malloc_free_on_host(*a_2);
// User is expected to free this
*a_2 = NewError;
}
if (ret) {
constexpr size_t ResultSize = sizeof(std::remove_pointer<decltype(ret)>::type);
void *NewPtr = malloc(ResultSize);
memcpy(NewPtr, ret, ResultSize);
FEX_malloc_free_on_host(ret);
ret = (decltype(ret))NewPtr;
}
return ret;
}
}
LOAD_LIB(libxcb_present)

View File

@ -15,23 +15,19 @@ $end_info$
#include <malloc.h>
#include "ldr_ptrs.inl"
static void fexfn_impl_libxcb_present_FEX_xcb_present_init_extension(xcb_connection_t * a_0, xcb_extension_t * a_1);
static size_t fexfn_impl_libxcb_present_FEX_usable_size(void *a_0){
return malloc_usable_size(a_0);
}
static void fexfn_impl_libxcb_present_FEX_free_on_host(void *a_0){
free(a_0);
}
#include "function_unpacks.inl"
void fexfn_unpack_libxcb_present_FEX_xcb_present_init_extension(void *argsv);
void fexfn_unpack_libxcb_present_FEX_usable_size(void *argsv){
struct arg_t {void* a_0;size_t rv;};
auto args = (arg_t*)argsv;
args->rv = malloc_usable_size(args->a_0);
}
void fexfn_unpack_libxcb_present_FEX_free_on_host(void *argsv){
struct arg_t {void* a_0;};
auto args = (arg_t*)argsv;
free(args->a_0);
}
static ExportEntry exports[] = {
#include "tab_function_unpacks.inl"
{ nullptr, nullptr }
@ -39,15 +35,13 @@ static ExportEntry exports[] = {
#include "ldr.inl"
void fexfn_unpack_libxcb_present_FEX_xcb_present_init_extension(void *argsv){
struct arg_t {xcb_connection_t * a_0;xcb_extension_t * a_1;};
auto args = (arg_t*)argsv;
static void fexfn_impl_libxcb_present_FEX_xcb_present_init_extension(xcb_connection_t * a_0, xcb_extension_t * a_1) {
xcb_extension_t *ext{};
if (strcmp(args->a_1->name, "Present") == 0) {
if (strcmp(a_1->name, "Present") == 0) {
ext = (xcb_extension_t *)dlsym(fexldr_ptr_libxcb_present_so, "xcb_present_id");
}
else {
fprintf(stderr, "Unknown xcb extension '%s'\n", args->a_1->name);
fprintf(stderr, "Unknown xcb extension '%s'\n", a_1->name);
__builtin_trap();
return;
}
@ -57,10 +51,10 @@ void fexfn_unpack_libxcb_present_FEX_xcb_present_init_extension(void *argsv){
fexldr_ptr_libxcb_xcb_get_extension_data = (fexldr_type_libxcb_xcb_get_extension_data*)dlsym(RTLD_DEFAULT, "xcb_get_extension_data");
auto res = fexldr_ptr_libxcb_xcb_get_extension_data(args->a_0, ext);
auto res = fexldr_ptr_libxcb_xcb_get_extension_data(a_0, ext);
// Copy over the global id
args->a_1->global_id = ext->global_id;
a_1->global_id = ext->global_id;
}
EXPORTS(libxcb_present)

View File

@ -0,0 +1,40 @@
#include <common/GeneratorInterface.h>
#include <xcb/present.h>
template<auto>
struct fex_gen_config;
void FEX_xcb_present_init_extension(xcb_connection_t*, xcb_extension_t*);
size_t FEX_usable_size(void*);
void FEX_free_on_host(void*);
template<> struct fex_gen_config<FEX_xcb_present_init_extension> : fexgen::custom_host_impl {};
template<> struct fex_gen_config<FEX_usable_size> : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<FEX_free_on_host> : fexgen::custom_host_impl, fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<xcb_present_notify_next> {};
template<> struct fex_gen_config<xcb_present_notify_end> {};
template<> struct fex_gen_config<xcb_present_query_version> : fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<xcb_present_query_version_unchecked> : fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<xcb_present_query_version_reply> : fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<xcb_present_pixmap_sizeof> {};
template<> struct fex_gen_config<xcb_present_pixmap_checked> {};
template<> struct fex_gen_config<xcb_present_pixmap> {};
template<> struct fex_gen_config<xcb_present_pixmap_notifies> {};
template<> struct fex_gen_config<xcb_present_pixmap_notifies_length> {};
template<> struct fex_gen_config<xcb_present_pixmap_notifies_iterator> {};
template<> struct fex_gen_config<xcb_present_notify_msc_checked> {};
template<> struct fex_gen_config<xcb_present_notify_msc> {};
template<> struct fex_gen_config<xcb_present_event_next> {};
template<> struct fex_gen_config<xcb_present_event_end> {};
template<> struct fex_gen_config<xcb_present_select_input_checked> {};
template<> struct fex_gen_config<xcb_present_select_input> {};
template<> struct fex_gen_config<xcb_present_query_capabilities> {};
template<> struct fex_gen_config<xcb_present_query_capabilities_unchecked> {};
template<> struct fex_gen_config<xcb_present_query_capabilities_reply> : fexgen::custom_guest_entrypoint {};
template<> struct fex_gen_config<xcb_present_redirect_notify_sizeof> {};
template<> struct fex_gen_config<xcb_present_redirect_notify_notifies> {};
template<> struct fex_gen_config<xcb_present_redirect_notify_notifies_length> {};
template<> struct fex_gen_config<xcb_present_redirect_notify_notifies_iterator> {};

View File

@ -1,123 +0,0 @@
/*
$info$
tags: thunklibs|xcb-present
$end_info$
*/
#include <xcb/present.h>
#include <xcb/xcbext.h>
#include <stdio.h>
#include <cstring>
#include <map>
#include <string>
#include "common/Guest.h"
#include <stdarg.h>
#include "thunks.inl"
#include "function_packs.inl"
#include "function_packs_public.inl"
extern "C" {
xcb_extension_t xcb_present_id = {
.name = "Present",
.global_id = 0,
};
void FEX_malloc_free_on_host(void *Ptr) {
struct {void *p;} args;
args.p = Ptr;
fexthunks_libxcb_present_FEX_free_on_host(&args);
}
size_t FEX_malloc_usable_size(void *Ptr) {
struct {void *p; size_t rv;} args;
args.p = Ptr;
fexthunks_libxcb_present_FEX_usable_size(&args);
return args.rv;
}
static void InitializeExtensions(xcb_connection_t *c) {
FEX_xcb_present_init_extension(c, &xcb_present_id);
}
static xcb_present_query_version_cookie_t fexfn_pack_xcb_present_query_version(xcb_connection_t * a_0,uint32_t a_1,uint32_t a_2){
struct {xcb_connection_t * a_0;uint32_t a_1;uint32_t a_2;xcb_present_query_version_cookie_t rv;} args;
args.a_0 = a_0;args.a_1 = a_1;args.a_2 = a_2;
fexthunks_libxcb_present_xcb_present_query_version(&args);
InitializeExtensions(a_0);
return args.rv;
}
static xcb_present_query_version_cookie_t fexfn_pack_xcb_present_query_version_unchecked(xcb_connection_t * a_0,uint32_t a_1,uint32_t a_2){
struct {xcb_connection_t * a_0;uint32_t a_1;uint32_t a_2;xcb_present_query_version_cookie_t rv;} args;
args.a_0 = a_0;args.a_1 = a_1;args.a_2 = a_2;
fexthunks_libxcb_present_xcb_present_query_version_unchecked(&args);
InitializeExtensions(a_0);
return args.rv;
}
static xcb_present_query_version_reply_t * fexfn_pack_xcb_present_query_version_reply(xcb_connection_t * a_0,xcb_present_query_version_cookie_t a_1,xcb_generic_error_t ** a_2){
struct {xcb_connection_t * a_0;xcb_present_query_version_cookie_t a_1;xcb_generic_error_t ** a_2;xcb_present_query_version_reply_t * rv;} args;
args.a_0 = a_0;args.a_1 = a_1;args.a_2 = a_2;
fexthunks_libxcb_present_xcb_present_query_version_reply(&args);
// We now need to do some fixups here
if (a_2 && *a_2) {
// If the error code pointer exists then we need to copy the contents and free the host facing pointer
xcb_generic_error_t *NewError = (xcb_generic_error_t *)malloc(sizeof(xcb_generic_error_t));
memcpy(NewError, *a_2, sizeof(xcb_generic_error_t));
FEX_malloc_free_on_host(*a_2);
// User is expected to free this
*a_2 = NewError;
}
if (args.rv) {
constexpr size_t ResultSize = sizeof(std::remove_pointer<decltype(args.rv)>::type);
void *NewPtr = malloc(ResultSize);
memcpy(NewPtr, args.rv, ResultSize);
FEX_malloc_free_on_host(args.rv);
args.rv = (decltype(args.rv))NewPtr;
}
return args.rv;
}
static xcb_present_query_capabilities_reply_t * fexfn_pack_xcb_present_query_capabilities_reply(xcb_connection_t * a_0,xcb_present_query_capabilities_cookie_t a_1,xcb_generic_error_t ** a_2){
struct {xcb_connection_t * a_0;xcb_present_query_capabilities_cookie_t a_1;xcb_generic_error_t ** a_2;xcb_present_query_capabilities_reply_t * rv;} args;
args.a_0 = a_0;args.a_1 = a_1;args.a_2 = a_2;
fexthunks_libxcb_present_xcb_present_query_capabilities_reply(&args);
// We now need to do some fixups here
if (a_2 && *a_2) {
// If the error code pointer exists then we need to copy the contents and free the host facing pointer
xcb_generic_error_t *NewError = (xcb_generic_error_t *)malloc(sizeof(xcb_generic_error_t));
memcpy(NewError, *a_2, sizeof(xcb_generic_error_t));
FEX_malloc_free_on_host(*a_2);
// User is expected to free this
*a_2 = NewError;
}
if (args.rv) {
constexpr size_t ResultSize = sizeof(std::remove_pointer<decltype(args.rv)>::type);
void *NewPtr = malloc(ResultSize);
memcpy(NewPtr, args.rv, ResultSize);
FEX_malloc_free_on_host(args.rv);
args.rv = (decltype(args.rv))NewPtr;
}
return args.rv;
}
xcb_present_query_version_cookie_t xcb_present_query_version(xcb_connection_t * a_0,uint32_t a_1,uint32_t a_2) __attribute__((alias("fexfn_pack_xcb_present_query_version")));
xcb_present_query_version_cookie_t xcb_present_query_version_unchecked(xcb_connection_t * a_0,uint32_t a_1,uint32_t a_2) __attribute__((alias("fexfn_pack_xcb_present_query_version_unchecked")));
xcb_present_query_version_reply_t * xcb_present_query_version_reply(xcb_connection_t * a_0,xcb_present_query_version_cookie_t a_1,xcb_generic_error_t ** a_2) __attribute__((alias("fexfn_pack_xcb_present_query_version_reply")));
xcb_present_query_capabilities_reply_t * xcb_present_query_capabilities_reply(xcb_connection_t * a_0,xcb_present_query_capabilities_cookie_t a_1,xcb_generic_error_t ** a_2) __attribute__((alias("fexfn_pack_xcb_present_query_capabilities_reply")));
}
LOAD_LIB(libxcb_present)