aboutsummaryrefslogtreecommitdiff
path: root/os-posix.c
diff options
context:
space:
mode:
Diffstat (limited to 'os-posix.c')
-rw-r--r--os-posix.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/os-posix.c b/os-posix.c
index a4284e2..52925c2 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -32,7 +32,7 @@
#include "qemu/error-report.h"
#include "qemu/log.h"
-#include "sysemu/runstate.h"
+#include "system/runstate.h"
#include "qemu/cutils.h"
#ifdef CONFIG_LINUX
@@ -270,7 +270,11 @@ void os_setup_limits(void)
return;
}
+#ifdef CONFIG_DARWIN
+ nofile.rlim_cur = OPEN_MAX < nofile.rlim_max ? OPEN_MAX : nofile.rlim_max;
+#else
nofile.rlim_cur = nofile.rlim_max;
+#endif
if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
warn_report("unable to set NOFILE limit: %s", strerror(errno));
@@ -323,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;
+
+ if (on_fault) {
+#ifdef HAVE_MLOCK_ONFAULT
+ flags |= MCL_ONFAULT;
+#else
+ error_report("mlockall: on_fault not supported");
+ return -EINVAL;
+#endif
+ }
- ret = mlockall(MCL_CURRENT | MCL_FUTURE);
+ ret = mlockall(flags);
if (ret < 0) {
error_report("mlockall: %s", strerror(errno));
}
return ret;
#else
+ (void)on_fault;
return -ENOSYS;
#endif
}