Files
Michał Kowalczyk d53729b201 [Pal] Rework manifest loading
This is a major refactor of the way manifests are loaded and handled,
which will be followed by a complete rework of the loader code (which
will include e.g. centralized config).

Changes/fixes:
- Huge part of manifest handling was refactored and untangled.
- Starting without a manifest is now disallowed. This was actually
  accidentally broken for some time and no one complained. It also makes
  little sense in practice and in Graphene's overall design, e.g. it
  conflicts with protected argv.
- Now we only allow starting by giving the executable, not manifest (the
  magic resolution logic was removed).
- Now manifests are sent over pipes between parent and children, instead
  of children finding and loading them on their own. This is a
  preparation for the upcoming centralized manifests change.
- Previously manifests were parsed 2 times on Linux and 3 times on
  Linux-SGX (by untrusted PAL, trusted PAL and LibOS). This is now
  fixed.
- The common `pal_main()` now requires that the backend-specific PAL
  loader loads the manifest before calling it. SGX code already has to
  do it (for proper initialization), so let's unify this interface for
  all PALs.
- Fix for a PAL crash when manifest size was divisible by page size
  (sic!). NULL termination was missing, but most of the time the padding
  to page size saved Graphene from crashing.
2020-12-05 01:46:03 +01:00

58 lines
1.7 KiB
C

#include "api.h"
#include "pal.h"
#include "pal_debug.h"
int main(int argc, char** argv, char** envp) {
char buffer1[20] = "Hello World 1", buffer2[20] = "Hello World 2";
char buffer3[20], buffer4[20];
int ret;
if (argc > 1 && !memcmp(argv[1], "Child", 6)) {
pal_printf("Child Process Created\n");
/* check arguments */
pal_printf("# of Arguments: %d\n", argc);
for (int i = 0; i < argc; i++) {
pal_printf("argv[%d] = %s\n", i, argv[i]);
}
DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
ret = DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
if (ret > 0)
pal_printf("Process Write 1 OK\n");
ret = DkStreamRead(pal_control.parent_process, 0, 20, buffer4, NULL, 0);
if (ret > 0)
pal_printf("Process Read 2: %s\n", buffer4);
} else {
PAL_STR args[3] = {"Process", "Child", 0};
PAL_HANDLE children[3];
for (int i = 0; i < 3; i++) {
pal_printf("Creating process\n");
children[i] = DkProcessCreate("file:Process", args);
if (children[i]) {
pal_printf("Process created %d\n", i + 1);
DkStreamRead(children[i], 0, 20, buffer4, NULL, 0);
}
}
for (int i = 0; i < 3; i++)
if (children[i]) {
ret = DkStreamRead(children[i], 0, 20, buffer3, NULL, 0);
if (ret > 0)
pal_printf("Process Read 1: %s\n", buffer3);
ret = DkStreamWrite(children[i], 0, 20, buffer2, NULL);
if (ret > 0)
pal_printf("Process Write 2 OK\n");
}
}
return 0;
}