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

Side by Side Diff: src/IceBrowserCompileServer.cpp

Issue 1041843003: Add argv[0] before parsing commandline flags. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: stuff Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceBrowserCompileServer.cpp - Browser compile server ---===// 1 //===- subzero/src/IceBrowserCompileServer.cpp - Browser compile server ---===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
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 // This file defines the browser-based compile server. 10 // This file defines the browser-based compile server.
(...skipping 23 matching lines...) Expand all
34 34
35 void getIRTInterfaces() { 35 void getIRTInterfaces() {
36 size_t QueryResult = 36 size_t QueryResult =
37 nacl_interface_query(NACL_IRT_PRIVATE_PNACL_TRANSLATOR_COMPILE_v0_1, 37 nacl_interface_query(NACL_IRT_PRIVATE_PNACL_TRANSLATOR_COMPILE_v0_1,
38 &gIRTFuncs, sizeof(gIRTFuncs)); 38 &gIRTFuncs, sizeof(gIRTFuncs));
39 if (QueryResult != sizeof(gIRTFuncs)) 39 if (QueryResult != sizeof(gIRTFuncs))
40 llvm::report_fatal_error("Failed to get translator compile IRT interface"); 40 llvm::report_fatal_error("Failed to get translator compile IRT interface");
41 } 41 }
42 42
43 char *onInitCallback(uint32_t NumThreads, int *ObjFileFDs, 43 char *onInitCallback(uint32_t NumThreads, int *ObjFileFDs,
44 size_t ObjFileFDCount, char **argv, size_t argc) { 44 size_t ObjFileFDCount, char **CLArgs, size_t CLArgsLen) {
45 if (ObjFileFDCount < 1) { 45 if (ObjFileFDCount < 1) {
46 std::string Buffer; 46 std::string Buffer;
47 llvm::raw_string_ostream StrBuf(Buffer); 47 llvm::raw_string_ostream StrBuf(Buffer);
48 StrBuf << "Invalid number of FDs for onInitCallback " << ObjFileFDCount 48 StrBuf << "Invalid number of FDs for onInitCallback " << ObjFileFDCount
49 << "\n"; 49 << "\n";
50 return strdup(StrBuf.str().c_str()); 50 return strdup(StrBuf.str().c_str());
51 } 51 }
52 int ObjFileFD = ObjFileFDs[0]; 52 int ObjFileFD = ObjFileFDs[0];
53 if (ObjFileFD < 0) { 53 if (ObjFileFD < 0) {
54 std::string Buffer; 54 std::string Buffer;
55 llvm::raw_string_ostream StrBuf(Buffer); 55 llvm::raw_string_ostream StrBuf(Buffer);
56 StrBuf << "Invalid FD given for onInitCallback " << ObjFileFD << "\n"; 56 StrBuf << "Invalid FD given for onInitCallback " << ObjFileFD << "\n";
57 return strdup(StrBuf.str().c_str()); 57 return strdup(StrBuf.str().c_str());
58 } 58 }
59 // NOTE: argv is owned by the caller, but we parse here before returning. 59 // CLArgs is almost an "argv", but is missing the argv[0] program name.
60 gCompileServer->getParsedFlags(NumThreads, argc, argv); 60 std::vector<char *> Argv;
Mircea Trofin 2015/03/31 17:24:04 you could just std::vector<char *> Argv(CLArgsLen
Jim Stichnoth 2015/03/31 17:26:44 True, but then the push_back() calls have to be re
jvoung (off chromium) 2015/03/31 20:41:16 Hmm, I'll stick with reserve() then. Another optio
61 char ProgramName[] = "pnacl-sz.nexe";
62 Argv.reserve(CLArgsLen + 1);
63 Argv.push_back(ProgramName);
64 for (size_t i = 0; i < CLArgsLen; ++i) {
65 Argv.push_back(CLArgs[i]);
66 }
67 // NOTE: strings pointed to by argv are owned by the caller, but we parse
68 // here before returning and don't store them.
69 gCompileServer->getParsedFlags(NumThreads, Argv.size(), Argv.data());
61 gCompileServer->startCompileThread(ObjFileFD); 70 gCompileServer->startCompileThread(ObjFileFD);
62 return nullptr; 71 return nullptr;
63 } 72 }
64 73
65 int onDataCallback(const void *Data, size_t NumBytes) { 74 int onDataCallback(const void *Data, size_t NumBytes) {
66 return gCompileServer->pushInputBytes(Data, NumBytes) ? 1 : 0; 75 return gCompileServer->pushInputBytes(Data, NumBytes) ? 1 : 0;
67 } 76 }
68 77
69 char *onEndCallback() { 78 char *onEndCallback() {
70 gCompileServer->endInputStream(); 79 gCompileServer->endInputStream();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 this->getCompiler().run(ExtraFlags, *Ctx.get(), 150 this->getCompiler().run(ExtraFlags, *Ctx.get(),
142 // Retain original reference, but the compiler 151 // Retain original reference, but the compiler
143 // (LLVM's MemoryObject) wants to handle deletion. 152 // (LLVM's MemoryObject) wants to handle deletion.
144 std::unique_ptr<llvm::DataStreamer>(InputStream)); 153 std::unique_ptr<llvm::DataStreamer>(InputStream));
145 }); 154 });
146 } 155 }
147 156
148 } // end of namespace Ice 157 } // end of namespace Ice
149 158
150 #endif // PNACL_BROWSER_TRANSLATOR 159 #endif // PNACL_BROWSER_TRANSLATOR
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698