3 * @brief Declarations of internal data structures and functions
9 * Copyright (c) 2016-2017 Stanley Uche Godfrey
10 * Copyright (c) 2016-2018 Jonathan Anderson
11 * All rights reserved.
13 * This software was developed at Memorial University under the
14 * NSERC Discovery program (RGPIN-2015-06048).
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #ifndef LIBPO_INTERNAL_H
39 #define LIBPO_INTERNAL_H
41 #ifdef __wasilibc_unmodified_upstream
42 #include <sys/cdefs.h>
45 #ifdef __wasilibc_unmodified_upstream
47 #include <sys/capsicum.h>
50 // We do Capsicum-style rights-checking, though we use the WASI API directly
51 // rather than the Capsicum API.
58 #include "libpreopen.h"
61 * An entry in a po_map.
67 * The name this file or directory is mapped to.
69 * This name should look like a path, but it does not necessarily need
70 * match to match the path it was originally obtained from.
74 /** File descriptor (which may be a directory) */
78 /** Capability rights associated with the file descriptor */
79 #ifdef __wasilibc_unmodified_upstream
82 __wasi_rights_t rights_base
;
83 __wasi_rights_t rights_inheriting
;
88 // Documented in external header file
92 struct po_map_entry
*entries
;
99 * Is a directory a prefix of a given path?
101 * @param dir a directory path, e.g., `/foo/bar`
102 * @param dirlen the length of @b dir
103 * @param path a path that may have @b dir as a prefix,
104 * e.g., `/foo/bar/baz`
108 #ifdef __wasilibc_unmodified_upstream
112 bool po_isprefix(const char *dir
, size_t dirlen
, const char *path
);
116 * Check that a @ref po_map is valid (assert out if it's not).
121 #define po_map_assertvalid(...)
123 #ifdef __wasilibc_unmodified_upstream
127 void po_map_assertvalid(const struct po_map
*);
131 * Enlarge a @ref po_map's capacity.
133 * This results in new memory being allocated and existing entries being copied.
134 * If the allocation fails, the function will return NULL but the original
135 * map will remain valid.
139 #ifdef __wasilibc_unmodified_upstream
143 struct po_map
* po_map_enlarge(struct po_map
*map
);
145 #ifdef __wasilibc_unmodified_upstream
147 * Store an error message in the global "last error message" buffer.
151 void po_errormessage(const char *msg
);
155 * Set the default map used by the libpreopen libc wrappers.
157 * If there is an existing default map, it will be freed before it is replaced.
158 * Passing NULL to this function will thus clear the default map.
160 #ifdef __wasilibc_unmodified_upstream
161 void po_set_libc_map(struct po_map
*);
164 #endif /* LIBPO_INTERNAL_H */