Linux programming unleash phần 4

tư nhân sử dụng, chẳng hạn như thực hiện một tùy chỉnh malloc (). MAP_FIXED làm hạt nhân để đặt các bản đồ tại một địa chỉ cụ thể. Nếu địa chỉ đã được sử dụng hoặc nếu không thì không có, mmap () không thành công. Nếu MAP_FIXED không được xác định và địa chỉ không có sẵn, hạt nhân sẽ cố gắng | System Programming 254 Part II private use such as a custom malloc implementation. MAP_FIXED causes the kernel to place the map at a specific address. If the address is already in use or otherwise unavailable mmap fails. If MAP_FIXED is not specified and address is unavailable the kernel will attempt to place the region elsewhere in memory. MAP_LOCKED allows processes with root privilege to lock the region into memory so it will never be swapped to disk. User space programs cannot use MAP_LOCKED a security feature that prevents unauthorized processes from locking all available memory which would essentially bring the system to a standstill. Using the munmap Function When you have finished using a memory mapped file call munmap to unmap the region and return the memory to the operating system. This function uses the following prototype int munmap void start size_t length The start argument points to the beginning of the region to unmap and length indicates how much of the region to unmap. After a memory block has been unmapped further attempts to access start will cause a segmentation fault generate a SIGSEGV . When a process terminates all memory maps are unmapped. The munmap function returns 0 on success or on failure -1 and sets errno. Using the msync Function The msync function writes a mapped file to disk. It uses the following prototype int msync const void start size_t length int flags Call msync to update the disk file with changes made to the in-core map. The region to flush to disk begins at the start address length bytes will be flushed. The flags argument is a bitwise OR of one or more of the following MS_ASYNC MS_SYNC MS_INVALIDATE Schedules a write and returns Data are written before msync returns Invalidate other maps of the same file so they will be updated with new data Using the mprotect Function The mprotect function modifies the protection on a memory map. This function uses the following prototype int protect const void addr size_t len int prot

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.