diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-28 20:57:53 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-12-01 21:44:11 +0200 |
commit | fc13d0782fd50bb038a717e310b6d94acc7ed523 (patch) | |
tree | 23c6a1acaddda7169bafac6ca98559d2cb252147 /Kernel | |
parent | 48f92f6482b31d852e64c7fa28f1b399dedc9e17 (diff) | |
download | serenity-fc13d0782fd50bb038a717e310b6d94acc7ed523.zip |
LibC: Make the madvise advice field a value instead of a bitfield
The advices are almost always exclusive of one another, and while POSIX
does not define madvise, most other unix-like and *BSD systems also only
accept a singular value per call.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/API/POSIX/sys/mman.h | 4 | ||||
-rw-r--r-- | Kernel/Syscalls/mmap.cpp | 8 |
2 files changed, 4 insertions, 8 deletions
diff --git a/Kernel/API/POSIX/sys/mman.h b/Kernel/API/POSIX/sys/mman.h index 65a6618385..bb37c481ac 100644 --- a/Kernel/API/POSIX/sys/mman.h +++ b/Kernel/API/POSIX/sys/mman.h @@ -31,8 +31,8 @@ extern "C" { #define MAP_FAILED ((void*)-1) -#define MADV_SET_VOLATILE 0x100 -#define MADV_SET_NONVOLATILE 0x200 +#define MADV_SET_VOLATILE 0x1 +#define MADV_SET_NONVOLATILE 0x2 #define MS_SYNC 1 #define MS_ASYNC 2 diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 5e358cd171..9660c8b1c2 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -424,18 +424,14 @@ ErrorOr<FlatPtr> Process::sys$madvise(Userspace<void*> address, size_t size, int return EINVAL; if (!region->is_mmap()) return EPERM; - bool set_volatile = advice & MADV_SET_VOLATILE; - bool set_nonvolatile = advice & MADV_SET_NONVOLATILE; - if (set_volatile && set_nonvolatile) - return EINVAL; - if (set_volatile || set_nonvolatile) { + if (advice == MADV_SET_VOLATILE || advice == MADV_SET_NONVOLATILE) { if (!region->vmobject().is_anonymous()) return EINVAL; auto& vmobject = static_cast<Memory::AnonymousVMObject&>(region->vmobject()); if (!vmobject.is_purgeable()) return EINVAL; bool was_purged = false; - TRY(vmobject.set_volatile(set_volatile, was_purged)); + TRY(vmobject.set_volatile(advice == MADV_SET_VOLATILE, was_purged)); return was_purged ? 1 : 0; } return EINVAL; |