Chromium Code Reviews| Index: src/untrusted/irt/irt_pnacl_translator_subzero.c |
| diff --git a/src/untrusted/irt/irt_pnacl_translator_subzero.c b/src/untrusted/irt/irt_pnacl_translator_subzero.c |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2eabaa45559cf57df96382293856f7ae82ff24e3 |
| --- /dev/null |
| +++ b/src/untrusted/irt/irt_pnacl_translator_subzero.c |
| @@ -0,0 +1,101 @@ |
| +/* |
| + * 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 PNaClSubzeroFunctions *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 < 1) { |
| + NaClLog(LOG_FATAL, "Invalid # of threads (%d)\n", num_threads); |
| + } |
| + /* |
| + * Only one object file is needed for subzero. |
|
Jim Stichnoth
2015/03/23 18:13:40
Subzero
JF
2015/03/23 18:33:54
SubZero.
/TroLol
jvoung (off chromium)
2015/03/23 21:18:55
Acknowledged.
|
| + * The others must be left empty and the linker must tolerate empty files. |
| + */ |
| + int obj_fd = in_args[1]->u.hval; |
| + const char *cmd_line = in_args[kMaxObjectFiles + 1]->arrays.carr; |
| + size_t cmd_line_len = in_args[kMaxObjectFiles + 1]->u.count; |
| + int result = g_funcs->init_callback(num_threads, obj_fd, |
| + cmd_line, cmd_line_len); |
| + rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; |
| + /* Currently, errors are logged via log_fatal instead of returned. */ |
| + 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, |
| + 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; |
| + out_args[0]->u.ival = 0; |
| + out_args[1]->arrays.str = strdup(""); |
| + out_args[2]->arrays.str = strdup(""); |
| + /* Currently, errors are logged via log_fatal instead of returned. */ |
| + 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); |
| +} |
| + |
| +const struct NaClSrpcHandlerDesc srpc_methods[] = { |
|
Mark Seaborn
2015/03/23 18:18:36
Nit: add "static"
jvoung (off chromium)
2015/03/23 21:18:55
Done.
|
| + /* |
| + * 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) |
| + */ |
| + { "StreamInitWithSplit:ihhhhhhhhhhhhhhhhC:s", stream_init_with_split }, |
| + { "StreamChunk:C:", stream_chunk }, |
| + { "StreamEnd::isss", stream_end }, |
| + { NULL, NULL }, |
| +}; |
| + |
| +static void serve_translate_request( |
| + const struct PNaClSubzeroFunctions *funcs) { |
| + g_funcs = funcs; |
| + if (!NaClSrpcModuleInit()) { |
| + NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); |
| + } |
| + if (!NaClSrpcAcceptClientConnection(srpc_methods)) { |
| + NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n"); |
| + } |
| + NaClSrpcModuleFini(); |
| +} |
| + |
| +static void log_fatal(const char *msg) { |
|
Mark Seaborn
2015/03/23 18:09:38
I don't understand the reason for having this.
Yo
jvoung (off chromium)
2015/03/23 21:18:55
Ah... didn't think that the hook was only for trus
|
| + NaClLog(LOG_FATAL, "%s\n", msg); |
| +} |
| + |
| +const struct nacl_irt_private_pnacl_translator_subzero |
| + nacl_irt_private_pnacl_translator_subzero = { |
| + serve_translate_request, |
| + log_fatal |
| +}; |