File tree 3 files changed +33
-1
lines changed
3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -567,6 +567,9 @@ var WasiLibrary = {
567
567
568
568
// random.h
569
569
570
+ #if ENVIRONMENT_MAY_BE_SHELL
571
+ $initRandomFill__deps : [ '$base64Decode '] ,
572
+ #endif
570
573
$initRandomFill : ( ) => {
571
574
#if ENVIRONMENT_MAY_BE_NODE && MIN_NODE_VERSION < 190000
572
575
// This block is not needed on v19+ since crypto.getRandomValues is builtin
@@ -576,6 +579,18 @@ var WasiLibrary = {
576
579
}
577
580
#endif // ENVIRONMENT_MAY_BE_NODE
578
581
582
+ #if ENVIRONMENT_MAY_BE_SHELL
583
+ if ( ENVIRONMENT_IS_SHELL ) {
584
+ return ( view ) => {
585
+ if ( ! os . system ) {
586
+ throw new Error ( 'randomFill not supported on d8 unless -- enable - os - system is passed ') ;
587
+ }
588
+ const b64 = os . system ( 'sh' , [ '-c' , `head -c${ view . byteLength } /dev/urandom | base64 --wrap=0` ] ) ;
589
+ view . set ( base64Decode ( b64 ) ) ;
590
+ } ;
591
+ }
592
+ #endif
593
+
579
594
#if SHARED_MEMORY
580
595
// like with most Web APIs, we can't use Web Crypto API directly on shared memory,
581
596
// so we need to create an intermediate buffer and copy it to the destination
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ function calculateLibraries() {
78
78
libraries . push ( 'libmemoryprofiler.js' ) ;
79
79
}
80
80
81
- if ( SUPPORT_BASE64_EMBEDDING ) {
81
+ if ( SUPPORT_BASE64_EMBEDDING || ENVIRONMENT_MAY_BE_SHELL ) {
82
82
libraries . push ( 'libbase64.js' ) ;
83
83
}
84
84
Original file line number Diff line number Diff line change @@ -16016,3 +16016,20 @@ def test_locate_file_abspath_esm(self, args):
16016
16016
output_suffix='.mjs',
16017
16017
emcc_args=['--pre-js', 'pre.js',
16018
16018
'--extern-post-js', test_file('modularize_post_js.js')] + args)
16019
+ @requires_v8
16020
+ def test_getentropy_d8(self):
16021
+ create_file('main.c', '''
16022
+ #include "assert.h"
16023
+ #include <unistd.h>
16024
+
16025
+ int main() {
16026
+ char buf[100];
16027
+ assert(getentropy(buf, sizeof(buf)) == 0);
16028
+ return 0;
16029
+ }
16030
+ ''')
16031
+
16032
+ msg = 'randomFill not supported on d8 unless --enable-os-system is passed'
16033
+ self.do_runf('main.c', msg, assert_returncode=1)
16034
+ self.v8_args += ['--enable-os-system']
16035
+ self.do_runf('main.c')
You can’t perform that action at this time.
0 commit comments