From 60c83697186728e002a840990935a1b087d48b68 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 14 Jul 2021 11:28:08 +0200 Subject: [PATCH] lib/fatfs: get rid of global static constructors There was one global static constructor: ! namespace Fatfs { static Constructible _platform; } This caused applications that used the lib or the VFS plugin to end up in an uncaught exception due to Genode::Component complaining that method 'construct' returned without executing pending static constructors if they didn't call Genode::Env::exec_static_constructors(). As the use of Genode::Env::exec_static_constructors() is discouraged in Genode, this commit rather moves the '_platform' object to the scope of the initializing function and introduces a global static pointer to the object that gets set by the initializing function. Although this prevents the exception, it is, technically speaking even worse than the former solution as the new pointer isn't checked for validity in contrast to the 'Constructible' object. However, so far, I don't see a clean solution to this problem without the need for Genode::Env::exec_static_constructors(). Fixes #4220 --- repos/libports/src/lib/fatfs/diskio_block.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/repos/libports/src/lib/fatfs/diskio_block.cc b/repos/libports/src/lib/fatfs/diskio_block.cc index f6bd3ae783..44819b34a7 100644 --- a/repos/libports/src/lib/fatfs/diskio_block.cc +++ b/repos/libports/src/lib/fatfs/diskio_block.cc @@ -51,10 +51,13 @@ extern "C" { } }; - static Constructible _platform; + static Platform *_platform; - void block_init(Genode::Env &env, Genode::Allocator &alloc) { - _platform.construct(env, alloc); } + void block_init(Genode::Env &env, Genode::Allocator &alloc) + { + static Platform platform { env, alloc }; + _platform = &platform; + } struct Drive : private Block::Connection<> { @@ -208,7 +211,7 @@ extern "C" DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff) *((WORD*)buff) = drive.info.block_size; return RES_OK; - case GET_BLOCK_SIZE : + case GET_BLOCK_SIZE: *((DWORD*)buff) = 1; return RES_OK;