1// Copyright 2016 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <lib/zx/process.h>
6
7#include <zircon/syscalls.h>
8
9#include <lib/zx/job.h>
10#include <lib/zx/thread.h>
11#include <lib/zx/vmar.h>
12
13namespace zx {
14
15zx_status_t process::create(const job& job, const char* name, uint32_t name_len,
16                            uint32_t flags, process* proc, vmar* vmar) {
17    // Assume |proc|, |vmar| and |job| must refer to different containers, due
18    // to strict aliasing.
19    return zx_process_create(
20        job.get(), name, name_len, flags, proc->reset_and_get_address(),
21        vmar->reset_and_get_address());
22}
23
24zx_status_t process::start(const thread& thread_handle, uintptr_t entry,
25                           uintptr_t stack, handle arg_handle,
26                           uintptr_t arg2) const {
27    return zx_process_start(get(), thread_handle.get(), entry, stack, arg_handle.release(), arg2);
28}
29
30zx_status_t process::get_child(uint64_t koid, zx_rights_t rights,
31                               thread* result) const {
32    // Assume |result| and |this| are distinct containers, due to strict
33    // aliasing.
34    return zx_object_get_child(
35        value_, koid, rights, result->reset_and_get_address());
36}
37
38} // namespace zx
39