Exemplo n.º 1
0
static void
initialize_mandatory_interfaces (void)
{
  const struct nacl_interface *i = __start_nacl_mandatory_interface_names;
  uintptr_t *t = __start_nacl_mandatory_interface_tables;
  while (i < __stop_nacl_mandatory_interface_names)
    {
      if (__nacl_irt_query (i->name, t, i->table_size) != i->table_size)
	missing_mandatory_interface (i);

      t = next_nacl_table (t, i);
      i = next_nacl_interface (i);
    }
}
Exemplo n.º 2
0
static void
initialize_optional_interfaces (void)
{
  const struct nacl_interface *i = __start_nacl_optional_interface_names;
  uintptr_t *t = __start_nacl_optional_interface_tables;
  while (i < __stop_nacl_optional_interface_names)
    {
      size_t filled = __nacl_irt_query (i->name, t, i->table_size);
      if (filled != i->table_size)
	for (size_t slot = 0; slot < i->table_size / sizeof *t; ++slot)
	  t[slot] = (uintptr_t) &nacl_missing_optional_interface;

      t = next_nacl_table (t, i);
      i = next_nacl_interface (i);
    }
}
Exemplo n.º 3
0
void
// ARC MOD BEGIN
// Renamed from init_irt_table to __init_irt_table.
__init_irt_table (void)
// ARC MOD END
{
  union {
    struct nacl_irt_basic nacl_irt_basic;
    struct nacl_irt_fdio nacl_irt_fdio;
    struct nacl_irt_filename nacl_irt_filename;
    // ARC MOD BEGIN
    // Use nacl_irt_memory instead of nacl_irt_memory_v0_2 if 0.3 is
    // available.
    struct nacl_irt_memory nacl_irt_memory;
    // As the first element (sysbrk) of nacl_irt_memory is removed in
    // v0.3, we should have different storage for v0.1 and v0.2.
    struct nacl_irt_memory_v0_2 nacl_irt_memory_v0_2;
    // ARC MOD END
    struct nacl_irt_dyncode nacl_irt_dyncode;
    struct nacl_irt_thread nacl_irt_thread;
    struct nacl_irt_mutex nacl_irt_mutex;
    struct nacl_irt_cond nacl_irt_cond;
    struct nacl_irt_tls nacl_irt_tls;
    struct nacl_irt_resource_open nacl_irt_resource_open;
    struct nacl_irt_clock nacl_irt_clock;
    struct nacl_irt_dev_getpid nacl_irt_dev_getpid;
    struct nacl_irt_dev_fdio nacl_irt_dev_fdio;
    struct nacl_irt_dev_filename_v0_2 nacl_irt_dev_filename_v0_2;
    struct nacl_irt_dev_filename nacl_irt_dev_filename;
    // ARC MOD BEGIN
    // Add some IRT interface structures.
    struct nacl_irt_futex nacl_irt_futex;
    struct nacl_irt_dev_list_mappings nacl_irt_list_mappings;
    struct nacl_irt_icache nacl_irt_icache;
#if defined(BARE_METAL_BIONIC)
    struct bare_metal_irt_debugger bare_metal_irt_debugger;
#endif
    // ARC MOD END
  } u;

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_BASIC_v0_1, &u.nacl_irt_basic,
                        sizeof(u.nacl_irt_basic)) == sizeof(u.nacl_irt_basic))
    {
      __nacl_irt_exit = u.nacl_irt_basic.exit;
      __nacl_irt_gettod = u.nacl_irt_basic.gettod;
      __nacl_irt_clock = u.nacl_irt_basic.clock;
      __nacl_irt_nanosleep = u.nacl_irt_basic.nanosleep;
      __nacl_irt_sched_yield = u.nacl_irt_basic.sched_yield;
      __nacl_irt_sysconf = u.nacl_irt_basic.sysconf;
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END
  // ARC MOD BEGIN
  // TODO(crbug.com/242349): Getting NACL_IRT_DEV_FDIO_v0_2 always fails at
  // this point. Need to fix native_client/src/untrusted/irt/irt_interfaces.c.
  // ARC MOD END
  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_FDIO_v0_1, &u.nacl_irt_fdio,
                        sizeof(u.nacl_irt_fdio)) == sizeof(u.nacl_irt_fdio))
    {
      __nacl_irt_close = u.nacl_irt_fdio.close;
      __nacl_irt_dup = u.nacl_irt_fdio.dup;
      __nacl_irt_dup2 = u.nacl_irt_fdio.dup2;
      __nacl_irt_read = u.nacl_irt_fdio.read;
      __nacl_irt_write = u.nacl_irt_fdio.write;
      __nacl_irt_seek = u.nacl_irt_fdio.seek;
      __nacl_irt_fstat = u.nacl_irt_fdio.fstat;
      __nacl_irt_getdents = u.nacl_irt_fdio.getdents;
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END
  // ARC MOD BEGIN
  // For Bare Metal's debugger support. See crbug.com/354290
  __nacl_irt_open = not_implemented_open;
#ifdef BARE_METAL_BIONIC
  // TODO(crbug.com/354290): Remove this code.
  __nacl_irt_open_real = not_implemented_open;
#endif
  // ARC MOD END
  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_FILENAME_v0_1, &u.nacl_irt_filename,
                        sizeof(u.nacl_irt_filename)) ==
      sizeof(u.nacl_irt_filename))
    {
      __nacl_irt_open = u.nacl_irt_filename.open;
      // ARC MOD BEGIN
      // Upstream uses nacl_abi_stat as it #define stat.
      // __nacl_irt_stat = u.nacl_irt_filename.nacl_abi_stat;
      __nacl_irt_stat = u.nacl_irt_filename.stat;
    }
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END
  // ARC MOD BEGIN
  // Do not fill __nacl_irt_sysbrk and use NACL_IRT_MEMORY_v0_3.
  __nacl_irt_sysbrk = not_implemented;
  if (__nacl_irt_query &&
      __nacl_irt_query(NACL_IRT_MEMORY_v0_3, &u.nacl_irt_memory,
                       sizeof(u.nacl_irt_memory)) ==
      sizeof(u.nacl_irt_memory)) {
    __nacl_irt_mmap = u.nacl_irt_memory.mmap;
    __nacl_irt_munmap = u.nacl_irt_memory.munmap;
    __nacl_irt_mprotect = u.nacl_irt_memory.mprotect;
  }
  // Remove the fallback to direct NaCl syscalls and old IRT handling.
  // ARC MOD END

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_DYNCODE_v0_1, &u.nacl_irt_dyncode,
                        sizeof(u.nacl_irt_dyncode)) ==
      sizeof(u.nacl_irt_dyncode))
    {
      __nacl_irt_dyncode_create = u.nacl_irt_dyncode.dyncode_create;
      __nacl_irt_dyncode_modify = u.nacl_irt_dyncode.dyncode_modify;
      __nacl_irt_dyncode_delete = u.nacl_irt_dyncode.dyncode_delete;
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_THREAD_v0_1, &u.nacl_irt_thread,
                        sizeof(u.nacl_irt_thread)) ==
      sizeof(u.nacl_irt_thread))
    {
      __nacl_irt_thread_create = u.nacl_irt_thread.thread_create;
      __nacl_irt_thread_exit = u.nacl_irt_thread.thread_exit;
      __nacl_irt_thread_nice = u.nacl_irt_thread.thread_nice;
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END
  // ARC MOD BEGIN
  // Remove deprecated NACL_IRT_MUTEX and NACL_IRT_COND.
  // ARC MOD END

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_TLS_v0_1, &u.nacl_irt_tls,
                        sizeof(u.nacl_irt_tls)) == sizeof(u.nacl_irt_tls))
    {
      __nacl_irt_tls_init = u.nacl_irt_tls.tls_init;
      __nacl_irt_tls_get = u.nacl_irt_tls.tls_get;
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_RESOURCE_OPEN_v0_1, &u.nacl_irt_resource_open,
                        sizeof(u.nacl_irt_resource_open)) ==
      sizeof(u.nacl_irt_resource_open))
    {
      ___nacl_irt_open_resource = u.nacl_irt_resource_open.open_resource;
      __nacl_irt_open_resource = nacl_irt_open_resource;
#ifdef IS_IN_rtld
      if (_dl_argc == 1)
        {
          static const char *argv[] =
        {
            DL_DST_LIB "/runnable-ld.so",
            DL_DST_LIB "/main.nexe",
            0
        };
          _dl_argc = 2;
          _dl_argv = (char **)argv;
        }
#endif
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_CLOCK_v0_1, &u.nacl_irt_clock,
                        sizeof(u.nacl_irt_clock)) == sizeof(u.nacl_irt_clock))
    {
      __nacl_irt_clock_getres = u.nacl_irt_clock.clock_getres;
      __nacl_irt_clock_gettime = u.nacl_irt_clock.clock_gettime;
    }
  // ARC MOD BEGIN
  // Remove the fallback to direct NaCl syscalls.
  // ARC MOD END

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_DEV_GETPID_v0_1, &u.nacl_irt_dev_getpid,
                        sizeof(u.nacl_irt_dev_getpid)) ==
      sizeof(u.nacl_irt_dev_getpid))
    {
      __nacl_irt_getpid = u.nacl_irt_dev_getpid.getpid;
    }
  else
    {
      __nacl_irt_getpid = not_implemented;
    }
  // ARC MOD BEGIN
  // TODO(crbug.com/242349): Getting NACL_IRT_DEV_FDIO_v0_2 always
  // fails at this point. For SFI NaCl, we should be able to use v0_3
  // interface, but this is not ready in non-SFI mode.
  // ARC MOD END
  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_DEV_FDIO_v0_2, &u.nacl_irt_dev_fdio,
                        sizeof(u.nacl_irt_dev_fdio)) ==
      sizeof(u.nacl_irt_dev_fdio))
    {
      __nacl_irt_fchdir = u.nacl_irt_dev_fdio.fchdir;
      __nacl_irt_fchmod = u.nacl_irt_dev_fdio.fchmod;
      __nacl_irt_fsync = u.nacl_irt_dev_fdio.fsync;
      __nacl_irt_fdatasync = u.nacl_irt_dev_fdio.fdatasync;
      __nacl_irt_ftruncate = u.nacl_irt_dev_fdio.ftruncate;
    }
  else
    {
      __nacl_irt_fchdir = not_implemented;
      // ARC MOD BEGIN
      // Add a cast. We need this because mode_t is a short and GCC
      // thinks this is incompatible with variable args.
      __nacl_irt_fchmod = (int (*)(int, mode_t))not_implemented;
      // ARC MOD END
      __nacl_irt_fsync = not_implemented;
      __nacl_irt_fdatasync = not_implemented;
      __nacl_irt_ftruncate = not_implemented;
    }

  if (__nacl_irt_query &&
      __nacl_irt_query (NACL_IRT_DEV_FILENAME_v0_3, &u.nacl_irt_dev_filename,
                        sizeof(u.nacl_irt_dev_filename)) ==
      sizeof(u.nacl_irt_dev_filename))
    {
      // ARC MOD BEGIN
      __nacl_irt_open = u.nacl_irt_dev_filename.open;
      // For Bare Metal's debugger support. See crbug.com/354290
#ifdef BARE_METAL_BIONIC
      // TODO(crbug.com/354290): Remove this code.
      __nacl_irt_open_real = u.nacl_irt_dev_filename.open;
#endif
      // Upstream uses nacl_abi_stat as it #define stat.
      // __nacl_irt_stat = u.nacl_irt_filename.nacl_abi_stat;
      __nacl_irt_stat = u.nacl_irt_filename.stat;
      // ARC MOD END
      __nacl_irt_mkdir = u.nacl_irt_dev_filename.mkdir;
      __nacl_irt_chdir = u.nacl_irt_dev_filename.chdir;
      __nacl_irt_rmdir = u.nacl_irt_dev_filename.rmdir;
      __nacl_irt_getcwd = u.nacl_irt_dev_filename.getcwd;
      __nacl_irt_unlink = u.nacl_irt_dev_filename.unlink;
      __nacl_irt_truncate = u.nacl_irt_dev_filename.truncate;
      __nacl_irt_lstat = u.nacl_irt_dev_filename.lstat;
      __nacl_irt_link = u.nacl_irt_dev_filename.link;
      __nacl_irt_rename = u.nacl_irt_dev_filename.rename;
      __nacl_irt_symlink = u.nacl_irt_dev_filename.symlink;
      __nacl_irt_chmod = u.nacl_irt_dev_filename.chmod;
      __nacl_irt_access = u.nacl_irt_dev_filename.access;
      __nacl_irt_readlink = u.nacl_irt_dev_filename.readlink;
      __nacl_irt_utimes = u.nacl_irt_dev_filename.utimes;
    }
  else if (__nacl_irt_query &&
           __nacl_irt_query (NACL_IRT_DEV_FILENAME_v0_2,
                             &u.nacl_irt_dev_filename_v0_2,
                             sizeof(u.nacl_irt_dev_filename_v0_2)) ==
           sizeof(u.nacl_irt_dev_filename_v0_2))
    {
      __nacl_irt_mkdir = u.nacl_irt_dev_filename_v0_2.mkdir;
      __nacl_irt_chdir = u.nacl_irt_dev_filename_v0_2.chdir;
      __nacl_irt_rmdir = u.nacl_irt_dev_filename_v0_2.rmdir;
      __nacl_irt_getcwd = u.nacl_irt_dev_filename_v0_2.getcwd;
      __nacl_irt_unlink = u.nacl_irt_dev_filename_v0_2.unlink;
      __nacl_irt_truncate = not_implemented;
      __nacl_irt_lstat = not_implemented;
      __nacl_irt_link = not_implemented;
      __nacl_irt_rename = not_implemented;
      __nacl_irt_symlink = not_implemented;
      // ARC MOD BEGIN
      // Add a cast. We need this because mode_t is a short and GCC
      // thinks this is incompatible with variable args.
      __nacl_irt_chmod = (int (*)(const char *, mode_t))not_implemented;
      // ARC MOD END
      __nacl_irt_access = not_implemented;
      __nacl_irt_readlink = not_implemented;
      __nacl_irt_utimes = not_implemented;
    }
  else
    {
      // ARC MOD BEGIN
      // Add a cast. We need this because mode_t is a short and GCC
      // thinks this is incompatible with variable args.
      __nacl_irt_mkdir = (int (*)(const char *, mode_t))not_implemented;
      // ARC MOD END
      __nacl_irt_chdir = not_implemented;
      __nacl_irt_rmdir = not_implemented;
      __nacl_irt_getcwd = not_implemented;
      __nacl_irt_unlink = not_implemented;
      __nacl_irt_truncate = not_implemented;
      __nacl_irt_lstat = not_implemented;
      __nacl_irt_link = not_implemented;
      __nacl_irt_rename = not_implemented;
      __nacl_irt_symlink = not_implemented;
      // ARC MOD BEGIN
      // Add a cast. We need this because mode_t is a short and GCC
      // thinks this is incompatible with variable args.
      __nacl_irt_chmod = (int (*)(const char *, mode_t))not_implemented;
      // ARC MOD END
      __nacl_irt_access = not_implemented;
      __nacl_irt_readlink = not_implemented;
      __nacl_irt_utimes = not_implemented;
    }
  // ARC MOD BEGIN
  // Get __nacl_irt_list_mappings.
  if (__nacl_irt_query &&
      __nacl_irt_query(NACL_IRT_DEV_LIST_MAPPINGS_v0_1,
                       &u.nacl_irt_list_mappings,
                       sizeof(u.nacl_irt_list_mappings)) ==
      sizeof(u.nacl_irt_list_mappings)) {
    __nacl_irt_list_mappings = u.nacl_irt_list_mappings.list_mappings;
  }
  // Get futex functions.
  if (__nacl_irt_query &&
      __nacl_irt_query(NACL_IRT_FUTEX_v0_1,
                       &u.nacl_irt_futex,
                       sizeof(u.nacl_irt_futex)) ==
      sizeof(u.nacl_irt_futex)) {
    __nacl_irt_futex_wait_abs = u.nacl_irt_futex.futex_wait_abs;
    __nacl_irt_futex_wake = u.nacl_irt_futex.futex_wake;
  }
  // Get __nacl_irt_clear_cache.
  // __nacl_irt_clear_cache is supported only for Non-SFI NaCl on ARM.
  __nacl_irt_clear_cache = not_implemented;
  if (__nacl_irt_query &&
      __nacl_irt_query(NACL_IRT_ICACHE_v0_1,
                       &u.nacl_irt_icache,
                       sizeof(u.nacl_irt_icache)) ==
      sizeof(u.nacl_irt_icache)) {
    __nacl_irt_clear_cache = u.nacl_irt_icache.clear_cache;
  }
  // ARC MOD END
  // ARC MOD BEGIN
  // Add Bare Metal specific interfaces.
