1 // vi:ft=cpp
2 /*
3  * Copyright (C) 2016 Kernkonzept GmbH.
4  * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
5  *
6  * This file is distributed under the terms of the GNU General Public
7  * License, version 2.  Please see the COPYING-GPL-2 file for details.
8  */
9 #include <l4/cxx/static_container>
10 
11 namespace {
12 struct Vfs_init
13 {
14   // The Static_containers are used to prevent automatic destruction during
15   // program shutdown. At least the `vfs` object must never be destructued
16   // because any later attempt to do any kind of file-descriptor access in
17   // the program would crash, and we could not be sure that the destructor
18   // would really be executed after each possible operation using files or file
19   // descriptors.
20   cxx::Static_container<Vfs> vfs;
21 
22   // The Static_containers below are just for providing ordering. The factories
23   // must be initialized after the `vfs` object.
24   cxx::Static_container<L4Re::Vfs::File_factory_t<L4Re::Dataspace, L4Re::Core::Ro_file> > ro_file;
25   cxx::Static_container<L4Re::Vfs::File_factory_t<L4Re::Namespace, L4Re::Core::Ns_dir> > ns_dir;
26   cxx::Static_container<L4Re::Vfs::File_factory_t<L4::Vcon, L4Re::Core::Vcon_stream> > vcon_stream;
27 
Vfs_initVfs_init28   Vfs_init()
29   {
30     vfs.construct();
31     __rtld_l4re_env_posix_vfs_ops = vfs;
32     ns_dir.construct();
33     auto ns_ptr = cxx::ref_ptr(ns_dir.get());
34     vfs->register_file_factory(ns_ptr);
35     ns_ptr.release(); // prevent deletion of static object
36 
37     ro_file.construct();
38     auto ro_ptr = cxx::ref_ptr(ro_file.get());
39     vfs->register_file_factory(ro_ptr);
40     ro_ptr.release(); // prevent deletion of static object
41 
42     vcon_stream.construct();
43     auto vcon_ptr = cxx::ref_ptr(vcon_stream.get());
44     vfs->register_file_factory(vcon_ptr);
45     vcon_ptr.release(); // prevent deletion of static object
46   }
47 };
48 
49 static Vfs_init __vfs_init __attribute__((init_priority(INIT_PRIO_VFS_INIT)));
50 
51 };
52