L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
default_ops_impl.h
1// vi:ft=cpp
2/*
3 * Copyright (C) 2016, 2023-2024 Kernkonzept GmbH.
4 * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
5 *
6 * License: see LICENSE.spdx (in this directory or the directories above)
7 */
8#include <l4/cxx/static_container>
9
10namespace {
11struct Vfs_init
12{
13 // The Static_containers are used to prevent automatic destruction during
14 // program shutdown. At least the `vfs` object must never be destructed
15 // because any later attempt to do any kind of file-descriptor access in
16 // the program would crash, and we could not be sure that the destructor
17 // would really be executed after each possible operation using files or file
18 // descriptors.
19 cxx::Static_container<Vfs> vfs;
20
21 // The Static_containers below are just for providing ordering. The factories
22 // must be initialized after the `vfs` object.
23 cxx::Static_container<L4Re::Vfs::File_factory_t<L4Re::Dataspace, L4Re::Core::Ro_file> > ro_file;
24 cxx::Static_container<L4Re::Vfs::File_factory_t<L4Re::Namespace, L4Re::Core::Ns_dir> > ns_dir;
25 cxx::Static_container<L4Re::Vfs::File_factory_t<L4::Vcon, L4Re::Core::Vcon_stream> > vcon_stream;
26
27 Vfs_init()
28 {
29 vfs.construct();
30 __rtld_l4re_env_posix_vfs_ops = vfs;
31 ns_dir.construct();
32 auto ns_ptr = cxx::ref_ptr(ns_dir.get());
33 vfs->register_file_factory(ns_ptr);
34 ns_ptr.release(); // prevent deletion of static object
35
36 ro_file.construct();
37 auto ro_ptr = cxx::ref_ptr(ro_file.get());
38 vfs->register_file_factory(ro_ptr);
39 ro_ptr.release(); // prevent deletion of static object
40
41 vcon_stream.construct();
42 auto vcon_ptr = cxx::ref_ptr(vcon_stream.get());
43 vfs->register_file_factory(vcon_ptr);
44 vcon_ptr.release(); // prevent deletion of static object
45 }
46};
47
48static Vfs_init __vfs_init __attribute__((init_priority(INIT_PRIO_VFS_INIT)));
49
50};