libports: avoid using deprecated APIs

Issue #1987
Issue #3125
This commit is contained in:
Norman Feske 2019-01-21 15:59:00 +01:00
parent ba2b0b8360
commit 6154d9067e
36 changed files with 461 additions and 456 deletions

View File

@ -15,9 +15,9 @@ SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \
malloc.cc progname.cc fd_alloc.cc file_operations.cc \
plugin.cc plugin_registry.cc select.cc exit.cc environ.cc nanosleep.cc \
pread_pwrite.cc readv_writev.cc poll.cc \
libc_pdbg.cc vfs_plugin.cc rtc.cc dynamic_linker.cc signal.cc \
vfs_plugin.cc rtc.cc dynamic_linker.cc signal.cc \
socket_operations.cc task.cc socket_fs_plugin.cc syscall.cc \
getpwent.cc
getpwent.cc
#
# Pthreads

View File

@ -1 +1 @@
3e6bd3a7705587485b1d4688db9f3922382ee48b
be4908ff7037258395bb0dfbc5d4c5ffef22f859

View File

@ -5,67 +5,66 @@
<events>
<timeout meaning="failed" sec="20" />
<log meaning="succeeded">
[init -> test-ldso] Lib_2_global 11223343*
[init -> test-ldso] Lib_1_global_1 5060707*
[init -> test-ldso] Lib_1_global_2 1020303*
[init -> test-ldso] lib_1_attr_constructor_2 4030200f*
[init -> test-ldso] lib_1_attr_constructor_1 8070604f*
[init -> test-ldso] Global_1 5060707*
[init -> test-ldso] Global_2 1020303*
[init -> test-ldso] attr_constructor_2 4030200f*
[init -> test-ldso] attr_constructor_1 8070604f*
[init -> test-ldso] Lib_2_global 0x11223343*
[init -> test-ldso] Lib_1_global_1 0x5060707*
[init -> test-ldso] Lib_1_global_2 0x1020303*
[init -> test-ldso] lib_1_attr_constructor_2 0x4030200f*
[init -> test-ldso] lib_1_attr_constructor_1 0x8070604f*
[init -> test-ldso] Global_1 0x5060707*
[init -> test-ldso] Global_2 0x1020303*
[init -> test-ldso] attr_constructor_2 0x4030200f*
[init -> test-ldso] attr_constructor_1 0x8070604f*
[init -> test-ldso] *
[init -> test-ldso] Dynamic-linker test*
[init -> test-ldso] ===================*
[init -> test-ldso] *
[init -> test-ldso] Global objects and local static objects of program*
[init -> test-ldso] --------------------------------------------------*
[init -> test-ldso] global_1 5060706*
[init -> test-ldso] global_2 1020302*
[init -> test-ldso] Local_1 5060707f*
[init -> test-ldso] local_1 5060707e*
[init -> test-ldso] Local_2 1020303f*
[init -> test-ldso] local_2 1020303e*
[init -> test-ldso] pod_1 8070604e*
[init -> test-ldso] pod_2 4030200e*
[init -> test-ldso] global_1 0x5060706*
[init -> test-ldso] global_2 0x1020302*
[init -> test-ldso] Local_1 0x5060707f*
[init -> test-ldso] local_1 0x5060707e*
[init -> test-ldso] Local_2 0x1020303f*
[init -> test-ldso] local_2 0x1020303e*
[init -> test-ldso] pod_1 0x8070604e*
[init -> test-ldso] pod_2 0x4030200e*
[init -> test-ldso] *
[init -> test-ldso] Access shared lib from program*
[init -> test-ldso] ------------------------------*
[init -> test-ldso] lib_2_global 11223342*
[init -> test-ldso] Lib_1_local_3 12345677*
[init -> test-ldso] lib_1_local_3 12345676*
[init -> test-ldso] lib_1_pod_1 8070604d*
[init -> test-ldso] lib_2_global 0x11223342*
[init -> test-ldso] Lib_1_local_3 0x12345677*
[init -> test-ldso] lib_1_local_3 0x12345676*
[init -> test-ldso] lib_1_pod_1 0x8070604d*
[init -> test-ldso] Libc::read:*
[init -> test-ldso] Error: no plugin found for read(3)*
[init -> test-ldso] Libc::abs(-10): 10*
[init -> test-ldso] *
[init -> test-ldso] Catch exceptions in program*
[init -> test-ldso] ---------------------------*
[init -> test-ldso] exception in remote procedure call:*
[init -> test-ldso] Error: ROM-session creation failed (ram_quota=*, cap_quota=*, label="unknown_file")*
[init -> test-ldso] Error: Could not open ROM session for "unknown_file"*
[init -> test-ldso] caught*
[init -> test-ldso] Error: ROM-session creation failed (ram_quota=*, cap_quota=*, label="unknown_rom")*
[init -> test-ldso] Error: Could not open ROM session for "unknown_rom"*
[init -> test-ldso] exception in remote procedure call: caught*
[init -> test-ldso] exception in program: caught*
[init -> test-ldso] exception in shared lib: caught*
[init -> test-ldso] exception in dynamic linker: caught*
[init -> test-ldso] *
[init -> test-ldso] global objects and local static objects of shared lib*
[init -> test-ldso] -----------------------------------------------------*
[init -> test-ldso] lib_1_global_1 5060706*
[init -> test-ldso] lib_1_global_2 1020302*
[init -> test-ldso] Lib_1_local_1 5060707f*
[init -> test-ldso] lib_1_local_1 5060707e*
[init -> test-ldso] Lib_1_local_2 1020303f*
[init -> test-ldso] lib_1_local_2 1020303e*
[init -> test-ldso] lib_1_pod_1 8070604e*
[init -> test-ldso] lib_1_pod_2 4030200e*
[init -> test-ldso] lib_1_global_1 0x5060706*
[init -> test-ldso] lib_1_global_2 0x1020302*
[init -> test-ldso] Lib_1_local_1 0x5060707f*
[init -> test-ldso] lib_1_local_1 0x5060707e*
[init -> test-ldso] Lib_1_local_2 0x1020303f*
[init -> test-ldso] lib_1_local_2 0x1020303e*
[init -> test-ldso] lib_1_pod_1 0x8070604e*
[init -> test-ldso] lib_1_pod_2 0x4030200e*
[init -> test-ldso] *
[init -> test-ldso] Access shared lib from another shared lib*
[init -> test-ldso] -----------------------------------------*
[init -> test-ldso] lib_2_global 11223341*
[init -> test-ldso] Lib_2_local 55667787*
[init -> test-ldso] lib_2_local 55667786*
[init -> test-ldso] lib_2_pod_1 87654320*
[init -> test-ldso] lib_2_global 0x11223341*
[init -> test-ldso] Lib_2_local 0x55667787*
[init -> test-ldso] lib_2_local 0x55667786*
[init -> test-ldso] lib_2_pod_1 0x87654320*
[init -> test-ldso] *
[init -> test-ldso] Catch exceptions in shared lib*
[init -> test-ldso] ------------------------------*
@ -89,19 +88,19 @@
[init -> test-ldso] *
[init -> test-ldso] Destruction*
[init -> test-ldso] -----------*
[init -> test-ldso] ~Lib_2_local 55667785*
[init -> test-ldso] ~Lib_1_local_2 1020303d*
[init -> test-ldso] ~Lib_1_local_1 5060707d*
[init -> test-ldso] ~Lib_1_local_3 12345675*
[init -> test-ldso] ~Local_2 1020303d*
[init -> test-ldso] ~Local_1 5060707d*
[init -> test-ldso] attr_destructor_2 4030200d*
[init -> test-ldso] attr_destructor_1 8070604c*
[init -> test-ldso] ~Global_2 1020301*
[init -> test-ldso] ~Global_1 5060705*
[init -> test-ldso] ~Lib_1_global_2 1020301*
[init -> test-ldso] ~Lib_1_global_1 5060705*
[init -> test-ldso] ~Lib_2_global 11223340*
[init -> test-ldso] ~Lib_2_local 0x55667785*
[init -> test-ldso] ~Lib_1_local_2 0x1020303d*
[init -> test-ldso] ~Lib_1_local_1 0x5060707d*
[init -> test-ldso] ~Lib_1_local_3 0x12345675*
[init -> test-ldso] ~Local_2 0x1020303d*
[init -> test-ldso] ~Local_1 0x5060707d*
[init -> test-ldso] attr_destructor_2 0x4030200d*
[init -> test-ldso] attr_destructor_1 0x8070604c*
[init -> test-ldso] ~Global_2 0x1020301*
[init -> test-ldso] ~Global_1 0x5060705*
[init -> test-ldso] ~Lib_1_global_2 0x1020301*
[init -> test-ldso] ~Lib_1_global_1 0x5060705*
[init -> test-ldso] ~Lib_2_global 0x11223340*
[init] child "test-ldso" exited with exit value 123
</log>
</events>

View File

@ -67,13 +67,13 @@ struct Acpica::Statechange
_system_state.update();
if (!_system_state.is_valid()) return;
if (!_system_state.valid()) return;
Genode::Xml_node system(_system_state.local_addr<char>(),
_system_state.size());
Genode::String<32> state;
system.attribute("state").value<32>(&state);
typedef Genode::String<32> State;
State const state = system.attribute_value("state", State());
if (_enable_poweroff && state == "poweroff") {
ACPI_STATUS res0 = AcpiEnterSleepStatePrep(5);

View File

@ -5,7 +5,7 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#include <base/printf.h>
#include <stdarg.h>
extern "C"
void AcpiOsPrintf (const char *fmt, ...)

View File

@ -147,19 +147,16 @@ struct Fetchurl::Main
catch (...) { }
auto const parse_fn = [&] (Genode::Xml_node node) {
Url url;
Path path;
Url proxy;
long retry;
try {
node.attribute("url").value(&url);
node.attribute("path").value(path.base(), path.capacity());
if (!node.has_attribute("url") || !node.has_attribute("path")) {
Genode::error("error reading 'fetch' XML node");
return;
}
catch (...) { Genode::error("error reading 'fetch' XML node"); return; }
proxy = node.attribute_value("proxy", Url());
retry = node.attribute_value("retry", 0L);
Url const url = node.attribute_value("url", Url());
Path const path = node.attribute_value("path", String<256>());
Url const proxy = node.attribute_value("proxy", Url());
long const retry = node.attribute_value("retry", 0L);
auto *f = new (_heap) Fetch(*this, url, path, proxy, retry);
_fetches.insert(f);

View File

@ -31,27 +31,34 @@ struct Qt_launchpad_namespace::Local_env : Genode::Env
Local_env(Env &genode_env) : genode_env(genode_env) { }
Parent &parent() { return genode_env.parent(); }
Ram_session &ram() { return genode_env.ram(); }
Cpu_session &cpu() { return genode_env.cpu(); }
Region_map &rm() { return genode_env.rm(); }
Pd_session &pd() { return genode_env.pd(); }
Entrypoint &ep() { return local_ep; }
Ram_session_capability ram_session_cap() { return genode_env.ram_session_cap(); }
Cpu_session_capability cpu_session_cap() { return genode_env.cpu_session_cap(); }
Pd_session_capability pd_session_cap() { return genode_env.pd_session_cap(); }
Id_space<Parent::Client> &id_space() { return genode_env.id_space(); }
Parent &parent() override { return genode_env.parent(); }
Cpu_session &cpu() override { return genode_env.cpu(); }
Region_map &rm() override { return genode_env.rm(); }
Pd_session &pd() override { return genode_env.pd(); }
Entrypoint &ep() override { return local_ep; }
Cpu_session_capability cpu_session_cap() override { return genode_env.cpu_session_cap(); }
Pd_session_capability pd_session_cap() override { return genode_env.pd_session_cap(); }
Id_space<Parent::Client> &id_space() override { return genode_env.id_space(); }
/*
* \deprecated
*
* Emulation of deprecated part of the 'Env' interface. To be
* removed once they are removed from 'Genode::Env'.
*/
Pd_session &ram() override { return pd(); }
Pd_session_capability ram_session_cap() override { return pd_session_cap(); }
Session_capability session(Parent::Service_name const &service_name,
Parent::Client::Id id,
Parent::Session_args const &session_args,
Affinity const &affinity)
Affinity const &affinity) override
{ return genode_env.session(service_name, id, session_args, affinity); }
void upgrade(Parent::Client::Id id, Parent::Upgrade_args const &args)
void upgrade(Parent::Client::Id id, Parent::Upgrade_args const &args) override
{ return genode_env.upgrade(id, args); }
void close(Parent::Client::Id id) { return genode_env.close(id); }
void close(Parent::Client::Id id) override { return genode_env.close(id); }
void exec_static_constructors() override { }

View File

@ -14,6 +14,7 @@
/* Genode includes */
#include <base/log.h>
#include <base/allocator.h>
#include <io_mem_session/connection.h>
#include <platform_session/connection.h>

View File

@ -16,13 +16,13 @@
#include <base/log.h>
#include <base/attached_ram_dataspace.h>
#include <base/attached_io_mem_dataspace.h>
#include <base/snprintf.h>
#include <base/allocator.h>
#include <util/avl_tree.h>
#include <util/misc_math.h>
#include <util/reconstructible.h>
#include <io_port_session/connection.h>
#include <base/printf.h> /* XXX for emulating X86emu::printk() */
/* local includes */
#include "ifx86emu.h"
#include "framebuffer.h"
@ -502,7 +502,9 @@ void X86emu::printk(const char *format, ...)
va_list list;
va_start(list, format);
Genode::vprintf(format, list);
char buf[128];
String_console sc(buf, sizeof(buf));
sc.vprintf(format, list);
va_end(list);
}

View File

@ -178,7 +178,7 @@ ACPI_STATUS AcpiOsReadPciConfiguration (ACPI_PCI_ID *pcidev, UINT32 reg,
break;
default:
Genode::error(__func__, " : unsupported access size ", width);
Acpica::platform().release_device(client);
Acpica::platform().release_device(client.rpc_cap());
return AE_ERROR;
};
@ -186,13 +186,13 @@ ACPI_STATUS AcpiOsReadPciConfiguration (ACPI_PCI_ID *pcidev, UINT32 reg,
dump_read(__func__, pcidev, reg, *value, width);
Acpica::platform().release_device(client);
Acpica::platform().release_device(client.rpc_cap());
return AE_OK;
}
cap = Acpica::platform().next_device(cap);
Acpica::platform().release_device(client);
Acpica::platform().release_device(client.rpc_cap());
}
dump_error(__func__, pcidev, reg, width);
@ -239,7 +239,7 @@ ACPI_STATUS AcpiOsWritePciConfiguration (ACPI_PCI_ID *pcidev, UINT32 reg,
break;
default:
Genode::error(__func__, " : unsupported access size ", width);
Acpica::platform().release_device(client);
Acpica::platform().release_device(client.rpc_cap());
return AE_ERROR;
};
@ -247,13 +247,13 @@ ACPI_STATUS AcpiOsWritePciConfiguration (ACPI_PCI_ID *pcidev, UINT32 reg,
dump_write(__func__, pcidev, reg, value, width);
Acpica::platform().release_device(client);
Acpica::platform().release_device(client.rpc_cap());
return AE_OK;
}
cap = Acpica::platform().next_device(cap);
Acpica::platform().release_device(client);
Acpica::platform().release_device(client.rpc_cap());
}
dump_error(__func__, pcidev, reg, width);

View File

@ -16,8 +16,8 @@
#include <base/env.h>
#include <base/heap.h>
#include <base/log.h>
#include <base/printf.h>
#include <base/sleep.h>
#include <base/snprintf.h>
#include <file_system_session/connection.h>
#include <file_system/util.h>
#include <util/string.h>
@ -143,19 +143,17 @@ extern "C" FILE *fopen(const char *path, const char *mode)
File_system::WRITE_ONLY, true) };
File_system::seek_off_t seek_offset = 0;
libgcov_node.for_each_sub_node("annotate",
[&] (Genode::Xml_node annotate_node) {
Absolute_path source_path;
annotate_node.attribute("source").value(source_path.base(),
source_path.capacity());
typedef Genode::String<File_system::MAX_PATH_LEN> Source;
Source const source = annotate_node.attribute_value("source", Source());
seek_offset += File_system::write(gcov_env->fs,
annotate_file_handle,
source_path.base(),
Genode::strlen(source_path.base()),
source.string(),
Genode::strlen(source.string()),
seek_offset);
seek_offset += File_system::write(gcov_env->fs,
@ -183,8 +181,7 @@ extern "C" int fprintf(FILE *stream, const char *format, ...)
va_list list;
va_start(list, format);
Genode::vprintf(format, list);
vfprintf(stream, format, list);
va_end(list);
return 0;
@ -232,7 +229,7 @@ extern "C" long ftell(FILE *stream)
extern "C" size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
if (stream == stderr) {
Genode::printf((const char*)ptr);
Genode::log(Genode::Cstring((const char*)ptr, size*nmemb));
return 0;
}
@ -276,11 +273,17 @@ extern "C" size_t strlen(const char *s)
}
extern "C" int vfprintf(FILE *stream, const char *format, va_list ap)
extern "C" int vfprintf(FILE *stream, const char *format, va_list list)
{
if (stream != stderr)
return 0;
Genode::vprintf(format, ap);
return 0;
using namespace Genode;
char buf[128] { };
String_console sc { buf, sizeof(buf) };
sc.vprintf(format, list);
log(Cstring(buf));
return sc.len();
}

View File

@ -13,7 +13,6 @@
#include <base/env.h>
#include <base/sleep.h>
#include <base/printf.h>
extern void genode_exit(int status) __attribute__((noreturn));

View File

@ -42,8 +42,14 @@ namespace Libc {
/**
* Malloc allocator
*/
*/
void init_malloc(Genode::Allocator &heap);
/**
* Allow thread.cc to access the 'Genode::Env' (needed for the
* implementation of condition variables with timeout)
*/
void init_pthread_support(Genode::Env &env);
}
#endif /* _LIBC_INIT_H_ */

View File

@ -42,7 +42,7 @@ Libc::Mem_alloc_impl::Dataspace_pool::~Dataspace_pool()
delete ds;
_region_map->detach(local_addr);
_ram_session->free(ds_cap);
_ram->free(ds_cap);
}
}
@ -54,7 +54,7 @@ int Libc::Mem_alloc_impl::Dataspace_pool::expand(size_t size, Range_allocator *a
/* make new ram dataspace available at our local address space */
try {
new_ds_cap = _ram_session->alloc(size);
new_ds_cap = _ram->alloc(size);
enum { MAX_SIZE = 0, NO_OFFSET = 0, ANY_LOCAL_ADDR = false };
local_addr = _region_map->attach(new_ds_cap, MAX_SIZE, NO_OFFSET,
@ -63,7 +63,7 @@ int Libc::Mem_alloc_impl::Dataspace_pool::expand(size_t size, Range_allocator *a
catch (Out_of_ram) { return -2; }
catch (Out_of_caps) { return -4; }
catch (Region_map::Region_conflict) {
_ram_session->free(new_ds_cap);
_ram->free(new_ds_cap);
return -3;
}
@ -147,7 +147,7 @@ static Libc::Mem_alloc *_libc_mem_alloc_rw = nullptr;
static Libc::Mem_alloc *_libc_mem_alloc_rwx = nullptr;
static void _init_mem_alloc(Genode::Region_map &rm, Genode::Ram_session &ram)
static void _init_mem_alloc(Genode::Region_map &rm, Genode::Ram_allocator &ram)
{
enum { MEMORY_EXECUTABLE = true };

View File

@ -8,11 +8,10 @@
#define _LIBC_MEM_ALLOC_H_
/* Genode includes */
#include <base/allocator.h>
#include <base/ram_allocator.h>
#include <base/allocator_avl.h>
#include <base/env.h>
#include <util/list.h>
#include <ram_session/ram_session.h>
#include <rm_session/rm_session.h>
namespace Libc {
@ -43,7 +42,7 @@ namespace Libc {
public:
Genode::Ram_dataspace_capability cap;
void *local_addr;
void *local_addr;
Dataspace(Genode::Ram_dataspace_capability c, void *a)
: cap(c), local_addr(a) {}
@ -58,18 +57,18 @@ namespace Libc {
{
private:
Genode::Ram_session *_ram_session; /* ram session for backing store */
Genode::Region_map *_region_map; /* region map of address space */
bool const _executable; /* whether to allocate executable dataspaces */
Genode::Ram_allocator *_ram; /* ram session for backing store */
Genode::Region_map *_region_map; /* region map of address space */
bool const _executable; /* whether to allocate executable dataspaces */
public:
/**
* Constructor
*/
Dataspace_pool(Genode::Ram_session *ram,
Dataspace_pool(Genode::Ram_allocator *ram,
Genode::Region_map *rm, bool executable) :
_ram_session(ram), _region_map(rm),
_ram(ram), _region_map(rm),
_executable(executable)
{ }
@ -91,8 +90,8 @@ namespace Libc {
*/
int expand(Genode::size_t size, Genode::Range_allocator *alloc);
void reassign_resources(Genode::Ram_session *ram, Genode::Region_map *rm) {
_ram_session = ram, _region_map = rm; }
void reassign_resources(Genode::Ram_allocator *ram, Genode::Region_map *rm) {
_ram = ram, _region_map = rm; }
};
Genode::Lock mutable _lock;
@ -113,7 +112,7 @@ namespace Libc {
public:
Mem_alloc_impl(Genode::Region_map &rm,
Genode::Ram_session &ram,
Genode::Ram_allocator &ram,
bool executable = false)
:
_ds_pool(&ram, &rm, executable),

View File

@ -1,22 +0,0 @@
/*
* \brief C implementation of 'Genode::printf()'
* \author Christian Prochaska
* \date 2013-07-29
*/
/*
* Copyright (C) 2013-2017 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.
*/
#include <base/printf.h>
extern "C" void genode_printf(const char *format, ...)
{
va_list list;
va_start(list, format);
Genode::vprintf(format, list);
va_end(list);
}

View File

@ -1,39 +0,0 @@
/*
* \brief 'PDBG()' implementation for use in '.c' files
* \author Christian Prochaska
* \date 2013-07-29
*/
/*
* Copyright (C) 2013-2017 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_PDBG_H_
#define _LIBC_PDBG_H_
extern void genode_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
/**
* Suppress debug messages in release version
*/
#ifdef GENODE_RELEASE
#define DO_PDBG 0
#else
#define DO_PDBG 1
#endif /* GENODE_RELEASE */
#define ESC_DBG "\033[33m"
#define ESC_END "\033[0m"
/**
* Print debug message with function name
*/
#define PDBG(fmt, ...) \
if (DO_PDBG) {\
genode_printf("%s: " ESC_DBG fmt ESC_END "\n", \
__PRETTY_FUNCTION__, ##__VA_ARGS__ ); }
#endif /* _LIBC_DEBUG_H_ */

View File

@ -9,7 +9,7 @@ From: Christian Prochaska <christian.prochaska@genode-labs.com>
#include "libc_private.h"
+#include <libc_pdbg.h>
+
+
/*
* Weak symbols: All libc internal usage of these functions should
@ -18,14 +18,14 @@ From: Christian Prochaska <christian.prochaska@genode-labs.com>
typedef ret (*FUNC_TYPE(name))(void); \
static ret FUNC_EXP(name)(void) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \
return (func()); \
} \
static ret FUNC_INT(name)(void) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \
return (func()); \
@ -33,14 +33,14 @@ From: Christian Prochaska <christian.prochaska@genode-labs.com>
typedef ret (*FUNC_TYPE(name))(p0_type); \
static ret FUNC_EXP(name)(p0_type p0) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \
return (func(p0)); \
} \
static ret FUNC_INT(name)(p0_type p0) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \
return (func(p0)); \
@ -48,14 +48,14 @@ From: Christian Prochaska <christian.prochaska@genode-labs.com>
typedef ret (*FUNC_TYPE(name))(p0_type, p1_type); \
static ret FUNC_EXP(name)(p0_type p0, p1_type p1) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \
return (func(p0, p1)); \
} \
static ret FUNC_INT(name)(p0_type p0, p1_type p1) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \
return (func(p0, p1)); \
@ -63,14 +63,14 @@ From: Christian Prochaska <christian.prochaska@genode-labs.com>
typedef ret (*FUNC_TYPE(name))(p0_type, p1_type, p2_type); \
static ret FUNC_EXP(name)(p0_type p0, p1_type p1, p2_type p2) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \
return (func(p0, p1, p2)); \
} \
static ret FUNC_INT(name)(p0_type p0, p1_type p1, p2_type p2) \
{ \
+ PDBG("%s called, not implemented", #name); \
+ puts(#name " called, not implemented"); \
FUNC_TYPE(name) func; \
func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \
return (func(p0, p1, p2)); \

View File

@ -52,7 +52,7 @@ extern "C" long sysconf(int name)
case _SC_PAGESIZE: return PAGESIZE;
case _SC_PHYS_PAGES:
return _global_env->ram().ram_quota().value / PAGESIZE;
return _global_env->pd().ram_quota().value / PAGESIZE;
default:
Genode::warning(__func__, "(", name, ") not implemented");
return Libc::Errno(EINVAL);
@ -131,10 +131,10 @@ extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
case HW_USERMEM:
switch (*oldlenp) {
case 4:
*(Genode::int32_t*)oldp = _global_env->ram().ram_quota().value;
*(Genode::int32_t*)oldp = _global_env->pd().ram_quota().value;
break;
case 8:
*(Genode::int64_t*)oldp = _global_env->ram().ram_quota().value;
*(Genode::int64_t*)oldp = _global_env->pd().ram_quota().value;
break;
default:
return Libc::Errno(EINVAL);

View File

@ -157,26 +157,12 @@ class Libc::Env_implementation : public Libc::Env
** Genode::Env interface **
***************************/
Parent &parent() override {
return _env.parent(); }
Parent &parent() override { return _env.parent(); }
Cpu_session &cpu() override { return _env.cpu(); }
Region_map &rm() override { return _env.rm(); }
Pd_session &pd() override { return _env.pd(); }
Entrypoint &ep() override { return _env.ep(); }
Ram_session &ram() override {
return _env.ram(); }
Cpu_session &cpu() override {
return _env.cpu(); }
Region_map &rm() override {
return _env.rm(); }
Pd_session &pd() override {
return _env.pd(); }
Entrypoint &ep() override {
return _env.ep(); }
Ram_session_capability ram_session_cap() override {
return _env.ram_session_cap(); }
Cpu_session_capability cpu_session_cap() override {
return _env.cpu_session_cap(); }
@ -187,12 +173,11 @@ class Libc::Env_implementation : public Libc::Env
return _env.id_space(); }
Session_capability session(Parent::Service_name const &name,
Parent::Client::Id id,
Parent::Session_args const &args,
Affinity const &aff) override {
Parent::Client::Id id,
Parent::Session_args const &args,
Affinity const &aff) override {
return _env.session(name, id, args, aff); }
void upgrade(Parent::Client::Id id,
Parent::Upgrade_args const &args) override {
return _env.upgrade(id, args); }
@ -200,6 +185,15 @@ class Libc::Env_implementation : public Libc::Env
void close(Parent::Client::Id id) override {
return _env.close(id); }
/*
* \deprecated
*
* Emulation of deprecated part of the 'Env' interface. To be
* removed once they are removed from 'Genode::Env'.
*/
Pd_session &ram() override { return pd(); }
Pd_session_capability ram_session_cap() override { return pd_session_cap(); }
/* already done by the libc */
void exec_static_constructors() override { }
@ -978,6 +972,7 @@ void Component::construct(Genode::Env &env)
Libc::init_mem_alloc(env);
Libc::init_dl(env);
Libc::sysctl_init(env);
Libc::init_pthread_support(env);
kernel = unmanaged_singleton<Libc::Kernel>(env, heap);

View File

@ -23,6 +23,7 @@
#include "thread.h"
#include "task.h"
#include "timed_semaphore.h"
#include "libc_init.h"
using namespace Genode;
@ -35,7 +36,7 @@ static Env *_env_ptr; /* solely needed to spawn the timeout thread for the
timed semaphore */
namespace Libc { void init_pthread_support(Env &env) { _env_ptr = &env; } }
void Libc::init_pthread_support(Genode::Env &env) { _env_ptr = &env; }
static Libc::Timeout_entrypoint &_global_timeout_ep()

View File

@ -110,19 +110,18 @@ namespace Libc {
{
private:
char _buf[Vfs::MAX_PATH_LEN];
typedef String<Vfs::MAX_PATH_LEN> Value;
Value const _value;
public:
Config_attr(char const *attr_name, char const *default_value)
{
Genode::strncpy(_buf, default_value, sizeof(_buf));
try {
Libc::config().attribute(attr_name).value(_buf, sizeof(_buf));
} catch (...) { }
}
:
_value(Libc::config().attribute_value(attr_name,
Value(default_value)))
{ }
char const *string() const { return _buf; }
char const *string() const { return _value.string(); }
};
char const *config_rtc() __attribute__((weak));

View File

@ -46,38 +46,36 @@ class Libc::Vfs_plugin : public Libc::Plugin
void _open_stdio(Genode::Xml_node const &node, char const *attr,
int libc_fd, unsigned flags)
{
try {
Genode::String<Vfs::MAX_PATH_LEN> path;
struct stat out_stat;
node.attribute(attr).value(&path);
if (stat(path.string(), &out_stat) != 0)
return;
Libc::File_descriptor *fd = open(path.string(), flags, libc_fd);
if (fd->libc_fd != libc_fd) {
Genode::error("could not allocate fd ",libc_fd," for ",path,", "
"got fd ",fd->libc_fd);
close(fd);
return;
}
/*
* We need to manually register the path. Normally this is done
* by '_open'. But we call the local 'open' function directly
* because we want to explicitly specify the libc fd ID.
*
* We have to allocate the path from the libc (done via 'strdup')
* such that the path can be freed when an stdio fd is closed.
*/
if (fd->fd_path) { Genode::warning("may leak former FD path memory"); }
fd->fd_path = strdup(path.string());
} catch (Xml_node::Nonexistent_attribute) {
/* fill the stdio number with a EBADF */
if (!node.has_attribute(attr)) {
Libc::file_descriptor_allocator()->alloc(nullptr, nullptr, libc_fd);
return;
}
typedef Genode::String<Vfs::MAX_PATH_LEN> Path;
Path const path = node.attribute_value(attr, Path());
struct stat out_stat { };
if (stat(path.string(), &out_stat) != 0)
return;
Libc::File_descriptor *fd = open(path.string(), flags, libc_fd);
if (fd->libc_fd != libc_fd) {
Genode::error("could not allocate fd ",libc_fd," for ",path,", "
"got fd ",fd->libc_fd);
close(fd);
return;
}
/*
* We need to manually register the path. Normally this is done
* by '_open'. But we call the local 'open' function directly
* because we want to explicitly specify the libc fd ID.
*
* We have to allocate the path from the libc (done via 'strdup')
* such that the path can be freed when an stdio fd is closed.
*/
if (fd->fd_path) { Genode::warning("may leak former FD path memory"); }
fd->fd_path = strdup(path.string());
}
/**
@ -160,19 +158,18 @@ class Libc::Vfs_plugin : public Libc::Plugin
if (_root_dir.num_dirent("/"))
env.config([&] (Xml_node const &top) {
try {
Xml_node const node = top.sub_node("libc");
try {
Genode::String<Vfs::MAX_PATH_LEN> path;
node.attribute("cwd").value(&path);
chdir(path.string());
} catch (Xml_node::Nonexistent_attribute) { }
top.with_sub_node("libc", [&] (Xml_node node) {
typedef Genode::String<Vfs::MAX_PATH_LEN> Path;
if (node.has_attribute("cwd"))
chdir(node.attribute_value("cwd", Path()).string());
_open_stdio(node, "stdin", 0, O_RDONLY);
_open_stdio(node, "stdout", 1, O_WRONLY);
_open_stdio(node, "stderr", 2, O_WRONLY);
} catch (Xml_node::Nonexistent_sub_node) { }
});
});
}

View File

@ -12,8 +12,7 @@
*/
/* Genode includes */
#include <base/printf.h>
#include <base/console.h>
#include <base/snprintf.h>
#include <base/lock.h>
#include <base/env.h>
@ -28,7 +27,9 @@ extern "C" {
va_list list;
va_start(list, format);
Genode::vprintf(format, list);
char buf[128] { };
Genode::String_console(buf, sizeof(buf)).vprintf(format, list);
Genode::log(Genode::Cstring(buf));
va_end(list);
}

View File

@ -61,35 +61,65 @@ static void construct_component(Libc::Env &env)
int arg_i = 0;
int env_i = 0;
node.for_each_sub_node([&] (Xml_node const &node) {
/* insert an argument */
if (node.has_type("arg")) try {
if (node.has_type("arg")) {
Xml_attribute attr = node.attribute("value");
attr.with_raw_value([&] (char const *start, size_t length) {
Genode::size_t const arg_len = attr.value_size()+1;
char *arg = argv[arg_i] = (char*)malloc(arg_len);
size_t const size = length + 1; /* for null termination */
argv[arg_i] = (char *)malloc(size);
Genode::strncpy(argv[arg_i], start, size);
});
attr.value(arg, arg_len);
++arg_i;
} catch (Xml_node::Nonexistent_sub_node) { }
}
else
/* insert an environment variable */
if (node.has_type("env")) try {
Xml_attribute key_attr = node.attribute("key");
Xml_attribute val_attr = node.attribute("value");
Genode::size_t const pair_len =
key_attr.value_size() +
val_attr.value_size() + 1;
char *env = envp[env_i] = (char*)malloc(pair_len);
Xml_attribute const key = node.attribute("key");
Xml_attribute const value = node.attribute("value");
using namespace Genode;
/*
* An environment variable has the form <key>=<value>, followed
* by a terminating zero.
*/
size_t const var_size = key .value_size() + 1
+ value.value_size() + 1;
envp[env_i] = (char*)malloc(var_size);
size_t pos = 0;
/* append characters to env variable with zero termination */
auto append = [&] (char const *s, size_t len) {
if (pos + len >= var_size) {
/* this should never happen */
warning("truncated environment variable: ", node);
return;
}
/* Genode's strncpy always zero-terminates */
Genode::strncpy(envp[env_i] + pos, s, len + 1);
pos += len;
};
key.with_raw_value([&] (char const *start, size_t length) {
append(start, length); });
append("=", 1);
value.with_raw_value([&] (char const *start, size_t length) {
append(start, length); });
Genode::size_t off = 0;
key_attr.value(&env[off], key_attr.value_size()+1);
off = key_attr.value_size();
env[off++] = '=';
val_attr.value(&env[off], val_attr.value_size()+1);
++env_i;
} catch (Xml_node::Nonexistent_sub_node) { }

View File

@ -166,10 +166,10 @@ struct Transform::Main {
Genode::String<16> key_type("PRESS_RELEASE");
Keys::Type press_release = Keys::Type::PRESS_RELEASE;
map_node.attribute("acpi").value(&acpi_type);
map_node.attribute("to_key").value(&to_key);
map_node.attribute("acpi").value(acpi_type);
map_node.attribute("to_key").value(to_key);
try {
map_node.attribute("as").value(&key_type);
map_node.attribute("as").value(key_type);
if (key_type == "PRESS")
press_release = Keys::Type::PRESS;
else if (key_type == "RELEASE")
@ -179,7 +179,7 @@ struct Transform::Main {
} catch (Xml_node::Nonexistent_attribute) { }
if (acpi_type == "lid" || acpi_type == "ac") {
map_node.attribute("value").value(&acpi_value_string);
map_node.attribute("value").value(acpi_value_string);
if (acpi_type == "lid") {
if (acpi_value_string == "OPEN")
@ -197,7 +197,7 @@ struct Transform::Main {
} else
throw 3;
} else
map_node.attribute("value").value(&acpi_value);
map_node.attribute("value").value(acpi_value);
Input::Keycode key_code = Input::Keycode::KEY_UNKNOWN;
@ -236,12 +236,18 @@ struct Transform::Main {
else
throw 5;
} catch (...) {
String<64> invalid_node(Genode::Cstring(map_node.addr(),
map_node.size()));
Genode::error("map item : '", invalid_node.string(), "'");
/* we want a well formated configuration ! - die */
class Invalid_config {} exception;
throw exception;
using namespace Genode;
map_node.with_raw_node([&] (char const *start, size_t length) {
String<64> invalid_node(Cstring(start, length));
error("map item : '", invalid_node, "'");
/* abort on malformed configuration */
class Invalid_config { };
throw Invalid_config();
});
}
});
@ -265,7 +271,7 @@ struct Transform::Main {
{
_acpi_ec.update();
if (!_acpi_ec.is_valid()) return;
if (!_acpi_ec.valid()) return;
Xml_node ec_event(_acpi_ec.local_addr<char>(), _acpi_ec.size());
@ -275,8 +281,8 @@ struct Transform::Main {
long acpi_value = 0;
unsigned long acpi_count = 0;
data_node.attribute("value").value(&acpi_value);
data_node.attribute("count").value(&acpi_count);
data_node.attribute("value").value(acpi_value);
data_node.attribute("count").value(acpi_count);
Keys * key = Keys::find_by_ec(acpi_value);
if (!key)
@ -309,7 +315,7 @@ struct Transform::Main {
{
_acpi_fixed.update();
if (!_acpi_fixed.is_valid()) return;
if (!_acpi_fixed.valid()) return;
Xml_node fixed_event(_acpi_fixed.local_addr<char>(), _acpi_fixed.size());
@ -318,8 +324,8 @@ struct Transform::Main {
bool pressed = false;
unsigned long acpi_count = 0;
pw_node.attribute("value").value(&pressed);
pw_node.attribute("count").value(&acpi_count);
pw_node.attribute("value").value(pressed);
pw_node.attribute("count").value(acpi_count);
Keys * key = Keys::find_by_fixed(ACPI_POWER_BUTTON);
if (!key)
@ -337,7 +343,7 @@ struct Transform::Main {
{
_acpi_battery.update();
if (!_acpi_battery.is_valid()) return;
if (!_acpi_battery.valid()) return;
/* make use of it if we need to ... */
Xml_node battery_node(_acpi_battery.local_addr<char>(),
@ -350,7 +356,7 @@ struct Transform::Main {
{
_acpi_ac.update();
if (!_acpi_ac.is_valid()) return;
if (!_acpi_ac.valid()) return;
Xml_node ac_node(_acpi_ac.local_addr<char>(), _acpi_ac.size());
@ -361,7 +367,7 @@ struct Transform::Main {
{
_acpi_lid.update();
if (!_acpi_lid.is_valid()) return;
if (!_acpi_lid.valid()) return;
Xml_node lid_node(_acpi_lid.local_addr<char>(), _acpi_lid.size());
@ -376,8 +382,8 @@ struct Transform::Main {
unsigned acpi_value = 0;
unsigned long acpi_count = 0;
node.attribute("value").value(&acpi_value);
node.attribute("count").value(&acpi_count);
node.attribute("value").value(acpi_value);
node.attribute("count").value(acpi_count);
enum { STATE_C = 0, STATE_O = 1 };

View File

@ -832,9 +832,8 @@ class Fatfs_fs::Root : public Root_component<Session_component>
Directory *session_root_dir = 0;
bool writeable = false;
enum { ROOT_MAX_LEN = 256 };
char root[ROOT_MAX_LEN];
root[0] = 0;
typedef String<256> Root_path;
Root_path root;
Session_label const label = label_from_args(args);
try {
@ -845,8 +844,8 @@ class Fatfs_fs::Root : public Root_component<Session_component>
* the session.
*/
try {
policy.attribute("root").value(root, sizeof(root));
if (is_root(root)) {
policy.attribute("root").value(root);
if (is_root(root.string())) {
session_root_dir = &_root_dir;
} else {
/*
@ -854,14 +853,14 @@ class Fatfs_fs::Root : public Root_component<Session_component>
* leading path delimiter. For performing the
* lookup, we skip the first character.
*/
if (root[0] != '/')
if (root.string()[0] != '/')
throw Lookup_failed();
/* Check if the root path exists */
using namespace Fatfs;
FRESULT res = f_chdir(root);
FRESULT res = f_chdir(root.string());
switch(res) {
case FR_OK:
@ -892,7 +891,7 @@ class Fatfs_fs::Root : public Root_component<Session_component>
throw Service_denied();
}
session_root_dir = new (&_md_alloc) Directory(root);
session_root_dir = new (&_md_alloc) Directory(root.string());
}
}
catch (Xml_node::Nonexistent_attribute) {
@ -900,7 +899,7 @@ class Fatfs_fs::Root : public Root_component<Session_component>
throw Service_denied();
}
catch (Lookup_failed) {
error("session root directory \"", Cstring(root), "\" does not exist");
error("session root directory \"", root, "\" does not exist");
throw Service_denied();
}

View File

@ -13,7 +13,7 @@
*/
/* Genode includes */
#include <base/printf.h>
#include <base/log.h>
#include <base/env.h>
/* local includes */
@ -29,18 +29,18 @@ using namespace Genode;
struct Lib_1_global_1
{
int x { 0x05060708 };
Lib_1_global_1() { printf("%s %x\n", __func__, --x); }
void lib_1_global_1() { printf("%s %x\n", __func__, --x); }
~Lib_1_global_1() { printf("%s %x\n", __func__, --x); x=0; }
Lib_1_global_1() { log(__func__, " ", Hex(--x)); }
void lib_1_global_1() { log(__func__, " ", Hex(--x)); }
~Lib_1_global_1() { log(__func__, " ", Hex(--x)); x=0; }
}
lib_1_global_1;
static struct Lib_1_global_2
{
int x { 0x01020304 };
Lib_1_global_2() { printf("%s %x\n", __func__, --x); }
void lib_1_global_2() { printf("%s %x\n", __func__, --x); }
~Lib_1_global_2() { printf("%s %x\n", __func__, --x); x=0; }
Lib_1_global_2() { log(__func__, " ", Hex(--x)); }
void lib_1_global_2() { log(__func__, " ", Hex(--x)); }
~Lib_1_global_2() { log(__func__, " ", Hex(--x)); x=0; }
}
lib_1_global_2;
@ -52,22 +52,22 @@ lib_1_global_2;
struct Lib_1_local_1
{
int x { 0x50607080 };
Lib_1_local_1() { printf("%s %x\n", __func__, --x); }
void lib_1_local_1() { printf("%s %x\n", __func__, --x); }
~Lib_1_local_1() { printf("%s %x\n", __func__, --x); x=0; }
Lib_1_local_1() { log(__func__, " ", Hex(--x)); }
void lib_1_local_1() { log(__func__, " ", Hex(--x)); }
~Lib_1_local_1() { log(__func__, " ", Hex(--x)); x=0; }
};
struct Lib_1_local_2
{
int x { 0x10203040 };
Lib_1_local_2() { printf("%s %x\n", __func__, --x); }
void lib_1_local_2() { printf("%s %x\n", __func__, --x); }
~Lib_1_local_2() { printf("%s %x\n", __func__, --x); x=0; }
Lib_1_local_2() { log(__func__, " ", Hex(--x)); }
void lib_1_local_2() { log(__func__, " ", Hex(--x)); }
~Lib_1_local_2() { log(__func__, " ", Hex(--x)); x=0; }
};
Lib_1_local_3::Lib_1_local_3() { printf("%s %x\n", __func__, --x); }
void Lib_1_local_3::lib_1_local_3() { printf("%s %x\n", __func__, --x); }
Lib_1_local_3::~Lib_1_local_3() { printf("%s %x\n", __func__, --x); x=0; }
Lib_1_local_3::Lib_1_local_3() { log(__func__, " ", Hex(--x)); }
void Lib_1_local_3::lib_1_local_3() { log(__func__, " ", Hex(--x)); }
Lib_1_local_3::~Lib_1_local_3() { log(__func__, " ", Hex(--x)); x=0; }
Lib_1_local_1 * lib_1_local_1()
{
@ -105,11 +105,11 @@ static void lib_1_attr_constructor_1()__attribute__((constructor));
void lib_1_attr_destructor_1() __attribute__((destructor));
static void lib_1_attr_destructor_2() __attribute__((destructor));
static void lib_1_attr_constructor_1() { printf("%s %x\n", __func__, --lib_1_pod_1); }
void lib_1_attr_constructor_2() { printf("%s %x\n", __func__, --lib_1_pod_2); }
static void lib_1_attr_constructor_1() { log(__func__, " ", Hex(--lib_1_pod_1)); }
void lib_1_attr_constructor_2() { log(__func__, " ", Hex(--lib_1_pod_2)); }
void lib_1_attr_destructor_1() { printf("%s %x\n", __func__, --lib_1_pod_1); lib_1_pod_1=0; }
static void lib_1_attr_destructor_2() { printf("%s %x\n", __func__, --lib_1_pod_2); lib_1_pod_2=0; }
void lib_1_attr_destructor_1() { log(__func__, " ", Hex(--lib_1_pod_1)); lib_1_pod_1=0; }
static void lib_1_attr_destructor_2() { log(__func__, " ", Hex(--lib_1_pod_2)); lib_1_pod_2=0; }
@ -121,31 +121,35 @@ void lib_1_good() { }
void lib_1_test()
{
printf("global objects and local static objects of shared lib\n");
printf("-----------------------------------------------------\n");
log("global objects and local static objects of shared lib");
log("-----------------------------------------------------");
lib_1_global_1.lib_1_global_1();
lib_1_global_2.lib_1_global_2();
lib_1_local_1()->lib_1_local_1();
lib_1_local_2()->lib_1_local_2();
printf("lib_1_pod_1 %x\n", --lib_1_pod_1);
printf("lib_1_pod_2 %x\n", --lib_1_pod_2);
printf("\n");
log("lib_1_pod_1 ", Hex(--lib_1_pod_1));
log("lib_1_pod_2 ", Hex(--lib_1_pod_2));
log("");
printf("Access shared lib from another shared lib\n");
printf("-----------------------------------------\n");
log("Access shared lib from another shared lib");
log("-----------------------------------------");
lib_2_global.lib_2_global();
lib_2_local()->lib_2_local();
printf("lib_2_pod_1 %x\n", --lib_2_pod_1);
printf("\n");
log("lib_2_pod_1 ", Hex(--lib_2_pod_1));
log("");
printf("Catch exceptions in shared lib\n");
printf("------------------------------\n");
printf("exception in lib: ");
try { exception(); }
catch (...) { printf("caught\n"); }
log("Catch exceptions in shared lib");
log("------------------------------");
try {
exception();
error("undelivered exception in lib");
}
catch (...) { log("exception in lib: caught"); }
printf("exception in another shared lib: ");
try { lib_2_exception(); }
catch(...) { printf("caught\n"); }
printf("\n");
try {
lib_2_exception();
error("undelivered exception in another shared lib");
}
catch(...) { log("exception in another shared lib: caught"); }
log("");
}

View File

@ -11,22 +11,22 @@
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#include <base/printf.h>
#include <base/log.h>
#include "test-ldso.h"
using namespace Genode;
void lib_2_exception() { throw 668; }
Lib_2_global::Lib_2_global() { printf("%s %x\n", __func__, --x); }
void Lib_2_global::lib_2_global() { printf("%s %x\n", __func__, --x); }
Lib_2_global::~Lib_2_global() { printf("%s %x\n", __func__, --x); x=0; }
Lib_2_global::Lib_2_global() { log(__func__, " ", Hex(--x)); }
void Lib_2_global::lib_2_global() { log(__func__, " ", Hex(--x)); }
Lib_2_global::~Lib_2_global() { log(__func__, " ", Hex(--x)); x=0; }
Lib_2_global lib_2_global;
Lib_2_local::Lib_2_local() { printf("%s %x\n", __func__, --x); }
void Lib_2_local::lib_2_local() { printf("%s %x\n", __func__, --x); }
Lib_2_local::~Lib_2_local() { printf("%s %x\n", __func__, --x); x=0; }
Lib_2_local::Lib_2_local() { log(__func__, " ", Hex(--x)); }
void Lib_2_local::lib_2_local() { log(__func__, " ", Hex(--x)); }
Lib_2_local::~Lib_2_local() { log(__func__, " ", Hex(--x)); x=0; }
Lib_2_local * lib_2_local()
{

View File

@ -13,7 +13,7 @@
*/
/* Genode includes */
#include <base/printf.h>
#include <base/log.h>
/* test-local includes */
#include "test-ldso.h"
@ -24,7 +24,7 @@ struct Global_object
{
Global_object()
{
Genode::printf("Global object constructed\n");
Genode::log("Global object constructed");
}
};
@ -40,7 +40,7 @@ Global_object global_object;
*/
extern "C" void lib_dl_symbol()
{
Genode::printf("called (from '%s')\n", __func__);
Genode::printf("Call 'lib_1_good': ");
Genode::log("called (from '", __func__, "')");
Genode::log("Call 'lib_1_good': ");
lib_1_good();
}

View File

@ -11,7 +11,7 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#include <base/printf.h>
#include <base/log.h>
#include <rom_session/connection.h>
#include <base/env.h>
#include <base/heap.h>
@ -37,18 +37,18 @@ namespace Libc {
struct Global_1
{
int x { 0x05060708 };
Global_1() { printf("%s %x\n", __func__, --x); }
void global_1() { printf("%s %x\n", __func__, --x); }
~Global_1() { printf("%s %x\n", __func__, --x); x=0; }
Global_1() { log(__func__, " ", Hex(--x)); }
void global_1() { log(__func__, " ", Hex(--x)); }
~Global_1() { log(__func__, " ", Hex(--x)); x=0; }
}
global_1;
static struct Global_2
{
int x { 0x01020304 };
Global_2() { printf("%s %x\n", __func__, --x); }
void global_2() { printf("%s %x\n", __func__, --x); }
~Global_2() { printf("%s %x\n", __func__, --x); x=0; }
Global_2() { log(__func__, " ", Hex(--x)); }
void global_2() { log(__func__, " ", Hex(--x)); }
~Global_2() { log(__func__, " ", Hex(--x)); x=0; }
}
global_2;
@ -60,17 +60,17 @@ global_2;
struct Local_1
{
int x { 0x50607080 };
Local_1() { printf("%s %x\n", __func__, --x); }
void local_1() { printf("%s %x\n", __func__, --x); }
~Local_1() { printf("%s %x\n", __func__, --x); x=0; }
Local_1() { log(__func__, " ", Hex(--x)); }
void local_1() { log(__func__, " ", Hex(--x)); }
~Local_1() { log(__func__, " ", Hex(--x)); x=0; }
};
struct Local_2
{
int x { 0x10203040 };
Local_2() { printf("%s %x\n", __func__, --x); }
void local_2() { printf("%s %x\n", __func__, --x); }
~Local_2() { printf("%s %x\n", __func__, --x); x=0; }
Local_2() { log(__func__, " ", Hex(--x)); }
void local_2() { log(__func__, " ", Hex(--x)); }
~Local_2() { log(__func__, " ", Hex(--x)); x=0; }
};
Local_1 * local_1()
@ -99,11 +99,11 @@ static void attr_constructor_1()__attribute__((constructor));
void attr_destructor_1() __attribute__((destructor));
static void attr_destructor_2() __attribute__((destructor));
static void attr_constructor_1() { printf("%s %x\n", __func__, --pod_1); }
void attr_constructor_2() { printf("%s %x\n", __func__, --pod_2); }
static void attr_constructor_1() { log(__func__, " ", Hex(--pod_1)); }
void attr_constructor_2() { log(__func__, " ", Hex(--pod_2)); }
void attr_destructor_1() { printf("%s %x\n", __func__, --pod_1); pod_1=0; }
static void attr_destructor_2() { printf("%s %x\n", __func__, --pod_2); pod_2=0; }
void attr_destructor_1() { log(__func__, " ", Hex(--pod_1)); pod_1=0; }
static void attr_destructor_2() { log(__func__, " ", Hex(--pod_2)); pod_2=0; }
/********************************************
@ -125,14 +125,18 @@ static void test_stack_align(char const *fmt, ...)
va_list list;
va_start(list, fmt);
vprintf(fmt, list);
char buf[128] { };
String_console(buf, sizeof(buf)).vprintf(fmt, list);
log(Cstring(buf));
va_end(list);
}
struct Test_stack_align_thread : Thread_deprecated<0x2000>
struct Test_stack_align_thread : Thread
{
Test_stack_align_thread() : Thread_deprecated<0x2000>("test_stack_align") { }
Test_stack_align_thread(Env &env)
: Thread(env, "test_stack_align", 0x2000) { }
void entry() { test_stack_align("%f\n%g\n", 3.142, 2.718); }
};
@ -143,12 +147,12 @@ struct Test_stack_align_thread : Thread_deprecated<0x2000>
struct Object_base
{
virtual void func() { printf("'Object_base' called: failed\n"); }
virtual void func() { log("'Object_base' called: failed"); }
};
struct Object : Object_base
{
void func() { printf("'Object' called: good\n"); }
void func() { log("'Object' called: good"); }
};
void test_dynamic_cast_call(Object_base *o)
@ -190,77 +194,88 @@ void Libc::Component::construct(Libc::Env &env)
{
static Heap heap(env.ram(), env.rm());
printf("\n");
printf("Dynamic-linker test\n");
printf("===================\n");
printf("\n");
using Genode::log;
printf("Global objects and local static objects of program\n");
printf("--------------------------------------------------\n");
log("");
log("Dynamic-linker test");
log("===================");
log("");
log("Global objects and local static objects of program");
log("--------------------------------------------------");
global_1.global_1();
global_2.global_2();
local_1()->local_1();
local_2()->local_2();
printf("pod_1 %x\n", --pod_1);
printf("pod_2 %x\n", --pod_2);
printf("\n");
log("pod_1 ", Hex(--pod_1));
log("pod_2 ", Hex(--pod_2));
log("");
printf("Access shared lib from program\n");
printf("------------------------------\n");
log("Access shared lib from program");
log("------------------------------");
lib_2_global.lib_2_global();
lib_1_local_3()->lib_1_local_3();
printf("lib_1_pod_1 %x\n", --pod_1);
log("lib_1_pod_1 ", Hex(--pod_1));
int fd = STDERR_FILENO + 1;
char buf[2];
printf("Libc::read:\n");
char buf[2] { };
log("Libc::read:");
Libc::read(fd, buf, 2);
int i = Libc::abs(-10);
printf("Libc::abs(-10): %d\n", i);
printf("\n");
log("Libc::abs(-10): ", i);
log("");
printf("Catch exceptions in program\n");
printf("---------------------------\n");
printf("exception in remote procedure call:\n");
try { Rom_connection rom(env, "unknown_file"); }
catch (Rom_connection::Rom_connection_failed) { printf("caught\n"); }
log("Catch exceptions in program");
log("---------------------------");
try {
Rom_connection rom(env, "unknown_rom");
error("undelivered exception in remote procedure call");
}
catch (Rom_connection::Rom_connection_failed) {
log("exception in remote procedure call: caught");
}
printf("exception in program: ");
try { exception(); }
catch (int) { printf("caught\n"); }
try {
exception();
error("undelivered exception in program");
}
catch (int) { log("exception in program: caught"); }
printf("exception in shared lib: ");
try { lib_1_exception(); }
catch (Region_map::Region_conflict) { printf("caught\n"); }
try {
lib_1_exception();
error("undelivered exception in shared lib");
}
catch (Region_map::Region_conflict) { log("exception in shared lib: caught"); }
printf("exception in dynamic linker: ");
try { __ldso_raise_exception(); }
catch (Genode::Exception) { printf("caught\n"); }
printf("\n");
try {
__ldso_raise_exception();
log("undelivered exception in dynamic linker");
}
catch (Genode::Exception) { log("exception in dynamic linker: caught"); }
log("");
lib_1_test();
printf("Test stack alignment\n");
printf("--------------------\n");
log("Test stack alignment");
log("--------------------");
test_stack_align("%f\n%g\n", 3.142, 2.718);
Test_stack_align_thread t;
Test_stack_align_thread t { env };
t.start();
t.join();
printf("\n");
printf("Dynamic cast\n");
printf("------------\n");
log("Dynamic cast");
log("------------");
test_dynamic_cast(heap);
printf("\n");
log("");
printf("Shared-object API\n");
printf("-----------------\n");
log("Shared-object API");
log("-----------------");
test_shared_object_api(env, heap);
printf("\n");
log("");
printf("Destruction\n");
printf("-----------\n");
log("Destruction");
log("-----------");
Libc::exit(123);
}

View File

@ -50,15 +50,15 @@ static void test_write_read(Genode::Xml_node node)
try {
Genode::Xml_node config = node.sub_node("write-read");
try { config.attribute("rounds").value(&rounds); } catch (...) { }
rounds = config.attribute_value("rounds", rounds);
Genode::Number_of_bytes n;
Genode::Number_of_bytes n { };
try {
config.attribute("size").value(&n);
config.attribute("size").value(n);
size = n;
} catch (...) { }
try {
config.attribute("buffer_size").value(&n);
config.attribute("buffer_size").value(n);
buffer_size = n;
} catch (...) { }
} catch (...) { }
@ -111,7 +111,7 @@ static void test(Genode::Xml_node node)
unsigned int iterations = 1;
try {
node.sub_node("iterations").attribute("value").value(&iterations);
node.sub_node("iterations").attribute("value").value(iterations);
} catch(...) { }
for (unsigned int i = 0; i < iterations; i++) {

View File

@ -1,5 +1,3 @@
TARGET = test-libc_vfs
LIBS = libc base
SRC_CC = main.cc
CC_CXX_WARN_STRICT =

View File

@ -43,35 +43,43 @@ static void test(Libc::Env &env)
continue;
}
/* read server IP address and port */
Ipv4_addr_str serv_addr;
unsigned port = 0;
Attached_rom_dataspace config(env, "config");
Xml_node config_node = config.xml();
try { config_node.attribute("server_ip").value(&serv_addr); }
catch (...) {
error("cannot read attribute 'server_ip'");
auto check_attr = [&] (char const *attr)
{
if (config_node.has_attribute(attr))
return true;
error("cannot read attribute '", attr, "'");
return false;
};
if (!check_attr("server_ip") || !check_attr("server_port"))
break;
}
try { config_node.attribute("server_port").value(&port); }
catch (...) {
error("cannot read attribute 'server_port'");
break;
}
Ipv4_addr_str const server_addr =
config_node.attribute_value("server_ip", Ipv4_addr_str());
unsigned const port =
config_node.attribute_value("server_port", 0U);
/* create server socket address */
struct sockaddr_in addr;
socklen_t addr_sz = sizeof(addr);
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(serv_addr.string());
addr.sin_addr.s_addr = inet_addr(server_addr.string());
/* send test message */
enum { BUF_SZ = 1024 };
char buf[BUF_SZ];
::snprintf(buf, BUF_SZ, "UDP server at %s:%u", serv_addr.string(), port);
if (sendto(s, buf, BUF_SZ, 0, (struct sockaddr*)&addr, addr_sz) != BUF_SZ) {
String<BUF_SZ> const message("UDP server at ", server_addr, ":", port);
if (sendto(s, message.string(), BUF_SZ, 0, (struct sockaddr*)&addr, addr_sz) != BUF_SZ) {
continue;
}
/* receive and print what has been received */
char buf[BUF_SZ] { };
if (recvfrom(s, buf, BUF_SZ, 0, (struct sockaddr*)&addr, &addr_sz) != BUF_SZ) {
continue;
}

View File

@ -43,7 +43,7 @@ static void test(Libc::Env & env)
/* read server port */
unsigned port = 0;
env.config([&] (Xml_node config_node) {
try { config_node.attribute("port").value(&port); }
try { config_node.attribute("port").value(port); }
catch (...) {
throw Read_port_attr_failed();
}

View File

@ -27,8 +27,8 @@ namespace Moon {
struct Main;
struct Env
{
Timer::Session &timer;
Genode::Ram_session &ram;
Timer::Session &timer;
Genode::Pd_session &pd;
};
Env *env;
}
@ -63,7 +63,7 @@ static int l_quota(lua_State *lua)
return 0;
}
lua_pushnumber(lua, Moon::env->ram.ram_quota().value);
lua_pushnumber(lua, Moon::env->pd.ram_quota().value);
return 1;
}
@ -126,7 +126,7 @@ struct Moon::Main
Timer::Connection _timer { _env };
Moon::Env _moon_env { _timer, _env.ram() };
Moon::Env _moon_env { _timer, _env.pd() };
Main(Libc::Env &env) : _env(env)
{