mirror of https://github.com/google/oss-fuzz.git
[njs] Fix the build failure and extend the seed corpus. (#2648)
This commit is contained in:
parent
0073eebe04
commit
c58e524b8d
|
@ -31,24 +31,26 @@ make njs
|
|||
|
||||
# build fuzzers
|
||||
# e.g.
|
||||
$CC $CFLAGS -Inxt -Ibuild -Injs -c \
|
||||
$CC $CFLAGS -Inxt -Ibuild -Isrc -c \
|
||||
$SRC/njs_process_script_fuzzer.c -o build/njs_process_script_fuzzer.o
|
||||
|
||||
$CXX $CXXFLAGS build/njs_process_script_fuzzer.o \
|
||||
-o $OUT/njs_process_script_fuzzer \
|
||||
$LIB_FUZZING_ENGINE build/libnxt.a build/libnjs.a \
|
||||
$LIB_FUZZING_ENGINE build/libnjs.a \
|
||||
$SRC/pcre/.libs/libpcre.a -lm -lreadline
|
||||
|
||||
SEED_CORPUS_PATH=$OUT/njs_process_script_fuzzer_seed_corpus
|
||||
mkdir -p $SEED_CORPUS_PATH
|
||||
|
||||
set +x
|
||||
cat njs/test/njs_interactive_test.c njs/test/njs_unit_test.c \
|
||||
cat src/test/njs_interactive_test.c src/test/njs_unit_test.c \
|
||||
| egrep -o '".*"' | awk '{print substr($0,2,length($0)-2)}' | sort | uniq \
|
||||
| while IFS= read -r line; do
|
||||
echo $line > $SEED_CORPUS_PATH/$(echo $line | sha1sum | awk '{ print $1 }');
|
||||
done
|
||||
set -x
|
||||
|
||||
cp -r test/fs test/module $SEED_CORPUS_PATH
|
||||
|
||||
zip -q $SEED_CORPUS_PATH.zip $SEED_CORPUS_PATH
|
||||
rm -rf $SEED_CORPUS_PATH
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <njs_core.h>
|
||||
#include <njs_main.h>
|
||||
#include <njs_value.h>
|
||||
|
||||
#include <njs_builtin.h>
|
||||
|
||||
// The vast majority of the code was copied from njs/njs_shell.c.
|
||||
|
@ -38,9 +40,9 @@ typedef struct {
|
|||
typedef struct {
|
||||
size_t index;
|
||||
size_t length;
|
||||
nxt_array_t *completions;
|
||||
nxt_array_t *suffix_completions;
|
||||
nxt_lvlhsh_each_t lhe;
|
||||
njs_array_t *completions;
|
||||
njs_array_t *suffix_completions;
|
||||
njs_lvlhsh_each_t lhe;
|
||||
|
||||
enum {
|
||||
NJS_COMPLETION_VAR = 0,
|
||||
|
@ -52,15 +54,15 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
njs_vm_event_t vm_event;
|
||||
nxt_queue_link_t link;
|
||||
njs_queue_link_t link;
|
||||
} njs_ev_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
njs_vm_t *vm;
|
||||
|
||||
nxt_lvlhsh_t events; /* njs_ev_t * */
|
||||
nxt_queue_t posted_events;
|
||||
njs_lvlhsh_t events; /* njs_ev_t * */
|
||||
njs_queue_t posted_events;
|
||||
|
||||
uint64_t time;
|
||||
|
||||
|
@ -68,38 +70,38 @@ typedef struct {
|
|||
} njs_console_t;
|
||||
|
||||
|
||||
static nxt_int_t njs_console_init(njs_vm_t *vm, njs_console_t *console);
|
||||
static nxt_int_t njs_externals_init(njs_vm_t *vm, njs_console_t *console);
|
||||
static nxt_int_t njs_interactive_shell(njs_opts_t *opts,
|
||||
njs_vm_opt_t *vm_options, nxt_str_t *line);
|
||||
static njs_int_t njs_console_init(njs_vm_t *vm, njs_console_t *console);
|
||||
static njs_int_t njs_externals_init(njs_vm_t *vm, njs_console_t *console);
|
||||
static njs_int_t njs_interactive_shell(njs_opts_t *opts,
|
||||
njs_vm_opt_t *vm_options, njs_str_t *line);
|
||||
static njs_vm_t *njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options);
|
||||
static nxt_int_t njs_process_script(njs_console_t *console, njs_opts_t *opts,
|
||||
const nxt_str_t *script);
|
||||
static njs_int_t njs_process_script(njs_console_t *console, njs_opts_t *opts,
|
||||
const njs_str_t *script);
|
||||
|
||||
static njs_ret_t njs_ext_console_log(njs_vm_t *vm, njs_value_t *args,
|
||||
nxt_uint_t nargs, njs_index_t unused);
|
||||
static njs_ret_t njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args,
|
||||
nxt_uint_t nargs, njs_index_t unused);
|
||||
static njs_ret_t njs_ext_console_help(njs_vm_t *vm, njs_value_t *args,
|
||||
nxt_uint_t nargs, njs_index_t unused);
|
||||
static njs_ret_t njs_ext_console_time(njs_vm_t *vm, njs_value_t *args,
|
||||
nxt_uint_t nargs, njs_index_t unused);
|
||||
static njs_ret_t njs_ext_console_time_end(njs_vm_t *vm, njs_value_t *args,
|
||||
nxt_uint_t nargs, njs_index_t unused);
|
||||
static njs_int_t njs_ext_console_log(njs_vm_t *vm, njs_value_t *args,
|
||||
njs_uint_t nargs, njs_index_t unused);
|
||||
static njs_int_t njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args,
|
||||
njs_uint_t nargs, njs_index_t unused);
|
||||
static njs_int_t njs_ext_console_help(njs_vm_t *vm, njs_value_t *args,
|
||||
njs_uint_t nargs, njs_index_t unused);
|
||||
static njs_int_t njs_ext_console_time(njs_vm_t *vm, njs_value_t *args,
|
||||
njs_uint_t nargs, njs_index_t unused);
|
||||
static njs_int_t njs_ext_console_time_end(njs_vm_t *vm, njs_value_t *args,
|
||||
njs_uint_t nargs, njs_index_t unused);
|
||||
|
||||
static njs_host_event_t njs_console_set_timer(njs_external_ptr_t external,
|
||||
uint64_t delay, njs_vm_event_t vm_event);
|
||||
static void njs_console_clear_timer(njs_external_ptr_t external,
|
||||
njs_host_event_t event);
|
||||
|
||||
static nxt_int_t lvlhsh_key_test(nxt_lvlhsh_query_t *lhq, void *data);
|
||||
static void *lvlhsh_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc);
|
||||
static njs_int_t lvlhsh_key_test(njs_lvlhsh_query_t *lhq, void *data);
|
||||
static void *lvlhsh_pool_alloc(void *pool, size_t size, njs_uint_t nalloc);
|
||||
static void lvlhsh_pool_free(void *pool, void *p, size_t size);
|
||||
|
||||
|
||||
static njs_external_t njs_ext_console[] = {
|
||||
|
||||
{ nxt_string("log"),
|
||||
{ njs_str("log"),
|
||||
NJS_EXTERN_METHOD,
|
||||
NULL,
|
||||
0,
|
||||
|
@ -111,7 +113,7 @@ static njs_external_t njs_ext_console[] = {
|
|||
njs_ext_console_log,
|
||||
0 },
|
||||
|
||||
{ nxt_string("dump"),
|
||||
{ njs_str("dump"),
|
||||
NJS_EXTERN_METHOD,
|
||||
NULL,
|
||||
0,
|
||||
|
@ -123,7 +125,7 @@ static njs_external_t njs_ext_console[] = {
|
|||
njs_ext_console_dump,
|
||||
0 },
|
||||
|
||||
{ nxt_string("help"),
|
||||
{ njs_str("help"),
|
||||
NJS_EXTERN_METHOD,
|
||||
NULL,
|
||||
0,
|
||||
|
@ -135,7 +137,7 @@ static njs_external_t njs_ext_console[] = {
|
|||
njs_ext_console_help,
|
||||
0 },
|
||||
|
||||
{ nxt_string("time"),
|
||||
{ njs_str("time"),
|
||||
NJS_EXTERN_METHOD,
|
||||
NULL,
|
||||
0,
|
||||
|
@ -147,7 +149,7 @@ static njs_external_t njs_ext_console[] = {
|
|||
njs_ext_console_time,
|
||||
0 },
|
||||
|
||||
{ nxt_string("timeEnd"),
|
||||
{ njs_str("timeEnd"),
|
||||
NJS_EXTERN_METHOD,
|
||||
NULL,
|
||||
0,
|
||||
|
@ -162,10 +164,10 @@ static njs_external_t njs_ext_console[] = {
|
|||
|
||||
static njs_external_t njs_externals[] = {
|
||||
|
||||
{ nxt_string("console"),
|
||||
{ njs_str("console"),
|
||||
NJS_EXTERN_OBJECT,
|
||||
njs_ext_console,
|
||||
nxt_nitems(njs_ext_console),
|
||||
njs_nitems(njs_ext_console),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
@ -176,8 +178,8 @@ static njs_external_t njs_externals[] = {
|
|||
};
|
||||
|
||||
|
||||
static const nxt_lvlhsh_proto_t lvlhsh_proto nxt_aligned(64) = {
|
||||
NXT_LVLHSH_LARGE_SLAB,
|
||||
static const njs_lvlhsh_proto_t lvlhsh_proto njs_aligned(64) = {
|
||||
NJS_LVLHSH_LARGE_SLAB,
|
||||
0,
|
||||
lvlhsh_key_test,
|
||||
lvlhsh_pool_alloc,
|
||||
|
@ -194,78 +196,78 @@ static njs_vm_ops_t njs_console_ops = {
|
|||
static njs_console_t njs_console;
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
static njs_int_t
|
||||
njs_console_init(njs_vm_t *vm, njs_console_t *console)
|
||||
{
|
||||
console->vm = vm;
|
||||
|
||||
nxt_lvlhsh_init(&console->events);
|
||||
nxt_queue_init(&console->posted_events);
|
||||
njs_lvlhsh_init(&console->events);
|
||||
njs_queue_init(&console->posted_events);
|
||||
|
||||
console->time = UINT64_MAX;
|
||||
|
||||
console->completion.completions = njs_vm_completions(vm, NULL);
|
||||
if (console->completion.completions == NULL) {
|
||||
return NXT_ERROR;
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
return NXT_OK;
|
||||
return NJS_OK;
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
static njs_int_t
|
||||
njs_externals_init(njs_vm_t *vm, njs_console_t *console)
|
||||
{
|
||||
nxt_uint_t ret;
|
||||
njs_uint_t ret;
|
||||
njs_value_t *value;
|
||||
const njs_extern_t *proto;
|
||||
|
||||
static const nxt_str_t name = nxt_string("console");
|
||||
static const njs_str_t name = njs_str("console");
|
||||
|
||||
proto = njs_vm_external_prototype(vm, &njs_externals[0]);
|
||||
if (proto == NULL) {
|
||||
nxt_error("failed to add console proto\n");
|
||||
return NXT_ERROR;
|
||||
njs_stderror("failed to add console proto\n");
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
value = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_opaque_value_t));
|
||||
value = njs_mp_zalloc(vm->mem_pool, sizeof(njs_opaque_value_t));
|
||||
if (value == NULL) {
|
||||
return NXT_ERROR;
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
ret = njs_vm_external_create(vm, value, proto, console);
|
||||
if (ret != NXT_OK) {
|
||||
return NXT_ERROR;
|
||||
if (ret != NJS_OK) {
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
ret = njs_vm_external_bind(vm, &name, value);
|
||||
if (ret != NXT_OK) {
|
||||
return NXT_ERROR;
|
||||
if (ret != NJS_OK) {
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
ret = njs_console_init(vm, console);
|
||||
if (ret != NXT_OK) {
|
||||
return NXT_ERROR;
|
||||
if (ret != NJS_OK) {
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
return NXT_OK;
|
||||
return NJS_OK;
|
||||
}
|
||||
|
||||
static nxt_int_t
|
||||
njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options, nxt_str_t *line)
|
||||
static njs_int_t
|
||||
njs_interactive_shell(njs_opts_t *opts, njs_vm_opt_t *vm_options, njs_str_t *line)
|
||||
{
|
||||
njs_vm_t *vm;
|
||||
|
||||
vm = njs_create_vm(opts, vm_options);
|
||||
if (vm == NULL) {
|
||||
return NXT_ERROR;
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
njs_process_script(vm_options->external, opts, line);
|
||||
njs_vm_destroy(vm);
|
||||
vm = NULL;
|
||||
|
||||
return NXT_OK;
|
||||
return NJS_OK;
|
||||
}
|
||||
|
||||
static njs_vm_t *
|
||||
|
@ -273,28 +275,28 @@ njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
|
|||
{
|
||||
u_char *p, *start;
|
||||
njs_vm_t *vm;
|
||||
nxt_int_t ret;
|
||||
nxt_str_t path;
|
||||
nxt_uint_t i;
|
||||
njs_int_t ret;
|
||||
njs_str_t path;
|
||||
njs_uint_t i;
|
||||
|
||||
vm = njs_vm_create(vm_options);
|
||||
if (vm == NULL) {
|
||||
nxt_error("failed to create vm\n");
|
||||
njs_stderror("failed to create vm\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (njs_externals_init(vm, vm_options->external) != NXT_OK) {
|
||||
nxt_error("failed to add external protos\n");
|
||||
if (njs_externals_init(vm, vm_options->external) != NJS_OK) {
|
||||
njs_stderror("failed to add external protos\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < opts->n_paths; i++) {
|
||||
path.start = (u_char *) opts->paths[i];
|
||||
path.length = nxt_strlen(opts->paths[i]);
|
||||
path.length = njs_strlen(opts->paths[i]);
|
||||
|
||||
ret = njs_vm_add_path(vm, &path);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_error("failed to add path\n");
|
||||
if (ret != NJS_OK) {
|
||||
njs_stderror("failed to add path\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -305,14 +307,14 @@ njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
|
|||
}
|
||||
|
||||
for ( ;; ) {
|
||||
p = nxt_strchr(start, ':');
|
||||
p = njs_strchr(start, ':');
|
||||
|
||||
path.start = start;
|
||||
path.length = (p != NULL) ? (size_t) (p - start) : nxt_strlen(start);
|
||||
path.length = (p != NULL) ? (size_t) (p - start) : njs_strlen(start);
|
||||
|
||||
ret = njs_vm_add_path(vm, &path);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_error("failed to add path\n");
|
||||
if (ret != NJS_OK) {
|
||||
njs_stderror("failed to add path\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -327,52 +329,52 @@ njs_create_vm(njs_opts_t *opts, njs_vm_opt_t *vm_options)
|
|||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
static njs_int_t
|
||||
njs_process_events(njs_console_t *console, njs_opts_t *opts)
|
||||
{
|
||||
njs_ev_t *ev;
|
||||
nxt_queue_t *events;
|
||||
nxt_queue_link_t *link;
|
||||
njs_queue_t *events;
|
||||
njs_queue_link_t *link;
|
||||
|
||||
events = &console->posted_events;
|
||||
|
||||
for ( ;; ) {
|
||||
link = nxt_queue_first(events);
|
||||
link = njs_queue_first(events);
|
||||
|
||||
if (link == nxt_queue_tail(events)) {
|
||||
if (link == njs_queue_tail(events)) {
|
||||
break;
|
||||
}
|
||||
|
||||
ev = nxt_queue_link_data(link, njs_ev_t, link);
|
||||
ev = njs_queue_link_data(link, njs_ev_t, link);
|
||||
|
||||
nxt_queue_remove(&ev->link);
|
||||
njs_queue_remove(&ev->link);
|
||||
ev->link.prev = NULL;
|
||||
ev->link.next = NULL;
|
||||
|
||||
njs_vm_post_event(console->vm, ev->vm_event, NULL, 0);
|
||||
}
|
||||
|
||||
return NXT_OK;
|
||||
return NJS_OK;
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
static njs_int_t
|
||||
njs_process_script(njs_console_t *console, njs_opts_t *opts,
|
||||
const nxt_str_t *script)
|
||||
const njs_str_t *script)
|
||||
{
|
||||
u_char *start;
|
||||
njs_vm_t *vm;
|
||||
nxt_int_t ret;
|
||||
njs_int_t ret;
|
||||
|
||||
vm = console->vm;
|
||||
start = script->start;
|
||||
|
||||
ret = njs_vm_compile(vm, &start, start + script->length);
|
||||
|
||||
if (ret == NXT_OK) {
|
||||
if (ret == NJS_OK) {
|
||||
if (opts->disassemble) {
|
||||
njs_disassembler(vm);
|
||||
nxt_printf("\n");
|
||||
njs_printf("\n");
|
||||
}
|
||||
|
||||
ret = njs_vm_start(vm);
|
||||
|
@ -384,8 +386,8 @@ njs_process_script(njs_console_t *console, njs_opts_t *opts,
|
|||
}
|
||||
|
||||
ret = njs_process_events(console, opts);
|
||||
if (nxt_slow_path(ret != NXT_OK)) {
|
||||
nxt_error("njs_process_events() failed\n");
|
||||
if (njs_slow_path(ret != NJS_OK)) {
|
||||
njs_stderror("njs_process_events() failed\n");
|
||||
ret = NJS_ERROR;
|
||||
break;
|
||||
}
|
||||
|
@ -393,7 +395,7 @@ njs_process_script(njs_console_t *console, njs_opts_t *opts,
|
|||
if (njs_vm_waiting(vm) && !njs_vm_posted(vm)) {
|
||||
/*TODO: async events. */
|
||||
|
||||
nxt_error("njs_process_script(): async events unsupported\n");
|
||||
njs_stderror("njs_process_script(): async events unsupported\n");
|
||||
ret = NJS_ERROR;
|
||||
break;
|
||||
}
|
||||
|
@ -405,12 +407,12 @@ njs_process_script(njs_console_t *console, njs_opts_t *opts,
|
|||
}
|
||||
|
||||
|
||||
static njs_ret_t
|
||||
njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
||||
static njs_int_t
|
||||
njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
|
||||
njs_index_t unused)
|
||||
{
|
||||
nxt_str_t msg;
|
||||
nxt_uint_t n;
|
||||
njs_str_t msg;
|
||||
njs_uint_t n;
|
||||
|
||||
n = 1;
|
||||
|
||||
|
@ -421,14 +423,14 @@ njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
nxt_printf("%s", (n != 1) ? " " : "");
|
||||
nxt_print(msg.start, msg.length);
|
||||
njs_printf("%s", (n != 1) ? " " : "");
|
||||
njs_print(msg.start, msg.length);
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
if (nargs > 1) {
|
||||
nxt_printf("\n");
|
||||
njs_printf("\n");
|
||||
}
|
||||
|
||||
vm->retval = njs_value_undefined;
|
||||
|
@ -437,12 +439,12 @@ njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
}
|
||||
|
||||
|
||||
static njs_ret_t
|
||||
njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
||||
static njs_int_t
|
||||
njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
|
||||
njs_index_t unused)
|
||||
{
|
||||
nxt_str_t msg;
|
||||
nxt_uint_t n;
|
||||
njs_str_t msg;
|
||||
njs_uint_t n;
|
||||
|
||||
n = 1;
|
||||
|
||||
|
@ -453,14 +455,14 @@ njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
nxt_printf("%s", (n != 1) ? " " : "");
|
||||
nxt_print(msg.start, msg.length);
|
||||
njs_printf("%s", (n != 1) ? " " : "");
|
||||
njs_print(msg.start, msg.length);
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
if (nargs > 1) {
|
||||
nxt_printf("\n");
|
||||
njs_printf("\n");
|
||||
}
|
||||
|
||||
vm->retval = njs_value_undefined;
|
||||
|
@ -469,30 +471,30 @@ njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
}
|
||||
|
||||
|
||||
static njs_ret_t
|
||||
njs_ext_console_help(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
||||
static njs_int_t
|
||||
njs_ext_console_help(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
|
||||
njs_index_t unused)
|
||||
{
|
||||
const njs_object_init_t *obj, **objpp;
|
||||
|
||||
nxt_printf("VM built-in objects:\n");
|
||||
njs_printf("VM built-in objects:\n");
|
||||
|
||||
for (objpp = njs_constructor_init; *objpp != NULL; objpp++) {
|
||||
obj = *objpp;
|
||||
|
||||
nxt_printf(" %V\n", &obj->name);
|
||||
njs_printf(" %V\n", &obj->name);
|
||||
}
|
||||
|
||||
for (objpp = njs_object_init; *objpp != NULL; objpp++) {
|
||||
obj = *objpp;
|
||||
|
||||
nxt_printf(" %V\n", &obj->name);
|
||||
njs_printf(" %V\n", &obj->name);
|
||||
}
|
||||
|
||||
nxt_printf("\nEmbedded objects:\n");
|
||||
nxt_printf(" console\n");
|
||||
njs_printf("\nEmbedded objects:\n");
|
||||
njs_printf(" console\n");
|
||||
|
||||
nxt_printf("\n");
|
||||
njs_printf("\n");
|
||||
|
||||
vm->retval = njs_value_undefined;
|
||||
|
||||
|
@ -500,8 +502,8 @@ njs_ext_console_help(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
}
|
||||
|
||||
|
||||
static njs_ret_t
|
||||
njs_ext_console_time(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
||||
static njs_int_t
|
||||
njs_ext_console_time(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
|
||||
njs_index_t unused)
|
||||
{
|
||||
njs_console_t *console;
|
||||
|
@ -512,11 +514,11 @@ njs_ext_console_time(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
}
|
||||
|
||||
console = njs_vm_external(vm, njs_arg(args, nargs, 0));
|
||||
if (nxt_slow_path(console == NULL)) {
|
||||
if (njs_slow_path(console == NULL)) {
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
console->time = nxt_time();
|
||||
console->time = njs_time();
|
||||
|
||||
vm->retval = njs_value_undefined;
|
||||
|
||||
|
@ -524,14 +526,14 @@ njs_ext_console_time(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
}
|
||||
|
||||
|
||||
static njs_ret_t
|
||||
njs_ext_console_time_end(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
||||
static njs_int_t
|
||||
njs_ext_console_time_end(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
|
||||
njs_index_t unused)
|
||||
{
|
||||
uint64_t ns, ms;
|
||||
njs_console_t *console;
|
||||
|
||||
ns = nxt_time();
|
||||
ns = njs_time();
|
||||
|
||||
if (!njs_value_is_undefined(njs_arg(args, nargs, 1))) {
|
||||
njs_vm_error(vm, "labels not implemented");
|
||||
|
@ -539,23 +541,23 @@ njs_ext_console_time_end(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
|
|||
}
|
||||
|
||||
console = njs_vm_external(vm, njs_arg(args, nargs, 0));
|
||||
if (nxt_slow_path(console == NULL)) {
|
||||
if (njs_slow_path(console == NULL)) {
|
||||
return NJS_ERROR;
|
||||
}
|
||||
|
||||
if (nxt_fast_path(console->time != UINT64_MAX)) {
|
||||
if (njs_fast_path(console->time != UINT64_MAX)) {
|
||||
|
||||
ns = ns - console->time;
|
||||
|
||||
ms = ns / 1000000;
|
||||
ns = ns % 1000000;
|
||||
|
||||
nxt_printf("default: %uL.%06uLms\n", ms, ns);
|
||||
njs_printf("default: %uL.%06uLms\n", ms, ns);
|
||||
|
||||
console->time = UINT64_MAX;
|
||||
|
||||
} else {
|
||||
nxt_printf("Timer \"default\" doesn’t exist.\n");
|
||||
njs_printf("Timer \"default\" doesn’t exist.\n");
|
||||
}
|
||||
|
||||
vm->retval = njs_value_undefined;
|
||||
|
@ -570,20 +572,20 @@ njs_console_set_timer(njs_external_ptr_t external, uint64_t delay,
|
|||
{
|
||||
njs_ev_t *ev;
|
||||
njs_vm_t *vm;
|
||||
nxt_int_t ret;
|
||||
njs_int_t ret;
|
||||
njs_console_t *console;
|
||||
nxt_lvlhsh_query_t lhq;
|
||||
njs_lvlhsh_query_t lhq;
|
||||
|
||||
if (delay != 0) {
|
||||
nxt_error("njs_console_set_timer(): async timers unsupported\n");
|
||||
njs_stderror("njs_console_set_timer(): async timers unsupported\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
console = external;
|
||||
vm = console->vm;
|
||||
|
||||
ev = nxt_mp_alloc(vm->mem_pool, sizeof(njs_ev_t));
|
||||
if (nxt_slow_path(ev == NULL)) {
|
||||
ev = njs_mp_alloc(vm->mem_pool, sizeof(njs_ev_t));
|
||||
if (njs_slow_path(ev == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -591,19 +593,19 @@ njs_console_set_timer(njs_external_ptr_t external, uint64_t delay,
|
|||
|
||||
lhq.key.start = (u_char *) &ev->vm_event;
|
||||
lhq.key.length = sizeof(njs_vm_event_t);
|
||||
lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length);
|
||||
lhq.key_hash = njs_djb_hash(lhq.key.start, lhq.key.length);
|
||||
|
||||
lhq.replace = 0;
|
||||
lhq.value = ev;
|
||||
lhq.proto = &lvlhsh_proto;
|
||||
lhq.pool = vm->mem_pool;
|
||||
|
||||
ret = nxt_lvlhsh_insert(&console->events, &lhq);
|
||||
if (nxt_slow_path(ret != NXT_OK)) {
|
||||
ret = njs_lvlhsh_insert(&console->events, &lhq);
|
||||
if (njs_slow_path(ret != NJS_OK)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nxt_queue_insert_tail(&console->posted_events, &ev->link);
|
||||
njs_queue_insert_tail(&console->posted_events, &ev->link);
|
||||
|
||||
return (njs_host_event_t) ev;
|
||||
}
|
||||
|
@ -614,9 +616,9 @@ njs_console_clear_timer(njs_external_ptr_t external, njs_host_event_t event)
|
|||
{
|
||||
njs_vm_t *vm;
|
||||
njs_ev_t *ev;
|
||||
nxt_int_t ret;
|
||||
njs_int_t ret;
|
||||
njs_console_t *console;
|
||||
nxt_lvlhsh_query_t lhq;
|
||||
njs_lvlhsh_query_t lhq;
|
||||
|
||||
ev = event;
|
||||
console = external;
|
||||
|
@ -624,50 +626,50 @@ njs_console_clear_timer(njs_external_ptr_t external, njs_host_event_t event)
|
|||
|
||||
lhq.key.start = (u_char *) &ev->vm_event;
|
||||
lhq.key.length = sizeof(njs_vm_event_t);
|
||||
lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length);
|
||||
lhq.key_hash = njs_djb_hash(lhq.key.start, lhq.key.length);
|
||||
|
||||
lhq.proto = &lvlhsh_proto;
|
||||
lhq.pool = vm->mem_pool;
|
||||
|
||||
if (ev->link.prev != NULL) {
|
||||
nxt_queue_remove(&ev->link);
|
||||
njs_queue_remove(&ev->link);
|
||||
}
|
||||
|
||||
ret = nxt_lvlhsh_delete(&console->events, &lhq);
|
||||
if (ret != NXT_OK) {
|
||||
nxt_error("nxt_lvlhsh_delete() failed\n");
|
||||
ret = njs_lvlhsh_delete(&console->events, &lhq);
|
||||
if (ret != NJS_OK) {
|
||||
njs_stderror("njs_lvlhsh_delete() failed\n");
|
||||
}
|
||||
|
||||
nxt_mp_free(vm->mem_pool, ev);
|
||||
njs_mp_free(vm->mem_pool, ev);
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
lvlhsh_key_test(nxt_lvlhsh_query_t *lhq, void *data)
|
||||
static njs_int_t
|
||||
lvlhsh_key_test(njs_lvlhsh_query_t *lhq, void *data)
|
||||
{
|
||||
njs_ev_t *ev;
|
||||
|
||||
ev = data;
|
||||
|
||||
if (memcmp(&ev->vm_event, lhq->key.start, sizeof(njs_vm_event_t)) == 0) {
|
||||
return NXT_OK;
|
||||
return NJS_OK;
|
||||
}
|
||||
|
||||
return NXT_DECLINED;
|
||||
return NJS_DECLINED;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
lvlhsh_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc)
|
||||
lvlhsh_pool_alloc(void *pool, size_t size, njs_uint_t nalloc)
|
||||
{
|
||||
return nxt_mp_align(pool, size, size);
|
||||
return njs_mp_align(pool, size, size);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
lvlhsh_pool_free(void *pool, void *p, size_t size)
|
||||
{
|
||||
nxt_mp_free(pool, p);
|
||||
njs_mp_free(pool, p);
|
||||
}
|
||||
|
||||
|
||||
|
@ -676,18 +678,18 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
|
||||
char* input = malloc(size);
|
||||
memcpy(input, data, size);
|
||||
nxt_str_t line = {size, input};
|
||||
njs_str_t line = {size, input};
|
||||
|
||||
njs_vm_t *vm;
|
||||
nxt_int_t ret;
|
||||
njs_int_t ret;
|
||||
njs_opts_t opts;
|
||||
nxt_str_t command;
|
||||
njs_str_t command;
|
||||
njs_vm_opt_t vm_options;
|
||||
|
||||
nxt_memzero(&opts, sizeof(njs_opts_t));
|
||||
njs_memzero(&opts, sizeof(njs_opts_t));
|
||||
opts.interactive = 1;
|
||||
|
||||
nxt_memzero(&vm_options, sizeof(njs_vm_opt_t));
|
||||
njs_memzero(&vm_options, sizeof(njs_vm_opt_t));
|
||||
|
||||
vm_options.init = !opts.interactive;
|
||||
vm_options.accumulative = opts.interactive;
|
||||
|
@ -702,7 +704,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
ret = njs_interactive_shell(&opts, &vm_options, &line);
|
||||
free(input);
|
||||
|
||||
if (ret != NXT_OK)
|
||||
if (ret != NJS_OK)
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue