The open source OpenXR runtime

ipc: Return XR_ERROR_INSTANCE_LOST instead of SIGABRT on the client side

+47 -23
+4 -4
src/xrt/ipc/ipc_client_utils.c
··· 33 return XRT_ERROR_IPC_FAILURE; 34 } 35 36 - ssize_t len = send(ipc_c->socket_fd, msg_ptr, msg_size, 0); 37 if ((size_t)len != msg_size) { 38 IPC_ERROR(ipc_c, "Error sending - cannot continue!"); 39 os_mutex_unlock(&ipc_c->mutex); ··· 54 msg.msg_iovlen = 1; 55 msg.msg_flags = 0; 56 57 - len = recvmsg(ipc_c->socket_fd, &msg, 0); 58 59 if (len < 0) { 60 IPC_ERROR(ipc_c, "recvmsg failed with error: %s", ··· 85 { 86 os_mutex_lock(&ipc_c->mutex); 87 88 - if (send(ipc_c->socket_fd, msg_ptr, msg_size, 0) == -1) { 89 IPC_ERROR(ipc_c, "Error sending - cannot continue!"); 90 os_mutex_unlock(&ipc_c->mutex); 91 return XRT_ERROR_IPC_FAILURE; ··· 109 msg.msg_control = u.buf; 110 msg.msg_controllen = cmsg_size; 111 112 - ssize_t len = recvmsg(ipc_c->socket_fd, &msg, 0); 113 114 if (len < 0) { 115 IPC_ERROR(ipc_c, "recvmsg failed with error: %s",
··· 33 return XRT_ERROR_IPC_FAILURE; 34 } 35 36 + ssize_t len = send(ipc_c->socket_fd, msg_ptr, msg_size, MSG_NOSIGNAL); 37 if ((size_t)len != msg_size) { 38 IPC_ERROR(ipc_c, "Error sending - cannot continue!"); 39 os_mutex_unlock(&ipc_c->mutex); ··· 54 msg.msg_iovlen = 1; 55 msg.msg_flags = 0; 56 57 + len = recvmsg(ipc_c->socket_fd, &msg, MSG_NOSIGNAL); 58 59 if (len < 0) { 60 IPC_ERROR(ipc_c, "recvmsg failed with error: %s", ··· 85 { 86 os_mutex_lock(&ipc_c->mutex); 87 88 + if (send(ipc_c->socket_fd, msg_ptr, msg_size, MSG_NOSIGNAL) == -1) { 89 IPC_ERROR(ipc_c, "Error sending - cannot continue!"); 90 os_mutex_unlock(&ipc_c->mutex); 91 return XRT_ERROR_IPC_FAILURE; ··· 109 msg.msg_control = u.buf; 110 msg.msg_controllen = cmsg_size; 111 112 + ssize_t len = recvmsg(ipc_c->socket_fd, &msg, MSG_NOSIGNAL); 113 114 if (len < 0) { 115 IPC_ERROR(ipc_c, "recvmsg failed with error: %s",
+26 -16
src/xrt/state_trackers/oxr/oxr_session.c
··· 35 DEBUG_GET_ONCE_NUM_OPTION(ipd, "OXR_DEBUG_IPD_MM", 63) 36 DEBUG_GET_ONCE_NUM_OPTION(prediction_ms, "OXR_DEBUG_PREDICTION_MS", 11) 37 38 static bool 39 is_running(struct oxr_session *sess) 40 { ··· 130 view_type); 131 } 132 133 - xrt_comp_begin_session(xc, (enum xrt_view_type)beginInfo 134 - ->primaryViewConfigurationType); 135 } 136 137 sess->has_begun = true; ··· 159 sess->frame_started = false; 160 } 161 162 - xrt_comp_end_session(xc); 163 } 164 165 oxr_session_change_state(log, sess, XR_SESSION_STATE_IDLE); ··· 417 418 uint64_t predicted_display_time; 419 uint64_t predicted_display_period; 420 - xrt_comp_wait_frame(xc, &predicted_display_time, 421 - &predicted_display_period); 422 423 if ((int64_t)predicted_display_time <= 0) { 424 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, ··· 463 if (sess->frame_started) { 464 ret = XR_FRAME_DISCARDED; 465 if (xc != NULL) { 466 - xrt_comp_discard_frame(xc); 467 } 468 } else { 469 ret = oxr_session_success_result(sess); 470 sess->frame_started = true; 471 } 472 if (xc != NULL) { 473 - xrt_comp_begin_frame(xc); 474 } 475 476 return ret; ··· 718 return XR_SUCCESS; 719 } 720 721 - static void 722 submit_quad_layer(struct xrt_compositor *xc, 723 struct oxr_logger *log, 724 XrCompositionLayerQuad *quad, ··· 732 struct xrt_pose pose; 733 math_pose_transform(inv_offset, (struct xrt_pose *)&quad->pose, &pose); 734 735 - xrt_comp_layer_quad( 736 xc, timestamp, head, XRT_INPUT_GENERIC_HEAD_POSE, quad->layerFlags, 737 (enum xrt_layer_eye_visibility)quad->eyeVisibility, sc->swapchain, 738 sc->released.index, (struct xrt_rect *)&quad->subImage.imageRect, 739 quad->subImage.imageArrayIndex, &pose, 740 - (struct xrt_vec2 *)&quad->size, false); 741 } 742 743 - static void 744 submit_projection_layer(struct xrt_compositor *xc, 745 struct oxr_logger *log, 746 XrCompositionLayerProjection *proj, ··· 764 math_pose_transform(inv_offset, (struct xrt_pose *)&proj->views[1].pose, 765 &pose[1]); 766 767 - xrt_comp_layer_stereo_projection( 768 xc, timestamp, head, XRT_INPUT_GENERIC_HEAD_POSE, flags, 769 scs[0]->swapchain, // Left 770 scs[0]->released.index, ··· 775 scs[1]->released.index, 776 (struct xrt_rect *)&proj->views[1].subImage.imageRect, 777 proj->views[1].subImage.imageArrayIndex, 778 - (struct xrt_fov *)&proj->views[1].fov, &pose[1], false); 779 } 780 781 XrResult ··· 845 * Early out for discarded frame if layer count is 0. 846 */ 847 if (frameEndInfo->layerCount == 0) { 848 - xrt_comp_discard_frame(xc); 849 sess->frame_started = false; 850 851 return oxr_session_success_result(sess); ··· 905 math_pose_invert(&sess->sys->head->tracking_origin->offset, 906 &inv_offset); 907 908 - xrt_comp_layer_begin(xc, blend_mode); 909 910 for (uint32_t i = 0; i < frameEndInfo->layerCount; i++) { 911 const XrCompositionLayerBaseHeader *layer = ··· 929 } 930 } 931 932 - xrt_comp_layer_commit(xc); 933 934 sess->frame_started = false; 935
··· 35 DEBUG_GET_ONCE_NUM_OPTION(ipd, "OXR_DEBUG_IPD_MM", 63) 36 DEBUG_GET_ONCE_NUM_OPTION(prediction_ms, "OXR_DEBUG_PREDICTION_MS", 11) 37 38 + #define CALL_CHK(call) \ 39 + if ((call) == XRT_ERROR_IPC_FAILURE) { \ 40 + return oxr_error(log, XR_ERROR_INSTANCE_LOST, \ 41 + "Error in function call over IPC"); \ 42 + } 43 + 44 static bool 45 is_running(struct oxr_session *sess) 46 { ··· 136 view_type); 137 } 138 139 + CALL_CHK(xrt_comp_begin_session( 140 + xc, (enum xrt_view_type) 141 + beginInfo->primaryViewConfigurationType)); 142 } 143 144 sess->has_begun = true; ··· 166 sess->frame_started = false; 167 } 168 169 + CALL_CHK(xrt_comp_end_session(xc)); 170 } 171 172 oxr_session_change_state(log, sess, XR_SESSION_STATE_IDLE); ··· 424 425 uint64_t predicted_display_time; 426 uint64_t predicted_display_period; 427 + CALL_CHK(xrt_comp_wait_frame(xc, &predicted_display_time, 428 + &predicted_display_period)); 429 430 if ((int64_t)predicted_display_time <= 0) { 431 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, ··· 470 if (sess->frame_started) { 471 ret = XR_FRAME_DISCARDED; 472 if (xc != NULL) { 473 + CALL_CHK(xrt_comp_discard_frame(xc)); 474 } 475 } else { 476 ret = oxr_session_success_result(sess); 477 sess->frame_started = true; 478 } 479 if (xc != NULL) { 480 + CALL_CHK(xrt_comp_begin_frame(xc)); 481 } 482 483 return ret; ··· 725 return XR_SUCCESS; 726 } 727 728 + static XrResult 729 submit_quad_layer(struct xrt_compositor *xc, 730 struct oxr_logger *log, 731 XrCompositionLayerQuad *quad, ··· 739 struct xrt_pose pose; 740 math_pose_transform(inv_offset, (struct xrt_pose *)&quad->pose, &pose); 741 742 + CALL_CHK(xrt_comp_layer_quad( 743 xc, timestamp, head, XRT_INPUT_GENERIC_HEAD_POSE, quad->layerFlags, 744 (enum xrt_layer_eye_visibility)quad->eyeVisibility, sc->swapchain, 745 sc->released.index, (struct xrt_rect *)&quad->subImage.imageRect, 746 quad->subImage.imageArrayIndex, &pose, 747 + (struct xrt_vec2 *)&quad->size, false)); 748 + 749 + return XR_SUCCESS; 750 } 751 752 + static XrResult 753 submit_projection_layer(struct xrt_compositor *xc, 754 struct oxr_logger *log, 755 XrCompositionLayerProjection *proj, ··· 773 math_pose_transform(inv_offset, (struct xrt_pose *)&proj->views[1].pose, 774 &pose[1]); 775 776 + CALL_CHK(xrt_comp_layer_stereo_projection( 777 xc, timestamp, head, XRT_INPUT_GENERIC_HEAD_POSE, flags, 778 scs[0]->swapchain, // Left 779 scs[0]->released.index, ··· 784 scs[1]->released.index, 785 (struct xrt_rect *)&proj->views[1].subImage.imageRect, 786 proj->views[1].subImage.imageArrayIndex, 787 + (struct xrt_fov *)&proj->views[1].fov, &pose[1], false)); 788 + return XR_SUCCESS; 789 } 790 791 XrResult ··· 855 * Early out for discarded frame if layer count is 0. 856 */ 857 if (frameEndInfo->layerCount == 0) { 858 + CALL_CHK(xrt_comp_discard_frame(xc)); 859 sess->frame_started = false; 860 861 return oxr_session_success_result(sess); ··· 915 math_pose_invert(&sess->sys->head->tracking_origin->offset, 916 &inv_offset); 917 918 + CALL_CHK(xrt_comp_layer_begin(xc, blend_mode)); 919 920 for (uint32_t i = 0; i < frameEndInfo->layerCount; i++) { 921 const XrCompositionLayerBaseHeader *layer = ··· 939 } 940 } 941 942 + CALL_CHK(xrt_comp_layer_commit(xc)); 943 944 sess->frame_started = false; 945
+17 -3
src/xrt/state_trackers/oxr/oxr_swapchain.c
··· 37 } 38 39 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 40 - if (xsc->acquire_image(xsc, &index) != XRT_SUCCESS) { 41 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 42 "Call to xsc->acquire_image failed"); 43 } ··· 84 u_index_fifo_pop(&sc->acquired.fifo, &index); 85 86 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 87 - if (xsc->wait_image(xsc, waitInfo->timeout, index) != XRT_SUCCESS) { 88 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 89 "Call to xsc->wait_image failed"); 90 } ··· 111 uint32_t index = sc->waited.index; 112 113 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 114 - if (xsc->release_image(xsc, index) != XRT_SUCCESS) { 115 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 116 "Call to xsc->release_image failed"); 117 }
··· 37 } 38 39 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 40 + 41 + xrt_result_t res = xsc->acquire_image(xsc, &index); 42 + if (res == XRT_ERROR_IPC_FAILURE) { 43 + return oxr_error(log, XR_ERROR_INSTANCE_LOST, 44 + "Call to xsc->acquire_image failed"); 45 + } else if (res != XRT_SUCCESS) { 46 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 47 "Call to xsc->acquire_image failed"); 48 } ··· 89 u_index_fifo_pop(&sc->acquired.fifo, &index); 90 91 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 92 + 93 + xrt_result_t res = xsc->wait_image(xsc, waitInfo->timeout, index); 94 + if (res == XRT_ERROR_IPC_FAILURE) { 95 + return oxr_error(log, XR_ERROR_INSTANCE_LOST, 96 + "Call to xsc->wait_image failed"); 97 + } else if (res != XRT_SUCCESS) { 98 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 99 "Call to xsc->wait_image failed"); 100 } ··· 121 uint32_t index = sc->waited.index; 122 123 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 124 + xrt_result_t res = xsc->release_image(xsc, index); 125 + if (res == XRT_ERROR_IPC_FAILURE) { 126 + return oxr_error(log, XR_ERROR_INSTANCE_LOST, 127 + "Call to xsc->release_image failed"); 128 + } else if (res != XRT_SUCCESS) { 129 return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, 130 "Call to xsc->release_image failed"); 131 }