diff --git a/src/amd/common/ac_linux_drm.c b/src/amd/common/ac_linux_drm.c index fd31fdae2fa..122daa07c44 100644 --- a/src/amd/common/ac_linux_drm.c +++ b/src/amd/common/ac_linux_drm.c @@ -5,6 +5,7 @@ #include "util/os_drm.h" #include "ac_linux_drm.h" +#include "util/os_misc.h" #include "util/u_math.h" #include "util/u_sync_provider.h" #include "ac_gpu_info.h" @@ -295,9 +296,9 @@ int ac_drm_cs_ctx_create2(ac_drm_device *dev, uint32_t priority, uint32_t *ctx_i { int r; union drm_amdgpu_ctx args; - char *override_priority; + const char *override_priority; - override_priority = getenv("AMD_PRIORITY"); + override_priority = os_get_option("AMD_PRIORITY"); if (override_priority) { /* The priority is a signed integer. The variable type is * wrong. If parsing fails, priority is unchanged. diff --git a/src/amd/compiler/aco_ir.cpp b/src/amd/compiler/aco_ir.cpp index 815437c1d4b..3d33b952f37 100644 --- a/src/amd/compiler/aco_ir.cpp +++ b/src/amd/compiler/aco_ir.cpp @@ -43,7 +43,7 @@ static once_flag init_once_flag = ONCE_FLAG_INIT; static void init_once() { - debug_flags = parse_debug_string(getenv("ACO_DEBUG"), aco_debug_options); + debug_flags = parse_debug_string(os_get_option("ACO_DEBUG"), aco_debug_options); #ifndef NDEBUG /* enable some flags by default on debug builds */ diff --git a/src/amd/drm-shim/amdgpu_noop_drm_shim.c b/src/amd/drm-shim/amdgpu_noop_drm_shim.c index 30ab30156fb..31e50078203 100644 --- a/src/amd/drm-shim/amdgpu_noop_drm_shim.c +++ b/src/amd/drm-shim/amdgpu_noop_drm_shim.c @@ -11,6 +11,7 @@ #include "drm-shim/drm_shim.h" #include "drm-uapi/amdgpu_drm.h" #include "util/log.h" +#include "util/os_misc.h" static const struct amdgpu_device *amdgpu_dev; @@ -201,7 +202,7 @@ static ioctl_fn_t amdgpu_ioctls[] = { static void amdgpu_select_device() { - const char *gpu_id = getenv("AMDGPU_GPU_ID"); + const char *gpu_id = os_get_option("AMDGPU_GPU_ID"); if (gpu_id) { for (uint32_t i = 0; i < num_amdgpu_devices; i++) { const struct amdgpu_device *dev = &amdgpu_devices[i]; diff --git a/src/amd/drm-shim/radeon_noop_drm_shim.c b/src/amd/drm-shim/radeon_noop_drm_shim.c index 8c9f9481927..954d2a53029 100644 --- a/src/amd/drm-shim/radeon_noop_drm_shim.c +++ b/src/amd/drm-shim/radeon_noop_drm_shim.c @@ -4,6 +4,7 @@ #include "common/amd_family.h" #include "drm-shim/drm_shim.h" #include "util/log.h" +#include "util/os_misc.h" #include #include @@ -153,7 +154,7 @@ static const struct radeon_pci_id radeon_pci_ids[] = { static void radeon_get_device_id() { - const char *gpu_id = getenv("RADEON_GPU_ID"); + const char *gpu_id = os_get_option("RADEON_GPU_ID"); if (!gpu_id) return; diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index a97bcb490d8..37251e33d5c 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -79,7 +79,7 @@ radv_spm_trace_enabled(const struct radv_instance *instance) static bool radv_trap_handler_enabled() { - return !!getenv("RADV_TRAP_HANDLER"); + return !!os_get_option("RADV_TRAP_HANDLER"); } bool @@ -405,7 +405,7 @@ radv_parse_vrs_rates(const char *str) static const char * radv_get_force_vrs_config_file(void) { - return getenv("RADV_FORCE_VRS_CONFIG_FILE"); + return os_get_option("RADV_FORCE_VRS_CONFIG_FILE"); } static enum radv_force_vrs @@ -1329,7 +1329,7 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr device->dispatch_initiator_task = device->dispatch_initiator | S_00B800_DISABLE_DISP_PREMPT_EN(1); if (pdev->info.gfx_level == GFX10_3) { - if (getenv("RADV_FORCE_VRS_CONFIG_FILE")) { + if (os_get_option("RADV_FORCE_VRS_CONFIG_FILE")) { const char *file = radv_get_force_vrs_config_file(); device->force_vrs = radv_parse_force_vrs_config_file(file); @@ -1339,8 +1339,8 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr } else { fprintf(stderr, "radv: Failed to initialize the notifier for RADV_FORCE_VRS_CONFIG_FILE!\n"); } - } else if (getenv("RADV_FORCE_VRS")) { - const char *vrs_rates = getenv("RADV_FORCE_VRS"); + } else if (os_get_option("RADV_FORCE_VRS")) { + const char *vrs_rates = os_get_option("RADV_FORCE_VRS"); device->force_vrs = radv_parse_vrs_rates(vrs_rates); device->force_vrs_enabled = device->force_vrs != RADV_FORCE_VRS_1x1; diff --git a/src/amd/vulkan/radv_instance.c b/src/amd/vulkan/radv_instance.c index 909788c02df..9dc4eab67fd 100644 --- a/src/amd/vulkan/radv_instance.c +++ b/src/amd/vulkan/radv_instance.c @@ -389,9 +389,9 @@ radv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationC simple_mtx_init(&instance->shader_dump_mtx, mtx_plain); - instance->debug_flags = parse_debug_string(getenv("RADV_DEBUG"), radv_debug_options); - instance->perftest_flags = parse_debug_string(getenv("RADV_PERFTEST"), radv_perftest_options); - instance->trap_excp_flags = parse_debug_string(getenv("RADV_TRAP_HANDLER_EXCP"), radv_trap_excp_options); + instance->debug_flags = parse_debug_string(os_get_option("RADV_DEBUG"), radv_debug_options); + instance->perftest_flags = parse_debug_string(os_get_option("RADV_PERFTEST"), radv_perftest_options); + instance->trap_excp_flags = parse_debug_string(os_get_option("RADV_TRAP_HANDLER_EXCP"), radv_trap_excp_options); instance->profile_pstate = radv_parse_pstate(debug_get_option("RADV_PROFILE_PSTATE", "peak")); const uint64_t shader_stage_flags = RADV_DEBUG_DUMP_VS | RADV_DEBUG_DUMP_TCS | RADV_DEBUG_DUMP_TES | @@ -425,7 +425,7 @@ radv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationC * device that allows to test the compiler without having an * AMDGPU instance. */ - if (getenv("RADV_FORCE_FAMILY")) + if (os_get_option("RADV_FORCE_FAMILY")) instance->vk.physical_devices.enumerate = create_null_physical_device; else instance->vk.physical_devices.try_create_for_drm = create_drm_physical_device; diff --git a/src/amd/vulkan/winsys/null/radv_null_winsys.c b/src/amd/vulkan/winsys/null/radv_null_winsys.c index 42ce2d30990..ec3ade9cfa7 100644 --- a/src/amd/vulkan/winsys/null/radv_null_winsys.c +++ b/src/amd/vulkan/winsys/null/radv_null_winsys.c @@ -61,7 +61,7 @@ static const struct { static void radv_null_winsys_query_info(struct radeon_winsys *rws, struct radeon_info *gpu_info) { - const char *family = getenv("RADV_FORCE_FAMILY"); + const char *family = os_get_option("RADV_FORCE_FAMILY"); unsigned i; gpu_info->gfx_level = CLASS_UNKNOWN; diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index f7d9efcb670..66014b9f76c 100644 --- a/src/asahi/lib/decode.c +++ b/src/asahi/lib/decode.c @@ -11,6 +11,7 @@ #include #include #include +#include "util/os_misc.h" #include "util/u_dynarray.h" #include "util/u_math.h" #include @@ -1024,7 +1025,7 @@ agxdecode_dump_file_open(void) * setenv to change the base at runtime. */ const char *dump_file_base = - getenv("AGXDECODE_DUMP_FILE") ?: "agxdecode.dump"; + os_get_option("AGXDECODE_DUMP_FILE") ?: "agxdecode.dump"; if (!strcmp(dump_file_base, "stderr")) agxdecode_dump_stream = stderr; else { diff --git a/src/asahi/vulkan/hk_physical_device.c b/src/asahi/vulkan/hk_physical_device.c index 71026f7c28e..8151f13a6c3 100644 --- a/src/asahi/vulkan/hk_physical_device.c +++ b/src/asahi/vulkan/hk_physical_device.c @@ -1244,7 +1244,7 @@ hk_create_drm_physical_device(struct vk_instance *_instance, hk_physical_device_init_pipeline_cache(pdev); - const char *hk_sysmem = getenv("HK_SYSMEM"); + const char *hk_sysmem = os_get_option("HK_SYSMEM"); if (hk_sysmem) { uint64_t sysmem = strtoll(hk_sysmem, NULL, 10); if (sysmem != LLONG_MIN && sysmem != LLONG_MAX) { diff --git a/src/broadcom/ds/v3d_pps_driver.cc b/src/broadcom/ds/v3d_pps_driver.cc index 563c8e5af99..8b29783556d 100644 --- a/src/broadcom/ds/v3d_pps_driver.cc +++ b/src/broadcom/ds/v3d_pps_driver.cc @@ -10,6 +10,7 @@ #include #include "perfcntrs/v3d_perfcntrs.h" +#include "util/os_misc.h" #include namespace pps @@ -24,7 +25,7 @@ V3DDriver::get_min_sampling_period_ns() bool V3DDriver::init_perfcnt() { - const char *v3d_ds_counter_env = getenv("V3D_DS_COUNTER"); + const char *v3d_ds_counter_env = os_get_option("V3D_DS_COUNTER"); if (!v3d_ds_counter_env || v3d_ds_counter_env[0] == '\0') return false; diff --git a/src/broadcom/vulkan/v3dv_bo.c b/src/broadcom/vulkan/v3dv_bo.c index 0dc4b244d38..9ec954bd908 100644 --- a/src/broadcom/vulkan/v3dv_bo.c +++ b/src/broadcom/vulkan/v3dv_bo.c @@ -402,7 +402,7 @@ v3dv_bo_cache_init(struct v3dv_device *device) */ device->bo_cache.size_list_size = 0; - const char *max_cache_size_str = getenv("V3DV_MAX_BO_CACHE_SIZE"); + const char *max_cache_size_str = os_get_option("V3DV_MAX_BO_CACHE_SIZE"); if (max_cache_size_str == NULL) device->bo_cache.max_cache_size = DEFAULT_MAX_BO_CACHE_SIZE; else diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index 1864974e181..14855c70b73 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -586,7 +586,7 @@ v3dv_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, instance->pipeline_cache_enabled = true; instance->default_pipeline_cache_enabled = true; instance->meta_cache_enabled = true; - const char *pipeline_cache_str = getenv("V3DV_ENABLE_PIPELINE_CACHE"); + const char *pipeline_cache_str = os_get_option("V3DV_ENABLE_PIPELINE_CACHE"); if (pipeline_cache_str != NULL) { if (strncmp(pipeline_cache_str, "full", 4) == 0) { /* nothing to do, just to filter correct values */ diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 05b9a4c76e0..ebb1950e8b8 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4708,7 +4708,7 @@ should_skip_nir(const char *name) static const char *list = NULL; if (!list) { /* Comma separated list of names to skip. */ - list = getenv("NIR_SKIP"); + list = os_get_option("NIR_SKIP"); if (!list) list = ""; } diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 80e51c0a95a..4470b7f2814 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -257,7 +257,7 @@ vtn_default_log_level(void) [NIR_SPIRV_DEBUG_LEVEL_INFO] = "info", [NIR_SPIRV_DEBUG_LEVEL_ERROR] = "error", }; - const char *str = getenv("MESA_SPIRV_LOG_LEVEL"); + const char *str = os_get_option("MESA_SPIRV_LOG_LEVEL"); if (str == NULL) return level; diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 61afc1efff4..fb5a8b6f7c1 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -699,7 +699,7 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); else { bool success = false; - if (!disp->Options.Zink && !getenv("GALLIUM_DRIVER")) { + if (!disp->Options.Zink && !os_get_option("GALLIUM_DRIVER")) { disp->Options.Zink = EGL_TRUE; success = _eglDriver.Initialize(disp); } diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 4eadb8f10aa..a75855c00c5 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -43,6 +43,7 @@ #include "c11/threads.h" #include "util/macros.h" #include "util/os_file.h" +#include "util/os_misc.h" #include "util/u_atomic.h" #include "eglcontext.h" @@ -98,10 +99,10 @@ _eglGetNativePlatformFromEnv(void) static_assert(ARRAY_SIZE(egl_platforms) == _EGL_NUM_PLATFORMS, "Missing platform"); - plat_name = getenv("EGL_PLATFORM"); + plat_name = os_get_option("EGL_PLATFORM"); /* try deprecated env variable */ if (!plat_name || !plat_name[0]) - plat_name = getenv("EGL_DISPLAY"); + plat_name = os_get_option("EGL_DISPLAY"); if (!plat_name || !plat_name[0]) return _EGL_INVALID_PLATFORM; diff --git a/src/freedreno/drm-shim/freedreno_noop.c b/src/freedreno/drm-shim/freedreno_noop.c index fcd28878978..57ff8030e31 100644 --- a/src/freedreno/drm-shim/freedreno_noop.c +++ b/src/freedreno/drm-shim/freedreno_noop.c @@ -10,6 +10,7 @@ #include "drm-uapi/msm_drm.h" #include +#include "util/os_misc.h" #include "util/u_math.h" bool drm_shim_driver_prefers_first_render_node = true; @@ -280,7 +281,7 @@ static const struct msm_device_info device_infos[] = { static void msm_driver_get_device_info(void) { - const char *env = getenv("FD_GPU_ID"); + const char *env = os_get_option("FD_GPU_ID"); if (!env) { device_info = &device_infos[0]; diff --git a/src/freedreno/rnn/rnn.c b/src/freedreno/rnn/rnn.c index 05607a24e19..db29978e298 100644 --- a/src/freedreno/rnn/rnn.c +++ b/src/freedreno/rnn/rnn.c @@ -838,7 +838,7 @@ static int trytop (struct rnndb *db, char *file, xmlNode *node) { static char * find_file(const char *file_orig) { - const char *rnn_path = getenv("RNN_PATH"); + const char *rnn_path = os_get_option("RNN_PATH"); char *fname; if (!rnn_path) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp index e5a7242fa78..26d7ad76faa 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp @@ -252,14 +252,14 @@ lp_profile(LLVMValueRef func, const void *code) * this except when running inside linux perf, which can be inferred * by the PERF_BUILDID_DIR environment variable. */ - if (getenv("PERF_BUILDID_DIR")) { + if (os_get_option("PERF_BUILDID_DIR")) { snprintf(filename, sizeof(filename), "/tmp/perf-%llu.map", pid); perf_map_file = fopen(filename, "wt"); snprintf(filename, sizeof(filename), "/tmp/perf-%llu.map.asm", pid); perf_asm_file.open(filename); } #else - if (const char* output_dir = getenv("JIT_SYMBOL_MAP_DIR")) { + if (const char* output_dir = os_get_option("JIT_SYMBOL_MAP_DIR")) { snprintf(filename, sizeof(filename), "%s/jit-symbols-%llu.map", output_dir, pid); perf_map_file = fopen(filename, "wt"); snprintf(filename, sizeof(filename), "%s/jit-symbols-%llu.map.asm", output_dir, pid); diff --git a/src/gallium/drivers/crocus/crocus_screen.c b/src/gallium/drivers/crocus/crocus_screen.c index 290506855df..14893758b9e 100644 --- a/src/gallium/drivers/crocus/crocus_screen.c +++ b/src/gallium/drivers/crocus/crocus_screen.c @@ -559,7 +559,7 @@ crocus_screen_create(int fd, const struct pipe_screen_config *config) if (screen->devinfo.ver == 8) { /* bind to cherryview or bdw if forced */ if (screen->devinfo.platform != INTEL_PLATFORM_CHV && - !getenv("CROCUS_GEN8")) + !os_get_option("CROCUS_GEN8")) return NULL; } diff --git a/src/gallium/drivers/d3d12/d3d12_dxcore_screen.cpp b/src/gallium/drivers/d3d12/d3d12_dxcore_screen.cpp index 9efa5741343..7bff5b8c140 100644 --- a/src/gallium/drivers/d3d12/d3d12_dxcore_screen.cpp +++ b/src/gallium/drivers/d3d12/d3d12_dxcore_screen.cpp @@ -74,7 +74,7 @@ choose_dxcore_adapter(IDXCoreAdapterFactory *factory, LUID *adapter_luid) #ifndef _WIN32 // Pick the user selected adapter if any - char *adapter_name = getenv("MESA_D3D12_DEFAULT_ADAPTER_NAME"); + const char *adapter_name = os_get_option("MESA_D3D12_DEFAULT_ADAPTER_NAME"); if (adapter_name) { for (unsigned i=0; iGetAdapterCount(); i++) { if (SUCCEEDED(list->GetAdapter(i, &adapter))) { diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_print.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_print.cpp index 18a9912fb70..bd5550690d4 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_print.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_print.cpp @@ -61,7 +61,7 @@ static const char **colour; static void init_colours() { - if (getenv("NV50_PROG_DEBUG_NO_COLORS") != NULL) + if (os_get_option("NV50_PROG_DEBUG_NO_COLORS") != NULL) colour = _nocolour; else colour = _colour; diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c index fe105908688..fcb67a31f88 100644 --- a/src/gallium/drivers/nouveau/nouveau_screen.c +++ b/src/gallium/drivers/nouveau/nouveau_screen.c @@ -305,7 +305,7 @@ nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev) glsl_type_singleton_init_or_ref(); - char *nv_dbg = getenv("NOUVEAU_MESA_DEBUG"); + const char *nv_dbg = os_get_option("NOUVEAU_MESA_DEBUG"); if (nv_dbg) nouveau_mesa_debug = atoi(nv_dbg); diff --git a/src/gallium/drivers/r600/r600_hw_context.c b/src/gallium/drivers/r600/r600_hw_context.c index 3309dbda8de..64bce2e6e1d 100644 --- a/src/gallium/drivers/r600/r600_hw_context.c +++ b/src/gallium/drivers/r600/r600_hw_context.c @@ -296,7 +296,7 @@ void r600_context_gfx_flush(void *context, unsigned flags, if (ctx->is_debug) { if (!ws->fence_wait(ws, ctx->b.last_gfx_fence, 10000000)) { - const char *fname = getenv("R600_TRACE"); + const char *fname = os_get_option("R600_TRACE"); if (!fname) exit(-1); FILE *fl = fopen(fname, "w+"); diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c index cd4c194daa1..476525cef19 100644 --- a/src/gallium/drivers/r600/r600_pipe.c +++ b/src/gallium/drivers/r600/r600_pipe.c @@ -161,7 +161,7 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, rctx->b.b.create_video_buffer = r600_video_buffer_create; } - if (getenv("R600_TRACE")) + if (os_get_option("R600_TRACE")) rctx->is_debug = true; r600_init_common_state_functions(rctx); diff --git a/src/gallium/drivers/radeonsi/glsl_tests/amdgcn_glslc.c b/src/gallium/drivers/radeonsi/glsl_tests/amdgcn_glslc.c index c45383c05fd..4c710fa8545 100644 --- a/src/gallium/drivers/radeonsi/glsl_tests/amdgcn_glslc.c +++ b/src/gallium/drivers/radeonsi/glsl_tests/amdgcn_glslc.c @@ -154,7 +154,7 @@ read_file(const char *filename) static void addenv(const char *name, const char *value) { - const char *orig = getenv(name); + const char *orig = os_get_option(name); if (orig) { char *newval; (void)!asprintf(&newval, "%s,%s", orig, value); diff --git a/src/gallium/drivers/radeonsi/si_sqtt.c b/src/gallium/drivers/radeonsi/si_sqtt.c index 20a2021c429..13cc8aa441f 100644 --- a/src/gallium/drivers/radeonsi/si_sqtt.c +++ b/src/gallium/drivers/radeonsi/si_sqtt.c @@ -331,7 +331,7 @@ bool si_init_sqtt(struct si_context *sctx) debug_get_bool_option("AMD_THREAD_TRACE_INSTRUCTION_TIMING", true); sctx->sqtt->start_frame = 10; - const char *trigger = getenv("AMD_THREAD_TRACE_TRIGGER"); + const char *trigger = os_get_option("AMD_THREAD_TRACE_TRIGGER"); if (trigger) { sctx->sqtt->start_frame = atoi(trigger); if (sctx->sqtt->start_frame <= 0) { diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c index fb636486d3e..a906f627ae8 100644 --- a/src/gallium/drivers/virgl/virgl_context.c +++ b/src/gallium/drivers/virgl/virgl_context.c @@ -1849,7 +1849,7 @@ struct pipe_context *virgl_context_create(struct pipe_screen *pscreen, virgl_encoder_set_sub_ctx(vctx, vctx->hw_sub_ctx_id); if (rs->caps.caps.v2.capability_bits & VIRGL_CAP_GUEST_MAY_INIT_LOG) { - host_debug_flagstring = getenv("VIRGL_HOST_DEBUG"); + host_debug_flagstring = os_get_option("VIRGL_HOST_DEBUG"); if (host_debug_flagstring) virgl_encode_host_debug_flagstring(vctx, host_debug_flagstring); } diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index dae8bb79875..2b3ec6517c4 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -3318,7 +3318,7 @@ zink_cl_cts_version(struct pipe_screen *pscreen) static struct zink_screen * zink_internal_create_screen(const struct pipe_screen_config *config, int64_t dev_major, int64_t dev_minor, uint64_t adapter_luid) { - if (getenv("ZINK_USE_LAVAPIPE")) { + if (os_get_option("ZINK_USE_LAVAPIPE")) { mesa_loge("ZINK_USE_LAVAPIPE is obsolete. Use LIBGL_ALWAYS_SOFTWARE\n"); return NULL; } diff --git a/src/gallium/frontends/dri/dri_context.c b/src/gallium/frontends/dri/dri_context.c index 467a48a1cef..bae29d639d5 100644 --- a/src/gallium/frontends/dri/dri_context.c +++ b/src/gallium/frontends/dri/dri_context.c @@ -220,7 +220,7 @@ dri_create_context(struct dri_screen *screen, /* if set (not -1), apply the app setting */ enable_glthread = app_enable_glthread == 1; } - if (getenv("mesa_glthread")) { + if (os_get_option("mesa_glthread")) { /* only apply the env var if set */ bool user_enable_glthread = debug_get_bool_option("mesa_glthread", false); if (user_enable_glthread != enable_glthread) { diff --git a/src/gallium/frontends/glx/xlib/glx_api.c b/src/gallium/frontends/glx/xlib/glx_api.c index 04d72c93af5..9ee3c94882b 100644 --- a/src/gallium/frontends/glx/xlib/glx_api.c +++ b/src/gallium/frontends/glx/xlib/glx_api.c @@ -199,7 +199,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo, if (dbFlag) { /* Check if the MESA_BACK_BUFFER env var is set */ - char *backbuffer = getenv("MESA_BACK_BUFFER"); + const char *backbuffer = os_get_option("MESA_BACK_BUFFER"); if (backbuffer) { if (backbuffer[0]=='p' || backbuffer[0]=='P') { ximageFlag = GL_FALSE; @@ -223,13 +223,13 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo, /* Comparing IDs uses less memory but sometimes fails. */ /* XXX revisit this after 3.0 is finished. */ - if (getenv("MESA_GLX_VISUAL_HACK")) + if (os_get_option("MESA_GLX_VISUAL_HACK")) comparePointers = GL_TRUE; else comparePointers = GL_FALSE; /* Force the visual to have an alpha channel */ - if (rgbFlag && getenv("MESA_GLX_FORCE_ALPHA")) + if (rgbFlag && os_get_option("MESA_GLX_FORCE_ALPHA")) alphaFlag = GL_TRUE; /* First check if a matching visual is already in the list */ @@ -288,7 +288,7 @@ static GLint default_depth_bits(void) { int zBits; - const char *zEnv = getenv("MESA_GLX_DEPTH_BITS"); + const char *zEnv = os_get_option("MESA_GLX_DEPTH_BITS"); if (zEnv) zBits = atoi(zEnv); else @@ -300,7 +300,7 @@ static GLint default_alpha_bits(void) { int aBits; - const char *aEnv = getenv("MESA_GLX_ALPHA_BITS"); + const char *aEnv = os_get_option("MESA_GLX_ALPHA_BITS"); if (aEnv) aBits = atoi(aEnv); else @@ -449,11 +449,11 @@ get_env_visual(Display *dpy, int scr, const char *varname) int depth, xclass = -1; XVisualInfo *vis; - if (!getenv( varname )) { + if (!os_get_option( varname )) { return NULL; } - strncpy( value, getenv(varname), 100 ); + strncpy( value, os_get_option(varname), 100 ); value[99] = 0; sscanf( value, "%s %d", type, &depth ); @@ -1181,7 +1181,7 @@ glXMakeContextCurrent( Display *dpy, GLXDrawable draw, static bool firsttime = 1, no_rast = 0; if (firsttime) { - no_rast = getenv("SP_NO_RAST") != NULL; + no_rast = os_get_option("SP_NO_RAST") != NULL; firsttime = 0; } @@ -1356,7 +1356,7 @@ glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ) if (b) { XMesaDestroyBuffer(b); } - else if (getenv("MESA_DEBUG")) { + else if (os_get_option("MESA_DEBUG")) { _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n"); } } @@ -1425,7 +1425,7 @@ glXSwapBuffers( Display *dpy, GLXDrawable drawable ) static bool firsttime = 1, no_rast = 0; if (firsttime) { - no_rast = getenv("SP_NO_RAST") != NULL; + no_rast = os_get_option("SP_NO_RAST") != NULL; firsttime = 0; } @@ -1435,7 +1435,7 @@ glXSwapBuffers( Display *dpy, GLXDrawable drawable ) if (buffer) { XMesaSwapBuffers(buffer); } - else if (getenv("MESA_DEBUG")) { + else if (os_get_option("MESA_DEBUG")) { _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n", (int) drawable); } @@ -1453,7 +1453,7 @@ glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, if (buffer) { XMesaCopySubBuffer(buffer, x, y, width, height); } - else if (getenv("MESA_DEBUG")) { + else if (os_get_option("MESA_DEBUG")) { _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n"); } } diff --git a/src/gallium/frontends/glx/xlib/xm_api.c b/src/gallium/frontends/glx/xlib/xm_api.c index 23e34e51251..14c4cd2bdd2 100644 --- a/src/gallium/frontends/glx/xlib/xm_api.c +++ b/src/gallium/frontends/glx/xlib/xm_api.c @@ -667,7 +667,7 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, * which can help Brian figure out what's going on when a user * reports bugs. */ - if (getenv("MESA_INFO")) { + if (os_get_option("MESA_INFO")) { printf("X/Mesa visual = %p\n", (void *) v); printf("X/Mesa depth = %d\n", v->visinfo->depth); printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); @@ -763,7 +763,7 @@ XMesaVisual XMesaCreateVisual( Display *display, return NULL; /* For debugging only */ - if (getenv("MESA_XSYNC")) { + if (os_get_option("MESA_XSYNC")) { /* This makes debugging X easier. * In your debugger, set a breakpoint on _XError to stop when an * X protocol error is generated. diff --git a/src/gallium/frontends/wgl/stw_pixelformat.c b/src/gallium/frontends/wgl/stw_pixelformat.c index f924cbe933d..8009f84daa9 100644 --- a/src/gallium/frontends/wgl/stw_pixelformat.c +++ b/src/gallium/frontends/wgl/stw_pixelformat.c @@ -250,10 +250,10 @@ add_color_format_variants(const struct stw_pf_color_info *color_formats, * to force all pixel formats to have a particular number of samples. */ { - const char *samples = getenv("WGL_FORCE_MSAA"); + const char *samples = os_get_option("WGL_FORCE_MSAA"); if (!samples) { static bool warned = false; - samples = getenv("SVGA_FORCE_MSAA"); + samples = os_get_option("SVGA_FORCE_MSAA"); if (samples && !warned) { fprintf(stderr, "*** SVGA_FORCE_MSAA is deprecated; " "use WGL_FORCE_MSAA instead ***\n"); diff --git a/src/gallium/targets/teflon/meson.build b/src/gallium/targets/teflon/meson.build index e445e091793..6a4d1aa7f84 100644 --- a/src/gallium/targets/teflon/meson.build +++ b/src/gallium/targets/teflon/meson.build @@ -45,6 +45,6 @@ if with_tests tflite_flatbuffer_h, dependencies : [ idep_mesautil, idep_gtest ], link_with : [ tensorflow_lite ], - include_directories : [ inc_include ], + include_directories : [ inc_include, inc_util ], ) endif diff --git a/src/gallium/targets/teflon/test_executor.cpp b/src/gallium/targets/teflon/test_executor.cpp index bf9449b73b8..a1ce66b7440 100644 --- a/src/gallium/targets/teflon/test_executor.cpp +++ b/src/gallium/targets/teflon/test_executor.cpp @@ -18,6 +18,8 @@ #include "test_executor.h" #include "tflite-schema-v2.15.0_generated.h" +#include "util/os_misc.h" + static float randf(float min, float max) { @@ -50,8 +52,8 @@ static void read_model(const char *file_name, tflite::ModelT &model) { std::ostringstream file_path; - assert(getenv("TEFLON_TEST_DATA")); - file_path << getenv("TEFLON_TEST_DATA") << "/" << file_name; + assert(os_get_option("TEFLON_TEST_DATA")); + file_path << os_get_option("TEFLON_TEST_DATA") << "/" << file_name; FILE *f = fopen(file_path.str().c_str(), "rb"); assert(f); @@ -372,7 +374,7 @@ void (*tflite_plugin_destroy_delegate)(TfLiteDelegate *delegate); static void load_delegate() { - const char *delegate_path = getenv("TEFLON_TEST_DELEGATE"); + const char *delegate_path = os_get_option("TEFLON_TEST_DELEGATE"); assert(delegate_path); void *delegate_lib = dlopen(delegate_path, RTLD_LAZY | RTLD_LOCAL); @@ -393,7 +395,7 @@ load_delegate() bool cache_is_enabled(void) { - return getenv("TEFLON_ENABLE_CACHE"); + return os_get_option("TEFLON_ENABLE_CACHE"); } void * diff --git a/src/gallium/targets/teflon/test_teflon.cpp b/src/gallium/targets/teflon/test_teflon.cpp index 3560f625338..2ec108c8105 100644 --- a/src/gallium/targets/teflon/test_teflon.cpp +++ b/src/gallium/targets/teflon/test_teflon.cpp @@ -18,6 +18,8 @@ #include "tensorflow/lite/c/c_api.h" #include "test_executor.h" +#include "util/os_misc.h" + #define TEST_CONV2D 1 #define TEST_DEPTHWISE 1 #define TEST_ADD 1 @@ -55,7 +57,7 @@ test_model(void *buf, size_t buf_size, std::string cache_dir, unsigned tolerance run_model(model, EXECUTOR_CPU, &input, &num_inputs, &cpu_output, &output_sizes, &output_types, &num_outputs, cache_dir); run_model(model, EXECUTOR_NPU, &input, &num_inputs, &npu_output, &output_sizes, &output_types, &num_outputs, cache_dir); - char *dump_output = getenv("TEFLON_DUMP_OUTPUT"); + const char *dump_output = os_get_option("TEFLON_DUMP_OUTPUT"); if (dump_output && atoi(dump_output) == 1) { for (unsigned i = 0; i < num_outputs; i++) { char name[250]; @@ -506,8 +508,8 @@ TEST_P(Models, Op) std::ostringstream file_path; auto test_name = GetParam(); test_name.replace(test_name.find("_"), 1, "/"); - assert(getenv("TEFLON_TEST_DATA")); - file_path << getenv("TEFLON_TEST_DATA") << "/models/" << test_name << ".tflite"; + assert(os_get_option("TEFLON_TEST_DATA")); + file_path << os_get_option("TEFLON_TEST_DATA") << "/models/" << test_name << ".tflite"; test_model_file(file_path.str(), TOLERANCE, true); } @@ -515,9 +517,9 @@ TEST_P(Models, Op) std::vector get_model_files(void) { - assert(getenv("TEFLON_TEST_DATA")); + assert(os_get_option("TEFLON_TEST_DATA")); std::stringstream dir; - dir << getenv("TEFLON_TEST_DATA") << "/models"; + dir << os_get_option("TEFLON_TEST_DATA") << "/models"; std::vector paths; std::filesystem::recursive_directory_iterator b(dir.str()); diff --git a/src/gallium/winsys/nouveau/drm/nouveau.c b/src/gallium/winsys/nouveau/drm/nouveau.c index 98aa557c1ba..cb69f10f763 100644 --- a/src/gallium/winsys/nouveau/drm/nouveau.c +++ b/src/gallium/winsys/nouveau/drm/nouveau.c @@ -35,13 +35,13 @@ static void debug_init(void) { static bool once = false; - char *debug, *out; + const char *debug, *out; if (once) return; once = true; - debug = getenv("NOUVEAU_LIBDRM_DEBUG"); + debug = os_get_option("NOUVEAU_LIBDRM_DEBUG"); if (debug) { int n = strtol(debug, NULL, 0); if (n >= 0) @@ -49,7 +49,7 @@ debug_init(void) } nouveau_out = stderr; - out = getenv("NOUVEAU_LIBDRM_OUT"); + out = os_get_option("NOUVEAU_LIBDRM_OUT"); if (out) { FILE *fout = fopen(out, "w"); if (fout) @@ -368,7 +368,7 @@ nouveau_device_new(struct nouveau_object *parent, struct nouveau_device **pdev) struct nouveau_drm *drm = nouveau_drm(parent); struct nouveau_device *dev; uint64_t v; - char *tmp; + const char *tmp; struct nouveau_device_priv *nvdev = calloc(1, sizeof(*nvdev)); if (!nvdev) @@ -455,14 +455,14 @@ nouveau_device_new(struct nouveau_object *parent, struct nouveau_device **pdev) goto done; nvdev->base.gart_size = v; - tmp = getenv("NOUVEAU_LIBDRM_VRAM_LIMIT_PERCENT"); + tmp = os_get_option("NOUVEAU_LIBDRM_VRAM_LIMIT_PERCENT"); if (tmp) nvdev->vram_limit_percent = atoi(tmp); else nvdev->vram_limit_percent = 80; nvdev->base.vram_limit = (nvdev->base.vram_size * nvdev->vram_limit_percent) / 100; - tmp = getenv("NOUVEAU_LIBDRM_GART_LIMIT_PERCENT"); + tmp = os_get_option("NOUVEAU_LIBDRM_GART_LIMIT_PERCENT"); if (tmp) nvdev->gart_limit_percent = atoi(tmp); else diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c index df1de705392..229518acc1c 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen.c +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -146,7 +146,7 @@ vmw_winsys_create( int fd ) vws->base.have_rasterizer_state_v2_cmd = vws->ioctl.have_drm_2_20 && vws->base.have_sm5; - getenv_val = getenv("SVGA_FORCE_KERNEL_UNMAPS"); + getenv_val = os_get_option("SVGA_FORCE_KERNEL_UNMAPS"); vws->cache_maps = !getenv_val || strcmp(getenv_val, "0") == 0; vws->fence_ops = vmw_fence_ops_create(vws); if (!vws->fence_ops) diff --git a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c index 7ac4c08c928..f9923e6c570 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c +++ b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c @@ -1025,7 +1025,7 @@ vmw_ioctl_init(struct vmw_winsys_screen *vws) goto out_no_3d; } vws->ioctl.hwversion = gp_arg.value; - getenv_val = getenv("SVGA_FORCE_HOST_BACKED"); + getenv_val = os_get_option("SVGA_FORCE_HOST_BACKED"); if (!getenv_val || strcmp(getenv_val, "0") == 0) { memset(&gp_arg, 0, sizeof(gp_arg)); gp_arg.param = DRM_VMW_PARAM_HW_CAPS; @@ -1093,7 +1093,7 @@ vmw_ioctl_init(struct vmw_winsys_screen *vws) debug_printf("Have VGPU10 interface and hardware.\n"); vws->base.have_vgpu10 = true; - vgpu10_val = getenv("SVGA_VGPU10"); + vgpu10_val = os_get_option("SVGA_VGPU10"); if (vgpu10_val && strcmp(vgpu10_val, "0") == 0) { debug_printf("Disabling VGPU10 interface.\n"); vws->base.have_vgpu10 = false; @@ -1157,7 +1157,7 @@ vmw_ioctl_init(struct vmw_winsys_screen *vws) if (vws->ioctl.have_drm_2_16) { vws->base.have_coherent = true; - getenv_val = getenv("SVGA_FORCE_COHERENT"); + getenv_val = os_get_option("SVGA_FORCE_COHERENT"); if (getenv_val && strcmp(getenv_val, "0") != 0) vws->force_coherent = true; } @@ -1183,7 +1183,7 @@ vmw_ioctl_init(struct vmw_winsys_screen *vws) /* Userspace surfaces are only supported on guest-backed hardware */ vws->userspace_surface = false; - getenv_val = getenv("VMW_SVGA_USERSPACE_SURFACE"); + getenv_val = os_get_option("VMW_SVGA_USERSPACE_SURFACE"); if (getenv_val && atoi(getenv_val)) { assert(vws->base.have_gb_objects); assert(vws->base.have_vgpu10); diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c index de6f872615d..a51e442b840 100644 --- a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c +++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c @@ -308,7 +308,7 @@ xlib_sw_display(struct xlib_drawable *xlib_drawable, struct pipe_box _box = {}; if (firsttime) { - no_swap = getenv("SP_NO_RAST") != NULL; + no_swap = os_get_option("SP_NO_RAST") != NULL; firsttime = 0; } diff --git a/src/gbm/main/backend.c b/src/gbm/main/backend.c index 321c7e10141..f49c86f0984 100644 --- a/src/gbm/main/backend.c +++ b/src/gbm/main/backend.c @@ -35,6 +35,7 @@ #include #include #include +#include "util/os_misc.h" #include "loader.h" #include "backend.h" @@ -149,7 +150,7 @@ _gbm_create_device(int fd) { struct gbm_device *dev = NULL; - const char *b = getenv("GBM_BACKEND"); + const char *b = os_get_option("GBM_BACKEND"); if (b) { dev = load_backend_by_name(b, fd, true); if (dev) return dev; diff --git a/src/gbm/meson.build b/src/gbm/meson.build index 97e8d5fa044..fbfdfb20f26 100644 --- a/src/gbm/meson.build +++ b/src/gbm/meson.build @@ -13,7 +13,7 @@ files_gbm = files( args_gbm = [ '-DDEFAULT_BACKENDS_PATH="@0@"'.format(gbm_backends_path), ] -incs_gbm = [include_directories('main'), inc_loader, inc_gallium] +incs_gbm = [include_directories('main'), inc_loader, inc_gallium, inc_util] libgbm_name = 'gbm' diff --git a/src/gfxstream/guest/platform/VirtGpu.cpp b/src/gfxstream/guest/platform/VirtGpu.cpp index 2f6267814e8..754215f9fd5 100644 --- a/src/gfxstream/guest/platform/VirtGpu.cpp +++ b/src/gfxstream/guest/platform/VirtGpu.cpp @@ -9,6 +9,7 @@ #include "Sync.h" #include "util/log.h" +#include "util/os_misc.h" namespace { @@ -17,7 +18,7 @@ static VirtGpuDevice* sDevice = nullptr; } // namespace VirtGpuDevice* createPlatformVirtGpuDevice(enum VirtGpuCapset capset, int32_t descriptor) { - if (getenv("VIRTGPU_KUMQUAT")) { + if (os_get_option("VIRTGPU_KUMQUAT")) { return kumquatCreateVirtGpuDevice(capset, descriptor); } else { return osCreateVirtGpuDevice(capset, descriptor); @@ -50,7 +51,7 @@ void VirtGpuDevice::resetInstance() { namespace gfxstream { SyncHelper* createPlatformSyncHelper() { - if (getenv("VIRTGPU_KUMQUAT")) { + if (os_get_option("VIRTGPU_KUMQUAT")) { return kumquatCreateSyncHelper(); } else { return osCreateSyncHelper(); diff --git a/src/gfxstream/guest/platform/kumquat/vulkan-mapper/GfxStreamVulkanMapper.cpp b/src/gfxstream/guest/platform/kumquat/vulkan-mapper/GfxStreamVulkanMapper.cpp index 17be2e3bfef..e984b1914a1 100644 --- a/src/gfxstream/guest/platform/kumquat/vulkan-mapper/GfxStreamVulkanMapper.cpp +++ b/src/gfxstream/guest/platform/kumquat/vulkan-mapper/GfxStreamVulkanMapper.cpp @@ -205,7 +205,7 @@ GfxStreamVulkanMapper* GfxStreamVulkanMapper::getInstance(std::optional(); if (!sVkMapper->initialize(*deviceIdOpt)) { diff --git a/src/glx/apple/apple_cgl.c b/src/glx/apple/apple_cgl.c index 648ed869497..81b6730f8e2 100644 --- a/src/glx/apple/apple_cgl.c +++ b/src/glx/apple/apple_cgl.c @@ -69,7 +69,7 @@ apple_cgl_init(void) if (initialized) return; - opengl_framework_path = getenv("OPENGL_FRAMEWORK_PATH"); + opengl_framework_path = os_get_option("OPENGL_FRAMEWORK_PATH"); if (!opengl_framework_path) { opengl_framework_path = OPENGL_FRAMEWORK_PATH; } diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 5c3dd807370..684acff87e9 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -67,7 +67,7 @@ glx_message(int level, const char *f, ...) int threshold = _LOADER_WARNING; const char *libgl_debug; - libgl_debug = getenv("LIBGL_DEBUG"); + libgl_debug = os_get_option("LIBGL_DEBUG"); if (libgl_debug) { if (strstr(libgl_debug, "quiet")) threshold = _LOADER_FATAL; @@ -986,7 +986,7 @@ __glXInitialize(Display * dpy) dpyPriv->glXDrawHash = __glxHashCreate(); enum glx_driver glx_driver = 0; - const char *env = getenv("MESA_LOADER_DRIVER_OVERRIDE"); + const char *env = os_get_option("MESA_LOADER_DRIVER_OVERRIDE"); #if defined(GLX_DIRECT_RENDERING) && (!defined(GLX_USE_APPLEGL) || defined(GLX_USE_APPLE)) Bool glx_direct = !debug_get_bool_option("LIBGL_ALWAYS_INDIRECT", false); @@ -1020,7 +1020,7 @@ __glXInitialize(Display * dpy) glx_driver |= GLX_DRIVER_ZINK_INFER; #if defined(HAVE_ZINK) if (!(glx_driver & GLX_DRIVER_DRI3)) - if (kopper && !getenv("GALLIUM_DRIVER")) + if (kopper && !os_get_option("GALLIUM_DRIVER")) glx_driver |= GLX_DRIVER_ZINK_INFER; #endif /* HAVE_ZINK */ } diff --git a/src/imagination/vulkan/pvr_device.c b/src/imagination/vulkan/pvr_device.c index 4541f7c70bd..a6c92804d68 100644 --- a/src/imagination/vulkan/pvr_device.c +++ b/src/imagination/vulkan/pvr_device.c @@ -1148,7 +1148,7 @@ static VkResult pvr_physical_device_init(struct pvr_physical_device *pdevice, goto err_pvr_winsys_destroy; if (!pvr_device_is_conformant(&pdevice->dev_info)) { - if (!getenv("PVR_I_WANT_A_BROKEN_VULKAN_DRIVER")) { + if (!os_get_option("PVR_I_WANT_A_BROKEN_VULKAN_DRIVER")) { result = vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER, "WARNING: powervr is not a conformant Vulkan " diff --git a/src/loader/loader.c b/src/loader/loader.c index e49d715d311..d06a368c1bb 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -446,7 +446,7 @@ static char *drm_get_id_path_tag_for_fd(int fd) bool loader_get_user_preferred_fd(int *fd_render_gpu, int *original_fd) { - const char *dri_prime = getenv("DRI_PRIME"); + const char *dri_prime = os_get_option("DRI_PRIME"); bool debug = debug_get_bool_option("DRI_PRIME_DEBUG", false); char *default_tag = NULL; drmDevicePtr devices[MAX_DRM_DEVICES]; diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 42212685972..0a4cf2b491d 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1415,7 +1415,7 @@ handle_first_current(struct gl_context *ctx) * first time each context is made current we'll print some useful * information. */ - if (getenv("MESA_INFO")) { + if (os_get_option("MESA_INFO")) { _mesa_print_info(ctx); } } diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index dcd35fd32b2..d70844069f4 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -228,8 +228,8 @@ set_debug_flags(const char *str) void _mesa_init_debug( struct gl_context *ctx ) { - set_debug_flags(getenv("MESA_DEBUG")); - set_verbose_flags(getenv("MESA_VERBOSE")); + set_debug_flags(os_get_option("MESA_DEBUG")); + set_verbose_flags(os_get_option("MESA_VERBOSE")); } diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c index 571918cb93c..58e152ea9ec 100644 --- a/src/mesa/main/errors.c +++ b/src/mesa/main/errors.c @@ -120,7 +120,7 @@ should_output(struct gl_context *ctx, GLenum error, const char *fmtString) /* Check debug environment variable only once: */ if (debug == -1) { - const char *debugEnv = getenv("MESA_DEBUG"); + const char *debugEnv = os_get_option("MESA_DEBUG"); #ifndef NDEBUG if (debugEnv && strstr(debugEnv, "silent")) diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 920ea5cef33..ad9617d8378 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -368,7 +368,7 @@ _mesa_make_extension_string(struct gl_context *ctx) /* Check if the MESA_EXTENSION_MAX_YEAR env var is set */ { - const char *env = getenv("MESA_EXTENSION_MAX_YEAR"); + const char *env = os_get_option("MESA_EXTENSION_MAX_YEAR"); if (env) { maxYear = atoi(env); _mesa_debug(ctx, "Note: limiting GL extensions to %u or earlier\n", diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index c3dc550cb23..eabd22430b2 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -126,7 +126,7 @@ GLbitfield _mesa_get_shader_flags(void) { GLbitfield flags = 0x0; - const char *env = getenv("MESA_GLSL"); + const char *env = os_get_option("MESA_GLSL"); if (env) { if (strstr(env, "dump_on_error")) @@ -167,7 +167,7 @@ _mesa_get_shader_flags(void) #endif /** - * Memoized version of getenv("MESA_SHADER_CAPTURE_PATH"). + * Memoized version of os_get_option_secure("MESA_SHADER_CAPTURE_PATH"). */ const char * _mesa_get_shader_capture_path(void) @@ -2026,7 +2026,7 @@ GLcharARB * _mesa_read_shader_source(const mesa_shader_stage stage, const char *source, const blake3_hash blake3) { - char *read_path; + const char *read_path; static bool path_exists = true; int len, shader_size = 0; GLcharARB *buffer; @@ -2061,7 +2061,7 @@ _mesa_read_shader_source(const mesa_shader_stage stage, const char *source, if (!path_exists) return NULL; - read_path = getenv("MESA_SHADER_READ_PATH"); + read_path = os_get_option("MESA_SHADER_READ_PATH"); if (!read_path) { path_exists = false; return NULL; diff --git a/src/mesa/main/version.c b/src/mesa/main/version.c index c3809bcc1ac..c97a338fc30 100644 --- a/src/mesa/main/version.c +++ b/src/mesa/main/version.c @@ -230,7 +230,7 @@ _mesa_override_glsl_version(struct gl_constants *consts) const char *version; int n; - version = getenv(env_var); + version = os_get_option(env_var); if (!version) { return; } diff --git a/src/microsoft/vulkan/dzn_device.c b/src/microsoft/vulkan/dzn_device.c index 163168e4ba8..1c959063895 100644 --- a/src/microsoft/vulkan/dzn_device.c +++ b/src/microsoft/vulkan/dzn_device.c @@ -1801,7 +1801,7 @@ dzn_instance_create(const VkInstanceCreateInfo *pCreateInfo, instance->vk.physical_devices.enumerate = dzn_enumerate_physical_devices; instance->vk.physical_devices.destroy = dzn_physical_device_destroy; instance->debug_flags = - parse_debug_string(getenv("DZN_DEBUG"), dzn_debug_options); + parse_debug_string(os_get_option("DZN_DEBUG"), dzn_debug_options); #ifdef _WIN32 if (instance->debug_flags & DZN_DEBUG_DEBUGGER) { diff --git a/src/nouveau/drm-shim/nouveau_noop.c b/src/nouveau/drm-shim/nouveau_noop.c index 024dc8a62a7..4a18eb3c6e4 100644 --- a/src/nouveau/drm-shim/nouveau_noop.c +++ b/src/nouveau/drm-shim/nouveau_noop.c @@ -30,6 +30,7 @@ #include "nouveau/nvif/ioctl.h" #include "nouveau/nvif/cl0080.h" #include "drm-shim/drm_shim.h" +#include "util/os_misc.h" #include "util//u_math.h" #include "../../gallium/drivers/nouveau/nv_object.xml.h" @@ -414,7 +415,7 @@ static ioctl_fn_t driver_ioctls[] = { static void nouveau_driver_get_device_info(void) { - const char *env = getenv("NOUVEAU_CHIPSET"); + const char *env = os_get_option("NOUVEAU_CHIPSET"); if (!env) { device_info.chip_id = 0xf0; diff --git a/src/nouveau/vulkan/nvk_instance.c b/src/nouveau/vulkan/nvk_instance.c index a8d7f1de304..18fe5ba7224 100644 --- a/src/nouveau/vulkan/nvk_instance.c +++ b/src/nouveau/vulkan/nvk_instance.c @@ -93,7 +93,7 @@ nvk_init_debug_flags(struct nvk_instance *instance) { NULL, 0 }, }; - instance->debug_flags = parse_debug_string(getenv("NVK_DEBUG"), flags); + instance->debug_flags = parse_debug_string(os_get_option("NVK_DEBUG"), flags); } static const driOptionDescription nvk_dri_options[] = { diff --git a/src/tool/pps/meson.build b/src/tool/pps/meson.build index 32a9405c9b5..428edf4fc28 100644 --- a/src/tool/pps/meson.build +++ b/src/tool/pps/meson.build @@ -18,7 +18,7 @@ pps_deps += pps_datasources lib_pps = static_library( 'pps', sources: pps_sources, - include_directories: [include_pps, inc_src, pps_includes], + include_directories: [include_pps, inc_src, inc_util, pps_includes], dependencies: pps_deps, ) diff --git a/src/tool/pps/pps_device.cc b/src/tool/pps/pps_device.cc index 400339fea24..e333a0753a5 100644 --- a/src/tool/pps/pps_device.cc +++ b/src/tool/pps/pps_device.cc @@ -15,6 +15,8 @@ #include #include +#include "util/os_misc.h" + namespace pps { #define MAX_DRM_DEVICES 64 @@ -55,7 +57,7 @@ std::optional create_drm_device(int fd, int32_t gpu_num) return std::nullopt; } - const char *dri_prime = getenv("DRI_PRIME"); + const char *dri_prime = os_get_option("DRI_PRIME"); if (dri_prime != NULL) { drmDevicePtr drm_device; uint16_t vendor_id, device_id; diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index d6212f6f1a0..18d8068ee3c 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -1021,9 +1021,9 @@ disk_cache_enabled() #endif char *envvar_name = "MESA_SHADER_CACHE_DISABLE"; #if !DETECT_OS_ANDROID - if (!getenv(envvar_name)) { + if (!os_get_option(envvar_name)) { envvar_name = "MESA_GLSL_CACHE_DISABLE"; - if (getenv(envvar_name)) + if (os_get_option(envvar_name)) fprintf(stderr, "*** MESA_GLSL_CACHE_DISABLE is deprecated; " "use MESA_SHADER_CACHE_DISABLE instead ***\n"); diff --git a/src/util/fossilize_db.c b/src/util/fossilize_db.c index 28d9688e0bb..492e5748d85 100644 --- a/src/util/fossilize_db.c +++ b/src/util/fossilize_db.c @@ -279,7 +279,7 @@ fail: } static void -load_foz_dbs_ro(struct foz_db *foz_db, char *foz_dbs_ro) +load_foz_dbs_ro(struct foz_db *foz_db, const char *foz_dbs_ro) { uint8_t file_idx = 1; char *filename = NULL; @@ -454,7 +454,7 @@ foz_dbs_list_updater_thrd(void *data) } static bool -foz_dbs_list_updater_init(struct foz_db *foz_db, char *list_filename) +foz_dbs_list_updater_init(struct foz_db *foz_db, const char *list_filename) { struct foz_dbs_list_updater *updater = &foz_db->updater; @@ -526,13 +526,13 @@ foz_prepare(struct foz_db *foz_db, char *cache_path) goto fail; } - char *foz_dbs_ro = getenv("MESA_DISK_CACHE_READ_ONLY_FOZ_DBS"); + const char *foz_dbs_ro = os_get_option("MESA_DISK_CACHE_READ_ONLY_FOZ_DBS"); if (foz_dbs_ro) load_foz_dbs_ro(foz_db, foz_dbs_ro); #ifdef FOZ_DB_UTIL_DYNAMIC_LIST - char *foz_dbs_list = - getenv("MESA_DISK_CACHE_READ_ONLY_FOZ_DBS_DYNAMIC_LIST"); + const char *foz_dbs_list = + os_get_option("MESA_DISK_CACHE_READ_ONLY_FOZ_DBS_DYNAMIC_LIST"); if (foz_dbs_list) foz_dbs_list_updater_init(foz_db, foz_dbs_list); #endif diff --git a/src/util/log.c b/src/util/log.c index 39cba6ecdaa..fa1b9506696 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -172,7 +172,7 @@ mesa_log_if_debug(enum mesa_log_level level, const char *outputString) /* Init the local 'debug' var once. */ if (debug == -1) { - const char *env = getenv("MESA_DEBUG"); + const char *env = os_get_option("MESA_DEBUG"); bool silent = env && strstr(env, "silent") != NULL; #ifndef NDEBUG /* in debug builds, print messages unless MESA_DEBUG="silent" */ diff --git a/src/util/tests/process_test.c b/src/util/tests/process_test.c index ec55a25b276..fbbc7aff729 100644 --- a/src/util/tests/process_test.c +++ b/src/util/tests/process_test.c @@ -59,7 +59,7 @@ test_util_get_process_name (void) const char *expected = "process_test"; #endif - const char *name_override = getenv("MESA_PROCESS_NAME"); + const char *name_override = os_get_option("MESA_PROCESS_NAME"); if (name_override) expected = name_override; diff --git a/src/util/u_cpu_detect.c b/src/util/u_cpu_detect.c index d9bf9cca7e7..fd667697d3a 100644 --- a/src/util/u_cpu_detect.c +++ b/src/util/u_cpu_detect.c @@ -170,7 +170,7 @@ check_os_altivec_support(void) } } #elif DETECT_OS_LINUX /* !DETECT_OS_APPLE && !DETECT_OS_NETBSD && !DETECT_OS_OPENBSD */ - char *env_vsx = getenv("GALLIVM_VSX"); + const char *env_vsx = os_get_option("GALLIVM_VSX"); uint64_t hwcap = getauxval(AT_HWCAP); util_cpu_caps.has_altivec = (hwcap >> 28) & 1; if (!env_vsx || env_vsx[0] != '0') @@ -190,13 +190,13 @@ check_os_altivec_support(void) * lp_build_create_jit_compiler_for_module(). * If you want to disable Altivec code generation, the best place to do it is here. */ - char *env_control = getenv("GALLIVM_ALTIVEC"); /* 1=enable (default); 0=disable */ + const char *env_control = os_get_option("GALLIVM_ALTIVEC"); /* 1=enable (default); 0=disable */ if (env_control && env_control[0] == '0') { enable_altivec = false; } #endif /* VSX instructions can be explicitly enabled/disabled via GALLIVM_VSX=1 or 0 */ - char *env_vsx = getenv("GALLIVM_VSX"); + const char *env_vsx = os_get_option("GALLIVM_VSX"); if (env_vsx && env_vsx[0] == '0') { enable_vsx = false; } diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c index f8a39894947..21cf1294dc9 100644 --- a/src/util/xmlconfig.c +++ b/src/util/xmlconfig.c @@ -69,7 +69,7 @@ static inline void regfree(regex_t* r) {} static bool be_verbose(void) { - const char *s = getenv("MESA_DEBUG"); + const char *s = os_get_option("MESA_DEBUG"); if (!s) return true; @@ -599,7 +599,7 @@ __driUtilMessage(const char *f, ...) va_list args; const char *libgl_debug; - libgl_debug=getenv("LIBGL_DEBUG"); + libgl_debug=os_get_option("LIBGL_DEBUG"); if (libgl_debug && !strstr(libgl_debug, "quiet")) { fprintf(stderr, "libGL: "); va_start(args, f); @@ -873,7 +873,7 @@ parseOptConfAttr(struct OptConfData *data, const char **attr) /* don't use XML_WARNING, drirc defines options for all drivers, * but not all drivers support them */ return; - else if (getenv(cache->info[opt].name)) { + else if (os_get_option(cache->info[opt].name)) { /* don't use XML_WARNING, we want the user to see this! */ if (be_verbose()) { fprintf(stderr, @@ -1256,10 +1256,11 @@ driParseConfigFiles(driOptionCache *cache, const driOptionCache *info, userData.execName = execname; #if WITH_XMLCONFIG - char *home, *configdir; + const char *configdir; + char *home; /* parse from either $DRIRC_CONFIGDIR or $datadir/drirc.d */ - if ((configdir = getenv("DRIRC_CONFIGDIR"))) + if ((configdir = os_get_option("DRIRC_CONFIGDIR"))) parseConfigDir(&userData, configdir); else { parseConfigDir(&userData, DATADIR "/drirc.d"); diff --git a/src/vulkan/device-select-layer/device_select_layer.c b/src/vulkan/device-select-layer/device_select_layer.c index 1b95b9ca1b6..35c2dc726dc 100644 --- a/src/vulkan/device-select-layer/device_select_layer.c +++ b/src/vulkan/device-select-layer/device_select_layer.c @@ -128,7 +128,7 @@ device_select_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, info->xserver = !strcmp(applicationName, "Xorg") || !strcmp(applicationName, "Xephyr"); #ifdef VK_USE_PLATFORM_WAYLAND_KHR - bool has_wayland = getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"); + bool has_wayland = os_get_option("WAYLAND_DISPLAY") || os_get_option("WAYLAND_SOCKET"); #endif #ifdef VK_USE_PLATFORM_XCB_KHR bool has_xcb = !!getenv("DISPLAY"); diff --git a/src/vulkan/overlay-layer/overlay.cpp b/src/vulkan/overlay-layer/overlay.cpp index 313851c33b8..435083379a4 100644 --- a/src/vulkan/overlay-layer/overlay.cpp +++ b/src/vulkan/overlay-layer/overlay.cpp @@ -2656,7 +2656,7 @@ static VkResult overlay_CreateInstance( instance_data->instance); instance_data_map_physical_devices(instance_data, true); - parse_overlay_env(&instance_data->params, getenv("VK_LAYER_MESA_OVERLAY_CONFIG")); + parse_overlay_env(&instance_data->params, os_get_option("VK_LAYER_MESA_OVERLAY_CONFIG")); /* If there's no control file, and an output_file was specified, start * capturing fps data right away. diff --git a/src/vulkan/runtime/vk_instance.c b/src/vulkan/runtime/vk_instance.c index 463ef8a03f6..2fc92e17b14 100644 --- a/src/vulkan/runtime/vk_instance.c +++ b/src/vulkan/runtime/vk_instance.c @@ -203,7 +203,7 @@ vk_instance_init(struct vk_instance *instance, return vk_error(instance, VK_ERROR_INITIALIZATION_FAILED); } - instance->trace_mode = parse_debug_string(getenv("MESA_VK_TRACE"), trace_options); + instance->trace_mode = parse_debug_string(os_get_option("MESA_VK_TRACE"), trace_options); instance->trace_per_submit = debug_get_bool_option("MESA_VK_TRACE_PER_SUBMIT", false); if (!instance->trace_per_submit) { instance->trace_frame = (uint32_t)debug_get_num_option("MESA_VK_TRACE_FRAME", 0xFFFFFFFF); @@ -403,7 +403,7 @@ void vk_instance_add_driver_trace_modes(struct vk_instance *instance, const struct debug_control *modes) { - instance->trace_mode |= parse_debug_string(getenv("MESA_VK_TRACE"), modes); + instance->trace_mode |= parse_debug_string(os_get_option("MESA_VK_TRACE"), modes); } static VkResult diff --git a/src/vulkan/screenshot-layer/screenshot.cpp b/src/vulkan/screenshot-layer/screenshot.cpp index f2a258e91ab..cc25690c165 100644 --- a/src/vulkan/screenshot-layer/screenshot.cpp +++ b/src/vulkan/screenshot-layer/screenshot.cpp @@ -1483,7 +1483,7 @@ static VkResult screenshot_CreateInstance( instance_data->instance); instance_data_map_physical_devices(instance_data, true); - parse_screenshot_env(&instance_data->params, getenv("VK_LAYER_MESA_SCREENSHOT_CONFIG")); + parse_screenshot_env(&instance_data->params, os_get_option("VK_LAYER_MESA_SCREENSHOT_CONFIG")); if (!globalLockInitialized) { loader_platform_thread_create_mutex(&globalLock); diff --git a/src/vulkan/util/vk_util.c b/src/vulkan/util/vk_util.c index 401988c84d4..289b8acfeab 100644 --- a/src/vulkan/util/vk_util.c +++ b/src/vulkan/util/vk_util.c @@ -55,7 +55,7 @@ uint32_t vk_get_driver_version(void) uint32_t vk_get_version_override(void) { - const char *str = getenv("MESA_VK_VERSION_OVERRIDE"); + const char *str = os_get_option("MESA_VK_VERSION_OVERRIDE"); if (str == NULL) return 0; diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index cfa9ba21afc..a6fa7ced888 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -75,7 +75,7 @@ wsi_device_init(struct wsi_device *wsi, const char *present_mode; UNUSED VkResult result; - WSI_DEBUG = parse_debug_string(getenv("MESA_VK_WSI_DEBUG"), debug_control); + WSI_DEBUG = parse_debug_string(os_get_option("MESA_VK_WSI_DEBUG"), debug_control); util_cpu_trace_init(); @@ -249,7 +249,7 @@ wsi_device_init(struct wsi_device *wsi, goto fail; #endif - present_mode = getenv("MESA_VK_WSI_PRESENT_MODE"); + present_mode = os_get_option("MESA_VK_WSI_PRESENT_MODE"); if (present_mode) { if (!strcmp(present_mode, "fifo")) { wsi->override_present_mode = VK_PRESENT_MODE_FIFO_KHR;