chromium/components/gwp_asan/client/BUILD.gn

# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//base/allocator/allocator.gni")
import("//base/allocator/partition_allocator/partition_alloc.gni")

config("gwp_asan_implementation") {
  defines = [ "GWP_ASAN_IMPLEMENTATION" ]
}

source_set("export") {
  sources = [ "export.h" ]
}

source_set("features") {
  sources = [
    "gwp_asan_features.cc",
    "gwp_asan_features.h",
  ]
  deps = [
    ":export",
    "//base",
  ]
  configs += [ ":gwp_asan_implementation" ]

  if (is_android) {
    sources += [ "feature_map.cc" ]
    deps += [ "android:gwp_asan_headers" ]
  }
}

component("client") {
  output_name = "gwp_asan_client"
  sources = [
    "guarded_page_allocator.cc",
    "guarded_page_allocator.h",
    "gwp_asan.cc",
    "gwp_asan.h",
    "lightweight_detector/poison_metadata_recorder.cc",
    "lightweight_detector/poison_metadata_recorder.h",
    "lightweight_detector/shared_state.h",
    "sampling_helpers.cc",
    "sampling_helpers.h",
    "sampling_state.h",
    "thread_local_random_bit_generator.h",
    "thread_local_state.h",
  ]

  if (is_win) {
    sources += [ "guarded_page_allocator_win.cc" ]
  }

  if (is_posix) {
    sources += [ "guarded_page_allocator_posix.cc" ]
  }

  if (use_allocator_shim) {
    sources += [
      "extreme_lightweight_detector_malloc_shims.cc",
      "extreme_lightweight_detector_malloc_shims.h",
      "lightweight_detector/malloc_shims.cc",
      "lightweight_detector/malloc_shims.h",
      "lightweight_detector/random_eviction_quarantine.cc",
      "lightweight_detector/random_eviction_quarantine.h",
      "sampling_malloc_shims.cc",
      "sampling_malloc_shims.h",
    ]
  }

  if (use_partition_alloc) {
    sources += [
      "lightweight_detector/partitionalloc_shims.cc",
      "lightweight_detector/partitionalloc_shims.h",
      "sampling_partitionalloc_shims.cc",
      "sampling_partitionalloc_shims.h",
    ]
  }

  deps = [
    ":export",
    ":features",
    "//base",
    "//base/allocator:buildflags",
    "//components/crash/core/common:crash_key",
    "//components/gwp_asan/common",
    "//components/gwp_asan/common:crash_keys",
  ]

  configs += [ ":gwp_asan_implementation" ]

  if (is_android) {
    deps += [ "//components/crash/core/app" ]
  }
}

source_set("unit_tests") {
  testonly = true
  sources = [
    "guarded_page_allocator_unittest.cc",
    "gwp_asan_unittest.cc",
    "lightweight_detector/poison_metadata_recorder_unittest.cc",
    "sampling_helpers_unittest.cc",
  ]

  if (use_allocator_shim) {
    sources += [
      "extreme_lightweight_detector_malloc_shims_unittest.cc",
      "lightweight_detector/malloc_shims_unittest.cc",
      "lightweight_detector/random_eviction_quarantine_unittest.cc",
      "sampling_malloc_shims_unittest.cc",
    ]
  }

  if (use_partition_alloc) {
    sources += [
      "lightweight_detector/partitionalloc_shims_unittest.cc",
      "sampling_partitionalloc_shims_unittest.cc",
    ]
  }

  deps = [
    ":client",
    "//base/allocator:buildflags",
    "//base/test:test_support",
    "//components/crash/core/common:crash_key",
    "//components/gwp_asan/common",
    "//components/gwp_asan/common:crash_keys",
    "//testing/gmock",
    "//testing/gtest",
  ]
}