lib/fatfs: get rid of global static constructors

There was one global static constructor:

! namespace Fatfs { static Constructible<Platform> _platform; }

This caused applications that used the lib or the <fatfs> 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
This commit is contained in:
Martin Stein 2021-07-14 11:28:08 +02:00 committed by Christian Helmuth
parent b59e2ba677
commit 60c8369718

View File

@ -51,10 +51,13 @@ extern "C" {
}
};
static Constructible<Platform> _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;