#include #include #include #include #include #include #include int posix_spawn(pid_t* pid, const char* path, const posix_spawn_file_actions_t* file_actions, const posix_spawnattr_t* attrp, char* const argv[], char* const envp[]) { FILE* image=fopen((char*)path,"r"); elf_header header; fread(&header,sizeof(elf_header),1,image); if (header.magic!=ELF_MAGIC) { serial_print("Bad magic number ("); char str[32]; hex_to_ascii(header.magic,str); serial_print(str); serial_print(")\n"); return 0; } else { void* address_space=new_address_space(); for (int i=0;i0) { fseek(image,pheader.offset,SEEK_SET); fread(ptr,sizeof(char),pheader.filesz,image); } copy_data(address_space,ptr,pheader.memsz,(void*)pheader.vaddr); } create_proc((void*)header.entry,address_space,NULL,NULL); } return 1; }