Commit 1139c6c2 authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Initial implementation of IRT for non-SFI mode.

This CL implements the mechanism to pass an irt querying function to the plugin
process via AT_SYSINFO. Also, as the first step to implement many irt functions
for non-SFI mode, this CL introduces nacl_irt_basic.

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3734
TEST=Tried to call a newly added function from plugin via AT_SYSINFO.

Review URL: https://codereview.chromium.org/125533004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244144 0039d316-1c4b-4281-b951-d872f2087c98
parent de2be454
......@@ -192,6 +192,9 @@
'nacl/loader/nacl_sandbox_linux.cc',
'nacl/loader/nonsfi/elf_loader.cc',
'nacl/loader/nonsfi/elf_loader.h',
'nacl/loader/nonsfi/irt_basic.cc',
'nacl/loader/nonsfi/irt_interfaces.cc',
'nacl/loader/nonsfi/irt_interfaces.h',
'nacl/loader/nonsfi/nonsfi_main.cc',
'nacl/loader/nonsfi/nonsfi_main.h',
'../base/posix/unix_domain_socket_linux.cc',
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <errno.h>
#include <sched.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "native_client/src/trusted/service_runtime/include/sys/time.h"
#include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
namespace nacl {
namespace nonsfi {
namespace {
void IrtExit(int status) {
_exit(status);
}
int IrtGetToD(struct nacl_abi_timeval* tv) {
struct timeval host_tv;
if (gettimeofday(&host_tv, NULL))
return errno;
tv->nacl_abi_tv_sec = host_tv.tv_sec;
tv->nacl_abi_tv_usec = host_tv.tv_usec;
return 0;
}
int IrtClock(nacl_abi_clock_t* ticks) {
// There is no definition of errno when clock is failed.
// So we assume it always succeeds.
*ticks = clock();
return 0;
}
int IrtNanoSleep(const struct nacl_abi_timespec* req,
struct nacl_abi_timespec* rem) {
struct timespec host_req;
host_req.tv_sec = req->tv_sec;
host_req.tv_nsec = req->tv_nsec;
struct timespec host_rem;
if (nanosleep(&host_req, &host_rem))
return errno;
if (rem) {
rem->tv_sec = host_rem.tv_sec;
rem->tv_nsec = host_rem.tv_nsec;
}
return 0;
}
int IrtSchedYield() {
if (sched_yield())
return errno;
return 0;
}
int IrtSysconf(int name, int* value) {
int result;
switch (name) {
case NACL_ABI__SC_NPROCESSORS_ONLN:
errno = 0;
result = sysconf(_SC_NPROCESSORS_ONLN);
break;
case NACL_ABI__SC_PAGESIZE:
errno = 0;
result = sysconf(_SC_PAGESIZE);
break;
default:
return EINVAL;
}
if (result == -1 && errno == EINVAL)
return EINVAL;
*value = result;
return 0;
}
} // namespace
// For gettod, clock and nanosleep, their argument types should be nacl_abi_X,
// rather than host type, such as timeval or clock_t etc. However, the
// definition of nacl_irt_basic uses host types, so here we need to cast them.
const nacl_irt_basic kIrtBasic = {
IrtExit,
reinterpret_cast<int(*)(struct timeval*)>(IrtGetToD),
reinterpret_cast<int(*)(clock_t*)>(IrtClock),
reinterpret_cast<int(*)(const struct timespec*, struct timespec*)>(
IrtNanoSleep),
IrtSchedYield,
IrtSysconf,
};
} // namespace nonsfi
} // namespace nacl
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include <cstring>
namespace nacl {
namespace nonsfi {
namespace {
// This table keeps a pair of IRT entry (such as nacl_irt_basic, nacl_irt_fdio
// etc.) and its registered name with its version (such as NACL_IRT_BASIC_v0_1,
// NACL_IRT_FDIO_v0_1, etc.).
struct NaClInterfaceTable {
const char* name;
const void* table;
size_t size;
};
#define NACL_INTERFACE_TABLE(name, value) { name, &value, sizeof(value) }
const NaClInterfaceTable kIrtInterfaces[] = {
NACL_INTERFACE_TABLE(NACL_IRT_BASIC_v0_1, kIrtBasic),
};
#undef NACL_INTERFACE_TABLE
} // namespace
size_t NaClIrtInterface(const char* interface_ident,
void* table, size_t tablesize) {
for (size_t i = 0; i < arraysize(kIrtInterfaces); ++i) {
if (std::strcmp(interface_ident, kIrtInterfaces[i].name) == 0) {
const size_t size = kIrtInterfaces[i].size;
if (size <= tablesize) {
std::memcpy(table, kIrtInterfaces[i].table, size);
return size;
}
break;
}
}
return 0;
}
} // namespace nonsfi
} // namespace nacl
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_NACL_LOADER_NONSFI_IRT_INTERFACES_H_
#define COMPONENTS_NACL_LOADER_NONSFI_IRT_INTERFACES_H_
#include "base/basictypes.h"
#include "native_client/src/untrusted/irt/irt.h"
namespace nacl {
namespace nonsfi {
size_t NaClIrtInterface(const char* interface_ident,
void* table, size_t tablesize);
extern const struct nacl_irt_basic kIrtBasic;
} // namespace nonsfi
} // namespace nacl
#endif // COMPONENTS_NACL_LOADER_NONSFI_IRT_INTERFACES_H_
......@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "components/nacl/loader/nonsfi/elf_loader.h"
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "native_client/src/include/elf_auxv.h"
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/public/secure_service.h"
......@@ -55,6 +56,8 @@ void LoadModuleRpc(struct NaClSrpcRpc* rpc,
0, // argc.
0, // Null terminate for argv.
0, // Null terminate for envv.
AT_SYSINFO,
reinterpret_cast<uintptr_t>(&NaClIrtInterface),
AT_NULL,
0, // Null terminate for auxv.
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment