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 #pragma once
6 
7 #include <zircon/compiler.h>
8 #include <zircon/processargs.h>
9 #include <zircon/types.h>
10 #include <stdalign.h>
11 
12 __BEGIN_CDECLS
13 
14 #pragma GCC visibility push(hidden)
15 
16 // Define a properly-aligned buffer on the stack for reading a processargs
17 // message.  The nbytes parameter should be gotten from zxr_message_size.
18 #define ZXR_PROCESSARGS_BUFFER(variable, nbytes) \
19     alignas(zx_proc_args_t) uint8_t variable[nbytes]
20 
21 // The buffer provided must be properly aligned (alignas(zx_proc_args_t))
22 // and large enough for the message pending on the given bootstrap
23 // message-pipe handle.  This reads the message into that buffer, validates
24 // the message format of, and yields pointers into the buffer for the
25 // header and the handle-info array.
26 zx_status_t zxr_processargs_read(zx_handle_t bootstrap,
27                                  void* buffer, uint32_t nbytes,
28                                  zx_handle_t handles[], uint32_t nhandles,
29                                  zx_proc_args_t** pargs,
30                                  uint32_t** handle_info);
31 
32 // This assumes zxr_processargs_read has already succeeded on the same
33 // buffer.  It unpacks the argument and environment strings into arrays
34 // provided by the caller.  If not NULL, the argv[] array must have
35 // zx_proc_args_t.args_num + 1 elements.  If not NULL, the envp[] array
36 // must have zx_proc_args_t.environ_num + 1 elements.  If not NULL, the
37 // names[] array must have zx_proc_args_t.names_num + 1 elements. The
38 // last element of each array is filled with a NULL pointer.
39 zx_status_t zxr_processargs_strings(void* msg, uint32_t bytes,
40                                     char* argv[], char* envp[],
41                                     char* names[]);
42 
43 #pragma GCC visibility pop
44 
45 __END_CDECLS
46