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 #ifndef LIB_ZX_PROCESS_H_ 6 #define LIB_ZX_PROCESS_H_ 7 8 #include <lib/zx/object.h> 9 #include <lib/zx/task.h> 10 #include <lib/zx/vmar.h> 11 #include <lib/zx/vmo.h> 12 #include <zircon/process.h> 13 14 namespace zx { 15 class job; 16 class thread; 17 18 class process : public task<process> { 19 public: 20 static constexpr zx_obj_type_t TYPE = ZX_OBJ_TYPE_PROCESS; 21 22 constexpr process() = default; 23 process(zx_handle_t value)24 explicit process(zx_handle_t value) : task(value) {} 25 process(handle && h)26 explicit process(handle&& h) : task(h.release()) {} 27 process(process && other)28 process(process&& other) : task(other.release()) {} 29 30 process& operator=(process&& other) { 31 reset(other.release()); 32 return *this; 33 } 34 35 // Rather than creating a process directly with this syscall, 36 // consider using the launchpad library, which properly sets up 37 // the many details of creating a process beyond simply creating 38 // the kernel structure. 39 static zx_status_t create(const job& job, const char* name, uint32_t name_len, 40 uint32_t flags, process* proc, vmar* root_vmar); 41 42 zx_status_t start(const thread& thread_handle, uintptr_t entry, 43 uintptr_t stack, handle arg_handle, uintptr_t arg2) const; 44 read_memory(uintptr_t vaddr,void * buffer,size_t len,size_t * actual)45 zx_status_t read_memory(uintptr_t vaddr, void* buffer, size_t len, size_t* actual) const { 46 return zx_process_read_memory(get(), vaddr, buffer, len, actual); 47 } 48 write_memory(uintptr_t vaddr,const void * buffer,size_t len,size_t * actual)49 zx_status_t write_memory(uintptr_t vaddr, const void* buffer, size_t len, size_t* actual) { 50 return zx_process_write_memory(get(), vaddr, buffer, len, actual); 51 } 52 53 // Provide strongly-typed overload, in addition to get_child(handle*). 54 using task<process>::get_child; 55 zx_status_t get_child(uint64_t koid, zx_rights_t rights, 56 thread* result) const; 57 self()58 static inline unowned<process> self() { 59 return unowned<process>(zx_process_self()); 60 } 61 }; 62 63 using unowned_process = unowned<process>; 64 65 } // namespace zx 66 67 #endif // LIB_ZX_PROCESS_H_ 68