#if defined(BARE_METAL_BIONIC)
  if (__nacl_irt_query &&
      __nacl_irt_query(BARE_METAL_IRT_DEBUGGER_v0_1,
                       &u.bare_metal_irt_debugger,
                       sizeof(u.bare_metal_irt_debugger)) ==
      sizeof(u.bare_metal_irt_debugger)) {
    __bare_metal_irt_notify_gdb_of_load =
        u.bare_metal_irt_debugger.notify_gdb_of_load;
    __bare_metal_irt_notify_gdb_of_unload =
        u.bare_metal_irt_debugger.notify_gdb_of_unload;
    __bare_metal_irt_notify_gdb_of_libraries =
        u.bare_metal_irt_debugger.notify_gdb_of_libraries;
  }
#endif
  // ARC MOD END

  __nacl_irt_epoll_create = not_implemented;
  __nacl_irt_epoll_create1 = not_implemented;
  __nacl_irt_epoll_ctl = not_implemented;
  __nacl_irt_epoll_pwait = not_implemented;
  __nacl_irt_epoll_wait = not_implemented;
  __nacl_irt_poll = not_implemented;
  __nacl_irt_ppoll = not_implemented;
  __nacl_irt_socket = not_implemented;
  __nacl_irt_accept = not_implemented;
  __nacl_irt_bind = not_implemented;
  __nacl_irt_listen = not_implemented;
  __nacl_irt_connect = not_implemented;
  __nacl_irt_send = not_implemented;
  __nacl_irt_sendmsg = not_implemented;
  __nacl_irt_sendto = not_implemented;
  __nacl_irt_recv = not_implemented;
  __nacl_irt_recvmsg = not_implemented;
  __nacl_irt_recvfrom = not_implemented;
  __nacl_irt_select = not_implemented;
  __nacl_irt_pselect = not_implemented;
  __nacl_irt_getpeername = not_implemented;
  __nacl_irt_getsockname = not_implemented;
  __nacl_irt_getsockopt = not_implemented;
  __nacl_irt_setsockopt = not_implemented;
  __nacl_irt_socketpair = not_implemented;
  __nacl_irt_shutdown = not_implemented;
  // ARC MOD BEGIN
  // Initialize __nacl_irt_write_real.
  __nacl_irt_write_real = __nacl_irt_write;
  // ARC MOD END
}