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 static const int kMaxObjectFiles = 16; | |
13 | |
14 static int (*g_func)(int nexe_fd, | |
15 const int *obj_file_fds, | |
16 int obj_file_fd_count); | |
17 | |
18 static void handle_link_request(NaClSrpcRpc *rpc, | |
19 NaClSrpcArg **in_args, | |
20 NaClSrpcArg **out_args, | |
21 NaClSrpcClosure *done) { | |
22 int obj_file_count = in_args[0]->u.ival; | |
23 int nexe_fd = in_args[kMaxObjectFiles + 1]->u.hval; | |
24 | |
25 if (obj_file_count < 1 || obj_file_count > kMaxObjectFiles) { | |
26 NaClLog(LOG_FATAL, "Bad object file count (%i)\n", obj_file_count); | |
27 } | |
28 int obj_file_fds[obj_file_count]; | |
29 int i; | |
30 for (i = 0; i < obj_file_count; i++) { | |
jvoung (off chromium)
2015/02/05 19:14:11
nit: could scope the "int i;" in the loop?
Mark Seaborn
2015/02/05 22:01:32
Done. I didn't actually realise that is allowed i
| |
31 obj_file_fds[i] = in_args[i + 1]->u.hval; | |
32 } | |
33 | |
34 int result = g_func(nexe_fd, obj_file_fds, obj_file_count); | |
35 | |
36 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; | |
37 done->Run(done); | |
38 } | |
39 | |
40 static const struct NaClSrpcHandlerDesc srpc_methods[] = { | |
41 { "RunWithSplit:ihhhhhhhhhhhhhhhhh:", handle_link_request }, | |
42 { NULL, NULL }, | |
43 }; | |
44 | |
45 static void serve_link_request(int (*func)(int nexe_fd, | |
46 const int *obj_file_fds, | |
47 int obj_file_fd_count)) { | |
48 g_func = func; | |
49 if (!NaClSrpcModuleInit()) { | |
50 NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); | |
51 } | |
52 NaClSrpcAcceptClientConnection(srpc_methods); | |
53 } | |
54 | |
55 const struct nacl_irt_private_pnacl_translator_link | |
56 nacl_irt_private_pnacl_translator_link = { | |
57 serve_link_request, | |
58 }; | |
OLD | NEW |