| 52 | } |
| 53 | |
| 54 | HANDLE CreateJobObjectForChildProcess() { |
| 55 | HANDLE job_handle = CreateJobObjectW(nullptr, nullptr); |
| 56 | if (!job_handle) { |
| 57 | return nullptr; |
| 58 | } |
| 59 | |
| 60 | JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_limit_info = {}; |
| 61 | |
| 62 | // Kill Sunshine.exe when the final job object handle is closed (which will happen if we terminate unexpectedly). |
| 63 | // This ensures we don't leave an orphaned Sunshine.exe running with an inherited handle to our log file. |
| 64 | job_limit_info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; |
| 65 | |
| 66 | // Allow Sunshine.exe to use CREATE_BREAKAWAY_FROM_JOB when spawning processes to ensure they can to live beyond |
| 67 | // the lifetime of SunshineSvc.exe. This avoids unexpected user data loss if we crash or are killed. |
| 68 | job_limit_info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_BREAKAWAY_OK; |
| 69 | |
| 70 | if (!SetInformationJobObject(job_handle, JobObjectExtendedLimitInformation, &job_limit_info, sizeof(job_limit_info))) { |
| 71 | CloseHandle(job_handle); |
| 72 | return nullptr; |
| 73 | } |
| 74 | |
| 75 | return job_handle; |
| 76 | } |
| 77 | |
| 78 | LPPROC_THREAD_ATTRIBUTE_LIST AllocateProcThreadAttributeList(DWORD attribute_count) { |
| 79 | SIZE_T size; |