crt0.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * crt0.c
  3. *
  4. * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <monolithium.h>
  22. int __crt_initialize_heap(void);
  23. int __crt_initialize_files(process_params_t *params);
  24. int main(int argc, char **argv);
  25. void process_startup(process_params_t *params)
  26. {
  27. int argc = 1;
  28. char *ptr;
  29. int space = 1;
  30. if (__crt_initialize_heap() < 0) syscall_terminate(INVALID_HANDLE, 255);
  31. if (__crt_initialize_files(params) < 0) syscall_terminate(INVALID_HANDLE, 255);
  32. for (ptr = params->command_line; *ptr; ptr++)
  33. {
  34. if (space != (isspace(*ptr) != 0))
  35. {
  36. argc++;
  37. space = !space;
  38. }
  39. }
  40. char **argv = (char**)__builtin_alloca(argc * sizeof(char*));
  41. argc = 0;
  42. for (ptr = strtok(params->command_line, " \t\r\n\v\f"); ptr != NULL; ptr = strtok(NULL, " \t\r\n\v\f"))
  43. {
  44. if (*ptr) argv[argc++] = ptr;
  45. }
  46. argv[argc] = NULL;
  47. int exit_code = main(argc, argv);
  48. exit(exit_code);
  49. }