From 597571ad9fc08cabb4820d91a27bd5ac2eb9616d Mon Sep 17 00:00:00 2001
From: notaz <notasas@gmail.com>
Date: Tue, 11 Feb 2025 00:37:32 +0200
Subject: [PATCH] gpu: some function mismatches

pointed out by ubsan
---
 Makefile              |  4 ++++
 frontend/main.c       |  2 +-
 libpcsxcore/gpu.h     |  9 +++++++++
 libpcsxcore/plugins.h |  7 +------
 plugins/gpulib/gpu.c  | 10 +---------
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index 1c2ad07b..eb822972 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,10 @@ CFLAGS += -fsanitize=address
 LDFLAGS += -fsanitize=address
 #LDFLAGS += -static-libasan
 endif
+ifeq ($(DEBUG_UBSAN), 1)
+CFLAGS += -fsanitize=undefined -fno-sanitize=shift-base
+LDFLAGS += -fsanitize=undefined
+endif
 ifneq ($(NO_FSECTIONS), 1)
 CFLAGS += -ffunction-sections -fdata-sections
 FSECTIONS_LDFLAGS ?= -Wl,--gc-sections
diff --git a/frontend/main.c b/frontend/main.c
index bc799b22..56f8fd45 100644
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -805,7 +805,7 @@ void SysRunGui() {
         printf("SysRunGui\n");
 }
 
-static void CALLBACK dummy_lace()
+static void CALLBACK dummy_lace(void)
 {
 }
 
diff --git a/libpcsxcore/gpu.h b/libpcsxcore/gpu.h
index c61986d8..95132532 100644
--- a/libpcsxcore/gpu.h
+++ b/libpcsxcore/gpu.h
@@ -24,6 +24,15 @@
 #ifndef __GPU_H__
 #define __GPU_H__
 
+#include <stdint.h>
+
+typedef struct GPUFreeze {
+	uint32_t ulFreezeVersion;
+	uint32_t ulStatus;
+	uint32_t ulControl[256];
+	unsigned char psxVRam[1024*512*2];
+} GPUFreeze_t;
+
 #define PSXGPU_LCF     (1u<<31)
 #define PSXGPU_nBUSY   (1u<<26)
 #define PSXGPU_ILACE   (1u<<22)
diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h
index b2efbcea..4755c17a 100644
--- a/libpcsxcore/plugins.h
+++ b/libpcsxcore/plugins.h
@@ -36,6 +36,7 @@ typedef long (CALLBACK *NETopen)(unsigned long *);
 typedef long (CALLBACK *SIO1open)(unsigned long *);
 
 #include "spu.h"
+#include "gpu.h"
 #include "decode_xa.h"
 
 int LoadPlugins();
@@ -63,12 +64,6 @@ typedef void (CALLBACK* GPUupdateLace)(void);
 typedef void (CALLBACK* GPUmakeSnapshot)(void);
 typedef void (CALLBACK* GPUkeypressed)(int);
 typedef void (CALLBACK* GPUdisplayText)(char *);
-typedef struct {
-	uint32_t ulFreezeVersion;
-	uint32_t ulStatus;
-	uint32_t ulControl[256];
-	unsigned char psxVRam[1024*512*2];
-} GPUFreeze_t;
 typedef long (CALLBACK* GPUfreeze)(uint32_t, GPUFreeze_t *);
 typedef long (CALLBACK* GPUgetScreenPic)(unsigned char *);
 typedef long (CALLBACK* GPUshowScreenPic)(unsigned char *);
diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c
index 4307e4de..3318549c 100644
--- a/plugins/gpulib/gpu.c
+++ b/plugins/gpulib/gpu.c
@@ -901,15 +901,7 @@ uint32_t GPUreadStatus(void)
   return ret;
 }
 
-struct GPUFreeze
-{
-  uint32_t ulFreezeVersion;      // should be always 1 for now (set by main emu)
-  uint32_t ulStatus;             // current gpu status
-  uint32_t ulControl[256];       // latest control register values
-  unsigned char psxVRam[1024*1024*2]; // current VRam image (full 2 MB for ZN)
-};
-
-long GPUfreeze(uint32_t type, struct GPUFreeze *freeze)
+long GPUfreeze(uint32_t type, GPUFreeze_t *freeze)
 {
   int i;
 
-- 
2.39.5