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

Side by Side Diff: src/untrusted/irt/irt_pnacl_translator_subzero.c

Issue 984713003: Add an IRT interface for subzero/compiler to serve_translate_requests. (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: add a log_fatal for now, to marshal back Created 5 years, 9 months 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 unified diff | Download patch
OLDNEW
(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 PNaClSubzeroFunctions *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 < 1) {
23 NaClLog(LOG_FATAL, "Invalid # of threads (%d)\n", num_threads);
24 }
25 /*
26 * 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.
27 * The others must be left empty and the linker must tolerate empty files.
28 */
29 int obj_fd = in_args[1]->u.hval;
30 const char *cmd_line = in_args[kMaxObjectFiles + 1]->arrays.carr;
31 size_t cmd_line_len = in_args[kMaxObjectFiles + 1]->u.count;
32 int result = g_funcs->init_callback(num_threads, obj_fd,
33 cmd_line, cmd_line_len);
34 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR;
35 /* Currently, errors are logged via log_fatal instead of returned. */
36 if (result)
37 out_args[0]->arrays.str = strdup("There was some sort of error");
38 else
39 out_args[0]->arrays.str = strdup("no error");
40 done->Run(done);
41 }
42
43 static void stream_chunk(NaClSrpcRpc *rpc, NaClSrpcArg **in_args,
44 NaClSrpcArg **out_args, NaClSrpcClosure *done) {
45 int result = g_funcs->data_callback(
46 (unsigned char *)in_args[0]->arrays.carr,
47 in_args[0]->u.count);
48 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR;
49 done->Run(done);
50 }
51
52 static void stream_end(NaClSrpcRpc *rpc, NaClSrpcArg **in_args,
53 NaClSrpcArg **out_args, NaClSrpcClosure *done) {
54 int result = g_funcs->end_callback();
55 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR;
56 out_args[0]->u.ival = 0;
57 out_args[1]->arrays.str = strdup("");
58 out_args[2]->arrays.str = strdup("");
59 /* Currently, errors are logged via log_fatal instead of returned. */
60 if (result)
61 out_args[3]->arrays.str = strdup("There was some sort of error");
62 else
63 out_args[3]->arrays.str = strdup("no error");
64 done->Run(done);
65 }
66
67 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.
68 /*
69 * Protocol for streaming:
70 * StreamInitWithSplit(num_threads, obj_fd x 16, cmdline_flags) -> error_str
71 * StreamChunk(data) +
72 * TODO(jvoung): remove these is_shared_lib, etc.
73 * StreamEnd() -> (is_shared_lib, soname,dependencies, error_str)
74 */
75 { "StreamInitWithSplit:ihhhhhhhhhhhhhhhhC:s", stream_init_with_split },
76 { "StreamChunk:C:", stream_chunk },
77 { "StreamEnd::isss", stream_end },
78 { NULL, NULL },
79 };
80
81 static void serve_translate_request(
82 const struct PNaClSubzeroFunctions *funcs) {
83 g_funcs = funcs;
84 if (!NaClSrpcModuleInit()) {
85 NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n");
86 }
87 if (!NaClSrpcAcceptClientConnection(srpc_methods)) {
88 NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n");
89 }
90 NaClSrpcModuleFini();
91 }
92
93 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
94 NaClLog(LOG_FATAL, "%s\n", msg);
95 }
96
97 const struct nacl_irt_private_pnacl_translator_subzero
98 nacl_irt_private_pnacl_translator_subzero = {
99 serve_translate_request,
100 log_fatal
101 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698