Monado OpenXR Runtime
u_windows.h
Go to the documentation of this file.
1// Copyright 2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Various helpers for doing Windows specific things.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 *
8 * @ingroup aux_os
9 */
10
11#pragma once
12
13#include "xrt/xrt_compiler.h"
14#include "xrt/xrt_windows.h"
15#include "util/u_logging.h"
16
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
23/*!
24 * This function formats a Windows error number, as returned by `GetLastError`,
25 * and writes it into the given buffer.
26 *
27 * @param buffer Buffer to format the error into.
28 * @param size Size of the given buffer.
29 * @param err Error number to format a string for.
30 * @param remove_end Removes and trailing `\n`, `\r` and `.` characters.
31 */
32const char *
33u_winerror(char *buffer, size_t size, DWORD err, bool remove_end);
34
35/*!
36 * Tries to grant the 'SeIncreaseBasePriorityPrivilege' privilege to this
37 * process. It is needed for HIGH and REALTIME priority Vulkan queues on NVIDIA.
38 *
39 * @param log_level Control the amount of logging this function does.
40 */
41bool
43
44/*!
45 * Tries to raise the CPU priority of the process as high as possible. Returns
46 * false if it could not raise the priority at all. Normal processes can raise
47 * themselves from NORMAL to HIGH, while REALTIME requires either administrator
48 * privileges or the 'SeIncreaseBasePriorityPrivilege' privilege to be granted.
49 *
50 * @param log_level Control the amount of logging this function does.
51 */
52bool
54
55/*!
56 * Small helper function that checks process arguments for which to try.
57 *
58 * The parsing is really simplistic and only looks at the first argument for the
59 * values `nothing`, `priority`, `privilege`, `both`. No argument at all implies
60 * the value `both` making the function try to set both.
61 *
62 * @param log_level Control the amount of logging this function does.
63 * @param argc Number of arguments, as passed into main.
64 * @param argv Array of argument strings, as passed into main.
65 */
66void
67u_win_try_privilege_or_priority_from_args(enum u_logging_level log_level, int argc, char *argv[]);
68
69
70#ifdef __cplusplus
71}
72#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
Basic logging functionality.
void u_win_try_privilege_or_priority_from_args(enum u_logging_level log_level, int argc, char *argv[])
Small helper function that checks process arguments for which to try.
Definition: u_windows.c:285
bool u_win_raise_cpu_priority(enum u_logging_level log_level)
Tries to raise the CPU priority of the process as high as possible.
Definition: u_windows.c:275
bool u_win_grant_inc_base_priorty_base_privileges(enum u_logging_level log_level)
Tries to grant the 'SeIncreaseBasePriorityPrivilege' privilege to this process.
Definition: u_windows.c:265
const char * u_winerror(char *buffer, size_t size, DWORD err, bool remove_end)
This function formats a Windows error number, as returned by GetLastError, and writes it into the giv...
Definition: u_windows.c:225
Header holding common defines.
A minimal way to include Windows.h.