Monado OpenXR Runtime
u_windows.c File Reference

Various helpers for doing Windows specific things. More...

#include "xrt/xrt_windows.h"
#include "util/u_windows.h"
#include "util/u_logging.h"
#include "assert.h"
Include dependency graph for u_windows.c:

Macros

#define LOG_D(...)   U_LOG_IFL_D(log_level, __VA_ARGS__)
 
#define LOG_I(...)   U_LOG_IFL_I(log_level, __VA_ARGS__)
 
#define LOG_W(...)   U_LOG_IFL_W(log_level, __VA_ARGS__)
 
#define LOG_E(...)   U_LOG_IFL_E(log_level, __VA_ARGS__)
 
#define GET_LAST_ERROR_STR(BUF)   (u_winerror(BUF, ARRAY_SIZE(BUF), GetLastError(), true))
 

Functions

static bool check_privilege_on_process (HANDLE hProcess, LPCTSTR lpszPrivilege, LPBOOL pfResult)
 
static bool enable_privilege_on_process (HANDLE hProcess, LPCTSTR lpszPrivilege)
 
bool try_to_grant_privilege (enum u_logging_level log_level, HANDLE hProcess, LPCTSTR lpszPrivilege)
 
static const char * get_priority_string (DWORD dwPriorityClass)
 
static bool try_to_raise_priority (enum u_logging_level log_level, HANDLE hProcess)
 
const char * u_winerror (char *s, size_t size, DWORD err, bool remove_end)
 This function formats a Windows error number, as returned by GetLastError, and writes it into the given buffer. More...
 
bool u_win_grant_inc_base_priorty_base_privileges (enum u_logging_level log_level)
 Tries to grant the 'SeIncreaseBasePriorityPrivilege' privilege to this process. More...
 
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. More...
 
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. More...
 

Detailed Description

Various helpers for doing Windows specific things.

Author
Jakob Bornecrantz jakob.nosp@m.@col.nosp@m.labor.nosp@m.a.co.nosp@m.m

Function Documentation

◆ u_win_grant_inc_base_priorty_base_privileges()

bool u_win_grant_inc_base_priorty_base_privileges ( enum u_logging_level  log_level)

Tries to grant the 'SeIncreaseBasePriorityPrivilege' privilege to this process.

It is needed for HIGH and REALTIME priority Vulkan queues on NVIDIA.

Parameters
log_levelControl the amount of logging this function does.

◆ u_win_raise_cpu_priority()

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.

Returns false if it could not raise the priority at all. Normal processes can raise themselves from NORMAL to HIGH, while REALTIME requires either administrator privileges or the 'SeIncreaseBasePriorityPrivilege' privilege to be granted.

Parameters
log_levelControl the amount of logging this function does.

◆ u_win_try_privilege_or_priority_from_args()

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.

The parsing is really simplistic and only looks at the first argument for the values nothing, priority, privilege, both. No argument at all implies the value both making the function try to set both.

Parameters
log_levelControl the amount of logging this function does.
argcNumber of arguments, as passed into main.
argvArray of argument strings, as passed into main.

◆ u_winerror()

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 given buffer.

Parameters
bufferBuffer to format the error into.
sizeSize of the given buffer.
errError number to format a string for.
remove_endRemoves and trailing \n, \r and . characters.