Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a public interface to preopened directory lookups. #10

Merged
merged 3 commits into from Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions expected/wasm32-wasi/defined-symbols.txt
Expand Up @@ -242,6 +242,7 @@ __unlist_locked_file
__uselocale
__utc
__wasilibc_fd_renumber
__wasilibc_find_relpath
__wasilibc_init_preopen
__wasilibc_register_preopened_fd
__wasilibc_rmdirat
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasi/include-all.c
Expand Up @@ -183,6 +183,7 @@
#include <utime.h>
#include <values.h>
#include <wasi/core.h>
#include <wasi/libc-find-relpath.h>
#include <wasi/libc.h>
#include <wchar.h>
#include <wctype.h>
1 change: 1 addition & 0 deletions expected/wasm32-wasi/predefined-macros.txt
Expand Up @@ -3622,6 +3622,7 @@
#define __va_copy(d,s) __builtin_va_copy(d,s)
#define __wasi__ 1
#define __wasi_core_h
#define __wasi_libc_find_relpath_h
#define __wasi_libc_h
#define __wasilibc___errno_values_h
#define __wasilibc___fd_set_h
Expand Down
25 changes: 25 additions & 0 deletions libc-bottom-half/headers/public/wasi/libc-find-relpath.h
@@ -0,0 +1,25 @@
#ifndef __wasi_libc_find_relpath_h
#define __wasi_libc_find_relpath_h

#ifdef __cplusplus
extern "C" {
#endif

/**
* Look up the given path in the preopened directory map. If a suitable
* entry is found, return its directory file descriptor, and store the
* computed relative path in *relative_path. Ignore preopened directories
* which don't provide the specified rights.
*
* Returns -1 if no directories were suitable.
*/
int __wasilibc_find_relpath(const char *path,
__wasi_rights_t rights_base,
__wasi_rights_t rights_inheriting,
const char **relative_path);

#ifdef __cplusplus
}
#endif

#endif
6 changes: 6 additions & 0 deletions libc-bottom-half/libpreopen/include/libpreopen.h
Expand Up @@ -82,6 +82,12 @@ struct po_relpath {
/** The path, relative to the directory represented by @ref dirfd */
const char *relative_path;
};
#ifdef __wasilibc_unmodified_upstream
#else
// This functionality is exposed in a libc header, so include that header
// and use its declarations.
#include <wasi/libc-find-relpath.h>
#endif

/**
* Create a @ref po_map of at least the specified capacity.
Expand Down
10 changes: 10 additions & 0 deletions libc-bottom-half/libpreopen/lib/po_libc_wrappers.c
Expand Up @@ -682,4 +682,14 @@ __wasilibc_register_preopened_fd(int fd, const char *path)

return 0;
}

int __wasilibc_find_relpath(const char *path,
__wasi_rights_t rights_base,
__wasi_rights_t rights_inheriting,
const char **relpath)
{
struct po_relpath rel = find_relative(path, rights_base, rights_inheriting);
*relpath = rel.relative_path;
return rel.dirfd;
}
#endif