Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(725)

Unified Diff: gold/nacl_file.cc

Issue 770833002: Gold translator: Use IRT open_resource instead of SRPC conn to nameservice. (Closed) Base URL: https://chromium.googlesource.com/native_client/nacl-binutils.git@master
Patch Set: cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gold/nacl_file.cc
diff --git a/gold/nacl_file.cc b/gold/nacl_file.cc
index 7610116fe405cc680d9cbf4a98138b5fb12caa13..b90cd960a9fcbed7579057fcd2a04af3553d0a46 100644
--- a/gold/nacl_file.cc
+++ b/gold/nacl_file.cc
@@ -33,8 +33,7 @@
#include <unistd.h>
#include <vector>
-#include "native_client/src/public/imc_syscalls.h"
-#include "native_client/src/public/name_service.h"
+#include "native_client/src/untrusted/irt/irt.h"
Mark Seaborn 2014/12/01 19:26:43 I believe this can be #included as <irt.h>, which
jvoung (off chromium) 2014/12/01 20:35:19 Done.
#include "native_client/src/shared/srpc/nacl_srpc.h"
#include "gold.h"
@@ -55,13 +54,8 @@ namespace
{
std::map<std::string, int> g_preopened_files;
-// Register some filename -> fd mappings so that we do not
-// need to use the ManifestNameService (aka directory) service.
-// Note, there seems to be the following convention:
-// the directory service knows about files like "files/<filename>".
-// Locally, we refer to the files as <filename>.
-// For object files passed in via Srpc, we register the incoming .o
-// descriptor as FILENAME_OBJ WITHOUT the "files/" prefix.
+// Register some filename -> fd mappings that correspond to pre-opened fds.
+// Otherwise files are opened via the IRT open_resource() function.
void RegisterPreopenedFd(const char* filename, int fd) {
std::string key(filename);
std::map<std::string, int>::iterator it = g_preopened_files.find(key);
@@ -74,73 +68,22 @@ void RegisterPreopenedFd(const char* filename, int fd) {
}
}
-// Look up additional resource files through the nacl manifest service
-// which essentially maps a (file)name to a (file)descriptor
-NaClSrpcChannel g_nacl_manifest_channel;
-
-// Make ManifestNameService service available for lookups.
-void ManifestLookupInit() {
- int nameservice_address = -1;
- int nameservice_fd = -1;
- int manifest_address = -1;
- int manifest_fd = -1;
- int status;
- NaClSrpcChannel nameservice_channel;
-
- /* Attach to the reverse service for doing manifest file queries. */
- nacl_nameservice(&nameservice_address);
- if (nameservice_address == -1) {
- gold_fatal(_("nacl_nameservice failed\n"));
- }
- nameservice_fd = imc_connect(nameservice_address);
- close(nameservice_address);
- if (nameservice_fd == -1) {
- gold_fatal(_("name service connect failed\n"));
- }
- if (!NaClSrpcClientCtor(&nameservice_channel, nameservice_fd)) {
- gold_fatal(_("name service channel ctor failed\n"));
- }
- if (NACL_SRPC_RESULT_OK !=
- NaClSrpcInvokeBySignature(&nameservice_channel, NACL_NAME_SERVICE_LOOKUP,
- "ManifestNameService", O_RDWR,
- &status, &manifest_address)) {
- gold_fatal(_("ManifestNameService SRPC failed, status %d\n"), status);
- }
- NaClSrpcDtor(&nameservice_channel);
- if (manifest_address == -1) {
- gold_fatal(_("manifest name service address is -1\n"));
- }
- manifest_fd = imc_connect(manifest_address);
- close(manifest_address);
- if (manifest_fd == -1) {
- gold_fatal(_("manifest name service connect failed\n"));
- }
- if (!NaClSrpcClientCtor(&g_nacl_manifest_channel, manifest_fd)) {
- gold_fatal(_("manifest channel ctor failed\n"));
- }
-}
+static struct nacl_irt_resource_open g_irt_resource_open;
Mark Seaborn 2014/12/01 19:26:43 "static" not neeed -- this is inside an anon names
jvoung (off chromium) 2014/12/01 20:35:19 Done.
-void ManifestLookupFini() {
- NaClSrpcDtor(&g_nacl_manifest_channel);
+// Set up interfaces for IRT open_resource.
+void GetIRTInterface() {
+ size_t query_result = nacl_interface_query(
+ NACL_IRT_RESOURCE_OPEN_v0_1,
+ &g_irt_resource_open, sizeof(g_irt_resource_open));
+ if (query_result != sizeof(g_irt_resource_open)) {
+ gold_fatal(_("nacl_file::GetIRTInterface failed"));
+ }
}
-const int kUnknownFd = -1;
-
-int LookupFileByName(const char* filename) {
- int fd = kUnknownFd;
- int status;
- // Files looked up via the nameservice are assumed to have a "files/" prefix.
- std::string prefix("files/");
- std::string full_filename = prefix + std::string(filename);
- NaClSrpcError error =
- NaClSrpcInvokeBySignature(&g_nacl_manifest_channel,
- NACL_NAME_SERVICE_LOOKUP,
- full_filename.c_str(),
- O_RDONLY,
- &status,
- &fd);
- if (error != NACL_SRPC_RESULT_OK) {
- gold_fatal(_("Lookup (%s) failed.\n"), filename);
+int IrtOpenFile(const char* filename) {
+ int fd = -1;
+ if (int res = g_irt_resource_open.open_resource(filename, &fd)) {
+ gold_fatal(_("IrtOpenFile (%s) failed: %d\n"), filename, res);
}
return fd;
}
@@ -161,8 +104,7 @@ void RunCommon(const std::vector<std::string>& arg_vec,
done->Run(done);
}
-
-// c.f.: pnacl/driver/pnacl-nativeld.py
+// c.f.: pnacl/driver/nativeld.py
const char* kDefaultCommandCommon[] = {
"gold",
"--eh-frame-hdr",
@@ -258,23 +200,24 @@ SrpcRunWithSplit(NaClSrpcRpc* rpc,
RunCommon(result_arg_vec, rpc, done);
}
-} // End namespace gold.
+} // End anonymous namespace.
namespace nacl_file
{
-// This is the only exported API from this file
int NaClOpenFileDescriptor(const char *filename) {
std::string key(filename);
std::map<std::string, int>::iterator it = g_preopened_files.find(key);
int fd;
+ // First check if it is a pre-opened file.
if (it != g_preopened_files.end()) {
fd = it->second;
} else {
- // Otherwise, ask the nameservice.
- fd = LookupFileByName(filename);
+ // Otherwise, open the file through the IRT.
+ fd = IrtOpenFile(filename);
}
- // in case the file was re-opened, say to do --start/end-group
+ // In case the file was re-opened, seek back to the beginning.
+ // This might be the case for the --start/end-group implementation.
lseek(fd, 0, SEEK_SET);
return fd;
}
@@ -289,13 +232,11 @@ void NaClReleaseFileDescriptor(int fd) {
} // End namespace nacl_file.
-int
-main()
-{
+int main() {
if (!NaClSrpcModuleInit()) {
gold_fatal(_("NaClSrpcModuleInit failed\n"));
}
- ManifestLookupInit();
+ GetIRTInterface();
// Start the message loop to process SRPCs.
// It usually never terminates unless killed.
@@ -308,7 +249,6 @@ main()
gold_fatal(_("NaClSrpcAcceptClientConnection failed\n"));
}
- ManifestLookupFini();
NaClSrpcModuleFini();
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698