Ticket #4224: haiku_mlock_map_locked_and_private_area.diff
File haiku_mlock_map_locked_and_private_area.diff, 6.1 KB (added by , 15 years ago) |
---|
-
headers/os/kernel/OS.h
79 79 /* area protection */ 80 80 #define B_READ_AREA 1 81 81 #define B_WRITE_AREA 2 82 #define B_PRIVATE_AREA 0x8000 82 83 83 84 extern area_id create_area(const char *name, void **startAddress, 84 85 uint32 addressSpec, size_t size, uint32 lock, -
headers/posix/sys/mman.h
22 22 #define MAP_FIXED 0x04 /* require mapping to specified addr */ 23 23 #define MAP_ANONYMOUS 0x08 /* no underlying object */ 24 24 #define MAP_ANON MAP_ANONYMOUS 25 #define MAP_LOCKED 0x2000 /* memory is locked into RAM */ 25 26 26 27 /* mmap() error return code */ 27 28 #define MAP_FAILED ((void*)-1) … … 50 51 51 52 int posix_madvise(void* address, size_t length, int advice); 52 53 54 int mlock(const void *address, size_t length); 55 int munlock(const void *address, size_t length); 56 53 57 int shm_open(const char* name, int openMode, mode_t permissions); 54 58 int shm_unlink(const char* name); 55 59 -
headers/private/kernel/vm.h
131 131 int protection); 132 132 status_t _user_sync_memory(void *address, size_t size, int flags); 133 133 status_t _user_memory_advice(void* address, size_t size, int advice); 134 status_t _user_lock_memory(void *address, size_t size, uint32 flags); 135 status_t _user_unlock_memory(void *address, size_t size, uint32 flags); 134 136 135 137 area_id _user_area_for(void *address); 136 138 area_id _user_find_area(const char *name); -
headers/private/system/syscalls.h
393 393 extern status_t _kern_sync_memory(void *address, size_t size, int flags); 394 394 extern status_t _kern_memory_advice(void *address, size_t size, 395 395 int advice); 396 extern status_t _kern_lock_memory(void *address, size_t size, uint32 flags); 397 extern status_t _kern_unlock_memory(void *address, size_t size, uint32 flags); 396 398 397 399 /* kernel port functions */ 398 400 extern port_id _kern_create_port(int32 queue_length, const char *name); -
headers/private/system/vm_defs.h
27 27 #define B_KERNEL_STACK_AREA 0x80 28 28 29 29 #define B_USER_PROTECTION \ 30 (B_READ_AREA | B_WRITE_AREA | B_EXECUTE_AREA | B_STACK_AREA )30 (B_READ_AREA | B_WRITE_AREA | B_EXECUTE_AREA | B_STACK_AREA | B_PRIVATE_AREA) 31 31 #define B_KERNEL_PROTECTION \ 32 32 (B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_KERNEL_EXECUTE_AREA \ 33 33 | B_KERNEL_STACK_AREA) -
src/system/kernel/vm/vm.cpp
2264 2264 TRACE(("_vm_map_file(fd = %d, offset = %Ld, size = %lu, mapping %ld)\n", 2265 2265 fd, offset, size, mapping)); 2266 2266 2267 uint32 lock = (mapping & MAP_LOCKED) ? B_FULL_LOCK : B_NO_LOCK; 2268 mapping &= ~MAP_LOCKED; 2269 2267 2270 offset = ROUNDDOWN(offset, B_PAGE_SIZE); 2268 2271 size = PAGE_ALIGN(size); 2269 2272 2270 2273 if (mapping == REGION_NO_PRIVATE_MAP) 2271 2274 protection |= B_SHARED_AREA; 2275 else if (mapping == REGION_PRIVATE_MAP) 2276 protection |= B_PRIVATE_AREA; 2272 2277 if (addressSpec != B_EXACT_ADDRESS) 2273 2278 unmapAddressRange = false; 2274 2279 2275 2280 if (fd < 0) { 2276 2281 uint32 flags = unmapAddressRange ? CREATE_AREA_UNMAP_ADDRESS_RANGE : 0; 2277 2282 return vm_create_anonymous_area(team, name, _address, addressSpec, size, 2278 B_NO_LOCK, protection, 0, flags, kernel);2283 lock, protection, 0, flags, kernel); 2279 2284 } 2280 2285 2281 2286 // get the open flags of the FD … … 2439 2444 if (status != B_OK) 2440 2445 return status; 2441 2446 2442 if (!kernel && (sourceArea->protection & B_KERNEL_AREA) != 0)2447 if (!kernel && (sourceArea->protection & (B_KERNEL_AREA | B_PRIVATE_AREA)) != 0) 2443 2448 return B_NOT_ALLOWED; 2444 2449 2445 2450 sourceArea->protection |= B_SHARED_AREA; … … 6443 6448 // TODO: Implement! 6444 6449 return B_OK; 6445 6450 } 6451 6452 status_t 6453 _user_lock_memory(void* _address, size_t size, uint32 flags) 6454 { 6455 addr_t address = (addr_t)_address; 6456 6457 // check params 6458 if (size == 0 || (addr_t)address + size < (addr_t)address || (address % B_PAGE_SIZE) != 0) 6459 return B_BAD_VALUE; 6460 6461 if (!IS_USER_ADDRESS(address) || !IS_USER_ADDRESS((addr_t)address + size)) 6462 return B_BAD_ADDRESS; 6463 6464 // lock 6465 return lock_memory(_address, size, flags); 6466 } 6467 6468 status_t 6469 _user_unlock_memory(void* _address, size_t size, uint32 flags) 6470 { 6471 addr_t address = (addr_t)_address; 6472 6473 // check params 6474 if (size == 0 || (addr_t)address + size < (addr_t)address || (address % B_PAGE_SIZE) != 0) 6475 return B_BAD_VALUE; 6476 6477 if (!IS_USER_ADDRESS(address) || !IS_USER_ADDRESS((addr_t)address + size)) 6478 return B_BAD_ADDRESS; 6479 6480 // lock 6481 return unlock_memory(_address, size, flags); 6482 } -
src/system/libroot/posix/sys/mman.cpp
110 110 // translate mapping, address specification, and protection 111 111 int mapping = (flags & MAP_SHARED) != 0 112 112 ? REGION_NO_PRIVATE_MAP : REGION_PRIVATE_MAP; 113 mapping |= (flags & MAP_LOCKED); 113 114 114 115 uint32 addressSpec = B_ANY_ADDRESS; 115 116 if ((flags & MAP_FIXED) != 0) … … 165 166 166 167 167 168 int 169 mlock(const void *address, size_t length) 170 { 171 void *_address = const_cast<void*>(address); 172 RETURN_AND_SET_ERRNO(_kern_lock_memory(_address, length, 0)); 173 } 174 175 int 176 munlock(const void *address, size_t length) 177 { 178 void *_address = const_cast<void*>(address); 179 RETURN_AND_SET_ERRNO(_kern_unlock_memory(_address, length, 0)); 180 } 181 182 183 int 168 184 shm_open(const char* name, int openMode, mode_t permissions) 169 185 { 170 186 char path[PATH_MAX];