diff --git a/repos/dde_rump/src/server/rump_cgd/random.cc b/repos/dde_rump/src/server/rump_cgd/random.cc
index 7ee4b23d9..e850ffa70 100644
--- a/repos/dde_rump/src/server/rump_cgd/random.cc
+++ b/repos/dde_rump/src/server/rump_cgd/random.cc
@@ -1,24 +1,26 @@
/**
* \brief Add random support for CGD
* \author Sebastian Sumpf
+ * \author Josef Soentgen
* \date 2015-02-13
*/
/*
- * Copyright (C) 2015 Genode Labs GmbH
+ * Copyright (C) 2015-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
+/* Genode includes */
#include
+
+/* local rump includes */
+#include
#include
-extern "C" {
- namespace Jitter {
- #include
- }
-}
+/* library includes */
+#include
typedef Genode::size_t size_t;
@@ -29,24 +31,31 @@ typedef Genode::size_t size_t;
struct Entropy
{
- struct Jitter::rand_data *ec_stir;
+ struct rand_data *ec_stir;
- Entropy()
- {
- Jitter::jent_entropy_init();
- ec_stir = Jitter::jent_entropy_collector_alloc(0, 0);
- }
+ struct Initialization_failed : Genode::Exception { };
- static Entropy *e()
+ Entropy(Genode::Allocator &alloc)
{
- static Entropy _e;
- return &_e;
+ jitterentropy_init(alloc);
+
+ int err = jent_entropy_init();
+ if (err) {
+ Genode::error("could not initialize jitterentropy library");
+ throw Initialization_failed();
+ }
+
+ ec_stir = jent_entropy_collector_alloc(0, 0);
+ if (ec_stir == nullptr) {
+ Genode::error("could not initialize jitterentropy library");
+ throw Initialization_failed();
+ }
}
size_t read(char *buf, size_t len)
{
int err;
- if ((err = Jitter::jent_read_entropy(ec_stir, buf, len) < 0)) {
+ if ((err = jent_read_entropy(ec_stir, buf, len) < 0)) {
Genode::error("failed to read entropy: ", err);
return 0;
}
@@ -56,8 +65,25 @@ struct Entropy
};
+static Genode::Constructible _entropy;
+static bool _init_failed;
+
+
int rumpuser_getrandom_backend(void *buf, size_t buflen, int flags, Genode::size_t *retp)
{
- *retp = Entropy::e()->read((char *)buf, buflen);
+ if (!_entropy.constructed()) {
+ if (_init_failed) {
+ *retp = 0;
+ return -1;
+ }
+
+ try { _entropy.construct(Rump::env().heap()); }
+ catch (Entropy::Initialization_failed) {
+ _init_failed = true;
+ return -1;
+ }
+ }
+
+ *retp = _entropy->read((char *)buf, buflen);
return 0;
}
diff --git a/repos/libports/ports/jitterentropy.hash b/repos/libports/ports/jitterentropy.hash
index 4ad8020d1..69ed87738 100644
--- a/repos/libports/ports/jitterentropy.hash
+++ b/repos/libports/ports/jitterentropy.hash
@@ -1 +1 @@
-0105c3c8c4b39c25aa0ecb7cd1ba6894571f37f0
+518a548281860815460342cf0e4afec305c07eee
diff --git a/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc
index 9c1300c5c..93712af7b 100644
--- a/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc
+++ b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.cc
@@ -5,28 +5,40 @@
*/
/*
- * Copyright (C) 2014 Genode Labs GmbH
+ * Copyright (C) 2014-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
-#include
+#include
+#include
/* local includes */
#include
+static Genode::Allocator *_alloc;
+
+
+void jitterentropy_init(Genode::Allocator &alloc)
+{
+ _alloc = &alloc;
+}
+
+
void *jent_zalloc(size_t len)
{
- return Genode::env()->heap()->alloc(len);
+ if (!_alloc) { return 0; }
+ return _alloc->alloc(len);
}
void jent_zfree(void *ptr, unsigned int len)
{
- Genode::env()->heap()->free(ptr, len);
+ if (!_alloc) { return; }
+ _alloc->free(ptr, 0);
}
diff --git a/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h
index 2abc7d90b..d983b9b3c 100644
--- a/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h
+++ b/repos/libports/src/lib/jitterentropy/jitterentropy-base-genode.h
@@ -5,7 +5,7 @@
*/
/*
- * Copyright (C) 2014 Genode Labs GmbH
+ * Copyright (C) 2014-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
@@ -17,7 +17,7 @@
/* needed type definitions */
#include
-typedef __SIZE_TYPE__ size_t;
+typedef unsigned long size_t;
typedef signed long ssize_t;
typedef genode_uint32_t uint32_t;
typedef genode_uint64_t uint64_t;
@@ -30,6 +30,12 @@ typedef genode_int64_t __s64;
#endif
#ifdef __cplusplus
+
+#include
+
+/* Genode specific function to set the backend allocator */
+void jitterentropy_init(Genode::Allocator &alloc);
+
extern "C" {
#endif
diff --git a/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch b/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch
index 1d97dabe8..dc718fd78 100644
--- a/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch
+++ b/repos/libports/src/lib/jitterentropy/jitterentropy_h.patch
@@ -1,6 +1,6 @@
---- a/jitterentropy.h 2014-04-07 21:07:13.000000000 +0200
-+++ b/jitterentropy.h 2014-08-18 14:42:32.609235231 +0200
-@@ -42,11 +42,15 @@
+--- a/jitterentropy.h.orig
++++ b/jitterentropy.h
+@@ -42,11 +42,19 @@
#ifndef _JITTERENTROPY_H
#define _JITTERENTROPY_H
@@ -12,7 +12,20 @@
#else
#include "jitterentropy-base-user.h"
#endif /* __KERNEL__ */
++#endif
++
++#ifdef __cplusplus
++extern "C" {
+#endif
/* Statistical data from the entropy source */
struct entropy_stat {
+@@ -171,4 +179,8 @@
+
+ /* -- END of statistical test function -- */
+
++#ifdef __cplusplus
++}
++#endif /* extern "C" */
++
+ #endif /* _JITTERENTROPY_H */
diff --git a/repos/libports/src/lib/vfs/jitterentropy/vfs.cc b/repos/libports/src/lib/vfs/jitterentropy/vfs.cc
index d2695736f..8e5a8098d 100644
--- a/repos/libports/src/lib/vfs/jitterentropy/vfs.cc
+++ b/repos/libports/src/lib/vfs/jitterentropy/vfs.cc
@@ -24,7 +24,7 @@ struct Jitterentropy_factory : Vfs::File_system_factory
Genode::Xml_node node,
Vfs::Io_response_handler &) override
{
- return new (alloc) Jitterentropy_file_system(node);
+ return new (alloc) Jitterentropy_file_system(alloc, node);
}
};
diff --git a/repos/libports/src/lib/vfs/jitterentropy/vfs_jitterentropy.h b/repos/libports/src/lib/vfs/jitterentropy/vfs_jitterentropy.h
index 1e77a2deb..dc4d42f2e 100644
--- a/repos/libports/src/lib/vfs/jitterentropy/vfs_jitterentropy.h
+++ b/repos/libports/src/lib/vfs/jitterentropy/vfs_jitterentropy.h
@@ -19,9 +19,7 @@
#include
/* jitterentropy includes */
-extern "C" {
#include
-}
class Jitterentropy_file_system : public Vfs::Single_file_system
{
@@ -30,8 +28,11 @@ class Jitterentropy_file_system : public Vfs::Single_file_system
struct rand_data *_ec_stir;
bool _initialized;
- bool _init_jitterentropy()
+ bool _init_jitterentropy(Genode::Allocator &alloc)
{
+ /* initialize private allocator backend */
+ jitterentropy_init(alloc);
+
int err = jent_entropy_init();
if (err) {
Genode::error("jitterentropy library could not be initialized!");
@@ -50,11 +51,12 @@ class Jitterentropy_file_system : public Vfs::Single_file_system
public:
- Jitterentropy_file_system(Genode::Xml_node config)
+ Jitterentropy_file_system(Genode::Allocator &alloc,
+ Genode::Xml_node config)
:
Single_file_system(NODE_TYPE_CHAR_DEVICE, name(), config),
_ec_stir(0),
- _initialized(_init_jitterentropy())
+ _initialized(_init_jitterentropy(alloc))
{ }
~Jitterentropy_file_system()