| OLD | NEW |
| 1 //===-- srpc_main.cpp - PNaCl sandboxed translator invocation -------------===// | 1 //===-- srpc_main.cpp - PNaCl sandboxed translator invocation -------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Main invocation of the sandboxed translator through SRPC. | 10 // Main invocation of the sandboxed translator through SRPC. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include <argz.h> | 25 #include <argz.h> |
| 26 #include <stdio.h> | 26 #include <stdio.h> |
| 27 #include <stdlib.h> | 27 #include <stdlib.h> |
| 28 #include <string.h> | 28 #include <string.h> |
| 29 | 29 |
| 30 #include <string> | 30 #include <string> |
| 31 | 31 |
| 32 #include "llvm/ADT/OwningPtr.h" | 32 #include "llvm/ADT/OwningPtr.h" |
| 33 #include "llvm/ADT/STLExtras.h" | 33 #include "llvm/ADT/STLExtras.h" |
| 34 #include "llvm/Option/Option.h" | 34 #include "llvm/Option/Option.h" |
| 35 #include "llvm/Support/ErrorHandling.h" |
| 35 #include "llvm/Support/system_error.h" | 36 #include "llvm/Support/system_error.h" |
| 36 | 37 |
| 37 using namespace llvm; | 38 using namespace llvm; |
| 38 using namespace llvm::opt; | 39 using namespace llvm::opt; |
| 39 using std::string; | 40 using std::string; |
| 40 | 41 |
| 41 // Imported from pnacl-llc.cpp | 42 // Imported from pnacl-llc.cpp |
| 42 extern int llc_main(int argc, char **argv); | 43 extern int llc_main(int argc, char **argv); |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 int ObjectFD() const { return object_fd_; } | 196 int ObjectFD() const { return object_fd_; } |
| 196 ArgStringList *CmdLineVec() const { return cmd_line_vec_.get(); } | 197 ArgStringList *CmdLineVec() const { return cmd_line_vec_.get(); } |
| 197 const int object_fd_; | 198 const int object_fd_; |
| 198 const OwningPtr<ArgStringList> cmd_line_vec_; | 199 const OwningPtr<ArgStringList> cmd_line_vec_; |
| 199 }; | 200 }; |
| 200 | 201 |
| 201 void *run_streamed(void *arg) { | 202 void *run_streamed(void *arg) { |
| 202 StreamingThreadData *data = reinterpret_cast<StreamingThreadData *>(arg); | 203 StreamingThreadData *data = reinterpret_cast<StreamingThreadData *>(arg); |
| 203 data->CmdLineVec()->push_back("-streaming-bitcode"); | 204 data->CmdLineVec()->push_back("-streaming-bitcode"); |
| 204 if (DoTranslate(data->CmdLineVec(), data->ObjectFD()) != 0) { | 205 if (DoTranslate(data->CmdLineVec(), data->ObjectFD()) != 0) { |
| 205 fprintf(stderr, "DoTranslate failed.\n"); | 206 // llc_main only returns 1 (as opposed to calling report_fatal_error) |
| 206 srpc_streamer->setError(); | 207 // in conditions we never expect to see in the browser (e.g. bad |
| 208 // command-line flags). |
| 209 srpc_streamer->setFatalError("llc_main unspecified failure"); |
| 207 return NULL; | 210 return NULL; |
| 208 } | 211 } |
| 209 delete data; | 212 delete data; |
| 210 return NULL; | 213 return NULL; |
| 211 } | 214 } |
| 212 | 215 |
| 213 // Actually do the work for stream initialization. | 216 // Actually do the work for stream initialization. |
| 214 void do_stream_init(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, | 217 void do_stream_init(NaClSrpcRpc *rpc, NaClSrpcArg **in_args, |
| 215 NaClSrpcArg **out_args, NaClSrpcClosure *done, | 218 NaClSrpcArg **out_args, NaClSrpcClosure *done, |
| 216 ArgStringList *command_line_vec) { | 219 ArgStringList *command_line_vec) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 { "StreamChunk:C:", stream_chunk }, { "StreamEnd::isss", stream_end }, | 347 { "StreamChunk:C:", stream_chunk }, { "StreamEnd::isss", stream_end }, |
| 345 { NULL, NULL }, | 348 { NULL, NULL }, |
| 346 }; | 349 }; |
| 347 | 350 |
| 348 } // namespace | 351 } // namespace |
| 349 | 352 |
| 350 int getObjectFileFD() { return object_file_fd; } | 353 int getObjectFileFD() { return object_file_fd; } |
| 351 | 354 |
| 352 DataStreamer *getNaClBitcodeStreamer() { return NaClBitcodeStreamer; } | 355 DataStreamer *getNaClBitcodeStreamer() { return NaClBitcodeStreamer; } |
| 353 | 356 |
| 357 // Called from the compilation thread |
| 358 void FatalErrorHandler(void *user_data, const std::string& reason, |
| 359 bool gen_crash_diag) { |
| 360 srpc_streamer->setFatalError(reason); |
| 361 } |
| 362 |
| 363 fatal_error_handler_t getSRPCErrorHandler() { return FatalErrorHandler; } |
| 364 |
| 354 int srpc_main(int argc, char **argv) { | 365 int srpc_main(int argc, char **argv) { |
| 355 if (!NaClSrpcModuleInit()) { | 366 if (!NaClSrpcModuleInit()) { |
| 356 return 1; | 367 return 1; |
| 357 } | 368 } |
| 358 | 369 |
| 359 if (!NaClSrpcAcceptClientConnection(srpc_methods)) { | 370 if (!NaClSrpcAcceptClientConnection(srpc_methods)) { |
| 360 return 1; | 371 return 1; |
| 361 } | 372 } |
| 362 NaClSrpcModuleFini(); | 373 NaClSrpcModuleFini(); |
| 363 return 0; | 374 return 0; |
| 364 } | 375 } |
| 365 | 376 |
| 366 #endif // __native_client__ | 377 #endif // __native_client__ |
| OLD | NEW |