2021-06-24 19:31:26 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
|
|
|
│ │
|
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2022-10-14 16:52:35 +00:00
|
|
|
#include "ape/sections.internal.h"
|
2022-11-06 02:49:41 +00:00
|
|
|
#include "libc/atomic.h"
|
|
|
|
#include "libc/calls/calls.h"
|
|
|
|
#include "libc/calls/struct/sigaction.h"
|
|
|
|
#include "libc/calls/struct/sigset.h"
|
2022-10-02 21:58:14 +00:00
|
|
|
#include "libc/errno.h"
|
2022-08-11 19:13:18 +00:00
|
|
|
#include "libc/intrin/bits.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
#include "libc/log/check.h"
|
2022-11-08 18:09:47 +00:00
|
|
|
#include "libc/macros.internal.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
#include "libc/math.h"
|
2022-11-06 02:49:41 +00:00
|
|
|
#include "libc/mem/gc.h"
|
|
|
|
#include "libc/mem/mem.h"
|
2021-07-06 02:10:06 +00:00
|
|
|
#include "libc/nexgen32e/x86feature.h"
|
2022-10-02 21:58:14 +00:00
|
|
|
#include "libc/runtime/runtime.h"
|
2022-08-11 19:26:30 +00:00
|
|
|
#include "libc/stdio/lcg.internal.h"
|
|
|
|
#include "libc/stdio/rand.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
#include "libc/stdio/stdio.h"
|
2022-11-06 02:49:41 +00:00
|
|
|
#include "libc/str/str.h"
|
|
|
|
#include "libc/str/tab.internal.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
#include "libc/sysv/consts/grnd.h"
|
2022-11-06 02:49:41 +00:00
|
|
|
#include "libc/sysv/consts/sig.h"
|
Make improvements to redbean
The following Lua APIs have been added:
- IsDaemon() → bool
- ProgramPidPath(str)
The following Lua hooks have been added:
- OnClientConnection(ip:int,port:int,serverip:int,serverport:int) → bool
- OnProcessCreate(pid:int,ip:int,port:int,serverip:int,serverport:int)
- OnProcessDestroy(pid:int)
- OnServerStart()
- OnServerStop()
- OnWorkerStart()
- OnWorkerStop()
redbean now does a better job at applying gzip on the fly from the local
filesystem, using a streaming chunked api with constant memory, which is
useful for doing things like serving a 4gb text file off NFS, and having
it start transmitting in milliseconds. redbean will also compute entropy
on the beginnings of files to determine if compression is profitable.
This change pays off technical debts relating to memory, such as relying
on exit() to free() allocations. That's now mostly fixed so it should be
easier now to spot memory leaks in malloc traces.
This change also fixes bugs and makes improvements to our SSL support.
Uniprocess mode failed handshakes are no longer an issue. Token Alpn is
offered so curl -v looks less weird. Hybrid SSL certificate loading is
now smarter about naming conflicts. Self-signed CA root anchors will no
longer be delivered to the client during the handshake.
2021-07-10 22:02:03 +00:00
|
|
|
#include "libc/testlib/ezbench.h"
|
|
|
|
#include "libc/testlib/hyperion.h"
|
2021-06-24 19:31:26 +00:00
|
|
|
#include "libc/testlib/testlib.h"
|
2022-11-06 02:49:41 +00:00
|
|
|
#include "libc/thread/thread.h"
|
2023-05-14 16:32:15 +00:00
|
|
|
#ifndef __aarch64__
|
|
|
|
// TODO(jart): Make this test less CPU intensive.
|
2022-11-06 02:49:41 +00:00
|
|
|
|
2022-11-08 18:09:47 +00:00
|
|
|
atomic_int done;
|
|
|
|
atomic_int ready;
|
|
|
|
pthread_t parent;
|
|
|
|
atomic_int gotsome;
|
|
|
|
|
|
|
|
void OnSig(int sig) {
|
|
|
|
++gotsome;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *TortureWorker(void *arg) {
|
|
|
|
sigset_t ss;
|
|
|
|
sigfillset(&ss);
|
|
|
|
ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &ss, 0));
|
|
|
|
ready = true;
|
|
|
|
while (!done) {
|
|
|
|
if (!IsWindows()) pthread_kill(parent, SIGUSR1);
|
|
|
|
usleep(1);
|
|
|
|
if (!IsWindows()) pthread_kill(parent, SIGUSR2);
|
|
|
|
usleep(1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-11-06 02:49:41 +00:00
|
|
|
TEST(getrandom, test) {
|
|
|
|
double e, w = 7.7;
|
|
|
|
int i, j, n = 999;
|
|
|
|
char *buf = _gc(calloc(1, n));
|
|
|
|
ASSERT_SYS(0, 0, getrandom(0, 0, 0));
|
|
|
|
ASSERT_SYS(0, n, getrandom(buf, n, 0));
|
|
|
|
ASSERT_SYS(EFAULT, -1, getrandom(0, n, 0));
|
|
|
|
ASSERT_SYS(EINVAL, -1, getrandom(buf, n, -1));
|
|
|
|
if ((e = MeasureEntropy(buf, n)) < w) {
|
|
|
|
fprintf(stderr, "error: entropy is suspect! got %g but want >=%g\n", e, w);
|
|
|
|
for (i = 0; i < n;) {
|
|
|
|
if (!(i % 16)) fprintf(stderr, "%6x ", i);
|
|
|
|
fprintf(stderr, "%lc", kCp437[buf[i] & 255]);
|
|
|
|
if (!(++i % 16)) fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2021-06-24 19:31:26 +00:00
|
|
|
|
2022-11-08 18:09:47 +00:00
|
|
|
TEST(getrandom, test2) {
|
|
|
|
pthread_t child;
|
|
|
|
double e, w = 7.7;
|
|
|
|
struct sigaction sa;
|
|
|
|
int i, j, k, m, n = 999;
|
|
|
|
char *buf = _gc(calloc(1, n));
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
sa.sa_handler = OnSig;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
ASSERT_SYS(0, 0, sigaction(SIGUSR1, &sa, 0));
|
|
|
|
ASSERT_SYS(0, 0, sigaction(SIGUSR2, &sa, 0));
|
|
|
|
parent = pthread_self();
|
|
|
|
ASSERT_EQ(0, pthread_create(&child, 0, TortureWorker, 0));
|
|
|
|
while (!ready) pthread_yield();
|
|
|
|
for (k = 0; k < 10; ++k) {
|
|
|
|
ASSERT_SYS(0, 0, getrandom(0, 0, 0));
|
|
|
|
for (i = 0; i < n; i += m) {
|
|
|
|
ASSERT_NE(-1, (m = getrandom(buf + i, n - i, 0)));
|
|
|
|
}
|
|
|
|
ASSERT_SYS(EFAULT, -1, getrandom(0, n, 0));
|
|
|
|
ASSERT_SYS(EINVAL, -1, getrandom(buf, n, -1));
|
|
|
|
if ((e = MeasureEntropy(buf, n)) < w) {
|
|
|
|
fprintf(stderr, "error: entropy suspect! got %g but want >=%g\n", e, w);
|
|
|
|
for (i = 0; i < n;) {
|
|
|
|
if (!(i % 16)) fprintf(stderr, "%6x ", i);
|
|
|
|
fprintf(stderr, "%lc", kCp437[buf[i] & 255]);
|
|
|
|
if (!(++i % 16)) fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
done = true;
|
|
|
|
pthread_join(child, 0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done = true;
|
|
|
|
ASSERT_EQ(0, pthread_join(child, 0));
|
|
|
|
if (!IsWindows()) ASSERT_GT(gotsome, 0);
|
|
|
|
}
|
|
|
|
|
2021-06-24 19:31:26 +00:00
|
|
|
/* JustReturnZero */
|
|
|
|
/* entropy: 0 */
|
|
|
|
/* chi-square: 2.55e+07 */
|
|
|
|
/* chi-square percent: 0 */
|
|
|
|
/* mean: 0 */
|
|
|
|
/* monte-carlo-pi: 27.324 */
|
|
|
|
/* serial-correlation: -100000 */
|
|
|
|
|
|
|
|
/* JustIncrement */
|
|
|
|
/* entropy: 2.63951 */
|
|
|
|
/* chi-square: 1.443e+07 */
|
|
|
|
/* chi-square percent: 0 */
|
|
|
|
/* mean: 18.8803 */
|
|
|
|
/* monte-carlo-pi: 27.324 */
|
|
|
|
/* serial-correlation: 0.0092003 */
|
|
|
|
|
|
|
|
/* UNIX Sixth Edition */
|
|
|
|
/* entropy: 8 */
|
|
|
|
/* chi-square: 0.1536 */
|
|
|
|
/* chi-square percent: 1 */
|
|
|
|
/* mean: 127.502 */
|
|
|
|
/* monte-carlo-pi: 3.4192 */
|
|
|
|
/* serial-correlation: -0.470645 */
|
|
|
|
|
|
|
|
/* UNIX Seventh Edition */
|
|
|
|
/* entropy: 7.99818 */
|
|
|
|
/* chi-square: 251.843 */
|
|
|
|
/* chi-square percent: 0.544128 */
|
|
|
|
/* mean: 127.955 */
|
|
|
|
/* monte-carlo-pi: 0.675703 */
|
|
|
|
/* serial-correlation: -0.00207669 */
|
|
|
|
|
|
|
|
/* KnuthLcg */
|
|
|
|
/* entropy: 7.99835 */
|
|
|
|
/* chi-square: 228.383 */
|
|
|
|
/* chi-square percent: 0.883476 */
|
|
|
|
/* mean: 127.1 */
|
|
|
|
/* monte-carlo-pi: 0.561935 */
|
|
|
|
/* serial-correlation: -0.0038954 */
|
|
|
|
|
|
|
|
/* rand64 */
|
|
|
|
/* entropy: 7.99832 */
|
|
|
|
/* chi-square: 233.267 */
|
|
|
|
/* chi-square percent: 0.831821 */
|
|
|
|
/* mean: 127.427 */
|
|
|
|
/* monte-carlo-pi: 0.0271532 */
|
|
|
|
/* serial-correlation: -0.00255319 */
|
|
|
|
|
|
|
|
/* Rand64LowByte */
|
|
|
|
/* entropy: 7.99798 */
|
|
|
|
/* chi-square: 278.344 */
|
|
|
|
/* chi-square percent: 0.150796 */
|
|
|
|
/* mean: 127.88 */
|
|
|
|
/* monte-carlo-pi: 0.00340573 */
|
|
|
|
/* serial-correlation: 0.00162231 */
|
|
|
|
|
|
|
|
/* GetRandomNoSystem */
|
|
|
|
/* entropy: 7.99819 */
|
|
|
|
/* chi-square: 249.743 */
|
|
|
|
/* chi-square percent: 0.58114 */
|
|
|
|
/* mean: 127.124 */
|
|
|
|
/* monte-carlo-pi: 0.293716 */
|
|
|
|
/* serial-correlation: 0.00198516 */
|
|
|
|
|
|
|
|
/* GetRandomNoRdrrnd */
|
|
|
|
/* entropy: 7.99816 */
|
|
|
|
/* chi-square: 254.797 */
|
|
|
|
/* chi-square percent: 0.491811 */
|
|
|
|
/* mean: 127.308 */
|
|
|
|
/* monte-carlo-pi: 0.0118738 */
|
|
|
|
/* serial-correlation: 0.000197669 */
|
|
|
|
|
|
|
|
/* GetRandom */
|
|
|
|
/* entropy: 7.99808 */
|
|
|
|
/* chi-square: 266.737 */
|
|
|
|
/* chi-square percent: 0.294131 */
|
|
|
|
/* mean: 127.178 */
|
|
|
|
/* monte-carlo-pi: 0.0577122 */
|
|
|
|
/* serial-correlation: 0.00598793 */
|
|
|
|
|
|
|
|
typedef uint64_t (*random_f)(void);
|
|
|
|
|
|
|
|
static uint32_t randx = 1;
|
|
|
|
|
|
|
|
uint64_t JustReturnZero(void) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t JustIncrement(void) {
|
|
|
|
static uint64_t x;
|
|
|
|
return x++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t SixthEditionRand(void) {
|
|
|
|
static int16_t gorp;
|
|
|
|
gorp = (gorp + 625) & 077777;
|
|
|
|
return gorp;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SixthEditionLowByte(void) {
|
|
|
|
unsigned i;
|
|
|
|
uint64_t x;
|
|
|
|
for (x = i = 0; i < 8; ++i) {
|
|
|
|
x <<= 8;
|
|
|
|
x |= SixthEditionRand() & 255;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
Make improvements to redbean
The following Lua APIs have been added:
- IsDaemon() → bool
- ProgramPidPath(str)
The following Lua hooks have been added:
- OnClientConnection(ip:int,port:int,serverip:int,serverport:int) → bool
- OnProcessCreate(pid:int,ip:int,port:int,serverip:int,serverport:int)
- OnProcessDestroy(pid:int)
- OnServerStart()
- OnServerStop()
- OnWorkerStart()
- OnWorkerStop()
redbean now does a better job at applying gzip on the fly from the local
filesystem, using a streaming chunked api with constant memory, which is
useful for doing things like serving a 4gb text file off NFS, and having
it start transmitting in milliseconds. redbean will also compute entropy
on the beginnings of files to determine if compression is profitable.
This change pays off technical debts relating to memory, such as relying
on exit() to free() allocations. That's now mostly fixed so it should be
easier now to spot memory leaks in malloc traces.
This change also fixes bugs and makes improvements to our SSL support.
Uniprocess mode failed handshakes are no longer an issue. Token Alpn is
offered so curl -v looks less weird. Hybrid SSL certificate loading is
now smarter about naming conflicts. Self-signed CA root anchors will no
longer be delivered to the client during the handshake.
2021-07-10 22:02:03 +00:00
|
|
|
uint64_t MobyDick(void) {
|
|
|
|
static int i;
|
|
|
|
if ((i += 8) > kMobySize) i = 8;
|
|
|
|
return READ64LE(kMoby + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ExecutableImage(void) {
|
|
|
|
static int i;
|
2023-05-19 02:05:08 +00:00
|
|
|
if ((i += 8) > _end - __executable_start) i = 8;
|
|
|
|
return READ64LE(__executable_start + i);
|
Make improvements to redbean
The following Lua APIs have been added:
- IsDaemon() → bool
- ProgramPidPath(str)
The following Lua hooks have been added:
- OnClientConnection(ip:int,port:int,serverip:int,serverport:int) → bool
- OnProcessCreate(pid:int,ip:int,port:int,serverip:int,serverport:int)
- OnProcessDestroy(pid:int)
- OnServerStart()
- OnServerStop()
- OnWorkerStart()
- OnWorkerStop()
redbean now does a better job at applying gzip on the fly from the local
filesystem, using a streaming chunked api with constant memory, which is
useful for doing things like serving a 4gb text file off NFS, and having
it start transmitting in milliseconds. redbean will also compute entropy
on the beginnings of files to determine if compression is profitable.
This change pays off technical debts relating to memory, such as relying
on exit() to free() allocations. That's now mostly fixed so it should be
easier now to spot memory leaks in malloc traces.
This change also fixes bugs and makes improvements to our SSL support.
Uniprocess mode failed handshakes are no longer an issue. Token Alpn is
offered so curl -v looks less weird. Hybrid SSL certificate loading is
now smarter about naming conflicts. Self-signed CA root anchors will no
longer be delivered to the client during the handshake.
2021-07-10 22:02:03 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 19:31:26 +00:00
|
|
|
uint32_t SeventhEditionRand(void) {
|
|
|
|
return ((randx = randx * 1103515245 + 12345) >> 16) & 077777;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SeventhEditionLowByte(void) {
|
|
|
|
unsigned i;
|
|
|
|
uint64_t x;
|
|
|
|
for (x = i = 0; i < 8; ++i) {
|
|
|
|
x <<= 8;
|
|
|
|
x |= SeventhEditionRand() & 255;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t KnuthLcg(void) {
|
|
|
|
unsigned i;
|
|
|
|
uint64_t x;
|
|
|
|
for (x = i = 0; i < 8; ++i) {
|
|
|
|
x <<= 8;
|
|
|
|
x |= rand() & 255;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Rand64LowByte(void) {
|
|
|
|
unsigned i;
|
|
|
|
uint64_t x;
|
|
|
|
for (x = i = 0; i < 8; ++i) {
|
|
|
|
x <<= 8;
|
2022-10-10 11:12:06 +00:00
|
|
|
x |= _rand64() & 255;
|
2021-06-24 19:31:26 +00:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t GetRandom(void) {
|
|
|
|
uint64_t x;
|
|
|
|
ASSERT_EQ(8, getrandom(&x, 8, 0));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct RandomFunction {
|
|
|
|
const char *s;
|
|
|
|
random_f f;
|
|
|
|
bool r;
|
|
|
|
} kRandomFunctions[] = {
|
|
|
|
{"JustReturnZero", JustReturnZero, false}, //
|
|
|
|
{"JustIncrement", JustIncrement, false}, //
|
Make improvements to redbean
The following Lua APIs have been added:
- IsDaemon() → bool
- ProgramPidPath(str)
The following Lua hooks have been added:
- OnClientConnection(ip:int,port:int,serverip:int,serverport:int) → bool
- OnProcessCreate(pid:int,ip:int,port:int,serverip:int,serverport:int)
- OnProcessDestroy(pid:int)
- OnServerStart()
- OnServerStop()
- OnWorkerStart()
- OnWorkerStop()
redbean now does a better job at applying gzip on the fly from the local
filesystem, using a streaming chunked api with constant memory, which is
useful for doing things like serving a 4gb text file off NFS, and having
it start transmitting in milliseconds. redbean will also compute entropy
on the beginnings of files to determine if compression is profitable.
This change pays off technical debts relating to memory, such as relying
on exit() to free() allocations. That's now mostly fixed so it should be
easier now to spot memory leaks in malloc traces.
This change also fixes bugs and makes improvements to our SSL support.
Uniprocess mode failed handshakes are no longer an issue. Token Alpn is
offered so curl -v looks less weird. Hybrid SSL certificate loading is
now smarter about naming conflicts. Self-signed CA root anchors will no
longer be delivered to the client during the handshake.
2021-07-10 22:02:03 +00:00
|
|
|
{"MobyDick", MobyDick, false}, //
|
|
|
|
{"ExecutableImage", ExecutableImage, false}, //
|
2021-06-24 19:31:26 +00:00
|
|
|
{"SixthEditionLowByte", SixthEditionLowByte, false}, //
|
|
|
|
{"SeventhEditionLowByte", SeventhEditionLowByte, false}, //
|
|
|
|
{"KnuthLcg", KnuthLcg, false}, //
|
2022-10-10 11:12:06 +00:00
|
|
|
{"rand64", _rand64, true}, //
|
2021-06-24 19:31:26 +00:00
|
|
|
{"Rand64LowByte", Rand64LowByte, true}, //
|
|
|
|
{"GetRandom", GetRandom, true}, //
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(getrandom, sanityTest) {
|
|
|
|
uint64_t q;
|
|
|
|
size_t i, j, k;
|
Make improvements to redbean
The following Lua APIs have been added:
- IsDaemon() → bool
- ProgramPidPath(str)
The following Lua hooks have been added:
- OnClientConnection(ip:int,port:int,serverip:int,serverport:int) → bool
- OnProcessCreate(pid:int,ip:int,port:int,serverip:int,serverport:int)
- OnProcessDestroy(pid:int)
- OnServerStart()
- OnServerStop()
- OnWorkerStart()
- OnWorkerStop()
redbean now does a better job at applying gzip on the fly from the local
filesystem, using a streaming chunked api with constant memory, which is
useful for doing things like serving a 4gb text file off NFS, and having
it start transmitting in milliseconds. redbean will also compute entropy
on the beginnings of files to determine if compression is profitable.
This change pays off technical debts relating to memory, such as relying
on exit() to free() allocations. That's now mostly fixed so it should be
easier now to spot memory leaks in malloc traces.
This change also fixes bugs and makes improvements to our SSL support.
Uniprocess mode failed handshakes are no longer an issue. Token Alpn is
offered so curl -v looks less weird. Hybrid SSL certificate loading is
now smarter about naming conflicts. Self-signed CA root anchors will no
longer be delivered to the client during the handshake.
2021-07-10 22:02:03 +00:00
|
|
|
double montepi, chip, scc, mean, chisq, ent;
|
2021-06-24 19:31:26 +00:00
|
|
|
for (k = 0; k < 1; ++k) {
|
|
|
|
for (j = 0; j < ARRAYLEN(kRandomFunctions); ++j) {
|
|
|
|
rt_init(0);
|
|
|
|
for (i = 0; i + 8 <= 100000; i += 8) {
|
|
|
|
q = kRandomFunctions[j].f();
|
|
|
|
rt_add(&q, 8);
|
|
|
|
}
|
|
|
|
rt_end(&ent, &chisq, &mean, &montepi, &scc);
|
|
|
|
chip = pochisq(chisq, 255);
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "/* %-32s */\n", kRandomFunctions[j].s);
|
|
|
|
fprintf(stderr, "/* entropy: %-12g */\n", ent);
|
|
|
|
fprintf(stderr, "/* chi-square: %-12g */\n", chisq);
|
|
|
|
fprintf(stderr, "/* chi-square percent: %-12g */\n", chip);
|
|
|
|
fprintf(stderr, "/* mean: %-12g */\n", mean);
|
|
|
|
fprintf(stderr, "/* monte-carlo-pi: %-12g */\n",
|
|
|
|
100 * fabs(M_PI - montepi) / M_PI);
|
|
|
|
fprintf(stderr, "/* serial-correlation: %-12g */\n", scc);
|
|
|
|
#endif
|
|
|
|
if (kRandomFunctions[j].r) {
|
Improve ZIP filesystem and change its prefix
The ZIP filesystem has a breaking change. You now need to use /zip/ to
open() / opendir() / etc. assets within the ZIP structure of your APE
binary, instead of the previous convention of using zip: or zip! URIs.
This is needed because Python likes to use absolute paths, and having
ZIP paths encoded like URIs simply broke too many things.
Many more system calls have been updated to be able to operate on ZIP
files and file descriptors. In particular fcntl() and ioctl() since
Python would do things like ask if a ZIP file is a terminal and get
confused when the old implementation mistakenly said yes, because the
fastest way to guarantee native file descriptors is to dup(2). This
change also improves the async signal safety of zipos and ensures it
doesn't maintain any open file descriptors beyond that which the user
has opened.
This change makes a lot of progress towards adding magic numbers that
are specific to platforms other than Linux. The philosophy here is that,
if you use an operating system like FreeBSD, then you should be able to
take advantage of FreeBSD exclusive features, even if we don't polyfill
them on other platforms. For example, you can now open() a file with the
O_VERIFY flag. If your program runs on other platforms, then Cosmo will
automatically set O_VERIFY to zero. This lets you safely use it without
the need for #ifdef or ifstatements which detract from readability.
One of the blindspots of the ASAN memory hardening we use to offer Rust
like assurances has always been that memory passed to the kernel via
system calls (e.g. writev) can't be checked automatically since the
kernel wasn't built with MODE=asan. This change makes more progress
ensuring that each system call will verify the soundness of memory
before it's passed to the kernel. The code for doing these checks is
fast, particularly for buffers, where it can verify 64 bytes a cycle.
- Correct O_LOOP definition on NT
- Introduce program_executable_name
- Add ASAN guards to more system calls
- Improve termios compatibility with BSDs
- Fix bug in Windows auxiliary value encoding
- Add BSD and XNU specific errnos and open flags
- Add check to ensure build doesn't talk to internet
2021-08-22 08:04:18 +00:00
|
|
|
CHECK_GT(chisq, 100, "%s", kRandomFunctions[j].s);
|
|
|
|
CHECK_LT(chisq, 400, "%s", kRandomFunctions[j].s);
|
2021-06-24 19:31:26 +00:00
|
|
|
CHECK_GE(ent * 10, 78, "%s", kRandomFunctions[j].s);
|
|
|
|
CHECK_LT(fabs(scc) * 100, 5, "%s", kRandomFunctions[j].s);
|
|
|
|
CHECK_LT(fabs(128 - mean), 3, "%s", kRandomFunctions[j].s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-02 21:58:14 +00:00
|
|
|
|
|
|
|
TEST(getrandom, badflags_einval) {
|
|
|
|
ASSERT_SYS(EINVAL, -1, getrandom(0, 0, -1));
|
|
|
|
}
|
2023-05-14 16:32:15 +00:00
|
|
|
|
|
|
|
#endif /* __aarch64__ */
|