Index: src/untrusted/irt/irt_pnacl_translator_compile.c |
diff --git a/src/untrusted/irt/irt_pnacl_translator_compile.c b/src/untrusted/irt/irt_pnacl_translator_compile.c |
new file mode 100644 |
index 0000000000000000000000000000000000000000..317366bdfbb8987d2d4235dcb0032fdf30096e35 |
--- /dev/null |
+++ b/src/untrusted/irt/irt_pnacl_translator_compile.c |
@@ -0,0 +1,103 @@ |
+/* |
+ * Copyright (c) 2015 The Native Client 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 "native_client/src/shared/platform/nacl_log.h" |
+#include "native_client/src/shared/srpc/nacl_srpc.h" |
+#include "native_client/src/untrusted/irt/irt_dev.h" |
+#include "native_client/src/untrusted/irt/irt_interfaces.h" |
+ |
+#include <string.h> |
+ |
+static const int kMaxObjectFiles = 16; |
+ |
+static const struct irt_pnacl_compile_funcs *g_funcs; |
+ |
+static void stream_init_with_split( |
+ NaClSrpcRpc *rpc, NaClSrpcArg **in_args, |
+ NaClSrpcArg **out_args, NaClSrpcClosure *done) { |
+ int num_threads = in_args[0]->u.ival; |
+ if (num_threads < 0 || num_threads > kMaxObjectFiles) { |
+ NaClLog(LOG_FATAL, "Invalid # of threads (%d)\n", num_threads); |
+ } |
+ int num_valid_fds = 0; |
+ int fd_start = 1; |
+ int obj_fds[kMaxObjectFiles]; |
+ for (int i = fd_start; i < kMaxObjectFiles + fd_start; i++) { |
+ int fd = in_args[i]->u.hval; |
+ obj_fds[i - fd_start] = fd; |
+ if (fd >= 0) |
+ ++num_valid_fds; |
Mark Seaborn
2015/03/26 20:39:00
This is odd...
If you get "-1, 100, -1, -1, ..."
jvoung (off chromium)
2015/03/26 22:30:12
True -- simplified to stop on the first fd < 0.
|
+ else |
+ break; |
+ } |
+ const char *cmd_line = in_args[kMaxObjectFiles + fd_start]->arrays.carr; |
+ size_t cmd_line_len = in_args[kMaxObjectFiles + fd_start]->u.count; |
+ int result = g_funcs->init_callback(num_threads, obj_fds, num_valid_fds, |
+ cmd_line, cmd_line_len); |
+ rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; |
+ /* TODO(jvoung): figure out how to get an error message out. */ |
Mark Seaborn
2015/03/26 20:39:00
The lack of error reporting means we can't switch
Derek Schuff
2015/03/26 22:29:35
It's deferred.
Today errors during translation cau
jvoung (off chromium)
2015/03/26 22:30:12
Okay fair enough -- might as well add it now inste
|
+ if (result) |
+ out_args[0]->arrays.str = strdup("There was some sort of error"); |
+ else |
+ out_args[0]->arrays.str = strdup("no error"); |
+ done->Run(done); |
+} |
+ |
+static void stream_chunk(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, |
+ NaClSrpcArg **out_args, NaClSrpcClosure *done) { |
+ int result = g_funcs->data_callback( |
+ (unsigned char *)in_args[0]->arrays.carr, |
Mark Seaborn
2015/03/26 20:39:00
Nit: NaCl cast style is "(type) expr", with a spac
jvoung (off chromium)
2015/03/26 22:30:12
Done. (not needed w/ the void * signature)
|
+ in_args[0]->u.count); |
+ rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; |
+ done->Run(done); |
+} |
+ |
+static void stream_end(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, |
+ NaClSrpcArg **out_args, NaClSrpcClosure *done) { |
+ int result = g_funcs->end_callback(); |
+ rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; |
+ /* Fill in the deprecated return values with dummy values. */ |
+ out_args[0]->u.ival = 0; |
+ out_args[1]->arrays.str = strdup(""); |
+ out_args[2]->arrays.str = strdup(""); |
+ /* TODO(jvoung): figure out how to get an error message out. */ |
+ if (result) |
+ out_args[3]->arrays.str = strdup("There was some sort of error"); |
+ else |
+ out_args[3]->arrays.str = strdup("no error"); |
+ done->Run(done); |
+} |
+ |
+static const struct NaClSrpcHandlerDesc srpc_methods[] = { |
+ /* |
+ * Protocol for streaming: |
+ * StreamInitWithSplit(num_threads, obj_fd x 16, cmdline_flags) -> error_str |
+ * StreamChunk(data) + |
+ * TODO(jvoung): remove these is_shared_lib, etc. |
+ * StreamEnd() -> (is_shared_lib, soname,dependencies, error_str) |
Mark Seaborn
2015/03/26 20:39:00
Nit: add space after ','
jvoung (off chromium)
2015/03/26 22:30:12
Done.
|
+ */ |
+ { "StreamInitWithSplit:ihhhhhhhhhhhhhhhhC:s", stream_init_with_split }, |
+ { "StreamChunk:C:", stream_chunk }, |
+ { "StreamEnd::isss", stream_end }, |
+ { NULL, NULL }, |
+}; |
+ |
+static void serve_translate_request( |
+ const struct irt_pnacl_compile_funcs *funcs) { |
+ g_funcs = funcs; |
+ if (!NaClSrpcModuleInit()) { |
+ NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); |
+ } |
+ if (!NaClSrpcAcceptClientConnection(srpc_methods)) { |
+ NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n"); |
+ } |
+ NaClSrpcModuleFini(); |
Mark Seaborn
2015/03/26 20:39:00
Nit: you might want to make _compile & _link.c con
jvoung (off chromium)
2015/03/26 22:30:12
Added check for NaClSrpcAcceptClientConnection() t
|
+} |
+ |
+const struct nacl_irt_private_pnacl_translator_compile |
+ nacl_irt_private_pnacl_translator_compile = { |
+ serve_translate_request |
+}; |