Skip to content

Commit

Permalink
[code coverage] Added Windows-specific path for sandbox file injection.
Browse files Browse the repository at this point in the history
Also deleted an unnecessary include of unistd.h.

Bug: 990480
Change-Id: I5caa9a1dabcbb9e90bab1372bc38b8079c5a640e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797644
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Sajjad Mirza <sajjadm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695848}
  • Loading branch information
sajjadm-google authored and Commit Bot committed Sep 12, 2019
1 parent b6fb8f9 commit 68de71d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion content/child/child_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@

#if BUILDFLAG(CLANG_COVERAGE)
#include <stdio.h>
#include <unistd.h>
#if defined(OS_WIN)
#include <io.h>
#endif
// Function provided by libclang_rt.profile-*.a, declared and documented at:
// https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/profile/InstrProfiling.h
extern "C" void __llvm_profile_set_file_object(FILE* File, int EnableMerge);
Expand Down Expand Up @@ -396,6 +398,11 @@ class ChildProcessImpl : public mojom::ChildProcess {
int fd = file.TakePlatformFile();
FILE* f = fdopen(fd, "r+b");
__llvm_profile_set_file_object(f, 1);
#elif defined(OS_WIN)
HANDLE handle = file.TakePlatformFile();
int fd = _open_osfhandle((intptr_t)handle, 0);
FILE* f = _fdopen(fd, "r+b");
__llvm_profile_set_file_object(f, 1);
#endif
}
#endif
Expand Down
11 changes: 11 additions & 0 deletions content/common/coverage_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"

namespace content {

Expand All @@ -26,7 +29,11 @@ base::File OpenCoverageFile() {
std::string prof_template;
base::FilePath path;
if (env->GetVar("LLVM_PROFILE_FILE", &prof_template)) {
#if defined(OS_WIN)
path = base::FilePath(base::UTF8ToUTF16(prof_template)).DirName();
#else
path = base::FilePath(prof_template).DirName();
#endif
base::CreateDirectory(path);
} else {
base::PathService::Get(base::DIR_CURRENT, &path);
Expand All @@ -37,7 +44,11 @@ base::File OpenCoverageFile() {
int pool_index = base::RandInt(0, 3);
std::string filename = base::StrCat(
{"child_pool-", base::NumberToString(pool_index), ".profraw"});
#if defined(OS_WIN)
path = path.Append(base::UTF8ToUTF16(filename));
#else
path = path.Append(filename);
#endif
uint32_t flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
base::File::FLAG_WRITE;

Expand Down

0 comments on commit 68de71d

Please sign in to comment.