Skip to content

Commit

Permalink
fixup! [LibOS] Implement mmap for encrypted and tmpfs files
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Marczewski <[email protected]>
  • Loading branch information
pwmarcz committed Apr 28, 2022
1 parent 9318b2e commit f1cbf19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 9 additions & 7 deletions LibOS/shim/src/bookkeep/shim_vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,13 +1249,15 @@ static bool vma_filter_needs_msync(struct shim_vma* vma, void* arg) {
if (!vma->file->fs || !vma->file->fs->fs_ops || !vma->file->fs->fs_ops->msync)
return false;

/* TODO: remove `lock()` here after we ensure that the `acc_mode` field never changes in
* handles */
lock(&vma->file->lock);
int acc_mode = vma->file->acc_mode;
unlock(&vma->file->lock);

if (!(acc_mode & MAY_WRITE))
/*
* XXX: Strictly speaking, reading `vma->file->acc_mode` requires taking `vma->file->lock`,
* which we cannot do in this function. However, the `acc_mode` field is only modified for
* sockets, and at this point we know that `vma->file` is not a socket (since it implements
* `msync`).
*
* TODO: Remove this comment when the socket code is rewritten.
*/
if (!(vma->file->acc_mode & MAY_WRITE))
return false;

return true;
Expand Down
9 changes: 7 additions & 2 deletions LibOS/shim/src/fs/shim_fs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ int generic_inode_poll(struct shim_handle* hdl, int poll_type) {
int generic_emulated_mmap(struct shim_handle* hdl, void* addr, size_t size, int prot, int flags,
uint64_t offset) {
assert(addr);
__UNUSED(flags);

int ret;

pal_prot_flags_t pal_prot = LINUX_PROT_TO_PAL(prot, flags);
/* The underlying PAL mapping should always be private. */
pal_prot_flags_t pal_prot = LINUX_PROT_TO_PAL(prot, MAP_PRIVATE);
pal_prot_flags_t pal_prot_writable = pal_prot | PAL_PROT_WRITE;

void* actual_addr = addr;
Expand Down Expand Up @@ -195,11 +197,14 @@ err:;
int generic_emulated_msync(struct shim_handle* hdl, void* addr, size_t size, int prot, int flags,
uint64_t offset) {
assert(!(flags & MAP_PRIVATE));
__UNUSED(flags);

lock(&hdl->inode->lock);
file_off_t file_size = hdl->inode->size;
unlock(&hdl->inode->lock);

pal_prot_flags_t pal_prot = LINUX_PROT_TO_PAL(prot, flags);
/* The underlying PAL mapping should always be private. */
pal_prot_flags_t pal_prot = LINUX_PROT_TO_PAL(prot, MAP_PRIVATE);
pal_prot_flags_t pal_prot_readable = pal_prot | PAL_PROT_READ;

int ret;
Expand Down

0 comments on commit f1cbf19

Please sign in to comment.