unify host programs across targets

This commit is contained in:
2026-04-16 22:36:36 +02:00
parent e73ab0a788
commit 329014aada
11 changed files with 226 additions and 346 deletions

View File

@ -4,21 +4,57 @@
#define INLINE __attribute__((always_inline)) inline
#define NOINLINE __attribute__((noinline))
#define EXPORT(fnct) __attribute__((export_name(fnct)))
#define IMPORT(fnct) __attribute__((import_module("env"), import_name(fnct)))
#if !defined(TARGET_FAIL) && !defined(TARGET_LINUX_BAREMETAL) && \
!defined(TARGET_LINUX)
// Set to linux while editing to prevent lsp errors
#define TARGET_LINUX
#endif
#ifdef TARGET_FAIL
#define MAIN void os_main(void)
#define PRINT(fmt, ...)
#define PRINT_ERROR(fmt, ...)
#define PRINT_SUCCESS(fmt, ...)
#define HOST_PRINT(msg)
#define RET(val) return
#endif
#ifdef TARGET_LINUX_BAREMETAL
#define MAIN int main(int argc, char *argv[])
#define PRINT(fmt, ...)
#define PRINT_ERROR(fmt, ...)
#define PRINT_SUCCESS(fmt, ...)
#define HOST_PRINT(msg)
#define RET(val) return
#endif
#ifdef TARGET_LINUX
#define MAIN int main(int argc, char *argv[])
#define PRINT(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
#define PRINT_ERROR(fmt, ...) \
fprintf(stderr, "[Error] "); \
fprintf(stderr, fmt, ##__VA_ARGS__)
#define PRINT_SUCCESS(fmt, ...) \
fprintf(stdout, "[Success] "); \
fprintf(stdout, fmt, ##__VA_ARGS__)
#define HOST_PRINT(msg) print(msg)
#define RET(val) return val;
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Mark start of injection
void NOINLINE fail_start_trace(void);
// Mark end of injection
void NOINLINE fail_stop_trace(void);
// everything ok: valid code and right values
void NOINLINE fail_marker_positive(void);
// everything ok: valid code but wrong values
void NOINLINE fail_marker_negative(void);
// invalid code
void NOINLINE fail_marker_detected(void);
// Those functions are defined in the host program
void NOINLINE fail_start_trace(void); // Mark start of injection
void NOINLINE fail_stop_trace(void); // Mark end of injection
void NOINLINE fail_marker_positive(void); // Everything ok
void NOINLINE fail_marker_detected(void); // Everything ok
void NOINLINE fail_marker_negative(void); // Invalid code
void NOINLINE print(const char *msg);
#ifdef __cplusplus
}