/**
 * @file wow64.h
 * @brief WoW64 thunk layer header
 *
 * MVGAL - Multi-Vendor GPU Aggregation Layer for Linux
 *
 * SPDX-License-Identifier: MIT
 */

#ifndef MVGAL_WOW64_H
#define MVGAL_WOW64_H

#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Thunk context for 32/64-bit translation
 */
struct wow64_thunk_context;

/**
 * @brief Allocate shared memory for 32/64-bit interop
 * @param size Size of shared memory region
 * @return Pointer to shared memory, or NULL on failure
 */
void *wow64_alloc_shared_memory(size_t size);

/**
 * @brief Free shared memory
 * @param ptr Pointer to shared memory
 * @param size Size of the region
 */
void wow64_free_shared_memory(void *ptr, size_t size);

/**
 * @brief Thunk a 32-bit pointer to 64-bit
 * @param ptr32 32-bit pointer value
 * @return 64-bit pointer
 */
void *wow64_thunk_pointer(uint32_t ptr32);

/**
 * @brief Thunk a 64-bit pointer to 32-bit
 * @param ptr 64-bit pointer
 * @return 32-bit pointer value
 */
uint32_t wow64_unthunk_pointer(const void *ptr);

/**
 * @brief Initialize WoW64 thunk layer
 * @param is_32bit Target architecture flag
 * @return 0 on success, -1 on failure
 */
int wow64_init(int is_32bit);

/**
 * @brief Cleanup WoW64 thunk layer
 */
void wow64_fini(void);

/**
 * @brief Call a 32-bit function from 64-bit context
 * @param func32 32-bit function pointer
 * @param args Arguments array
 * @param arg_count Number of arguments
 * @return Return value
 */
uint64_t wow64_call_32bit(uint32_t func32, uint64_t *args, int arg_count);

#ifdef __cplusplus
}
#endif

#endif /* MVGAL_WOW64_H */