forked from google/xls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch our C++ subprocess library from
fork
to posix_spawn
for sa…
…fety/portability This seems to reduce overhead more than I would have expected; we also end up seeing a bit less than a 10x speedup when running our C++-driven fuzzer, almost certainly due to `posix_spawn`'s use of `vfork` rather than `fork`. This restores the C++-driven fuzzer to within ~10% of the speeds we were previously seeing with the Python-driven fuzzer on the same machines, while also moving us to a much safer interface that's still POSIX-portable. Since we can't rely on our environment supporting the chdir file action, we use a dedicated helper executable to continue supporting executing a subprocess with a different working directory. PiperOrigin-RevId: 574537445
- Loading branch information
1 parent
29858f4
commit 4bc0970
Showing
7 changed files
with
184 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2023 The XLS Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Usage: subprocess_helper <desired working directory> <executable> [args...] | ||
// | ||
// Exec's the given executable in the specified working directory. If the first | ||
// argument is an empty string, stays in the current working directory. | ||
|
||
#include <unistd.h> | ||
|
||
#include <string_view> | ||
|
||
int main(int argc, char** argv) { | ||
if (!std::string_view(argv[1]).empty()) { | ||
chdir(argv[1]); | ||
} | ||
execvp(argv[2], &argv[2]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.