drop cmdline limits
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
#include <zinnia/utils.h>
|
#include <zinnia/utils.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define _CMDLINE_OPTION(x, opt_name, opt_desc, opt_func, opt_limit) \
|
#define _CMDLINE_OPTION(x, opt_name, opt_desc, opt_func) \
|
||||||
static const struct cmdline_option x = { \
|
static const struct cmdline_option x = { \
|
||||||
.name = opt_name, \
|
.name = opt_name, \
|
||||||
.desc = opt_desc, \
|
.desc = opt_desc, \
|
||||||
@@ -16,23 +16,12 @@
|
|||||||
void (*)(uintptr_t): CMDLINE_UINTPTR \
|
void (*)(uintptr_t): CMDLINE_UINTPTR \
|
||||||
), \
|
), \
|
||||||
.func = (void*)(opt_func), \
|
.func = (void*)(opt_func), \
|
||||||
.limit = (void*)(opt_limit) \
|
|
||||||
}; \
|
}; \
|
||||||
static_assert(_Generic( \
|
|
||||||
(opt_limit), \
|
|
||||||
const char**: true, \
|
|
||||||
const struct cmdline_range_int*: true, \
|
|
||||||
const struct cmdline_range_uint*: true, \
|
|
||||||
void*: true \
|
|
||||||
)); \
|
|
||||||
[[__used, __section(".cmdline")]] \
|
[[__used, __section(".cmdline")]] \
|
||||||
static const struct cmdline_option* CONCAT(x, _ptr) = &x
|
static const struct cmdline_option* CONCAT(x, _ptr) = &x
|
||||||
|
|
||||||
#define CMDLINE_OPTION(opt_name, opt_desc, opt_func) \
|
#define CMDLINE_OPTION(opt_name, opt_desc, opt_func) \
|
||||||
_CMDLINE_OPTION(UNIQUE_IDENT(cmdline_option), opt_name, opt_desc, opt_func, (void*)nullptr)
|
_CMDLINE_OPTION(UNIQUE_IDENT(cmdline_option), opt_name, opt_desc, opt_func)
|
||||||
|
|
||||||
#define CMDLINE_OPTION_RANGE(opt_name, opt_desc, opt_func, opt_values) \
|
|
||||||
_CMDLINE_OPTION(UNIQUE_IDENT(cmdline_option), opt_name, opt_desc, opt_func, opt_values)
|
|
||||||
|
|
||||||
enum cmdline_type {
|
enum cmdline_type {
|
||||||
CMDLINE_STRING,
|
CMDLINE_STRING,
|
||||||
@@ -55,16 +44,6 @@ struct cmdline_option {
|
|||||||
void (*func_uintptr)(uintptr_t value);
|
void (*func_uintptr)(uintptr_t value);
|
||||||
void* func;
|
void* func;
|
||||||
};
|
};
|
||||||
union {
|
|
||||||
const char** str_limit;
|
|
||||||
struct cmdline_range_int {
|
|
||||||
intptr_t min, max;
|
|
||||||
}* intptr_limit;
|
|
||||||
struct cmdline_range_uint {
|
|
||||||
uintptr_t min, max;
|
|
||||||
}* uintptr_limit;
|
|
||||||
void* limit;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parses the command line and invokes all options.
|
// Parses the command line and invokes all options.
|
||||||
|
|||||||
+1
-41
@@ -65,44 +65,4 @@ if __name__ == "__main__":
|
|||||||
case 3:
|
case 3:
|
||||||
kind_str = "unsigned integer"
|
kind_str = "unsigned integer"
|
||||||
|
|
||||||
# Skip function pointer
|
print(f"- {name}:\t{desc} ({kind_str})")
|
||||||
|
|
||||||
# Allowed values
|
|
||||||
limit = ""
|
|
||||||
limit_ptr = int.from_bytes(option[32:][:SIZEOF_PTR], byteorder=ENDIAN)
|
|
||||||
|
|
||||||
if limit_ptr != 0:
|
|
||||||
elffile.seek(next(file.address_offsets(start=limit_ptr)))
|
|
||||||
match kind:
|
|
||||||
case 0:
|
|
||||||
limit = []
|
|
||||||
i = 0
|
|
||||||
while True:
|
|
||||||
ptr = next(file.address_offsets(start=limit_ptr + i * SIZEOF_PTR))
|
|
||||||
elffile.seek(ptr)
|
|
||||||
str_ptr = int.from_bytes(elffile.read(SIZEOF_PTR), byteorder=ENDIAN)
|
|
||||||
if str_ptr == 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
strstr_off = next(file.address_offsets(start=str_ptr))
|
|
||||||
val = ""
|
|
||||||
elffile.seek(strstr_off)
|
|
||||||
while True:
|
|
||||||
b = int.from_bytes(elffile.read(1))
|
|
||||||
if b == 0:
|
|
||||||
break
|
|
||||||
val += chr(b)
|
|
||||||
i += 1
|
|
||||||
limit.append(val)
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
min = int.from_bytes(elffile.read(SIZEOF_PTR), byteorder=ENDIAN, signed=True)
|
|
||||||
max = int.from_bytes(elffile.read(SIZEOF_PTR), byteorder=ENDIAN)
|
|
||||||
limit = f"[{min}, {max}]"
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
min = int.from_bytes(elffile.read(SIZEOF_PTR), byteorder=ENDIAN)
|
|
||||||
max = int.from_bytes(elffile.read(SIZEOF_PTR), byteorder=ENDIAN)
|
|
||||||
limit = f"[{min}, {max}]"
|
|
||||||
|
|
||||||
print(f"- {name}:\t{desc} ({kind_str}) {limit if len(limit) != 0 else ""}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user