Skip to content

Commit

Permalink
posix: options: mlock: refine imply for MMU and DEMAND_PAGING
Browse files Browse the repository at this point in the history
POSIX mlock() and munlock() require an MMU as well as
DEMAND_PAGING.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
  • Loading branch information
cfriedt committed Jan 10, 2025
1 parent ec7d272 commit a58aee3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/posix/options/Kconfig.mem
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ config POSIX_MEMLOCK

config POSIX_MEMLOCK_RANGE
bool "POSIX range memory locking"
imply MMU
imply MMU if (CPU_HAS_MMU && ARCH_HAS_DEMAND_PAGING)
imply DEMAND_PAGING
help
Select 'y' here and Zephyr will provide support for mlock() and munlock().
Expand Down
22 changes: 16 additions & 6 deletions lib/posix/options/mlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,28 @@

int mlock(const void *addr, size_t len)
{
void *const _addr = (void *)addr;
if (IS_ENABLED(CONFIG_DEMAND_PAGING)) {
void *const _addr = (void *)addr;

k_mem_pin(_addr, len);
k_mem_pin(_addr, len);

return 0;
return 0;
}

errno = ENOTSUP;
return -1;
}

int munlock(const void *addr, size_t len)
{
void *const _addr = (void *)addr;
if (IS_ENABLED(CONFIG_DEMAND_PAGING)) {
void *const _addr = (void *)addr;

k_mem_unpin(_addr, len);

k_mem_unpin(_addr, len);
return 0;
}

return 0;
errno = ENOTSUP;
return -1;
}

0 comments on commit a58aee3

Please sign in to comment.