Exemplo n.º 1
0
Arquivo: crt0.c Projeto: jakre/sulong
int _start(int type, char *application_path_java_byte_array) {
  long *p = __sulong_start_arguments;
  int argc = p[0];
  char **argv = (void *)(p + 1);
  char **envp = argv + argc + 1;

  int envc = 0;
  char **ptr;
  for (ptr = envp; *ptr; ptr++) {
    envc++;
  }

  environ = envp;
  __auxv = (Elf64_auxv_t *)(envp + envc + 1);

  // update the application path now that we know it
  char *application_path = __sulong_byte_array_to_native(application_path_java_byte_array);
  __sulong_update_application_path(application_path, argv, __auxv);

  switch (type) {
  /* C/C++/... */
  default:
  case 0:
    exit(main(argc, argv, envp));
    break;
  /* Rust */
  case 1: {
    long (*i64main)(long argc, char **argv) = (long (*)(long, char **))main;
    exit(i64main(argc, argv));
    break;
  }
  /* non-standard C: void main(int, char**, char**) */
  case 2: {
    void (*vmain)(int argc, char **argv, char **envp) = (void (*)(int, char **, char **))main;
    vmain(argc, argv, envp);
    exit(0);
    break;
  }
  /* non-standard C: char main(int, char**, char**) */
  case 3: {
    char (*i8main)(int argc, char **argv, char **envp) = (char (*)(int, char **, char **))main;
    exit(i8main(argc, argv, envp));
    break;
  }
  /* non-standard C: short main(int, char**, char**) */
  case 4: {
    short (*i16main)(int argc, char **argv, char **envp) = (short (*)(int, char **, char **))main;
    exit(i16main(argc, argv, envp));
    break;
  }
  /* non-standard C: long main(int, char**, char**) */
  case 5: {
    long (*i64main)(int argc, char **argv, char **envp) = (long (*)(int, char **, char **))main;
    exit(i64main(argc, argv, envp));
    break;
  }
  }
  abort();
}
Exemplo n.º 2
0
__attribute__((weak)) int _start(long *p, int type) {
  int argc = p[0];
  char **argv = (void *)(p + 1);
  char **envp = argv + argc + 1;

  int envc = 0;
  char **ptr;
  for (ptr = envp; *ptr; ptr++) {
    envc++;
  }

  __auxv = (Elf64_auxv_t *)(envp + envc + 1);

  switch (type) {
  /* C/C++/... */
  default:
  case 0:
    exit(main(argc, argv, envp));
    break;
  /* Rust */
  case 1: {
    long (*i64main)(long argc, char **argv) = (long (*)(long, char **))main;
    exit(i64main(argc, argv));
    break;
  }
  }
  abort();
}