all: ldlinux.c32
ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \
- adv.o ipappend.o
+ adv.o ipappend.o execute.o kernel.o
$(LD) $(LDFLAGS) -o $@ $^
tidy dist:
void execute(const char *cmdline, enum kernel_type type)
{
- com32sys_t ireg;
const char *p, *const *pp;
- char *q;
const char *kernel, *args;
-
- /* work around for spawn_load parameter */
- char *spawn_load_param[2] = { NULL, NULL};
+ com32sys_t ireg;
+ char *q;
memset(&ireg, 0, sizeof ireg);
if (type == KT_COM32) {
/* new entry for elf format c32 */
- spawn_load_param[0] = args;
+ char **argv;
+ int i, argc;
+
+ q = args;
+ for (argc = 0; *q; q++) {
+ argc++;
+
+ /* Find the end of this arg */
+ while(*q && !my_isspace(*q))
+ q++;
+
+ /*
+ * Now skip all whitespace between arguments.
+ */
+ while (*q && my_isspace(*q))
+ q++;
+ }
+
+ /*
+ * Generate a copy of argv on the stack as this is
+ * traditionally where process arguments go.
+ *
+ * argv[0] must be the command name, so bump argc to
+ * include argv[0].
+ */
+ argc += 1;
+ argv = alloca(argc * sizeof(char *));
+ argv[0] = kernel;
+
+ for (q = args, i = 1; i < argc - 1; i++) {
+ char *start;
+ int len = 0;
+
+ start = q;
+
+ /* Find the end of this arg */
+ while(*q && !my_isspace(*q)) {
+ q++;
+ len++;
+ }
+
+ argv[i] = malloc(len + 1);
+ strncpy(argv[i], start, len);
+ argv[i][len] = '\0';
+
+ /*
+ * Now skip all whitespace between arguments.
+ */
+ while (*q && my_isspace(*q))
+ q++;
+ }
+
+ argv[argc] = NULL;
module_load_dependencies(kernel, "modules.dep");
- spawn_load(kernel, spawn_load_param);
+ spawn_load(kernel, argc, argv);
} else if (type <= KT_KERNEL) {
/* Need add one item for kernel load, as we don't use
* the assembly runkernel.inc any more */
new_linux_kernel(kernel, cmdline);
} else if (type == KT_CONFIG) {
/* kernel contains the config file name */
- spawn_load_param[0] = args;
+ char *spawn_load_param[2] = { args, NULL };
module_load_dependencies("ui.c32", "modules.dep");
- spawn_load(kernel, spawn_load_param);
+ spawn_load(kernel, 1, spawn_load_param);
} else {
/* process the image need int 22 support */
if (type == KT_LOCALBOOT) {
* spawn_load - Load a library module or executes an executable one
* @name the name of the library/executable to use, including the extension
* (e.g. 'sort.c32')
+ * @argc: the number of string arguments in @argv
* @argv: a NULL-terminated vector of string arguments, starting with
* the program name.
*
* kind of module it is ( executable or library ), after which is performs the
* appropriate action, either spawning or simply loading the module into memory.
*/
-extern int spawn_load(const char *name,const char **argv);
+extern int spawn_load(const char *name, int argc, char **argv);
extern int module_load_dependencies(const char*name,const char*dep_file);
struct elf_module *cur_module;
-int spawn_load(const char *name,const char **argv)
+/*
+ * Load a module and runs its start function.
+ *
+ * For library modules the start function is module->init_func and for
+ * executable modules its module->main_func.
+ *
+ * "name" is the name of the module to load.
+ *
+ * "argv" and "argc" are only passed to module->main_func, for library
+ * modules these arguments can be NULL and 0, respectively.
+ *
+ * "argv" is an array of arguments to pass to module->main_func.
+ * argv[0] must be a pointer to "name" and argv[argc] must be NULL.
+ *
+ * "argc" is the number of arguments in "argv".
+ */
+int spawn_load(const char *name, int argc, char **argv)
{
int res, ret_val = 0;
- const char **arg;
- int argc;
- char **argp, **args;
struct elf_module *previous;
//malloc_tag_t prev_mem_tag;
struct elf_module *module = module_alloc(name);
if (module == NULL)
return -1;
+ if (get_module_type(module) == EXEC_MODULE) {
+ if (!argc || !argv || strcmp(argv[0], name))
+ return -1;
+ }
+
if (!strcmp(cur_module->name, module->name)) {
dprintf("We is running this module %s already!", module->name);
__syslinux_current = module;
//__mem_set_tag_global((malloc_tag_t)module);
- // Generate a new process copy of argv (on the stack)
- argc = 0;
- for (arg = argv; *arg; arg++)
- argc++;
-
- args = alloca((argc+1) * sizeof(char *));
-
- for (arg = argv, argp = args; *arg; arg++, argp++) {
- size_t l = strlen(*arg)+1;
- *argp = alloca(l);
- memcpy(*argp, *arg, l);
- }
-
- *args = NULL;
-
// Execute the program
ret_val = setjmp(module->u.x.process_exit);
else if (!module->main_func)
ret_val = -1;
else
- exit((module->main_func)(argc, args)); /* Actually run! */
+ exit((module->main_func)(argc, argv)); /* Actually run! */
// Clean up the allocation context
i++; /* skip a space */
if (strlen(temp_name)) {
- char *argv[2] = { NULL, NULL };
+ char *argv[2] = { temp_name, NULL };
int ret;
ret = module_load_dependencies(temp_name,
MODULES_DEP);
if (!ret) {
- if (spawn_load(temp_name, argv) < 0)
+ if (spawn_load(temp_name, 1, argv) < 0)
continue;
}
}
#include "menu.h"
#include "core-elf.h"
+#define LDLINUX "ldlinux.c32"
+
typedef void (*constructor_t) (void);
constructor_t __ctors_start[], __ctors_end[];
/* note to self: do _*NOT*_ use static key word on this function */
void load_env32(com32sys_t * regs)
{
+ char *argv[] = { LDLINUX, NULL };
+
dprintf("Starting 32 bit elf module subsystem...\n");
call_constr();
init_module_subsystem(&core_module);
- execute("ldlinux.c32", KT_COM32);
+ module_load_dependencies(LDLINUX, "modules.dep");
+ spawn_load(LDLINUX, 1, argv);
}