Revert "ipcz: OS primitives for reference drivers"

This reverts commit a0ce43fb810d0f706b921663ca7b8793c1bb4e1e.

Reason for revert: crbug.com/1327584: ipc_tests started failing
consistently on Linux MSan. Suspecting this CL as the culprit.

Original change's description:
> ipcz: OS primitives for reference drivers
>
> In preparation for landing an async multiprocess reference driver, this
> lands some foundational primitives first. These are essentially cheesier
> versions of what we find in Chromium for scoped handles and shared
> memory.
>
> As with all reference driver code, these are not intended for production
> use, but for documentation and use in tests.
>
> Bug: 1299283
> Change-Id: I18357f3401073b2c4d4f9711737ab6a67ec64e43
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3648395
> Commit-Queue: Ken Rockot <rockot@google.com>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1005512}

Bug: 1299283
Change-Id: I885e53ceab1c5133bc28eb1e451aec21f20c8cfa
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3657287
Reviewed-by: Rainhard Findling <rainhard@chromium.org>
Commit-Queue: Rainhard Findling <rainhard@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Rainhard Findling <rainhard@chromium.org>
Reviewed-by: Theodore Olsauskas-Warren <sauski@google.com>
Cr-Commit-Position: refs/heads/main@{#1005705}
NOKEYCHECK=True
GitOrigin-RevId: 955eddeef47d8e7a017fa24e4b236646bbc7936d
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 9f214d0..13dc9c5 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -5,10 +5,6 @@
 import("//build_overrides/ipcz.gni")
 import("//testing/test.gni")
 
-# ipcz will not implement a multiprocess reference driver or its supporting
-# primitives for iOS or NaCl platforms. Note that this only affects ipcz tests.
-enable_ipcz_multiprocess_test_support = !is_ios && !is_nacl
-
 shared_library("ipcz_shared") {
   output_name = "ipcz"
   sources = [
@@ -130,8 +126,6 @@
 }
 
 ipcz_source_set("reference_drivers") {
-  testonly = true
-
   public = [ "reference_drivers/single_process_reference_driver.h" ]
 
   sources = [
@@ -142,58 +136,9 @@
     "reference_drivers/single_process_reference_driver.cc",
   ]
 
-  if (enable_ipcz_multiprocess_test_support) {
-    public += [
-      "reference_drivers/memory.h",
-      "reference_drivers/os_handle.h",
-    ]
-    sources += [ "reference_drivers/memory.cc" ]
-
-    if (is_android) {
-      sources += [
-        "reference_drivers/memory_android.cc",
-        "reference_drivers/os_handle_posix.cc",
-        "reference_drivers/os_handle_posix.h",
-      ]
-    } else if (is_mac) {
-      sources += [
-        "reference_drivers/memory_mac.cc",
-        "reference_drivers/os_handle_mac.cc",
-        "reference_drivers/os_handle_mac.h",
-      ]
-    } else if (is_win) {
-      sources += [
-        "reference_drivers/memory_win.cc",
-        "reference_drivers/os_handle_win.cc",
-        "reference_drivers/os_handle_win.h",
-      ]
-    } else if (is_fuchsia) {
-      sources += [
-        "reference_drivers/memory_fuchsia.cc",
-        "reference_drivers/os_handle_fuchsia.cc",
-        "reference_drivers/os_handle_fuchsia.h",
-      ]
-    } else if (is_posix) {
-      sources += [
-        "reference_drivers/memory_posix.cc",
-        "reference_drivers/os_handle_posix.cc",
-        "reference_drivers/os_handle_posix.h",
-      ]
-    }
-  }
-
   ipcz_deps = [ ":util" ]
   public_deps = [ ":ipcz_header" ]
   configs = [ ":ipcz_include_src_dir" ]
-
-  deps = []
-  if (is_fuchsia) {
-    public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/zx" ]
-  }
-
-  if (is_android) {
-    deps += [ "//third_party/ashmem" ]
-  }
 }
 
 ipcz_source_set("util") {
@@ -350,10 +295,6 @@
     "util/stack_trace_test.cc",
   ]
 
-  if (enable_ipcz_multiprocess_test_support) {
-    sources += [ "reference_drivers/memory_test.cc" ]
-  }
-
   deps = [
     "//testing/gmock",
     "//testing/gtest",
diff --git a/src/reference_drivers/memory.cc b/src/reference_drivers/memory.cc
deleted file mode 100644
index 041fa84..0000000
--- a/src/reference_drivers/memory.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <utility>
-
-#include "build/build_config.h"
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-Memory::Mapping::Mapping() = default;
-
-Memory::Mapping::Mapping(void* base_address, size_t size)
-    : base_address_(base_address), size_(size) {}
-
-Memory::Mapping::Mapping(Mapping&& other)
-    : base_address_(std::exchange(other.base_address_, nullptr)),
-      size_(std::exchange(other.size_, 0)) {}
-
-Memory::Mapping& Memory::Mapping::operator=(Mapping&& other) {
-  Reset();
-  base_address_ = std::exchange(other.base_address_, nullptr);
-  size_ = std::exchange(other.size_, 0);
-  return *this;
-}
-
-Memory::Mapping::~Mapping() {
-  Reset();
-}
-
-Memory::Memory() = default;
-
-Memory::Memory(OSHandle handle, size_t size)
-    : handle_(std::move(handle)), size_(size) {}
-
-Memory::Memory(Memory&&) = default;
-
-Memory& Memory::operator=(Memory&&) = default;
-
-Memory::~Memory() = default;
-
-Memory Memory::Clone() {
-  ABSL_ASSERT(is_valid());
-  return Memory(handle_.Clone(), size_);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/memory.h b/src/reference_drivers/memory.h
deleted file mode 100644
index eaf2485..0000000
--- a/src/reference_drivers/memory.h
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IPCZ_SRC_REFERENCE_DRIVERS_MEMORY_H_
-#define IPCZ_SRC_REFERENCE_DRIVERS_MEMORY_H_
-
-#include "reference_drivers/os_handle.h"
-#include "third_party/abseil-cpp/absl/types/span.h"
-
-namespace ipcz::reference_drivers {
-
-// Cross-platform abstraction for a shared memory region.
-class Memory {
- public:
-  // Cross-platform abstraction for an active mapping of a shared memory region.
-  //
-  // Instances of this object should be acquired from Memory::Map().
-  class Mapping {
-   public:
-    Mapping();
-    Mapping(void* base_address, size_t size);
-    Mapping(Mapping&&);
-    Mapping& operator=(Mapping&&);
-    Mapping(const Mapping&) = delete;
-    Mapping& operator=(const Mapping&) = delete;
-    ~Mapping();
-
-    bool is_valid() const { return base_address_ != nullptr; }
-
-    size_t size() const { return size_; }
-    void* base() const { return base_address_; }
-
-    absl::Span<uint8_t> bytes() const {
-      return {static_cast<uint8_t*>(base()), size_};
-    }
-
-    template <typename T>
-    T* As() const {
-      return static_cast<T*>(base());
-    }
-
-    void Reset();
-
-   private:
-    void* base_address_ = nullptr;
-    size_t size_ = 0;
-  };
-
-  // Constructs an invalid Memory object which cannot be mapped.
-  Memory();
-
-  // Constructs a new Memory object over `handle`, an OSHandle which should have
-  // been previously taken from some other valid Memory object. `size` must
-  // correspond to the size of that original region.
-  Memory(OSHandle handle, size_t size);
-
-  // Constructs a new Memory object over a newly allocated shared memory region
-  // of at least `size` bytes.
-  explicit Memory(size_t size);
-
-  Memory(Memory&&);
-  Memory& operator=(Memory&&);
-  Memory(const Memory&) = delete;
-  Memory& operator=(const Memory&) = delete;
-  ~Memory();
-
-  size_t size() const { return size_; }
-  bool is_valid() const { return handle_.is_valid(); }
-  const OSHandle& handle() const { return handle_; }
-
-  // Invalidates this Memory object and returns an OSHandle which can be used
-  // later to reconstruct an equivalent Memory object, given the same size().
-  OSHandle TakeHandle() { return std::move(handle_); }
-
-  // Resets this object, closing its handle to the underlying region.
-  void reset() { handle_.reset(); }
-
-  // Returns a new Memory object with its own handle to the same underlying
-  // region as `this`. Must only be called on a valid Memory object (i.e.
-  // is_valid() must be true.)
-  Memory Clone();
-
-  // Maps the entire region owned by Memory and returns a Mapping for it. Must
-  // only be called on a valid Memory object (i.e. is_valid() must be true.)
-  Mapping Map();
-
- private:
-  OSHandle handle_;
-  size_t size_ = 0;
-};
-
-}  // namespace ipcz::reference_drivers
-
-#endif  // IPCZ_SRC_REFERENCE_DRIVERS_MEMORY_H_
diff --git a/src/reference_drivers/memory_android.cc b/src/reference_drivers/memory_android.cc
deleted file mode 100644
index 355b20f..0000000
--- a/src/reference_drivers/memory_android.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <sys/mman.h>
-#include <unistd.h>
-
-#include <cstddef>
-
-#include "reference_drivers/os_handle.h"
-#include "third_party/abseil-cpp/absl/base/macros.h"
-#include "third_party/ashmem/ashmem.h"
-
-namespace ipcz::reference_drivers {
-
-void Memory::Mapping::Reset() {
-  if (base_address_) {
-    munmap(base_address_, size_);
-    base_address_ = nullptr;
-    size_ = 0;
-  }
-}
-
-Memory::Memory(size_t size) {
-  const size_t page_size = static_cast<size_t>(sysconf(_SC_PAGESIZE));
-  const size_t rounded_size = (size + page_size - 1) & (page_size - 1);
-  int fd = ashmem_create_region("ipcz-memory", rounded_size);
-  ABSL_ASSERT(fd >= 0);
-  int err = ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE);
-  ABSL_ASSERT(err == 0);
-  handle_ = OSHandle(fd);
-  size_ = size;
-}
-
-Memory::Mapping Memory::Map() {
-  ABSL_ASSERT(is_valid());
-  void* addr =
-      mmap(nullptr, size_, PROT_READ | PROT_WRITE, MAP_SHARED, handle_.fd(), 0);
-  ABSL_ASSERT(addr && addr != MAP_FAILED);
-  return Mapping(addr, size_);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/memory_fuchsia.cc b/src/reference_drivers/memory_fuchsia.cc
deleted file mode 100644
index e2c8e2c..0000000
--- a/src/reference_drivers/memory_fuchsia.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <lib/zx/vmar.h>
-#include <zircon/syscalls.h>
-
-#include <cstddef>
-#include <cstdint>
-#include <utility>
-
-#include "reference_drivers/os_handle.h"
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-void Memory::Mapping::Reset() {
-  if (base_address_) {
-    uintptr_t addr = reinterpret_cast<uintptr_t>(base_address_);
-    zx_status_t status = zx::vmar::root_self()->unmap(addr, size_);
-    ABSL_ASSERT(status == ZX_OK);
-  }
-}
-
-Memory::Memory(size_t size) {
-  const uint32_t page_size = zx_system_get_page_size();
-  const size_t rounded_size = (size + page_size - 1) & (page_size - 1);
-  zx::vmo vmo;
-  zx_status_t status = zx::vmo::create(rounded_size, 0, &vmo);
-  ABSL_ASSERT(status == ZX_OK);
-  const int kNoExec = ZX_DEFAULT_VMO_RIGHTS & ~ZX_RIGHT_EXECUTE;
-  status = vmo.replace(kNoExec, &vmo);
-  ABSL_ASSERT(status == ZX_OK);
-  handle_ = OSHandle(std::move(vmo));
-  size_ = size;
-}
-
-Memory::Mapping Memory::Map() {
-  ABSL_ASSERT(is_valid());
-  uintptr_t addr;
-  zx_vm_option_t options =
-      ZX_VM_REQUIRE_NON_RESIZABLE | ZX_VM_PERM_READ | ZX_VM_PERM_WRITE;
-  zx_status_t status = zx::vmar::root_self()->map(
-      options, /*vmar_offset=*/0, *zx::unowned_vmo(handle_.handle().get()), 0,
-      size_, &addr);
-  if (status != ZX_OK) {
-    return {};
-  }
-  return Mapping(reinterpret_cast<void*>(addr), size_);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/memory_mac.cc b/src/reference_drivers/memory_mac.cc
deleted file mode 100644
index 4f1c561..0000000
--- a/src/reference_drivers/memory_mac.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <mach/mach_vm.h>
-
-#include "reference_drivers/os_handle.h"
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-void Memory::Mapping::Reset() {
-  if (base_address_) {
-    kern_return_t kr = mach_vm_deallocate(
-        mach_task_self(), reinterpret_cast<mach_vm_address_t>(base_address_),
-        size_);
-    ABSL_ASSERT(kr == KERN_SUCCESS);
-  }
-}
-
-Memory::Memory(size_t size) {
-  mach_vm_size_t vm_size = size;
-  mach_port_t named_right;
-  kern_return_t kr = mach_make_memory_entry_64(
-      mach_task_self(), &vm_size, 0,
-      MAP_MEM_NAMED_CREATE | VM_PROT_READ | VM_PROT_WRITE, &named_right,
-      MACH_PORT_NULL);
-  ABSL_ASSERT(kr == KERN_SUCCESS);
-  ABSL_ASSERT(vm_size >= size);
-  handle_ = OSHandle(OSHandle::MachSendRight(named_right));
-  size_ = size;
-}
-
-Memory::Mapping Memory::Map() {
-  ABSL_ASSERT(is_valid());
-  mach_vm_address_t address = 0;
-  kern_return_t kr = mach_vm_map(mach_task_self(), &address, size_, 0,
-                                 VM_FLAGS_ANYWHERE, handle_.mach_send_right(),
-                                 0, FALSE, VM_PROT_READ | VM_PROT_WRITE,
-                                 VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_NONE);
-  ABSL_ASSERT(kr == KERN_SUCCESS);
-  return Mapping(reinterpret_cast<void*>(address), size_);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/memory_posix.cc b/src/reference_drivers/memory_posix.cc
deleted file mode 100644
index 37e7775..0000000
--- a/src/reference_drivers/memory_posix.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "reference_drivers/os_handle.h"
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-void Memory::Mapping::Reset() {
-  if (base_address_) {
-    munmap(base_address_, size_);
-    base_address_ = nullptr;
-    size_ = 0;
-  }
-}
-
-Memory::Memory(size_t size) {
-  int fd = memfd_create("/ipcz/mem", MFD_ALLOW_SEALING);
-  ABSL_ASSERT(fd >= 0);
-
-  int result = ftruncate(fd, size);
-  ABSL_ASSERT(result == 0);
-
-  result = fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK);
-  ABSL_ASSERT(result == 0);
-
-  handle_ = OSHandle(fd);
-  size_ = size;
-}
-
-Memory::Mapping Memory::Map() {
-  ABSL_ASSERT(is_valid());
-  void* addr =
-      mmap(nullptr, size_, PROT_READ | PROT_WRITE, MAP_SHARED, handle_.fd(), 0);
-  ABSL_ASSERT(addr && addr != MAP_FAILED);
-  return Mapping(addr, size_);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/memory_test.cc b/src/reference_drivers/memory_test.cc
deleted file mode 100644
index 7017852..0000000
--- a/src/reference_drivers/memory_test.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <tuple>
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ipcz::reference_drivers {
-namespace {
-
-using MemoryTest = testing::Test;
-
-TEST_F(MemoryTest, CreateAndMap) {
-  Memory memory(64);
-
-  Memory::Mapping mapping0 = memory.Map();
-  Memory::Mapping mapping1 = memory.Map();
-
-  int* data0 = mapping0.As<int>();
-  int* data1 = mapping1.As<int>();
-
-  // Each mapping should have a different base address.
-  EXPECT_NE(data0, data1);
-
-  // But they should be backed by the same physical memory.
-  data1[0] = 0;
-  data0[0] = 42;
-  EXPECT_EQ(42, data1[0]);
-}
-
-TEST_F(MemoryTest, CreateMapClose) {
-  Memory memory(64);
-
-  Memory::Mapping mapping0 = memory.Map();
-  Memory::Mapping mapping1 = memory.Map();
-
-  // Even with the memfd closed, the mappings above should persist.
-  memory.reset();
-
-  int* data0 = mapping0.As<int>();
-  int* data1 = mapping1.As<int>();
-  EXPECT_NE(data0, data1);
-  data1[0] = 0;
-  data0[0] = 42;
-  EXPECT_EQ(42, data1[0]);
-}
-
-TEST_F(MemoryTest, CreateCloneMapClose) {
-  Memory memory(64);
-  Memory clone = memory.Clone();
-
-  Memory::Mapping mapping0 = memory.Map();
-  Memory::Mapping mapping1 = clone.Map();
-
-  memory.reset();
-  clone.reset();
-
-  int* data0 = mapping0.As<int>();
-  int* data1 = mapping1.As<int>();
-  EXPECT_NE(data0, data1);
-  data1[0] = 0;
-  data0[0] = 42;
-  EXPECT_EQ(42, data1[0]);
-}
-
-}  // namespace
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/memory_win.cc b/src/reference_drivers/memory_win.cc
deleted file mode 100644
index 77ef5b6..0000000
--- a/src/reference_drivers/memory_win.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/memory.h"
-
-#include <windows.h>
-
-#include "reference_drivers/os_handle.h"
-#include "third_party/abseil-cpp/absl/base/macros.h"
-#include "util/safe_math.h"
-
-namespace ipcz::reference_drivers {
-
-void Memory::Mapping::Reset() {
-  if (base_address_) {
-    ::UnmapViewOfFile(base_address_);
-  }
-}
-
-Memory::Memory(size_t size) {
-  HANDLE h = ::CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE,
-                                 0, checked_cast<DWORD>(size), nullptr);
-  const HANDLE process = ::GetCurrentProcess();
-  HANDLE h2;
-
-  // NOTE: DuplicateHandle is called here to remove some permissions from the
-  // handle (at least WRITE_DAC, among others). This allows the handle to be
-  // duplicated to other processes under strict sandboxing conditions, which may
-  // be useful in some test scenarios.
-  BOOL ok = ::DuplicateHandle(process, h, process, &h2,
-                              FILE_MAP_READ | FILE_MAP_WRITE, FALSE, 0);
-  ::CloseHandle(h);
-  ABSL_ASSERT(ok);
-
-  handle_ = OSHandle(h2);
-  size_ = size;
-}
-
-Memory::Mapping Memory::Map() {
-  ABSL_ASSERT(is_valid());
-  void* addr = ::MapViewOfFile(handle_.handle(), FILE_MAP_READ | FILE_MAP_WRITE,
-                               0, 0, size_);
-  ABSL_ASSERT(addr);
-  return Mapping(addr, size_);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/os_handle.h b/src/reference_drivers/os_handle.h
deleted file mode 100644
index 1ed3802..0000000
--- a/src/reference_drivers/os_handle.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_H_
-#define IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_H_
-
-#include "build/build_config.h"
-
-#if BUILDFLAG(IS_WIN)
-#include "reference_drivers/os_handle_win.h"
-#elif BUILDFLAG(IS_MAC)
-#include "reference_drivers/os_handle_mac.h"
-#elif BUILDFLAG(IS_FUCHSIA)
-#include "reference_drivers/os_handle_fuchsia.h"
-#elif BUILDFLAG(IS_POSIX)
-#include "reference_drivers/os_handle_posix.h"
-#else
-#error "Unsupported platform"
-#endif
-
-#endif  // IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_H_
diff --git a/src/reference_drivers/os_handle_fuchsia.cc b/src/reference_drivers/os_handle_fuchsia.cc
deleted file mode 100644
index c329b7d..0000000
--- a/src/reference_drivers/os_handle_fuchsia.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/os_handle.h"
-
-#include <lib/zx/handle.h>
-#include <zircon/status.h>
-
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-OSHandle::OSHandle() = default;
-
-OSHandle::OSHandle(zx::handle handle) : handle_(std::move(handle)) {}
-
-OSHandle::OSHandle(OSHandle&& other) = default;
-
-OSHandle& OSHandle::operator=(OSHandle&& other) = default;
-
-OSHandle::~OSHandle() = default;
-
-void OSHandle::reset() {
-  handle_.reset();
-}
-
-OSHandle OSHandle::Clone() const {
-  ABSL_ASSERT(is_valid());
-
-  zx::handle dupe;
-  zx_status_t status = handle_.duplicate(ZX_RIGHT_SAME_RIGHTS, &dupe);
-  ABSL_ASSERT(status == ZX_OK);
-  return OSHandle(std::move(dupe));
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/os_handle_fuchsia.h b/src/reference_drivers/os_handle_fuchsia.h
deleted file mode 100644
index 4f03657..0000000
--- a/src/reference_drivers/os_handle_fuchsia.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_FUCHSIA_H_
-#define IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_FUCHSIA_H_
-
-#include <lib/zx/handle.h>
-
-namespace ipcz::reference_drivers {
-
-// The Fuchsia OSHandle implementation can wrap any zx::handle.
-class OSHandle {
- public:
-  OSHandle();
-  explicit OSHandle(zx::handle handle);
-
-  OSHandle(const OSHandle&) = delete;
-  OSHandle& operator=(const OSHandle&) = delete;
-
-  OSHandle(OSHandle&& other);
-  OSHandle& operator=(OSHandle&& other);
-
-  ~OSHandle();
-
-  void reset();
-
-  // Duplicates the underlying handle, returning a new OSHandle to wrap it. The
-  // handle must be valid.
-  OSHandle Clone() const;
-
-  bool is_valid() const { return handle_.is_valid(); }
-  const zx::handle& handle() const { return handle_; }
-
- private:
-  zx::handle handle_;
-};
-
-}  // namespace ipcz::reference_drivers
-
-#endif  // IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_FUCHSIA_H_
diff --git a/src/reference_drivers/os_handle_mac.cc b/src/reference_drivers/os_handle_mac.cc
deleted file mode 100644
index a62061e..0000000
--- a/src/reference_drivers/os_handle_mac.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/os_handle.h"
-
-#include <errno.h>
-#include <mach/mach.h>
-#include <mach/mach_vm.h>
-#include <unistd.h>
-
-#include <utility>
-
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-OSHandle::OSHandle() = default;
-
-OSHandle::OSHandle(Value value) : value_(value) {}
-
-OSHandle::OSHandle(OSHandle&& other)
-    : value_(std::exchange(other.value_, {})) {}
-
-OSHandle& OSHandle::operator=(OSHandle&& other) {
-  reset();
-  value_ = std::exchange(other.value_, {});
-  return *this;
-}
-
-OSHandle::~OSHandle() {
-  reset();
-}
-
-void OSHandle::reset() {
-  if (is_valid_fd()) {
-    int rv = close(fd());
-    ABSL_ASSERT(rv == 0 || errno == EINTR);
-  } else if (is_valid_mach_send_right()) {
-    kern_return_t kr =
-        mach_port_deallocate(mach_task_self(), mach_send_right());
-    ABSL_ASSERT(kr == KERN_SUCCESS);
-  } else if (is_valid_mach_receive_right()) {
-    kern_return_t kr = mach_port_mod_refs(
-        mach_task_self(), mach_receive_right(), MACH_PORT_RIGHT_RECEIVE, -1);
-    ABSL_ASSERT(kr == KERN_SUCCESS);
-  }
-
-  value_ = {};
-}
-
-OSHandle OSHandle::Clone() const {
-  ABSL_ASSERT(is_valid());
-
-  // Cloning of receive rights is not supported.
-  ABSL_ASSERT(!absl::holds_alternative<MachReceiveRight>(value_));
-
-  if (is_valid_fd()) {
-    int duped_fd = dup(fd());
-    ABSL_ASSERT(duped_fd >= 0);
-    return OSHandle(FileDescriptor(duped_fd));
-  }
-
-  if (is_valid_mach_send_right()) {
-    kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_send_right(),
-                                          MACH_PORT_RIGHT_SEND, 1);
-    if (kr != KERN_SUCCESS) {
-      return OSHandle();
-    }
-    return OSHandle(MachSendRight(mach_send_right()));
-  }
-
-  return {};
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/os_handle_mac.h b/src/reference_drivers/os_handle_mac.h
deleted file mode 100644
index 1c9d7e2..0000000
--- a/src/reference_drivers/os_handle_mac.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_MAC_H_
-#define IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_MAC_H_
-
-#include <mach/mach.h>
-
-#include "third_party/abseil-cpp/absl/base/macros.h"
-#include "third_party/abseil-cpp/absl/types/variant.h"
-#include "util/strong_alias.h"
-
-namespace ipcz::reference_drivers {
-
-// The macOS implementation of OSHandle supports wrapping a single Mach send
-// right, or a POSIX file descriptor.
-class OSHandle {
- public:
-  using FileDescriptor = StrongAlias<class FileDescriptorTag, int>;
-  using MachSendRight = StrongAlias<class MachSendRightTag, mach_port_t>;
-  using MachReceiveRight = StrongAlias<class MachReceiveRightTag, mach_port_t>;
-  using Value = absl::
-      variant<absl::monostate, FileDescriptor, MachSendRight, MachReceiveRight>;
-
-  OSHandle();
-  explicit OSHandle(Value value);
-
-  OSHandle(const OSHandle&) = delete;
-  OSHandle& operator=(const OSHandle&) = delete;
-
-  OSHandle(OSHandle&& other);
-  OSHandle& operator=(OSHandle&& other);
-
-  ~OSHandle();
-
-  void reset();
-
-  // Duplicates the underlying handle, returning a new OSHandle to wrap it.
-  // The handle must be a valid file descriptor or Mach send right. Cloning of
-  // of Mach receive rights is not supported.
-  OSHandle Clone() const;
-
-  bool is_valid() const {
-    return is_valid_fd() || is_valid_mach_send_right() ||
-           is_valid_mach_receive_right();
-  }
-
-  bool is_valid_fd() const {
-    return absl::holds_alternative<FileDescriptor>(value_) && fd() != -1;
-  }
-
-  bool is_valid_mach_send_right() const {
-    return absl::holds_alternative<MachSendRight>(value_) &&
-           mach_send_right() != MACH_PORT_NULL;
-  }
-
-  bool is_valid_mach_receive_right() const {
-    return absl::holds_alternative<MachReceiveRight>(value_) &&
-           mach_receive_right() != MACH_PORT_NULL;
-  }
-
-  int fd() const {
-    ABSL_ASSERT(is_valid_fd());
-    return absl::get<FileDescriptor>(value_).value();
-  }
-
-  mach_port_t mach_send_right() const {
-    ABSL_ASSERT(is_valid_mach_send_right());
-    return absl::get<MachSendRight>(value_).value();
-  }
-
-  mach_port_t mach_receive_right() const {
-    ABSL_ASSERT(is_valid_mach_receive_right());
-    return absl::get<MachReceiveRight>(value_).value();
-  }
-
- private:
-  Value value_;
-};
-
-}  // namespace ipcz::reference_drivers
-
-#endif  // IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_MAC_H_
diff --git a/src/reference_drivers/os_handle_posix.cc b/src/reference_drivers/os_handle_posix.cc
deleted file mode 100644
index c96dbdf..0000000
--- a/src/reference_drivers/os_handle_posix.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/os_handle.h"
-
-#include <errno.h>
-#include <unistd.h>
-
-#include <utility>
-
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-OSHandle::OSHandle() = default;
-
-OSHandle::OSHandle(int fd) : fd_(fd) {}
-
-OSHandle::OSHandle(OSHandle&& other) : fd_(std::exchange(other.fd_, -1)) {}
-
-OSHandle& OSHandle::operator=(OSHandle&& other) {
-  reset();
-  fd_ = std::exchange(other.fd_, -1);
-  return *this;
-}
-
-OSHandle::~OSHandle() {
-  reset();
-}
-
-void OSHandle::reset() {
-  int fd = std::exchange(fd_, -1);
-  if (fd >= 0) {
-    int rv = close(fd);
-    ABSL_ASSERT(rv == 0 || errno == EINTR);
-  }
-}
-
-OSHandle OSHandle::Clone() const {
-  ABSL_ASSERT(is_valid());
-  int dupe = dup(fd_);
-  return OSHandle(dupe);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/os_handle_posix.h b/src/reference_drivers/os_handle_posix.h
deleted file mode 100644
index 0ab5efc..0000000
--- a/src/reference_drivers/os_handle_posix.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_POSIX_H_
-#define IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_POSIX_H_
-
-namespace ipcz::reference_drivers {
-
-// The POSIX OSHandle implementation wraps a file descriptor.
-class OSHandle {
- public:
-  OSHandle();
-  explicit OSHandle(int fd);
-
-  OSHandle(const OSHandle&) = delete;
-  OSHandle& operator=(const OSHandle&) = delete;
-
-  OSHandle(OSHandle&& other);
-  OSHandle& operator=(OSHandle&& other);
-
-  ~OSHandle();
-
-  void reset();
-
-  // Duplicates the underlying handle, returning a new OSHandle to wrap it. The
-  // handle must be valid.
-  OSHandle Clone() const;
-
-  bool is_valid() const { return fd_ != -1; }
-
-  int fd() const { return fd_; }
-
- private:
-  int fd_ = -1;
-};
-
-}  // namespace ipcz::reference_drivers
-
-#endif  // IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_POSIX_H_
diff --git a/src/reference_drivers/os_handle_win.cc b/src/reference_drivers/os_handle_win.cc
deleted file mode 100644
index 570f45e..0000000
--- a/src/reference_drivers/os_handle_win.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "reference_drivers/os_handle.h"
-
-#include <windows.h>
-
-#include <utility>
-
-#include "third_party/abseil-cpp/absl/base/macros.h"
-
-namespace ipcz::reference_drivers {
-
-OSHandle::OSHandle() = default;
-
-OSHandle::OSHandle(HANDLE handle) : handle_(handle) {}
-
-OSHandle::OSHandle(OSHandle&& other)
-    : handle_(std::exchange(other.handle_, INVALID_HANDLE_VALUE)) {}
-
-OSHandle& OSHandle::operator=(OSHandle&& other) {
-  reset();
-  handle_ = std::exchange(other.handle_, INVALID_HANDLE_VALUE);
-  return *this;
-}
-
-OSHandle::~OSHandle() {
-  reset();
-}
-
-void OSHandle::reset() {
-  HANDLE handle = std::exchange(handle_, INVALID_HANDLE_VALUE);
-  if (handle != INVALID_HANDLE_VALUE) {
-    ::CloseHandle(handle);
-  }
-}
-
-OSHandle OSHandle::Clone() const {
-  ABSL_ASSERT(is_valid());
-
-  HANDLE dupe;
-  BOOL result =
-      ::DuplicateHandle(::GetCurrentProcess(), handle_, ::GetCurrentProcess(),
-                        &dupe, 0, FALSE, DUPLICATE_SAME_ACCESS);
-  if (!result) {
-    return OSHandle();
-  }
-
-  ABSL_ASSERT(dupe != INVALID_HANDLE_VALUE);
-  return OSHandle(dupe);
-}
-
-}  // namespace ipcz::reference_drivers
diff --git a/src/reference_drivers/os_handle_win.h b/src/reference_drivers/os_handle_win.h
deleted file mode 100644
index 2506f95..0000000
--- a/src/reference_drivers/os_handle_win.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2022 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_WIN_H_
-#define IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_WIN_H_
-
-#include <windows.h>
-
-namespace ipcz::reference_drivers {
-
-// The Windows OSHandle implementation can wrap any HANDLE value.
-class OSHandle {
- public:
-  OSHandle();
-  explicit OSHandle(HANDLE handle);
-
-  OSHandle(const OSHandle&) = delete;
-  OSHandle& operator=(const OSHandle&) = delete;
-
-  OSHandle(OSHandle&& other);
-  OSHandle& operator=(OSHandle&& other);
-
-  ~OSHandle();
-
-  void reset();
-
-  // Duplicates the underlying handle, returning a new OSHandle to wrap it. The
-  // handle must be valid.
-  OSHandle Clone() const;
-
-  bool is_valid() const { return handle_ != INVALID_HANDLE_VALUE; }
-
-  HANDLE handle() const { return handle_; }
-
- private:
-  HANDLE handle_ = INVALID_HANDLE_VALUE;
-};
-
-}  // namespace ipcz::reference_drivers
-
-#endif  // IPCZ_SRC_REFERENCE_DRIVERS_OS_HANDLE_WIN_H_