Skip to content

Commit

Permalink
fix(core) replace intptr_t with uintptr_t. Close LWJGL#720
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Spasi authored and fayer3 committed Jul 14, 2023
1 parent 73a4b74 commit 1e61ab9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 14 additions & 14 deletions modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1e61ab9

Please sign in to comment.