mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:47:45 +00:00
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.
This commit is contained in:
parent
48f92f6482
commit
fc13d0782f
2 changed files with 4 additions and 8 deletions
|
@ -31,8 +31,8 @@ extern "C" {
|
||||||
|
|
||||||
#define MAP_FAILED ((void*)-1)
|
#define MAP_FAILED ((void*)-1)
|
||||||
|
|
||||||
#define MADV_SET_VOLATILE 0x100
|
#define MADV_SET_VOLATILE 0x1
|
||||||
#define MADV_SET_NONVOLATILE 0x200
|
#define MADV_SET_NONVOLATILE 0x2
|
||||||
|
|
||||||
#define MS_SYNC 1
|
#define MS_SYNC 1
|
||||||
#define MS_ASYNC 2
|
#define MS_ASYNC 2
|
||||||
|
|
|
@ -424,18 +424,14 @@ ErrorOr<FlatPtr> Process::sys$madvise(Userspace<void*> address, size_t size, int
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
if (!region->is_mmap())
|
if (!region->is_mmap())
|
||||||
return EPERM;
|
return EPERM;
|
||||||
bool set_volatile = advice & MADV_SET_VOLATILE;
|
if (advice == MADV_SET_VOLATILE || advice == MADV_SET_NONVOLATILE) {
|
||||||
bool set_nonvolatile = advice & MADV_SET_NONVOLATILE;
|
|
||||||
if (set_volatile && set_nonvolatile)
|
|
||||||
return EINVAL;
|
|
||||||
if (set_volatile || set_nonvolatile) {
|
|
||||||
if (!region->vmobject().is_anonymous())
|
if (!region->vmobject().is_anonymous())
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
auto& vmobject = static_cast<Memory::AnonymousVMObject&>(region->vmobject());
|
auto& vmobject = static_cast<Memory::AnonymousVMObject&>(region->vmobject());
|
||||||
if (!vmobject.is_purgeable())
|
if (!vmobject.is_purgeable())
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
bool was_purged = false;
|
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 was_purged ? 1 : 0;
|
||||||
}
|
}
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue