diff --git a/repos/base-linux/src/core/include/core_linux_syscalls.h b/repos/base-linux/src/core/include/core_linux_syscalls.h index 1b7adb6f3f..8966cf367a 100644 --- a/repos/base-linux/src/core/include/core_linux_syscalls.h +++ b/repos/base-linux/src/core/include/core_linux_syscalls.h @@ -117,8 +117,7 @@ inline int lx_ioctl_irq(int fd, int irq) ** Process creation and destruction ** **************************************/ -inline int lx_execve(const char *filename, char *const argv[], - char *const envp[]) +inline int lx_execve(char const *filename, char const *argv[], char const *envp[]) { return (int)lx_syscall(SYS_execve, filename, argv, envp); } diff --git a/repos/base-linux/src/core/include/resource_path.h b/repos/base-linux/src/core/include/resource_path.h index 6e73aa77fd..caa09139bd 100644 --- a/repos/base-linux/src/core/include/resource_path.h +++ b/repos/base-linux/src/core/include/resource_path.h @@ -18,7 +18,7 @@ #include /* Genode includes */ -#include +#include /** * Return resource path for Genode @@ -27,18 +27,8 @@ */ static inline char const *resource_path() { - struct Resource_path - { - char string[32]; - - Resource_path() - { - Genode::snprintf(string, sizeof(string), "/tmp/genode-%d", lx_getuid()); - } - }; - - static Resource_path path; - return path.string; + static Genode::String<32> path("/tmp/genode-", lx_getuid()); + return path.string(); } #endif /* _CORE__INCLUDE__RESOURCE_PATH_H_ */ diff --git a/repos/base-linux/src/core/native_pd_component.cc b/repos/base-linux/src/core/native_pd_component.cc index b16511a23f..5f0bdd2958 100644 --- a/repos/base-linux/src/core/native_pd_component.cc +++ b/repos/base-linux/src/core/native_pd_component.cc @@ -13,7 +13,6 @@ /* Genode includes */ #include -#include #include /* core includes */ @@ -42,8 +41,8 @@ struct Execve_args_and_stack struct Args { char const *filename; - char **argv; - char **envp; + char const **argv; + char const **envp; Lx_sd parent_sd; }; @@ -111,8 +110,7 @@ void Native_pd_component::_start(Dataspace_component &ds) const char *tmp_filename = "temporary_executable_elf_dataspace_file_for_execve"; /* we need 's' on stack to make it an lvalue with an lvalue member we use the pointer to */ - Linux_dataspace::Filename s = ds.fname(); - const char *filename = s.buf; + Linux_dataspace::Filename filename = ds.fname(); /* * In order to be executable via 'execve', a program must be represented as @@ -121,11 +119,11 @@ void Native_pd_component::_start(Dataspace_component &ds) * the dataspace content into a temporary file whose path is passed to * 'execve()'. */ - if (Genode::strcmp(filename, "") == 0) { + if (filename == "") { filename = tmp_filename; - int tmp_binary_fd = lx_open(filename, O_CREAT | O_EXCL | O_WRONLY, S_IRWXU); + int tmp_binary_fd = lx_open(filename.string(), O_CREAT | O_EXCL | O_WRONLY, S_IRWXU); if (tmp_binary_fd < 0) { error("Could not create file '", filename, "'"); return; /* XXX reflect error to client */ @@ -141,30 +139,24 @@ void Native_pd_component::_start(Dataspace_component &ds) } /* pass parent capability as environment variable to the child */ - enum { ENV_STR_LEN = 256 }; - static char envbuf[5][ENV_STR_LEN]; - Genode::snprintf(envbuf[1], ENV_STR_LEN, "parent_local_name=%lu", - _pd_session._parent.local_name()); - Genode::snprintf(envbuf[2], ENV_STR_LEN, "DISPLAY=%s", - get_env("DISPLAY")); - Genode::snprintf(envbuf[3], ENV_STR_LEN, "HOME=%s", - get_env("HOME")); - Genode::snprintf(envbuf[4], ENV_STR_LEN, "LD_LIBRARY_PATH=%s", - get_env("LD_LIBRARY_PATH")); - - char *env[] = { &envbuf[0][0], &envbuf[1][0], &envbuf[2][0], - &envbuf[3][0], &envbuf[4][0], 0 }; + using Env_string = String<256>; + static Env_string env_strings[] { + { "parent_local_name=", _pd_session._parent.local_name() }, + { "DISPLAY=", get_env("DISPLAY") }, + { "HOME=", get_env("HOME") }, + { "LD_LIBRARY_PATH=", get_env("LD_LIBRARY_PATH") }, + }; + char const *env[] = { env_strings[0].string(), env_strings[1].string(), + env_strings[2].string(), env_strings[3].string(), + nullptr }; /* prefix name of Linux program (helps killing some zombies) */ - char const *prefix = "[Genode] "; - char pname_buf[sizeof(_pd_session._label) + sizeof(prefix)]; - snprintf(pname_buf, sizeof(pname_buf), "%s%s", prefix, _pd_session._label.string()); - char *argv_buf[2]; - argv_buf[0] = pname_buf; - argv_buf[1] = 0; + using Pname = String; + Pname const pname("[Genode] ", _pd_session._label); + char const *argv_buf[] { pname.string(), nullptr }; _execve_args_and_stack().args = Execve_args_and_stack::Args { - .filename = filename, + .filename = filename.string(), .argv = argv_buf, .envp = env, .parent_sd = Capability_space::ipc_cap_data(_pd_session._parent).dst.socket @@ -173,8 +165,8 @@ void Native_pd_component::_start(Dataspace_component &ds) _pid = lx_create_process((int (*)())_exec_child, _execve_args_and_stack().initial_sp()); - if (Genode::strcmp(filename, tmp_filename) == 0) - lx_unlink(filename); + if (filename == tmp_filename) + lx_unlink(filename.string()); } diff --git a/repos/base-linux/src/core/ram_dataspace_support.cc b/repos/base-linux/src/core/ram_dataspace_support.cc index 8ff4103c6e..433811a9e9 100644 --- a/repos/base-linux/src/core/ram_dataspace_support.cc +++ b/repos/base-linux/src/core/ram_dataspace_support.cc @@ -14,9 +14,6 @@ /* glibc includes */ #include -/* Genode includes */ -#include - /* local includes */ #include #include @@ -35,12 +32,11 @@ static int ram_ds_cnt = 0; /* counter for creating unique dataspace IDs */ void Ram_dataspace_factory::_export_ram_ds(Dataspace_component &ds) { - char fname[Linux_dataspace::FNAME_LEN]; + Linux_dataspace::Filename const fname(resource_path(), "/ds-", ram_ds_cnt++); /* create file using a unique file name in the resource path */ - snprintf(fname, sizeof(fname), "%s/ds-%d", resource_path(), ram_ds_cnt++); - lx_unlink(fname); - int const fd = lx_open(fname, O_CREAT|O_RDWR|O_TRUNC|LX_O_CLOEXEC, S_IRWXU); + lx_unlink(fname.string()); + int const fd = lx_open(fname.string(), O_CREAT|O_RDWR|O_TRUNC|LX_O_CLOEXEC, S_IRWXU); lx_ftruncate(fd, ds.size()); /* remember file descriptor in dataspace component object */ @@ -52,7 +48,7 @@ void Ram_dataspace_factory::_export_ram_ds(Dataspace_component &ds) * gone (i.e., an open file descriptor referring to the file). A process * w/o the right file descriptor won't be able to open and access the file. */ - lx_unlink(fname); + lx_unlink(fname.string()); } diff --git a/repos/base-linux/src/core/spec/linux/dataspace_component.cc b/repos/base-linux/src/core/spec/linux/dataspace_component.cc index 54f50407ee..0abfb74b5e 100644 --- a/repos/base-linux/src/core/spec/linux/dataspace_component.cc +++ b/repos/base-linux/src/core/spec/linux/dataspace_component.cc @@ -21,13 +21,10 @@ /* Genode includes */ #include -#include -#include -#include #include /* local includes */ -#include "dataspace_component.h" +#include using namespace Core; @@ -35,17 +32,15 @@ using namespace Core; Linux_dataspace::Filename Dataspace_component::_file_name(const char *args) { Session_label const label = label_from_args(args); - Linux_dataspace::Filename fname; - - if (label.last_element().length() > sizeof(fname.buf)) { + if (label.last_element().length() > Linux_dataspace::Filename::capacity()) { error("file name too long: ", label.last_element()); throw Service_denied(); } - copy_cstring(fname.buf, label.last_element().string(), sizeof(fname.buf)); + Linux_dataspace::Filename const fname = label.last_element(); /* only files inside the current working directory are allowed */ - for (const char *c = fname.buf; *c; ++c) + for (const char *c = fname.string(); *c; ++c) if (*c == '/') throw Service_denied(); return fname; @@ -55,7 +50,7 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args) size_t Dataspace_component::_file_size() { Genode::uint64_t size = 0; - if (lx_stat_size(_fname.buf, size) < 0) + if (lx_stat_size(_fname.string(), size) < 0) throw Service_denied(); return align_addr((size_t)size, 12); @@ -67,7 +62,7 @@ Dataspace_component::Dataspace_component(const char *args) _fname(_file_name(args)), _size(_file_size()), _addr(0), - _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), + _cap(_fd_to_cap(lx_open(_fname.string(), O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), _writeable(false), _owner(0) { } @@ -79,5 +74,4 @@ Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr, _size(size), _addr(phys_addr), _cap(), _writeable(false), _owner(_owner) { warning("Should only be used for IOMEM and not within Linux."); - _fname.buf[0] = 0; } diff --git a/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h b/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h index 8803c3afda..c6940f25bb 100644 --- a/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h +++ b/repos/base-linux/src/include/linux_dataspace/linux_dataspace.h @@ -16,16 +16,15 @@ #include #include -#include #include +#include namespace Genode { struct Linux_dataspace; } struct Genode::Linux_dataspace : Dataspace { - enum { FNAME_LEN = 64 }; - struct Filename { char buf[FNAME_LEN]; }; + using Filename = String<64>; virtual ~Linux_dataspace() { } @@ -42,11 +41,11 @@ struct Genode::Linux_dataspace : Dataspace */ virtual Untyped_capability fd() = 0; + /********************* ** RPC declaration ** *********************/ - GENODE_RPC(Rpc_fname, Filename, fname); GENODE_RPC(Rpc_fd, Untyped_capability, fd); GENODE_RPC_INTERFACE_INHERIT(Dataspace, Rpc_fname, Rpc_fd); diff --git a/repos/base-linux/src/lib/base/thread_linux.cc b/repos/base-linux/src/lib/base/thread_linux.cc index 5db0888e5e..6a8d5e8f16 100644 --- a/repos/base-linux/src/lib/base/thread_linux.cc +++ b/repos/base-linux/src/lib/base/thread_linux.cc @@ -15,7 +15,6 @@ /* Genode includes */ #include #include -#include #include #include #include diff --git a/repos/base-linux/src/lib/syscall/linux_syscalls.h b/repos/base-linux/src/lib/syscall/linux_syscalls.h index 8c7e96da23..0cf1bd8e41 100644 --- a/repos/base-linux/src/lib/syscall/linux_syscalls.h +++ b/repos/base-linux/src/lib/syscall/linux_syscalls.h @@ -36,7 +36,6 @@ /* Genode includes */ #include -#include #include #include @@ -77,14 +76,6 @@ extern "C" void wait_for_continue(void); -#define PRAW(fmt, ...) \ - do { \ - char str[128]; \ - Genode::snprintf(str, sizeof(str), \ - ESC_ERR fmt ESC_END "\n", ##__VA_ARGS__); \ - Genode::raw(Genode::Cstring(str)); \ - } while (0) - /********************************************************* ** System-call bindings implemented in syscall library ** diff --git a/repos/base-nova/src/test/platform/main.cc b/repos/base-nova/src/test/platform/main.cc index e8748b667a..debc793f7c 100644 --- a/repos/base-nova/src/test/platform/main.cc +++ b/repos/base-nova/src/test/platform/main.cc @@ -15,9 +15,7 @@ #include #include #include -#include #include - #include #include #include @@ -625,24 +623,18 @@ class Greedy : public Genode::Thread { } }; -void check(uint8_t res, const char *format, ...) + +template +void check(uint8_t res, ARGS &&... args) { - static char buf[128]; - - va_list list; - va_start(list, format); - - String_console sc(buf, sizeof(buf)); - sc.vprintf(format, list); - - va_end(list); + String<128> msg(args...); if (res == Nova::NOVA_OK) { - error("res=", res, " ", Cstring(buf), " - TEST FAILED"); + error("res=", res, " ", msg, " - TEST FAILED"); failed++; } else - log("res=", res, " ", Cstring(buf)); + log("res=", res, " ", msg); } struct Main @@ -708,7 +700,7 @@ Main::Main(Env &env) : env(env) for (unsigned i = 0; i < (1U << Nova::NUM_INITIAL_PT_LOG2); i++) { addr_t sel_exc = myself->native_thread().exc_pt_sel + i; res = Nova::pt_ctrl(sel_exc, 0xbadbad); - check(res, "pt_ctrl %2u", i); + check(res, "pt_ctrl ", i); } /* test PAT kernel feature */ diff --git a/repos/base-sel4/src/include/base/internal/assert.h b/repos/base-sel4/src/include/base/internal/assert.h index 17c1bbbf7d..f6e86e541c 100644 --- a/repos/base-sel4/src/include/base/internal/assert.h +++ b/repos/base-sel4/src/include/base/internal/assert.h @@ -18,18 +18,16 @@ #define _INCLUDE__BASE__INTERNAL__ASSERT_H_ /* Genode includes */ -#include +#include /* base-internal includes */ #include #define ASSERT(e) \ do { if (!(e)) { \ - char line_buf[32]; \ - Genode::snprintf(line_buf, sizeof(line_buf), "%d", __LINE__); \ kernel_debugger_outstring("Assertion failed: " #e "\n"); \ kernel_debugger_outstring(__FILE__ ":"); \ - kernel_debugger_outstring(line_buf); \ + kernel_debugger_outstring(Genode::String<32>(__LINE__).string()); \ kernel_debugger_panic("\n"); \ } \ } while(0) diff --git a/repos/base/include/base/connection.h b/repos/base/include/base/connection.h index 89ec29df93..fcf855e2b2 100644 --- a/repos/base/include/base/connection.h +++ b/repos/base/include/base/connection.h @@ -18,6 +18,7 @@ #include #include #include +#include /* deprecated */ namespace Genode { diff --git a/repos/base/include/base/session_label.h b/repos/base/include/base/session_label.h index e5728ed7a7..e23b3b2928 100644 --- a/repos/base/include/base/session_label.h +++ b/repos/base/include/base/session_label.h @@ -15,7 +15,6 @@ #ifndef _INCLUDE__BASE__SESSION_LABEL_H_ #define _INCLUDE__BASE__SESSION_LABEL_H_ -#include #include #include @@ -40,8 +39,7 @@ struct Genode::Session_label : String<160> * copy constructors as candidate. */ template - Session_label(Genode::String const &other) - : Genode::String<160>(other) { } + Session_label(Genode::String const &other) : Genode::String<160>(other) { } Session_label last_element() const { diff --git a/repos/base/include/deprecated/env.h b/repos/base/include/deprecated/env.h index 4164e40c2c..b96f55cdb9 100644 --- a/repos/base/include/deprecated/env.h +++ b/repos/base/include/deprecated/env.h @@ -24,7 +24,6 @@ #include #include #include -#include namespace Genode { diff --git a/repos/base/include/util/arg_string.h b/repos/base/include/util/arg_string.h index 907134492e..1522638bb2 100644 --- a/repos/base/include/util/arg_string.h +++ b/repos/base/include/util/arg_string.h @@ -29,7 +29,6 @@ #include #include -#include namespace Genode { @@ -329,10 +328,8 @@ class Genode::Arg_string static bool set_arg(char *args, size_t args_len, const char *key, int value) { - enum { STRING_LONG_MAX = 32 }; - char buf[STRING_LONG_MAX]; - snprintf(buf, sizeof(buf), "%d", value); - return remove_arg(args, key) && add_arg(args, args_len, key, buf); + return remove_arg(args, key) + && add_arg(args, args_len, key, String<16>(value).string()); } /** diff --git a/repos/base/include/util/xml_generator.h b/repos/base/include/util/xml_generator.h index 16e1926623..3ef833a94a 100644 --- a/repos/base/include/util/xml_generator.h +++ b/repos/base/include/util/xml_generator.h @@ -16,7 +16,6 @@ #include #include -#include namespace Genode { class Xml_generator; } @@ -336,9 +335,7 @@ class Genode::Xml_generator void attribute(char const *name, long long value) { - char buf[64]; - Genode::snprintf(buf, sizeof(buf), "%lld", value); - _curr_node->insert_attribute(name, buf); + _curr_node->insert_attribute(name, String<64>(value).string()); } void attribute(char const *name, long value) @@ -353,9 +350,7 @@ class Genode::Xml_generator void attribute(char const *name, unsigned long long value) { - char buf[64]; - Genode::snprintf(buf, sizeof(buf), "%llu", value); - _curr_node->insert_attribute(name, buf); + _curr_node->insert_attribute(name, String<64>(value).string()); } void attribute(char const *name, unsigned long value) diff --git a/repos/base/run/smp.run b/repos/base/run/smp.run index 99bfed3c34..30a93051b6 100644 --- a/repos/base/run/smp.run +++ b/repos/base/run/smp.run @@ -100,8 +100,8 @@ grep_output {\[init -\> test-smp\] Affinity: Round} set rounds "10" set good_string {} for {set r 0} {$r <= $rounds} {incr r} { - append good_string {[init -> test-smp] Affinity: Round } - append good_string [format "%02d" $r] + append good_string {[init -> test-smp] Affinity: Round } + append good_string [format "%2d" $r] append good_string ":" for {set i 0} {$i < $cpus} {incr i} { append good_string " A" diff --git a/repos/base/src/core/main.cc b/repos/base/src/core/main.cc index 2d1d15f250..1307e2e189 100644 --- a/repos/base/src/core/main.cc +++ b/repos/base/src/core/main.cc @@ -12,7 +12,6 @@ */ /* Genode includes */ -#include #include #include #include diff --git a/repos/base/src/lib/base/thread.cc b/repos/base/src/lib/base/thread.cc index b7ee561a44..b21ffb319d 100644 --- a/repos/base/src/lib/base/thread.cc +++ b/repos/base/src/lib/base/thread.cc @@ -18,7 +18,6 @@ #include #include #include -#include #include /* base-internal includes */ @@ -133,7 +132,7 @@ void Thread::_free_stack(Stack *stack) void Thread::name(char *dst, size_t dst_len) { - snprintf(dst, dst_len, "%s", _stack->name().string()); + copy_cstring(dst, name().string(), dst_len); } diff --git a/repos/base/src/test/smp/main.cc b/repos/base/src/test/smp/main.cc index 53ada8a743..b1096779fc 100644 --- a/repos/base/src/test/smp/main.cc +++ b/repos/base/src/test/smp/main.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -203,42 +204,59 @@ namespace Affinity_test { volatile uint64_t cnt = 0; unsigned round = 0; - char const text_cpu[] = "Affinity: CPU: "; - char const text_round[] = "Affinity: Round %2u: "; - char * output_buffer = new (heap) char [sizeof(text_cpu) + 3 * cpus.total()]; + static char const text_cpu[] = "Affinity: CPU: "; for (; round < 11;) { cnt++; /* try to get a life sign by the main thread from the remote threads */ if (cnt % COUNT_VALUE == 0) { - char * output = output_buffer; - snprintf(output, sizeof(text_cpu), text_cpu); - output += sizeof(text_cpu) - 1; - for (unsigned i = 0; i < cpus.total(); i++) { - snprintf(output, 4, "%2u ", i); - output += 3; - } - log(Cstring(output_buffer)); - output = output_buffer; - snprintf(output, sizeof(text_round), text_round, round); - output += sizeof(text_round) - 2; + struct Table_header + { + unsigned num_cpus; - for (unsigned i = 0; i < cpus.total(); i++) { - snprintf(output, 4, "%s ", - thread_cnt[i] == threads[i]->cnt ? " D" : " A"); - output += 3; + void print(Output &out) const + { + using Genode::print; + + print(out, text_cpu); + for (unsigned i = 0; i < num_cpus; i++) + print(out, Right_aligned(2, i), " "); + } + }; + + struct Table_entries + { + unsigned num_cpus; + unsigned round; + Spinning_thread **threads; + uint64_t *thread_cnt; + + void print(Output &out) const + { + using Genode::print; + + print(out, "Affinity: Round ", Right_aligned(2, round), ": "); + + for (unsigned i = 0; i < num_cpus; i++) + print(out, thread_cnt[i] == threads[i]->cnt ? " D " : " A "); + } + }; + + log(Table_header { .num_cpus = cpus.total() }); + log(Table_entries { .num_cpus = cpus.total(), + .round = round, + .threads = threads, + .thread_cnt = thread_cnt }); + + for (unsigned i = 0; i < cpus.total(); i++) thread_cnt[i] = threads[i]->cnt; - } - log(Cstring(output_buffer)); round ++; } } - destroy(heap, output_buffer); - for (unsigned i = 0; i < cpus.total(); i++) destroy(heap, threads[i]); destroy(heap, threads); diff --git a/repos/base/src/test/thread/main.cc b/repos/base/src/test/thread/main.cc index 786777b060..3d430dc916 100644 --- a/repos/base/src/test/thread/main.cc +++ b/repos/base/src/test/thread/main.cc @@ -25,6 +25,9 @@ #include #include +/* compiler includes */ +#include + using namespace Genode; @@ -194,7 +197,7 @@ struct Cpu_helper : Thread { Env &_env; - Cpu_helper(Env &env, const char * name, Cpu_session &cpu) + Cpu_helper(Env &env, Name const &name, Cpu_session &cpu) : Thread(env, name, STACK_SIZE, Thread::Location(), Thread::Weight(), cpu), _env(env) @@ -306,7 +309,6 @@ static void test_create_as_many_threads(Env &env) Thread::stack_virtual_size(); Cpu_helper * threads[max]; - static char thread_name[8]; Heap heap(env.ram(), env.rm()); @@ -314,8 +316,7 @@ static void test_create_as_many_threads(Env &env) try { for (; i < max; i++) { try { - snprintf(thread_name, sizeof(thread_name), "%u", i + 1); - threads[i] = new (heap) Cpu_helper(env, thread_name, env.cpu()); + threads[i] = new (heap) Cpu_helper(env, Thread::Name(i + 1), env.cpu()); threads[i]->start(); threads[i]->join(); } catch (Cpu_session::Thread_creation_failed) {