Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This provides a way to register such calls, and sets them up at startup. A call has an unchecked implementation body that will pull received args out without needing to validate them, along with metadata used to do the validation. A boot-syscall, when it's fully implemented, will on its first dispatch do these checks and set up the guards. The ultimate goal is that we can do standard guard elimination on these in spesh, then call the C function, providing a far more uniform interface for the VM interanls.
- Loading branch information
Showing
18 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
MVMObject * MVM_disp_boot_constant_dispatch(MVMThreadContext *tc); | ||
MVMObject * MVM_disp_boot_value_dispatch(MVMThreadContext *tc); | ||
MVMObject * MVM_disp_boot_code_constant_dispatch(MVMThreadContext *tc); | ||
MVMObject * MVM_disp_boot_syscall_dispatch(MVMThreadContext *tc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "moar.h" | ||
|
||
#define EMPTY_HASH_HANDLE { 0, 0, 0, 0, 0 } | ||
|
||
/* dispatcher-register */ | ||
static void dispatcher_register_impl(MVMThreadContext *tc, MVMArgs arg_info) { | ||
MVM_panic(1, "in syscall but NYI"); | ||
} | ||
static MVMDispSysCall dispatcher_register = { | ||
.c_name = "dispatcher-register", | ||
.implementation = dispatcher_register_impl, | ||
.min_args = 2, | ||
.max_args = 3, | ||
.expected_kinds = { MVM_CALLSITE_ARG_STR, MVM_CALLSITE_ARG_OBJ, MVM_CALLSITE_ARG_OBJ }, | ||
.expected_reprs = { 0, MVM_REPR_ID_MVMCode, MVM_REPR_ID_MVMCode }, | ||
.expected_concrete = { 1, 1, 1 }, | ||
.hash_handle = EMPTY_HASH_HANDLE | ||
}; | ||
|
||
/* Add all of the syscalls into the hash. */ | ||
MVM_STATIC_INLINE void add_to_hash(MVMThreadContext *tc, MVMDispSysCall *syscall) { | ||
syscall->name = MVM_string_ascii_decode_nt(tc, tc->instance->VMString, syscall->c_name); | ||
MVM_gc_root_add_permanent_desc(tc, (MVMCollectable **)&(syscall->name), "MoarVM syscall name"); | ||
|
||
MVMObject *BOOTCCode = tc->instance->boot_types.BOOTCCode; | ||
MVMObject *code_obj = REPR(BOOTCCode)->allocate(tc, STABLE(BOOTCCode)); | ||
((MVMCFunction *)code_obj)->body.func = syscall->implementation; | ||
syscall->wrapper = code_obj; | ||
MVM_gc_root_add_permanent_desc(tc, (MVMCollectable **)&(syscall->wrapper), "MoarVM syscall wrapper"); | ||
|
||
MVM_HASH_BIND(tc, tc->instance->syscalls, syscall->name, syscall); | ||
} | ||
void MVM_disp_syscall_setup(MVMThreadContext *tc) { | ||
MVM_gc_allocate_gen2_default_set(tc); | ||
add_to_hash(tc, &dispatcher_register); | ||
MVM_gc_allocate_gen2_default_clear(tc); | ||
} | ||
|
||
/* Look up a syscall by name. Returns NULL if it's not found. */ | ||
MVMDispSysCall * MVM_disp_syscall_find(MVMThreadContext *tc, MVMString *name) { | ||
MVMDispSysCall *syscall; | ||
MVM_HASH_GET(tc, tc->instance->syscalls, name, syscall); | ||
return syscall; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#define MVM_DISP_SYSCALL_MAX_ARGS 8 | ||
|
||
/* Information about a VM-provided call. */ | ||
struct MVMDispSysCall { | ||
/* Syscall name. */ | ||
const char *c_name; | ||
MVMString *name; | ||
|
||
/* The implementation. This assumes it can pull out arguments without | ||
* any validation being required on argument count, kinds, and | ||
* representations, which are checked below (and their checks thus | ||
* lifted out as guards, which may be eliminated in optimized code). */ | ||
void (*implementation) (MVMThreadContext *tc, MVMArgs arg_info); | ||
|
||
/* The function wrapper around the implementation. */ | ||
MVMObject *wrapper; | ||
|
||
/* Minimum and maximum acceptable number of positional arguments. */ | ||
MVMuint8 min_args; | ||
MVMuint8 max_args; | ||
|
||
/* Expected argument kinds. */ | ||
MVMCallsiteFlags expected_kinds[MVM_DISP_SYSCALL_MAX_ARGS]; | ||
|
||
/* Expected argument representations. 0 is used to mean "unimportant" | ||
* (the number is actually given to MVMString, but that should always be | ||
* in an s register, not an o register, and so this should never be | ||
* an issue). Only relevant for obj kind registers. */ | ||
MVMuint8 expected_reprs[MVM_DISP_SYSCALL_MAX_ARGS]; | ||
|
||
/* Set to 1 if we expect it to be concrete, otherwise means we don't | ||
* care. Only relevant for obj kind registers. */ | ||
MVMuint8 expected_concrete[MVM_DISP_SYSCALL_MAX_ARGS]; | ||
|
||
/* Inline handle to the hash we use to lookup the calls by name. */ | ||
UT_hash_handle hash_handle; | ||
}; | ||
|
||
void MVM_disp_syscall_setup(MVMThreadContext *tc); | ||
MVMDispSysCall * MVM_disp_syscall_find(MVMThreadContext *tc, MVMString *name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters