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 ZIRCON_PROCESSARGS_H_ 6 #define ZIRCON_PROCESSARGS_H_ 7 8 #include <zircon/compiler.h> 9 #include <zircon/types.h> 10 #include <stdint.h> 11 12 __BEGIN_CDECLS 13 14 // This is a protocol for passing state to a new process 15 // via a message in a channel. 16 17 #define ZX_PROCARGS_PROTOCOL ((uint32_t)0x4150585du) // MXPA 18 #define ZX_PROCARGS_VERSION ((uint32_t)0x0001000u) 19 20 typedef struct zx_proc_args zx_proc_args_t; 21 22 struct zx_proc_args { 23 // Protocol and version identifiers to allow for 24 // different process start message protocols and 25 // versioning of the same. 26 uint32_t protocol; 27 uint32_t version; 28 29 // Offset from start of message to handle info 30 // array, which contains one uint32_t per handle 31 // passed along with the message. 32 uint32_t handle_info_off; 33 34 // Offset from start of message to arguments and 35 // count of arguments. Arguments are provided as 36 // a set of null-terminated utf-8 strings, one 37 // after the other. 38 uint32_t args_off; 39 uint32_t args_num; 40 41 // Offset from start of message to environment strings and count of 42 // them. Environment entries are provided as a set of null-terminated 43 // UTF-8 strings, one after the other. Canonically each string has 44 // the form "NAME=VALUE", but nothing enforces this. 45 uint32_t environ_off; 46 uint32_t environ_num; 47 48 // Offset from start of message to name strings and count of them. 49 // These strings are packed similar to the argument strings, 50 // but are referenced by PA_NS_* handle table entries and used 51 // to set up namespaces. 52 // 53 // Specifically: In a handle table entry with PA_HND_TYPE(info) 54 // of PA_NS_*, PA_HND_ARG(info) is an index into this name table. 55 uint32_t names_off; 56 uint32_t names_num; 57 }; 58 59 // Handle Info entries associate a type and optional 60 // argument with each handle included in the process 61 // arguments message. 62 #define PA_HND(type, arg) (((type)&0xFF)| (((arg)&0xFFFF)<<16)) 63 #define PA_HND_TYPE(n) ((n) & 0xFF) 64 #define PA_HND_SUBTYPE(n) (((n) >> 8) & 0xFF) 65 #define PA_HND_ARG(n) (((n) >> 16) & 0xFFFF) 66 67 // --- Core Runtime Handles --- 68 // Used by libc init (or equivalent) and dynamic loader 69 70 // Handle to our own process. 71 #define PA_PROC_SELF 0x01u 72 73 // Handle to the initial thread of our own process. 74 #define PA_THREAD_SELF 0x02u 75 76 // Handle to a Job object which can be used to make child processes. The 77 // Job can be the same as the one used to create this process or it can 78 // be different. 79 #define PA_JOB_DEFAULT 0x03u 80 81 // Handle to the root of our address space 82 #define PA_VMAR_ROOT 0x04u 83 84 // Handle to the VMAR used to load the initial program image. 85 #define PA_VMAR_LOADED 0x05u 86 87 88 // --- Loader Service and VMO Handles --- 89 // Used by libc init (or equivalent) and dynamic loader 90 91 // Service for loading shared libraries. 92 // See |fuchsia.ldsvc.Loader| for the interface definition. 93 #define PA_LDSVC_LOADER 0x10u 94 95 // Handle to the VMO containing the ELF image of the system vDSO. This 96 // handle is duplicable, transferable, readable, and executable, but not 97 // writable. The contents of the VM object should be treated like any 98 // other general-purpose ELF file image of type ET_DYN. A process only 99 // needs this handle so that it can map the vDSO into new processes it 100 // might create or propagate it on to its children so they can do so. 101 // Each process's own vDSO was mapped in by its creator before the 102 // process started, its address passed as an argument to entry point. 103 #define PA_VMO_VDSO 0x11u 104 105 // Handle to the VMO used to map the initial thread's stack. This 106 // handle usually has all rights. The protocol between process creator 107 // and new process is that this entire VM object has been mapped in 108 // before the process starts. The initial value for the SP register in 109 // the new process is the high edge of the mapping (assuming stacks grow 110 // downwards), adjusted down as required by the particular machine's C 111 // calling convention for function entry. Thus the new process can 112 // compute its exact stack bounds by subtracting the size reported by 113 // this VMO from the (adjusted back up) initial SP value. 114 #define PA_VMO_STACK 0x13u 115 116 // VM object handle for the main executable file 117 #define PA_VMO_EXECUTABLE 0x14u 118 119 // Used by kernel and userboot during startup 120 #define PA_VMO_BOOTDATA 0x1Au 121 122 // Used by kernel and userboot during startup 123 #define PA_VMO_BOOTFS 0x1Bu 124 125 // Used by the kernel to export debug information as a file in bootfs. When 126 // devmgr starts, it looks for handles of this type, and adds them as files in 127 // /boot/kernel/<vmo-name>. 128 #define PA_VMO_KERNEL_FILE 0x1Cu 129 130 131 // --- Namespace Handles --- 132 133 // A handle which will handle OPEN requests relative 134 // to a particular path which is specified by the 135 // nametable entry referred to by the "arg" field 136 #define PA_NS_DIR 0x20u 137 138 139 // --- FDIO Handles --- 140 // Used by libfdio for passing fdtable, fsroot, etc 141 142 // Handle types the fdio library uses 143 #define PA_FDIO_REMOTE 0x32u 144 #define PA_FDIO_LOGGER 0x35u 145 #define PA_FDIO_SOCKET 0x36u 146 147 // Server endpoint for handling connection to appmgr services. 148 #define PA_DIRECTORY_REQUEST 0x3Bu 149 150 // Used by devmgr and devhosts 151 #define PA_RESOURCE 0x3Fu 152 153 154 // --- Various --- 155 156 // Handle types for one-off use and prototyping 157 #define PA_USER0 0xF0u 158 #define PA_USER1 0xF1u 159 #define PA_USER2 0xF2u 160 161 __END_CDECLS 162 163 #endif // ZIRCON_PROCESSARGS_H_ 164