Commit 68de71dc authored by Sajjad Mirza's avatar Sajjad Mirza Committed by Commit Bot

[code coverage] Added Windows-specific path for sandbox file injection.

Also deleted an unnecessary include of unistd.h.

Bug: 990480
Change-Id: I5caa9a1dabcbb9e90bab1372bc38b8079c5a640e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797644Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Commit-Queue: Sajjad Mirza <sajjadm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695848}
parent b6fb8f9a
...@@ -91,7 +91,9 @@ ...@@ -91,7 +91,9 @@
#if BUILDFLAG(CLANG_COVERAGE) #if BUILDFLAG(CLANG_COVERAGE)
#include <stdio.h> #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: // 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 // 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); extern "C" void __llvm_profile_set_file_object(FILE* File, int EnableMerge);
...@@ -396,6 +398,11 @@ class ChildProcessImpl : public mojom::ChildProcess { ...@@ -396,6 +398,11 @@ class ChildProcessImpl : public mojom::ChildProcess {
int fd = file.TakePlatformFile(); int fd = file.TakePlatformFile();
FILE* f = fdopen(fd, "r+b"); FILE* f = fdopen(fd, "r+b");
__llvm_profile_set_file_object(f, 1); __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
} }
#endif #endif
......
...@@ -15,8 +15,11 @@ ...@@ -15,8 +15,11 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
namespace content { namespace content {
...@@ -26,7 +29,11 @@ base::File OpenCoverageFile() { ...@@ -26,7 +29,11 @@ base::File OpenCoverageFile() {
std::string prof_template; std::string prof_template;
base::FilePath path; base::FilePath path;
if (env->GetVar("LLVM_PROFILE_FILE", &prof_template)) { 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(); path = base::FilePath(prof_template).DirName();
#endif
base::CreateDirectory(path); base::CreateDirectory(path);
} else { } else {
base::PathService::Get(base::DIR_CURRENT, &path); base::PathService::Get(base::DIR_CURRENT, &path);
...@@ -37,7 +44,11 @@ base::File OpenCoverageFile() { ...@@ -37,7 +44,11 @@ base::File OpenCoverageFile() {
int pool_index = base::RandInt(0, 3); int pool_index = base::RandInt(0, 3);
std::string filename = base::StrCat( std::string filename = base::StrCat(
{"child_pool-", base::NumberToString(pool_index), ".profraw"}); {"child_pool-", base::NumberToString(pool_index), ".profraw"});
#if defined(OS_WIN)
path = path.Append(base::UTF8ToUTF16(filename));
#else
path = path.Append(filename); path = path.Append(filename);
#endif
uint32_t flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ | uint32_t flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
base::File::FLAG_WRITE; base::File::FLAG_WRITE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment