From 1dac0484132f70e5e7534c05d65951d7e6e1d1a1 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 15 May 2023 17:29:51 +0200 Subject: [PATCH] base: make RPC framework compatible to C++20 Avoid the use of arithmetics on enum values. Issue #4869 --- repos/base/include/base/rpc.h | 50 +++++++++---------- repos/base/include/base/rpc_client.h | 12 +++-- repos/base/include/base/rpc_server.h | 5 +- repos/base/include/cpu_session/cpu_session.h | 3 +- .../include/io_mem_session/io_mem_session.h | 3 +- .../include/io_port_session/io_port_session.h | 3 +- repos/base/include/irq_session/irq_session.h | 3 +- repos/base/include/log_session/log_session.h | 3 +- repos/base/include/pd_session/pd_session.h | 3 +- repos/base/include/rom_session/rom_session.h | 3 +- 10 files changed, 49 insertions(+), 39 deletions(-) diff --git a/repos/base/include/base/rpc.h b/repos/base/include/base/rpc.h index db31fbfc23..889f712144 100644 --- a/repos/base/include/base/rpc.h +++ b/repos/base/include/base/rpc.h @@ -167,29 +167,27 @@ namespace Genode { { long value; - enum { - SUCCESS = 0, + static constexpr long SUCCESS = 0; - /** - * Server-side object does not exist - * - * This exception code is not meant to be reflected from the server - * to the client. On kernels with capability support, the condition - * can never occur. On kernels without capability protection, the - * code is merely used for diagnostic purposes at the server side. - */ - INVALID_OBJECT = -1, + /** + * Server-side object does not exist + * + * This exception code is not meant to be reflected from the server + * to the client. On kernels with capability support, the condition + * can never occur. On kernels without capability protection, the + * code is merely used for diagnostic purposes at the server side. + */ + static constexpr long INVALID_OBJECT = -1; - /** - * Special exception code used to respond to illegal opcodes - */ - INVALID_OPCODE = -2, + /** + * Special exception code used to respond to illegal opcodes + */ + static constexpr long INVALID_OPCODE = -2; - /** - * Opcode base used for passing exception information - */ - EXCEPTION_BASE = -1000 - }; + /** + * Opcode base used for passing exception information + */ + static constexpr long EXCEPTION_BASE = -1000; explicit Rpc_exception_code(int value) : value(value) { } }; @@ -268,14 +266,16 @@ namespace Genode { template struct Rpc_function_msg_size { - enum { Value = Rpc_msg_payload_size::Value - + sizeof(Rpc_opcode) }; }; + static constexpr unsigned + Value = Rpc_msg_payload_size::Value + + sizeof(Rpc_opcode); }; template struct Rpc_function_msg_size { - enum { Value = Rpc_msg_payload_size::Value - + Rpc_retval_size::Value - + sizeof(Rpc_exception_code) }; }; + static constexpr unsigned + Value = Rpc_msg_payload_size::Value + + Rpc_retval_size::Value + + sizeof(Rpc_exception_code); }; /** diff --git a/repos/base/include/base/rpc_client.h b/repos/base/include/base/rpc_client.h index 491a28f3d0..bd4319b6bf 100644 --- a/repos/base/include/base/rpc_client.h +++ b/repos/base/include/base/rpc_client.h @@ -49,16 +49,18 @@ namespace Genode { template struct Rpc_caps_out { - enum { Value = Cap_para_out::Value - + Rpc_caps_out::Value }; }; + static constexpr unsigned + Value = Cap_para_out::Value + + Rpc_caps_out::Value; }; template <> - struct Rpc_caps_out { enum { Value = 0 }; }; + struct Rpc_caps_out { static constexpr unsigned Value = 0; }; template struct Rpc_function_caps_out { - enum { Value = Rpc_caps_out::Value + - Cap_return ::Value}; }; + static constexpr unsigned + Value = Rpc_caps_out::Value + + Cap_return ::Value; }; /*************************************************** diff --git a/repos/base/include/base/rpc_server.h b/repos/base/include/base/rpc_server.h index 66998550eb..605c6b35e2 100644 --- a/repos/base/include/base/rpc_server.h +++ b/repos/base/include/base/rpc_server.h @@ -120,8 +120,9 @@ class Genode::Rpc_dispatcher : public RPC_INTERFACE _do_serve(typename RPC_FUNCTION::Server_args &args, Meta::Overload_selector) { - enum { EXCEPTION_CODE = Rpc_exception_code::EXCEPTION_BASE - - Meta::Length::Value }; + static constexpr unsigned + EXCEPTION_CODE = Rpc_exception_code::EXCEPTION_BASE + - Meta::Length::Value; try { typedef typename EXC_TL::Tail Exc_tail; return _do_serve(args, diff --git a/repos/base/include/cpu_session/cpu_session.h b/repos/base/include/cpu_session/cpu_session.h index 1af3b390a2..25474bc8ae 100644 --- a/repos/base/include/cpu_session/cpu_session.h +++ b/repos/base/include/cpu_session/cpu_session.h @@ -43,7 +43,8 @@ struct Genode::Cpu_session : Session * allocation, its session capability, the capability of the 'Native_cpu' * RPC interface, and a capability for the trace-control dataspace. */ - enum { CAP_QUOTA = 6, RAM_QUOTA = 36*1024 }; + static constexpr unsigned CAP_QUOTA = 6; + static constexpr size_t RAM_QUOTA = 36*1024; typedef Cpu_session_client Client; diff --git a/repos/base/include/io_mem_session/io_mem_session.h b/repos/base/include/io_mem_session/io_mem_session.h index bdb1e4a8a1..38530ca232 100644 --- a/repos/base/include/io_mem_session/io_mem_session.h +++ b/repos/base/include/io_mem_session/io_mem_session.h @@ -41,7 +41,8 @@ struct Genode::Io_mem_session : Session * session-object allocation, its session capability, and a dataspace * capability for the handed-out memory-mapped I/O dataspace. */ - enum { CAP_QUOTA = 3, RAM_QUOTA = 6*1024 }; + static constexpr unsigned CAP_QUOTA = 3; + static constexpr size_t RAM_QUOTA = 6*1024; virtual ~Io_mem_session() { } diff --git a/repos/base/include/io_port_session/io_port_session.h b/repos/base/include/io_port_session/io_port_session.h index b440d44803..7bae0f605f 100644 --- a/repos/base/include/io_port_session/io_port_session.h +++ b/repos/base/include/io_port_session/io_port_session.h @@ -38,7 +38,8 @@ struct Genode::Io_port_session : Session */ static const char *service_name() { return "IO_PORT"; } - enum { CAP_QUOTA = 2, RAM_QUOTA = 6*1024 }; + static constexpr unsigned CAP_QUOTA = 2; + static constexpr size_t RAM_QUOTA = 6*1024; virtual ~Io_port_session() { } diff --git a/repos/base/include/irq_session/irq_session.h b/repos/base/include/irq_session/irq_session.h index 900816e11f..e0160a4cc5 100644 --- a/repos/base/include/irq_session/irq_session.h +++ b/repos/base/include/irq_session/irq_session.h @@ -78,7 +78,8 @@ struct Genode::Irq_session : Session */ static const char * service_name() { return "IRQ"; } - enum { CAP_QUOTA = 3, RAM_QUOTA = 6*1024 }; + static constexpr unsigned CAP_QUOTA = 3; + static constexpr size_t RAM_QUOTA = 6*1024; /********************* diff --git a/repos/base/include/log_session/log_session.h b/repos/base/include/log_session/log_session.h index 4c029ac3a0..4fa773ed52 100644 --- a/repos/base/include/log_session/log_session.h +++ b/repos/base/include/log_session/log_session.h @@ -37,7 +37,8 @@ struct Genode::Log_session : Session * A LOG connection consumes a dataspace capability for the session-object * allocation and its session capability. */ - enum { CAP_QUOTA = 2, RAM_QUOTA = 8*1024 }; + static constexpr unsigned CAP_QUOTA = 2; + static constexpr size_t RAM_QUOTA = 8*1024; typedef Log_session_client Client; diff --git a/repos/base/include/pd_session/pd_session.h b/repos/base/include/pd_session/pd_session.h index ca42977660..f824b77d3a 100644 --- a/repos/base/include/pd_session/pd_session.h +++ b/repos/base/include/pd_session/pd_session.h @@ -46,7 +46,8 @@ struct Genode::Pd_session : Session, Ram_allocator * Furthermore, we account for the dataspace capabilities allocated during * the component bootstrapping. */ - enum { CAP_QUOTA = 6 + 7, RAM_QUOTA = 24*1024*sizeof(long) }; + static constexpr unsigned CAP_QUOTA = 6 + 7; + static constexpr size_t RAM_QUOTA = 24*1024*sizeof(long); typedef Pd_session_client Client; diff --git a/repos/base/include/rom_session/rom_session.h b/repos/base/include/rom_session/rom_session.h index d79efd3efc..f3db7c693e 100644 --- a/repos/base/include/rom_session/rom_session.h +++ b/repos/base/include/rom_session/rom_session.h @@ -46,7 +46,8 @@ struct Genode::Rom_session : Session * allocation, a dataspace capability for the ROM dataspace, and its * session capability. */ - enum { CAP_QUOTA = 3, RAM_QUOTA = 6*1024 }; + static constexpr unsigned CAP_QUOTA = 3; + static constexpr size_t RAM_QUOTA = 6*1024; typedef Rom_session_client Client;