From 1e61ab90c6492b9d19aff25b55658837b5a19063 Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Sun, 6 Feb 2022 21:52:13 +0200 Subject: [PATCH] fix(core) replace intptr_t with uintptr_t. Close #720 This fixes pointer casts on 32-bit architectures. Previously, addresses that happened to be greater than 2GB on x86/arm32 would overflow when cast to intptr_t and, via the cast to jlong, propagate as negative values to Java code. --- .../c/org_lwjgl_openvr_VRChaperone.c | 4 +-- .../c/org_lwjgl_openvr_VRCompositor.c | 4 +-- .../generated/c/org_lwjgl_openvr_VROverlay.c | 12 ++++---- .../generated/c/org_lwjgl_openvr_VRSystem.c | 28 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c index d7959ea2dd..6ac02b28ce 100644 --- a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c +++ b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c @@ -24,8 +24,8 @@ typedef void (APIENTRY *VRChaperone_SetSceneColorPROC) (HmdColor_t); EXTERN_C_ENTER JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRChaperone_nVRChaperone_1SetSceneColor(JNIEnv *__env, jclass clazz, jlong colorAddress, jlong __functionAddress) { - VRChaperone_SetSceneColorPROC VRChaperone_SetSceneColor = (VRChaperone_SetSceneColorPROC)(intptr_t)__functionAddress; - HmdColor_t *color = (HmdColor_t *)(intptr_t)colorAddress; + VRChaperone_SetSceneColorPROC VRChaperone_SetSceneColor = (VRChaperone_SetSceneColorPROC)(uintptr_t)__functionAddress; + HmdColor_t *color = (HmdColor_t *)(uintptr_t)colorAddress; UNUSED_PARAMS(__env, clazz) VRChaperone_SetSceneColor(*color); } diff --git a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRCompositor.c b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRCompositor.c index 490fcec6eb..b1e4c0cb92 100644 --- a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRCompositor.c +++ b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRCompositor.c @@ -24,9 +24,9 @@ typedef HmdColor_t (APIENTRY *VRCompositor_GetCurrentFadeColorPROC) (jboolean); EXTERN_C_ENTER JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRCompositor_nVRCompositor_1GetCurrentFadeColor(JNIEnv *__env, jclass clazz, jboolean bBackground, jlong __functionAddress, jlong __result) { - VRCompositor_GetCurrentFadeColorPROC VRCompositor_GetCurrentFadeColor = (VRCompositor_GetCurrentFadeColorPROC)(intptr_t)__functionAddress; + VRCompositor_GetCurrentFadeColorPROC VRCompositor_GetCurrentFadeColor = (VRCompositor_GetCurrentFadeColorPROC)(uintptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) - *((HmdColor_t*)(intptr_t)__result) = VRCompositor_GetCurrentFadeColor(bBackground); + *((HmdColor_t*)(uintptr_t)__result) = VRCompositor_GetCurrentFadeColor(bBackground); } EXTERN_C_EXIT diff --git a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c index 41e95c8332..4d87389944 100644 --- a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c +++ b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c @@ -22,22 +22,22 @@ typedef struct HmdRect2_t struct HmdVector2_t vBottomRight; } HmdRect2_t; -typedef jint (APIENTRY *VROverlay_GetTransformForOverlayCoordinatesPROC) (jlong, jint, HmdVector2_t, intptr_t); +typedef jint (APIENTRY *VROverlay_GetTransformForOverlayCoordinatesPROC) (jlong, jint, HmdVector2_t, uintptr_t); typedef void (APIENTRY *VROverlay_SetKeyboardPositionForOverlayPROC) (jlong, HmdRect2_t); EXTERN_C_ENTER JNIEXPORT jint JNICALL Java_org_lwjgl_openvr_VROverlay_nVROverlay_1GetTransformForOverlayCoordinates(JNIEnv *__env, jclass clazz, jlong ulOverlayHandle, jint eTrackingOrigin, jlong coordinatesInOverlayAddress, jlong pmatTransformAddress, jlong __functionAddress) { - VROverlay_GetTransformForOverlayCoordinatesPROC VROverlay_GetTransformForOverlayCoordinates = (VROverlay_GetTransformForOverlayCoordinatesPROC)(intptr_t)__functionAddress; - HmdVector2_t *coordinatesInOverlay = (HmdVector2_t *)(intptr_t)coordinatesInOverlayAddress; - intptr_t pmatTransform = (intptr_t)pmatTransformAddress; + VROverlay_GetTransformForOverlayCoordinatesPROC VROverlay_GetTransformForOverlayCoordinates = (VROverlay_GetTransformForOverlayCoordinatesPROC)(uintptr_t)__functionAddress; + HmdVector2_t *coordinatesInOverlay = (HmdVector2_t *)(uintptr_t)coordinatesInOverlayAddress; + uintptr_t pmatTransform = (uintptr_t)pmatTransformAddress; UNUSED_PARAMS(__env, clazz) return (jint)VROverlay_GetTransformForOverlayCoordinates(ulOverlayHandle, eTrackingOrigin, *coordinatesInOverlay, pmatTransform); } JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VROverlay_nVROverlay_1SetKeyboardPositionForOverlay(JNIEnv *__env, jclass clazz, jlong ulOverlayHandle, jlong avoidRectAddress, jlong __functionAddress) { - VROverlay_SetKeyboardPositionForOverlayPROC VROverlay_SetKeyboardPositionForOverlay = (VROverlay_SetKeyboardPositionForOverlayPROC)(intptr_t)__functionAddress; - HmdRect2_t *avoidRect = (HmdRect2_t *)(intptr_t)avoidRectAddress; + VROverlay_SetKeyboardPositionForOverlayPROC VROverlay_SetKeyboardPositionForOverlay = (VROverlay_SetKeyboardPositionForOverlayPROC)(uintptr_t)__functionAddress; + HmdRect2_t *avoidRect = (HmdRect2_t *)(uintptr_t)avoidRectAddress; UNUSED_PARAMS(__env, clazz) VROverlay_SetKeyboardPositionForOverlay(ulOverlayHandle, *avoidRect); } diff --git a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRSystem.c b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRSystem.c index 4ad95512c1..ac1c997950 100644 --- a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRSystem.c +++ b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRSystem.c @@ -48,46 +48,46 @@ typedef HmdMatrix44_t (APIENTRY *VRSystem_GetProjectionMatrixPROC) (jint, jfloat typedef HmdMatrix34_t (APIENTRY *VRSystem_GetEyeToHeadTransformPROC) (jint); typedef HmdMatrix34_t (APIENTRY *VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPosePROC) (void); typedef HmdMatrix34_t (APIENTRY *VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPosePROC) (void); -typedef HmdMatrix34_t (APIENTRY *VRSystem_GetMatrix34TrackedDevicePropertyPROC) (jint, jint, intptr_t); +typedef HmdMatrix34_t (APIENTRY *VRSystem_GetMatrix34TrackedDevicePropertyPROC) (jint, jint, uintptr_t); typedef HiddenAreaMesh_t (APIENTRY *VRSystem_GetHiddenAreaMeshPROC) (jint, jint); EXTERN_C_ENTER JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRSystem_nVRSystem_1GetProjectionMatrix(JNIEnv *__env, jclass clazz, jint eEye, jfloat fNearZ, jfloat fFarZ, jlong __functionAddress, jlong __result) { - VRSystem_GetProjectionMatrixPROC VRSystem_GetProjectionMatrix = (VRSystem_GetProjectionMatrixPROC)(intptr_t)__functionAddress; + VRSystem_GetProjectionMatrixPROC VRSystem_GetProjectionMatrix = (VRSystem_GetProjectionMatrixPROC)(uintptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) - *((HmdMatrix44_t*)(intptr_t)__result) = VRSystem_GetProjectionMatrix(eEye, fNearZ, fFarZ); + *((HmdMatrix44_t*)(uintptr_t)__result) = VRSystem_GetProjectionMatrix(eEye, fNearZ, fFarZ); } JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRSystem_nVRSystem_1GetEyeToHeadTransform(JNIEnv *__env, jclass clazz, jint eEye, jlong __functionAddress, jlong __result) { - VRSystem_GetEyeToHeadTransformPROC VRSystem_GetEyeToHeadTransform = (VRSystem_GetEyeToHeadTransformPROC)(intptr_t)__functionAddress; + VRSystem_GetEyeToHeadTransformPROC VRSystem_GetEyeToHeadTransform = (VRSystem_GetEyeToHeadTransformPROC)(uintptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) - *((HmdMatrix34_t*)(intptr_t)__result) = VRSystem_GetEyeToHeadTransform(eEye); + *((HmdMatrix34_t*)(uintptr_t)__result) = VRSystem_GetEyeToHeadTransform(eEye); } JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRSystem_nVRSystem_1GetSeatedZeroPoseToStandingAbsoluteTrackingPose(JNIEnv *__env, jclass clazz, jlong __functionAddress, jlong __result) { - VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPosePROC VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPose = (VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPosePROC)(intptr_t)__functionAddress; + VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPosePROC VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPose = (VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPosePROC)(uintptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) - *((HmdMatrix34_t*)(intptr_t)__result) = VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPose(); + *((HmdMatrix34_t*)(uintptr_t)__result) = VRSystem_GetSeatedZeroPoseToStandingAbsoluteTrackingPose(); } JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRSystem_nVRSystem_1GetRawZeroPoseToStandingAbsoluteTrackingPose(JNIEnv *__env, jclass clazz, jlong __functionAddress, jlong __result) { - VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPosePROC VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPose = (VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPosePROC)(intptr_t)__functionAddress; + VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPosePROC VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPose = (VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPosePROC)(uintptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) - *((HmdMatrix34_t*)(intptr_t)__result) = VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPose(); + *((HmdMatrix34_t*)(uintptr_t)__result) = VRSystem_GetRawZeroPoseToStandingAbsoluteTrackingPose(); } JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRSystem_nVRSystem_1GetMatrix34TrackedDeviceProperty(JNIEnv *__env, jclass clazz, jint unDeviceIndex, jint prop, jlong pErrorAddress, jlong __functionAddress, jlong __result) { - VRSystem_GetMatrix34TrackedDevicePropertyPROC VRSystem_GetMatrix34TrackedDeviceProperty = (VRSystem_GetMatrix34TrackedDevicePropertyPROC)(intptr_t)__functionAddress; - intptr_t pError = (intptr_t)pErrorAddress; + VRSystem_GetMatrix34TrackedDevicePropertyPROC VRSystem_GetMatrix34TrackedDeviceProperty = (VRSystem_GetMatrix34TrackedDevicePropertyPROC)(uintptr_t)__functionAddress; + uintptr_t pError = (uintptr_t)pErrorAddress; UNUSED_PARAMS(__env, clazz) - *((HmdMatrix34_t*)(intptr_t)__result) = VRSystem_GetMatrix34TrackedDeviceProperty(unDeviceIndex, prop, pError); + *((HmdMatrix34_t*)(uintptr_t)__result) = VRSystem_GetMatrix34TrackedDeviceProperty(unDeviceIndex, prop, pError); } JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRSystem_nVRSystem_1GetHiddenAreaMesh(JNIEnv *__env, jclass clazz, jint eEye, jint type, jlong __functionAddress, jlong __result) { - VRSystem_GetHiddenAreaMeshPROC VRSystem_GetHiddenAreaMesh = (VRSystem_GetHiddenAreaMeshPROC)(intptr_t)__functionAddress; + VRSystem_GetHiddenAreaMeshPROC VRSystem_GetHiddenAreaMesh = (VRSystem_GetHiddenAreaMeshPROC)(uintptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) - *((HiddenAreaMesh_t*)(intptr_t)__result) = VRSystem_GetHiddenAreaMesh(eEye, type); + *((HiddenAreaMesh_t*)(uintptr_t)__result) = VRSystem_GetHiddenAreaMesh(eEye, type); } EXTERN_C_EXIT