The main focus of this commit is 'bal_safety.h'. This header file
adds magic numbers to prevent Undefined Behavior. Right now this
has only been added to 'bal_assembler_t'.
This introduces 3 magic numbers:
#define BAL_MAGIC_UNINITIALIZED 0x00000000U
#define BAL_ASSEMBLER_MAGIC_ALIVE 0xBA11A550U
#define BAL_ASSEMBLER_MAGIC_DEAD 0xDEADBA11U
'ALIVE' magic numbers will be set only if the struct has been
initialized properly. Every function should check a struct's magic
number to make sure it's not operating on a memory corrupted struct.
'DEAD' magic numbers should be set on a struct's 'destory()' function.
This is done to prevent Double Free and Use-After-Free scenarios.
Convenience macro 'BAL_CHECK_MAGIC' and 'BAL_CHECK_MAGIC_VOID' have
been added to easily validate struct integrity.
Signed-off-by: Ronald Caesar <github43132@proton.me>
This introduces BAL_ERROR_INVALID_CAPACITY which happens when a
buffer capacity exceeds SIZE_MAX or whatever the type's max value is.
Signed-off-by: Ronald Caesar <github43132@proton.me>
I've added `tools/generate_ffi.lua` which generates lua ffi bindings
to C for all structs in a header file and functions in that have the
`BAL_EXPORT` keyword.
Right now only `tools/dashboard/dashboard_file_dialog.h` have ffi
bindings generated for it and saved to
`tools/dashboard/scripts/generated/dashboard_file_dialog_ffi.lua`.
The script only handles one header file at a time. Later on I will need
to add support for recursively scanning all header files in a folder
with options to exclude certain folders.
Signed-off-by: Ronald Caesar <github43132@proton.me>
I want hot-reloading on the file dialog, so a moved
'dashboard_file_dialog_draw()' to Lua and named it
'dashboard_render_file_dialog()'. This requires adding the following
helper functions:
* dashboard_file_dialog_refresh()
* dashboard_file_dialog_append_path()
* dashboard_file_dialog_navigate_home()
Signed-off-by: Ronald Caesar <github43132@proton.me>
The B (unconditional branch) instruction encoding used integer
division (/) instead of bitwise OR (|) to combine the opcode with
the branch offset. This produced incorrect machine code for every
branch target other than zero.
Also add bal_assembler_reset() to match the reset API provided by
every other module in Ballistic (bal_x86_assembler, sliding window,
tier1 compiler). The function zeroes the instruction buffer and
resets offset and status.
Wrap the hot function in BAL_UNLIKELY.
Signed-off-by: mcrib884 <farukkaya229@outlook.com>
If a hash bucket is empty, the test still loops 2,097,152 times which
is crazy. An empty bucket means `bal_decode_arm64()` will always
return NULL, so I've added a `continue` statement to skip the massive
loop.
Signed-off-by: Ronald Caesar <github43132@proton.me>