Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2015 The Native Client Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style license that can be | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 #include "native_client/src/shared/platform/nacl_log.h" | |
| 8 #include "native_client/src/shared/srpc/nacl_srpc.h" | |
| 9 #include "native_client/src/untrusted/irt/irt_dev.h" | |
| 10 #include "native_client/src/untrusted/irt/irt_interfaces.h" | |
| 11 | |
| 12 #include <string.h> | |
| 13 | |
| 14 static const int kMaxObjectFiles = 16; | |
| 15 | |
| 16 static const struct irt_pnacl_compile_funcs *g_funcs; | |
| 17 | |
| 18 static void stream_init_with_split( | |
| 19 NaClSrpcRpc *rpc, NaClSrpcArg **in_args, | |
| 20 NaClSrpcArg **out_args, NaClSrpcClosure *done) { | |
| 21 int num_threads = in_args[0]->u.ival; | |
| 22 if (num_threads < 0 || num_threads > kMaxObjectFiles) { | |
| 23 NaClLog(LOG_FATAL, "Invalid # of threads (%d)\n", num_threads); | |
| 24 } | |
| 25 int num_valid_fds = 0; | |
| 26 int fd_start = 1; | |
| 27 int obj_fds[kMaxObjectFiles]; | |
| 28 for (int i = fd_start; i < kMaxObjectFiles + fd_start; i++) { | |
| 29 int fd = in_args[i]->u.hval; | |
| 30 obj_fds[i - fd_start] = fd; | |
| 31 if (fd >= 0) | |
| 32 ++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.
| |
| 33 else | |
| 34 break; | |
| 35 } | |
| 36 const char *cmd_line = in_args[kMaxObjectFiles + fd_start]->arrays.carr; | |
| 37 size_t cmd_line_len = in_args[kMaxObjectFiles + fd_start]->u.count; | |
| 38 int result = g_funcs->init_callback(num_threads, obj_fds, num_valid_fds, | |
| 39 cmd_line, cmd_line_len); | |
| 40 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; | |
| 41 /* 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
| |
| 42 if (result) | |
| 43 out_args[0]->arrays.str = strdup("There was some sort of error"); | |
| 44 else | |
| 45 out_args[0]->arrays.str = strdup("no error"); | |
| 46 done->Run(done); | |
| 47 } | |
| 48 | |
| 49 static void stream_chunk(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, | |
| 50 NaClSrpcArg **out_args, NaClSrpcClosure *done) { | |
| 51 int result = g_funcs->data_callback( | |
| 52 (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)
| |
| 53 in_args[0]->u.count); | |
| 54 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; | |
| 55 done->Run(done); | |
| 56 } | |
| 57 | |
| 58 static void stream_end(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, | |
| 59 NaClSrpcArg **out_args, NaClSrpcClosure *done) { | |
| 60 int result = g_funcs->end_callback(); | |
| 61 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; | |
| 62 /* Fill in the deprecated return values with dummy values. */ | |
| 63 out_args[0]->u.ival = 0; | |
| 64 out_args[1]->arrays.str = strdup(""); | |
| 65 out_args[2]->arrays.str = strdup(""); | |
| 66 /* TODO(jvoung): figure out how to get an error message out. */ | |
| 67 if (result) | |
| 68 out_args[3]->arrays.str = strdup("There was some sort of error"); | |
| 69 else | |
| 70 out_args[3]->arrays.str = strdup("no error"); | |
| 71 done->Run(done); | |
| 72 } | |
| 73 | |
| 74 static const struct NaClSrpcHandlerDesc srpc_methods[] = { | |
| 75 /* | |
| 76 * Protocol for streaming: | |
| 77 * StreamInitWithSplit(num_threads, obj_fd x 16, cmdline_flags) -> error_str | |
| 78 * StreamChunk(data) + | |
| 79 * TODO(jvoung): remove these is_shared_lib, etc. | |
| 80 * 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.
| |
| 81 */ | |
| 82 { "StreamInitWithSplit:ihhhhhhhhhhhhhhhhC:s", stream_init_with_split }, | |
| 83 { "StreamChunk:C:", stream_chunk }, | |
| 84 { "StreamEnd::isss", stream_end }, | |
| 85 { NULL, NULL }, | |
| 86 }; | |
| 87 | |
| 88 static void serve_translate_request( | |
| 89 const struct irt_pnacl_compile_funcs *funcs) { | |
| 90 g_funcs = funcs; | |
| 91 if (!NaClSrpcModuleInit()) { | |
| 92 NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); | |
| 93 } | |
| 94 if (!NaClSrpcAcceptClientConnection(srpc_methods)) { | |
| 95 NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n"); | |
| 96 } | |
| 97 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
| |
| 98 } | |
| 99 | |
| 100 const struct nacl_irt_private_pnacl_translator_compile | |
| 101 nacl_irt_private_pnacl_translator_compile = { | |
| 102 serve_translate_request | |
| 103 }; | |
| OLD | NEW |