posix: options: mlock: refine imply for MMU and DEMAND_PAGING

POSIX mlock() and munlock() require an MMU as well as
DEMAND_PAGING.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2024-12-22 10:29:23 -05:00 committed by Benjamin Cabé
commit 8609a05236
2 changed files with 17 additions and 7 deletions

View file

@ -49,7 +49,7 @@ config POSIX_MEMLOCK
config POSIX_MEMLOCK_RANGE config POSIX_MEMLOCK_RANGE
bool "POSIX range memory locking" bool "POSIX range memory locking"
imply MMU imply MMU if (CPU_HAS_MMU && ARCH_HAS_DEMAND_PAGING)
imply DEMAND_PAGING imply DEMAND_PAGING
help help
Select 'y' here and Zephyr will provide support for mlock() and munlock(). Select 'y' here and Zephyr will provide support for mlock() and munlock().

View file

@ -13,18 +13,28 @@
int mlock(const void *addr, size_t len) 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) 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;
} }