From db02e04d0c5465579a3d7d66dac17f2fc5ca830a Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 22 Oct 2024 19:41:32 +0200 Subject: [PATCH] libdrm: move Gpu::Vram into separate namespace Because the implemantations for Lima and Vivante are linked into a single library we cannot have two Gpu::Vram classes in the same namespace. In case this happens any methods using the same signature are weak symbols and the first one found by ld will be used = undefined behavior. issue #5356 issue #5369 --- .../libports/src/lib/libdrm/ioctl_etnaviv.cc | 20 ++++++----- repos/libports/src/lib/libdrm/ioctl_lima.cc | 33 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/repos/libports/src/lib/libdrm/ioctl_etnaviv.cc b/repos/libports/src/lib/libdrm/ioctl_etnaviv.cc index fe342cfe50..df7bca20f0 100644 --- a/repos/libports/src/lib/libdrm/ioctl_etnaviv.cc +++ b/repos/libports/src/lib/libdrm/ioctl_etnaviv.cc @@ -266,11 +266,15 @@ namespace Etnaviv { using namespace Genode; using namespace Gpu; + struct Vram; struct Call; } /* namespace Etnaviv */ -struct Gpu::Vram +struct Gpu::Vram { }; + +/* use separate namespace for Vram implementation */ +struct Etnaviv::Vram : Gpu::Vram { struct Allocation_failed : Genode::Exception { }; @@ -346,7 +350,7 @@ class Etnaviv::Call Gpu::Vram const &_vram; Buffer(Genode::Id_space &space, - Gpu::Vram const &vram) + Vram const &vram) : _elem { *this, space, Genode::Id_space::Id { .value = vram.id().value } }, @@ -440,7 +444,7 @@ class Etnaviv::Call * required by the Gpu session to pass on the driver specific * command buffer. */ - Gpu::Vram *_exec_buffer; + Vram *_exec_buffer; public: @@ -457,8 +461,8 @@ class Etnaviv::Call _fd { _open_gpu() }, _id { _stat_gpu(_fd) }, _elem { *this, space }, - _exec_buffer { new (alloc) Gpu::Vram(_gpu, _exec_buffer_size, - _vram_space) } + _exec_buffer { new (alloc) Vram(_gpu, _exec_buffer_size, + _vram_space) } { } ~Gpu_context() @@ -486,13 +490,13 @@ class Etnaviv::Call Gpu::Vram_capability export_vram(Gpu::Vram_id id) { Gpu::Vram_capability cap { }; - _try_apply(id, [&] (Gpu::Vram const &b) { + _try_apply(id, [&] (Vram const &b) { cap = _gpu.export_vram(b.id()); }); return cap; } - Buffer *import_vram(Gpu::Vram_capability cap, Gpu::Vram const &v) + Buffer *import_vram(Gpu::Vram_capability cap, Vram const &v) { Buffer *b = nullptr; @@ -675,7 +679,7 @@ class Etnaviv::Call [&] () { _main_ctx->gpu().upgrade_ram(donate); }); - } catch (Gpu::Vram::Allocation_failed) { + } catch (Vram::Allocation_failed) { return; } diff --git a/repos/libports/src/lib/libdrm/ioctl_lima.cc b/repos/libports/src/lib/libdrm/ioctl_lima.cc index 5641676558..28fa91da53 100644 --- a/repos/libports/src/lib/libdrm/ioctl_lima.cc +++ b/repos/libports/src/lib/libdrm/ioctl_lima.cc @@ -198,6 +198,7 @@ namespace Lima { using namespace Genode; using namespace Gpu; + struct Vram; struct Call; } /* namespace Lima */ @@ -205,7 +206,11 @@ namespace Lima { /* * Gpu::Vram encapsulates a buffer object allocation */ -struct Gpu::Vram + +struct Gpu::Vram { }; + +/* use separate namespace for Vram implementation */ +struct Lima::Vram : Gpu::Vram { struct Allocation_failed : Genode::Exception { }; @@ -331,10 +336,10 @@ class Lima::Call { Genode::Id_space::Element const _elem; - Gpu::Vram const &_vram; + Vram const &_vram; Buffer(Genode::Id_space &space, - Gpu::Vram const &vram) + Vram const &vram) : _elem { *this, space, Genode::Id_space::Id { .value = vram.id().value } }, @@ -437,7 +442,7 @@ class Lima::Call * required by the Gpu session to pass on driver specific * command buffer. */ - Gpu::Vram *_exec_buffer; + Vram *_exec_buffer; public: @@ -455,9 +460,9 @@ class Lima::Call _id { _stat_gpu(_fd) }, _elem { *this, space }, _va_alloc { va_alloc }, - _exec_buffer { new (alloc) Gpu::Vram(_gpu, _exec_buffer_size, - _va_alloc.alloc(_exec_buffer_size), - _vram_space) } + _exec_buffer { new (alloc) Vram(_gpu, _exec_buffer_size, + _va_alloc.alloc(_exec_buffer_size), + _vram_space) } { } ~Gpu_context() @@ -482,16 +487,16 @@ class Lima::Call return _gpu; } - Gpu::Vram_capability export_vram(Gpu::Vram_id id) + Gpu::Vram_capability export_vram(Vram_id id) { Gpu::Vram_capability cap { }; - _try_apply(id, [&] (Gpu::Vram const &b) { + _try_apply(id, [&] (Vram const &b) { cap = _gpu.export_vram(b.id()); }); return cap; } - Buffer *import_vram(Gpu::Vram_capability cap, Gpu::Vram const &v) + Buffer *import_vram(Gpu::Vram_capability cap, Vram const &v) { Buffer *b = nullptr; @@ -764,7 +769,7 @@ class Lima::Call [&] () { _main_ctx->gpu().upgrade_ram(donate); }); - } catch (Gpu::Vram::Allocation_failed) { + } catch (Vram::Allocation_failed) { _va_alloc.free(va); return; } @@ -802,7 +807,7 @@ class Lima::Call Buffer_space::Id const id = { .value = handle }; if (!gc.buffer_space_contains(id)) { - (void)_apply_handle(handle, [&] (Gpu::Vram const &v) { + (void)_apply_handle(handle, [&] (Vram const &v) { Gpu::Vram_capability cap = _main_ctx->export_vram(v.id()); if (gc.import_vram(cap, v) == nullptr) { Genode::error("could force mapping of buffer ", handle); @@ -824,7 +829,7 @@ class Lima::Call if (!gc.buffer_space_contains(id)) { bool imported = false; - (void)_apply_handle(bo.handle, [&] (Gpu::Vram const &v) { + (void)_apply_handle(bo.handle, [&] (Vram const &v) { Gpu::Vram_capability cap = _main_ctx->export_vram(v.id()); if (gc.import_vram(cap, v) == nullptr) return; @@ -986,7 +991,7 @@ class Lima::Call _gpu_context_space.for_each(free_buffer); return _apply_handle(gem_close.handle, - [&] (Gpu::Vram &b) { + [&] (Lima::Vram &b) { _va_alloc.free(b.va); destroy(_heap, &b); }) ? 0 : -1;