Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
misc.h File Reference

Miscellaneous declarations for Linux. More...

#include <chrono>
#include <fcntl.h>
#include <filesystem>
#include <thread>
#include <unistd.h>
#include <vector>
#include "src/utility.h"
Include dependency graph for misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

using dyn::apiproc = void (*)(void)
 Generic GLX procedure pointer returned by the loader.

Enumerations

enum class  window_system_e { NONE , X11 , WAYLAND }
 Enumerates supported window system options. More...

Functions

library_t * dyn::handle (const std::vector< const char * > &libs)
 Open the first available shared library from a nonempty list.
void platf::handle_pacing (std::chrono::steady_clock::time_point &next_frame, std::chrono::nanoseconds delay, auto &logger)
 Generic frame pacing logic for Linux capture methods.
int dyn::load (library_t *handle, const std::vector< std::tuple< apiproc *, const char * > > &funcs, bool strict)
 Load named functions from an open shared library.
int platf::open_drm_card_fd (const std::filesystem::path &path, int flags)
 Open a DRM card node, dropping implicit DRM master when possible.
bool platf::sanitize_process_environment ()
 Remove environment variables that can load untrusted GUI modules.

Variables

window_system_e window_system
 Window system.

Detailed Description

Miscellaneous declarations for Linux.

Enumeration Type Documentation

◆ window_system_e

enum class window_system_e
strong

Enumerates supported window system options.

Enumerator
NONE 

No window system.

X11 

X11.

WAYLAND 

Wayland.

Function Documentation

◆ handle()

void * dyn::handle ( const std::vector< const char * > & libs)

Open the first available shared library from a nonempty list.

Return the native handle owned by the wrapper.

Returns
Open library handle, or null if none could be loaded.
Parameters
libsList of libraries to probe for the requested symbol.
Returns
Native dynamic-library handle, or nullptr when no library can be opened.

◆ handle_pacing()

void platf::handle_pacing ( std::chrono::steady_clock::time_point & next_frame,
std::chrono::nanoseconds delay,
auto & logger )
inline

Generic frame pacing logic for Linux capture methods.

Advances the frame pacing timeline and re-anchors it if the capture thread falls behind.

Parameters
next_frameTime point that the next frame will be targeted against.
delayDelay interval used to pace next frame.
loggerThe sleep_overshoot_logger for tracking discontinuities.

◆ load()

int dyn::load ( library_t * handle,
const std::vector< std::tuple< apiproc *, const char * > > & funcs,
bool strict = true )

Load named functions from an open shared library.

Parameters
handleLibrary whose symbols are queried.
funcsFunction pointer destinations and corresponding symbol names.
strictWhether missing symbols make the operation fail.
Returns
Zero on success or minus one when a required symbol is missing.

◆ open_drm_card_fd()

int platf::open_drm_card_fd ( const std::filesystem::path & path,
int flags )

Open a DRM card node, dropping implicit DRM master when possible.

Open a DRM card node and drop implicit DRM master, if any.

See misc.h for full documentation. Master check/drop failures are logged as warnings but do not fail the call.

Performs open(path, flags | O_CLOEXEC) and probes the resulting fd with DRM_IOCTL_AUTH_MAGIC. If the kernel implicitly handed us master, calls drmDropMaster and re-verifies before returning. Master check/drop failures are logged as warnings but do not fail the call: the caller still receives a usable fd.

Callers should use this helper for any /dev/dri/cardN open so we never keep implicit master and block compositors from re-acquiring it on VT switches.

Parameters
pathPath to the DRM card node (e.g. /dev/dri/card0).
flagsopen() flags. O_CLOEXEC is always OR-ed in.
Returns
A file descriptor on success, or -1 if open() itself fails.

◆ sanitize_process_environment()

bool platf::sanitize_process_environment ( )

Remove environment variables that can load untrusted GUI modules.

Loader paths and module lists used by Qt, GTK, GIO, and GdkPixbuf are removed before any of those libraries can initialize. The caller determines whether privileged execution requires the policy.

Returns
true when the environment is safe to use; false if a variable could not be removed.