The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipc: Ensure that app/client ID is not zero or already in use

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2619>

authored by

Jakob Bornecrantz and committed by
Marge Bot
d9fe8e9a a320964a

+29 -2
+29 -2
src/xrt/ipc/server/ipc_server_process.c
··· 771 771 return XRT_SUCCESS; 772 772 } 773 773 774 + static uint32_t 775 + allocate_id_locked(struct ipc_server *s) 776 + { 777 + uint32_t id = 0; 778 + while (id == 0) { 779 + // Allocate a new one. 780 + id = ++s->id_generator; 781 + 782 + for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { 783 + volatile struct ipc_client_state *ics = &s->threads[i].ics; 784 + 785 + // If we find the ID, get a new one by setting to zero. 786 + if (ics->client_state.id == id) { 787 + id = 0; 788 + break; 789 + } 790 + } 791 + } 792 + 793 + // Paranoia. 794 + if (id == 0) { 795 + U_LOG_E("Got app(client) id 0, not allowed!"); 796 + assert(id > 0); 797 + } 798 + 799 + return id; 800 + } 801 + 774 802 775 803 /* 776 804 * ··· 937 965 it->state = IPC_THREAD_STARTING; 938 966 939 967 // Allocate a new ID, avoid zero. 940 - //! @todo validate ID. 941 - uint32_t id = ++vs->id_generator; 968 + uint32_t id = allocate_id_locked(vs); 942 969 943 970 // Reset everything. 944 971 U_ZERO((struct ipc_client_state *)ics);