summaryrefslogtreecommitdiff
path: root/chromium/base/process/process_handle_fuchsia.cc
blob: f1a7b5efad4797369e0a77d100f5980b0efc7e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2017 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 "base/process/process_handle.h"

#include <magenta/process.h>
#include <magenta/syscalls.h>

#include "base/logging.h"

namespace base {

ProcessId GetCurrentProcId() {
  return GetProcId(GetCurrentProcessHandle());
}

ProcessHandle GetCurrentProcessHandle() {
  // Note that mx_process_self() returns a real handle, and ownership is not
  // transferred to the caller (i.e. this should never be closed).
  return mx_process_self();
}

ProcessId GetProcId(ProcessHandle process) {
  mx_info_handle_basic_t basic;
  mx_status_t status = mx_object_get_info(process, MX_INFO_HANDLE_BASIC, &basic,
                                          sizeof(basic), nullptr, nullptr);
  if (status != NO_ERROR) {
    DLOG(ERROR) << "mx_object_get_info failed: " << status;
    return MX_KOID_INVALID;
  }
  return basic.koid;
}

}  // namespace base