lindows/lsmss/main.cxx

81 lines
1.6 KiB
C++

#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <filesystem>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/mount.h>
/**
* Log something.
*
* \param message to log
*/
void Pii_Log(const std::string& message) {
std::cout << message << "\n";
return;
}
/**
* execute a program from an absolute path
*
* \param path absolute path to program (duh)
* \return program return value, 1 if it does not exist or -1 on error
*/
int Pii_ExecuteProgram(const std::string& path) {
if (pid_t child = fork()) {
int exitcode = -1;
waitpid(child, &exitcode, 0);
return exitcode;
} else {
char* args[] = { strdup(path.c_str()), nullptr };
execv(args[0], args);
// this should only be reached if we cant load the program
std::exit(1);
}
}
/**
* Abort the boot process and drop the user into a recovery shell
*/
[[noreturn]]
void Pii_AbortBoot() {
Pii_Log("Unable to complete preinitialization. You have been dropped into a minimal recovery environment. Good luck.");
Pii_ExecuteProgram("/Windows/System32/bash.exe");
std::exit(1);
}
int main() {
// -- just print shit --
Pii_Log("Starting Lindows Session Manager Subsystem");
// -- dynamic linking fun --
Pii_Log("Regenerating dynamic linker cache");
Pii_ExecuteProgram("/Windows/System32/ldconfig.exe");
// -- registry --
Pii_Log("Starting Lindows Registry Subsystem");
// TODO
Pii_Log("Loading Lindows registry");
// TODO
// -- swap --
Pii_Log("Creating pagefiles");
// TODO
// -- env --
Pii_Log("Setting environment variables");
// TODO
// we are never ok
Pii_AbortBoot();
return 0;
}