Spawn is creating the processes correctly now

This commit is contained in:
Jeremiah Orians 2021-11-22 21:41:11 -05:00
parent 0284bc6ebc
commit 9de58d6d9c
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
5 changed files with 54 additions and 39 deletions

18
cc.c
View File

@ -42,8 +42,10 @@ int main(int argc, char** argv, char** envp)
FUZZING = FALSE;
MAX_STRING = 4096;
PREPROCESSOR_MODE = FALSE;
int debug_flag = TRUE;
FILE* in = stdin;
FILE* tempfile;
char* destination_name = "/dev/stdout";
FILE* destination_file = stdout;
init_macro_env("__M2__", "42", "__INTERNAL_M2__", 0); /* Setup __M2__ */
char* name;
@ -172,13 +174,21 @@ int main(int argc, char** argv, char** envp)
}
else
{
char* filename = calloc(100, sizeof(char));
strcpy(filename, "/tmp/M2-Mesoplanet-XXXXXX");
i = mkstemp(filename);
tempfile = fdopen(i, "rw");
name = calloc(100, sizeof(char));
strcpy(name, "/tmp/M2-Mesoplanet-XXXXXX");
i = mkstemp(name);
tempfile = fdopen(i, "w+");
if(NULL != tempfile)
{
/* Our preprocessed crap */
output_tokens(global_token, tempfile);
fclose(tempfile);
/* Make me a real binary */
spawn_processes(debug_flag, name, destination_name, envp);
/* And clean up the donkey */
remove(name);
}
else
{

View File

@ -38,7 +38,6 @@ int MAX_STRING;
int PREPROCESSOR_MODE;
/* enable spawn behavior to be effective */
char* PATH;
char* M2LIBC_PATH;
/* So we don't shoot ourself in the face */

View File

@ -39,7 +39,6 @@ extern long MAX_STRING;
extern int PREPROCESSOR_MODE;
/* enable spawn behavior to be effective */
extern char* PATH;
extern char* M2LIBC_PATH;
extern char* Architecture;
extern int WORDSIZE;

View File

@ -47,6 +47,8 @@ char* find_char(char* string, char a)
/* Find the full path to an executable */
char* find_executable(char* name)
{
char* PATH = env_lookup("PATH");
require(NULL != PATH, "No PATH found\nAborting\n");
if(match("", name))
{
return NULL;
@ -186,12 +188,13 @@ int spawn_hex2(char* input, char* output, char* architecture, char** envp, int d
{
/* TODO FINISH */
char** array = calloc(MAX_ARRAY, sizeof(char*));
insert_array(array, 0, "--file");
insert_array(array, 1, input);
insert_array(array, 2, "--output");
insert_array(array, 3, output);
insert_array(array, 4, "--architecture");
insert_array(array, 5, architecture);
insert_array(array, 0, "hex2");
insert_array(array, 1, "--file");
insert_array(array, 2, input);
insert_array(array, 3, "--output");
insert_array(array, 4, output);
insert_array(array, 5, "--architecture");
insert_array(array, 6, architecture);
int r = _execute("hex2", array, envp);
return r;
}
@ -200,23 +203,24 @@ int spawn_hex2(char* input, char* output, char* architecture, char** envp, int d
int spawn_M1(char* input, char* debug_file, char* output, char* architecture, char** envp, int debug_flag)
{
char** array = calloc(MAX_ARRAY, sizeof(char*));
insert_array(array, 0, "--file");
insert_array(array, 1, input);
insert_array(array, 0, "M1");
insert_array(array, 1, "--file");
insert_array(array, 2, input);
if(debug_flag)
{
insert_array(array, 2, "--file");
insert_array(array, 3, debug_file);
insert_array(array, 4, "--output");
insert_array(array, 5, output);
insert_array(array, 6, "--architecture");
insert_array(array, 7, architecture);
insert_array(array, 3, "--file");
insert_array(array, 4, debug_file);
insert_array(array, 5, "--output");
insert_array(array, 6, output);
insert_array(array, 7, "--architecture");
insert_array(array, 8, architecture);
}
else
{
insert_array(array, 2, "--output");
insert_array(array, 3, output);
insert_array(array, 4, "--architecture");
insert_array(array, 5, architecture);
insert_array(array, 3, "--output");
insert_array(array, 4, output);
insert_array(array, 5, "--architecture");
insert_array(array, 6, architecture);
}
int r = _execute("M1", array, envp);
return r;
@ -226,13 +230,14 @@ int spawn_M1(char* input, char* debug_file, char* output, char* architecture, ch
int spawn_blood_elf(char* input, char* output, char* architecture, char** envp, int large_flag)
{
char** array = calloc(MAX_ARRAY, sizeof(char*));
insert_array(array, 0, "--file");
insert_array(array, 1, input);
insert_array(array, 2, "--output");
insert_array(array, 3, output);
insert_array(array, 4, "--architecture");
insert_array(array, 5, architecture);
if(large_flag) insert_array(array, 6, "--64");
insert_array(array, 0, "blood-elf");
insert_array(array, 1, "--file");
insert_array(array, 2, input);
insert_array(array, 3, "--output");
insert_array(array, 4, output);
insert_array(array, 5, "--architecture");
insert_array(array, 6, architecture);
if(large_flag) insert_array(array, 7, "--64");
int r = _execute("blood-elf", array, envp);
return r;
}
@ -240,13 +245,14 @@ int spawn_blood_elf(char* input, char* output, char* architecture, char** envp,
int spawn_M2(char* input, char* output, char* architecture, char** envp, int debug_flag)
{
char** array = calloc(MAX_ARRAY, sizeof(char*));
insert_array(array, 0, "--file");
insert_array(array, 1, input);
insert_array(array, 2, "--output");
insert_array(array, 3, output);
insert_array(array, 4, "--architecture");
insert_array(array, 5, architecture);
if(debug_flag) insert_array(array, 6, "--debug");
insert_array(array, 0, "M2-Planet");
insert_array(array, 1, "--file");
insert_array(array, 2, input);
insert_array(array, 3, "--output");
insert_array(array, 4, output);
insert_array(array, 5, "--architecture");
insert_array(array, 6, architecture);
if(debug_flag) insert_array(array, 7, "--debug");
int r = _execute("M2-Planet", array, envp);
return r;
}

View File

@ -25,13 +25,14 @@ CFLAGS:=$(CFLAGS) -D_GNU_SOURCE -O0 -std=c99 -ggdb
all: M2-Mesoplanet
M2-Mesoplanet: bin results cc.h cc_reader.c cc_core.c cc.c cc_globals.c cc_globals.h
M2-Mesoplanet: bin results cc.h cc_reader.c cc_core.c cc_macro.c cc_env.c cc_spawn.c cc.c cc_globals.c cc_globals.h
$(CC) $(CFLAGS) \
M2libc/bootstrappable.c \
cc_reader.c \
cc_core.c \
cc_macro.c \
cc_env.c \
cc_spawn.c \
cc.c \
cc.h \
cc_globals.c \