mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 08:25:38 +00:00
libc: move current working directory into kernel
This commit is contained in:
parent
40e936911f
commit
9453287a6b
@ -43,6 +43,8 @@ extern "C" {
|
||||
#include <internal/mem_alloc.h>
|
||||
#include <internal/mmap_registry.h>
|
||||
#include <internal/errno.h>
|
||||
#include <internal/init.h>
|
||||
#include <internal/cwd.h>
|
||||
|
||||
using namespace Libc;
|
||||
|
||||
@ -61,6 +63,14 @@ Libc::Mmap_registry *Libc::mmap_registry()
|
||||
}
|
||||
|
||||
|
||||
static Cwd *_cwd_ptr;
|
||||
|
||||
void Libc::init_file_operations(Cwd &cwd)
|
||||
{
|
||||
_cwd_ptr = &cwd;
|
||||
}
|
||||
|
||||
|
||||
/***************
|
||||
** Utilities **
|
||||
***************/
|
||||
@ -70,8 +80,11 @@ Libc::Mmap_registry *Libc::mmap_registry()
|
||||
*/
|
||||
static Absolute_path &cwd()
|
||||
{
|
||||
static Absolute_path _cwd("/");
|
||||
return _cwd;
|
||||
struct Missing_call_of_init_file_operations : Exception { };
|
||||
if (!_cwd_ptr)
|
||||
throw Missing_call_of_init_file_operations();
|
||||
|
||||
return _cwd_ptr->cwd();
|
||||
}
|
||||
|
||||
/**
|
||||
|
35
repos/libports/src/lib/libc/internal/cwd.h
Normal file
35
repos/libports/src/lib/libc/internal/cwd.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* \brief Interface for access to current working directory
|
||||
* \author Christian Helmuth
|
||||
* \date 2020-07-20
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2020 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU Affero General Public License version 3.
|
||||
*/
|
||||
|
||||
#ifndef _LIBC__INTERNAL__CWD_H_
|
||||
#define _LIBC__INTERNAL__CWD_H_
|
||||
|
||||
/* libc-internal includes */
|
||||
#include <internal/types.h>
|
||||
#include <libc-plugin/plugin.h>
|
||||
|
||||
namespace Libc {
|
||||
|
||||
/**
|
||||
* Interface to resume all user contexts
|
||||
*/
|
||||
struct Cwd : Interface
|
||||
{
|
||||
/**
|
||||
* Provide access to current working directory (modifiable)
|
||||
*/
|
||||
virtual Absolute_path &cwd() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _LIBC__INTERNAL__CWD_H_ */
|
@ -39,6 +39,7 @@ namespace Libc {
|
||||
struct Signal;
|
||||
struct File_descriptor_allocator;
|
||||
struct Timer_accessor;
|
||||
struct Cwd;
|
||||
|
||||
/**
|
||||
* Support for shared libraries
|
||||
@ -64,6 +65,7 @@ namespace Libc {
|
||||
* Virtual file system
|
||||
*/
|
||||
void init_vfs_plugin(Suspend &);
|
||||
void init_file_operations(Cwd &);
|
||||
|
||||
/**
|
||||
* Select support
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <internal/signal.h>
|
||||
#include <internal/monitor.h>
|
||||
#include <internal/pthread.h>
|
||||
#include <internal/cwd.h>
|
||||
|
||||
namespace Libc {
|
||||
class Kernel;
|
||||
@ -107,7 +108,8 @@ struct Libc::Kernel final : Vfs::Io_response_handler,
|
||||
Select,
|
||||
Kernel_routine_scheduler,
|
||||
Current_time,
|
||||
Watch
|
||||
Watch,
|
||||
Cwd
|
||||
{
|
||||
private:
|
||||
|
||||
@ -286,6 +288,8 @@ struct Libc::Kernel final : Vfs::Io_response_handler,
|
||||
|
||||
Constructible<Clone_connection> _clone_connection { };
|
||||
|
||||
Absolute_path _cwd { "/" };
|
||||
|
||||
struct Resumer
|
||||
{
|
||||
GENODE_RPC(Rpc_resume, void, resume);
|
||||
@ -658,6 +662,11 @@ struct Libc::Kernel final : Vfs::Io_response_handler,
|
||||
? watch_handle : nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cwd interface
|
||||
*/
|
||||
Absolute_path &cwd() { return _cwd; }
|
||||
|
||||
|
||||
/****************************************
|
||||
** Vfs::Io_response_handler interface **
|
||||
|
@ -168,7 +168,7 @@ void Libc::Kernel::_init_file_descriptors()
|
||||
typedef String<Vfs::MAX_PATH_LEN> Path;
|
||||
|
||||
if (node.has_attribute("cwd"))
|
||||
chdir(node.attribute_value("cwd", Path()).string());
|
||||
_cwd.import(node.attribute_value("cwd", Path()).string(), _cwd.base());
|
||||
|
||||
init_fd(node, "stdin", 0, O_RDONLY);
|
||||
init_fd(node, "stdout", 1, O_WRONLY);
|
||||
@ -418,6 +418,7 @@ Libc::Kernel::Kernel(Genode::Env &env, Genode::Allocator &heap)
|
||||
init_plugin(*this);
|
||||
init_sleep(*this);
|
||||
init_vfs_plugin(*this);
|
||||
init_file_operations(*this);
|
||||
init_time(*this, _rtc_path, *this);
|
||||
init_select(*this, *this, *this, _signal);
|
||||
init_socket_fs(*this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user