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