mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-26 20:03:54 -06:00
os: add an ability to lock memory on_fault
This will be used in the following commits to make it possible to only lock memory on fault instead of right away. Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Link: https://lore.kernel.org/r/20250212143920.1269754-2-d-tatianin@yandex-team.ru [peterx: fail os_mlock(on_fault=1) when not supported] [peterx: use G_GNUC_UNUSED instead of "(void)on_fault", per Dan] Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
parent
30943e496f
commit
e76fadf93e
6 changed files with 23 additions and 6 deletions
15
os-posix.c
15
os-posix.c
|
@ -327,18 +327,29 @@ void os_set_line_buffering(void)
|
|||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
}
|
||||
|
||||
int os_mlock(void)
|
||||
int os_mlock(bool on_fault)
|
||||
{
|
||||
#ifdef HAVE_MLOCKALL
|
||||
int ret = 0;
|
||||
int flags = MCL_CURRENT | MCL_FUTURE;
|
||||
|
||||
ret = mlockall(MCL_CURRENT | MCL_FUTURE);
|
||||
if (on_fault) {
|
||||
#ifdef HAVE_MLOCK_ONFAULT
|
||||
flags |= MCL_ONFAULT;
|
||||
#else
|
||||
error_report("mlockall: on_fault not supported");
|
||||
return -EINVAL;
|
||||
#endif
|
||||
}
|
||||
|
||||
ret = mlockall(flags);
|
||||
if (ret < 0) {
|
||||
error_report("mlockall: %s", strerror(errno));
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else
|
||||
(void)on_fault;
|
||||
return -ENOSYS;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue