- video_x.cpp: the_buffer shall always be mapped through vm_alloc() so

that it can be vm_protect()'ed at will afterwards
- video_x.cpp: let driver_base free() the_buffer_copy and the_host_buffer,
  if necessary
- video_vosf.h: reverted to use malloc() for mainBuffer.dirtyPages and
  mainBuffer.pageInfo
- vm_alloc.cpp: small cleanups
- fixed typos
This commit is contained in:
gbeauche 2001-07-14 18:41:05 +00:00
parent 20db0c7260
commit 55df210d27
3 changed files with 27 additions and 57 deletions

View File

@ -181,8 +181,8 @@ static bool video_vosf_init(void)
// The "2" more bytes requested are a safety net to insure the
// loops in the update routines will terminate.
// See "How can we deal with array overrun conditions ?" hereunder for further details.
mainBuffer.dirtyPages = (char *) vm_acquire(mainBuffer.pageCount + 2);
if (mainBuffer.dirtyPages == VM_MAP_FAILED)
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2);
if (mainBuffer.dirtyPages == NULL)
return false;
PFLAG_CLEAR_ALL;
@ -190,8 +190,8 @@ static bool video_vosf_init(void)
PFLAG_SET(mainBuffer.pageCount+1);
// Allocate and fill in pageInfo with start and end (inclusive) row in number of bytes
mainBuffer.pageInfo = (ScreenPageInfo *) vm_acquire(mainBuffer.pageCount * sizeof(ScreenPageInfo));
if (mainBuffer.pageInfo == VM_MAP_FAILED)
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo));
if (mainBuffer.pageInfo == NULL)
return false;
uint32 a = 0;
@ -232,13 +232,13 @@ static bool video_vosf_init(void)
static void video_vosf_exit(void)
{
if (mainBuffer.pageInfo != VM_MAP_FAILED) {
vm_release(mainBuffer.pageInfo, mainBuffer.pageCount * sizeof(ScreenPageInfo));
mainBuffer.pageInfo = (ScreenPageInfo *) VM_MAP_FAILED;
if (mainBuffer.pageInfo) {
free(mainBuffer.pageInfo);
mainBuffer.pageInfo = NULL;
}
if (mainBuffer.dirtyPages != VM_MAP_FAILED) {
vm_release(mainBuffer.dirtyPages, mainBuffer.pageCount + 2);
mainBuffer.dirtyPages = (char *) VM_MAP_FAILED;
if (mainBuffer.dirtyPages) {
free(mainBuffer.dirtyPages);
mainBuffer.dirtyPages = NULL;
}
}

View File

@ -523,16 +523,17 @@ driver_base::~driver_base()
}
#ifdef ENABLE_VOSF
else {
// the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will
if (the_buffer != VM_MAP_FAILED) {
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
vm_release(the_buffer, the_buffer_size);
the_buffer = NULL;
}
if (the_host_buffer) {
D(bug(" freeing the_host_buffer at %p\n", the_host_buffer));
free(the_host_buffer);
the_host_buffer = NULL;
}
if (the_buffer) {
D(bug(" freeing the_buffer at %p\n", the_buffer));
free(the_buffer);
the_buffer = NULL;
}
if (the_buffer_copy) {
D(bug(" freeing the_buffer_copy at %p\n", the_buffer_copy));
free(the_buffer_copy);
@ -583,7 +584,7 @@ driver_window::driver_window(const video_mode &mode)
// Set absolute mouse mode
ADBSetRelMouseMode(mouse_grabbed);
// Create window (setting backround_pixel, border_pixel and colormap is
// Create window (setting background_pixel, border_pixel and colormap is
// mandatory when using a non-default visual; in 1-bit mode we use the
// default visual, so we can also use the default colormap)
XSetWindowAttributes wattr;
@ -675,8 +676,8 @@ driver_window::driver_window(const video_mode &mode)
// Allocate memory for frame buffer (SIZE is extended to page-boundary)
the_host_buffer = the_buffer_copy;
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line);
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size);
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
#else
// Allocate memory for frame buffer
@ -725,21 +726,6 @@ driver_window::~driver_window()
the_buffer_copy = NULL; // don't free() in driver_base dtor
#endif
}
#ifdef ENABLE_VOSF
if (use_vosf) {
// don't free() memory mapped buffers in driver_base dtor
if (the_buffer != VM_MAP_FAILED) {
D(bug(" releasing the_buffer at %p\n", the_buffer));
vm_release(the_buffer, the_buffer_size);
the_buffer = NULL;
}
if (the_buffer_copy != VM_MAP_FAILED) {
D(bug(" releasing the_buffer_copy at %p\n", the_buffer_copy));
vm_release(the_buffer_copy, the_buffer_size);
the_buffer_copy = NULL;
}
}
#endif
if (img) {
if (!have_shm)
img->data = NULL;
@ -1086,7 +1072,7 @@ driver_fbdev::driver_fbdev(const video_mode &mode)
// Allocate memory for frame buffer (SIZE is extended to page-boundary)
the_host_buffer = the_buffer;
the_buffer_size = page_extend((height + 2) * bytes_per_row);
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size);
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
}
#else
@ -1121,14 +1107,6 @@ driver_fbdev::~driver_fbdev()
munmap(the_host_buffer, the_buffer_size);
the_host_buffer = NULL;
}
if (the_buffer_copy != VM_MAP_FAILED) {
vm_release(the_buffer_copy, the_buffer_size);
the_buffer_copy = NULL;
}
if (the_buffer != VM_MAP_FAILED) {
vm_release(the_buffer, the_buffer_size);
the_buffer = NULL;
}
}
#endif
}
@ -1227,7 +1205,7 @@ driver_xf86dga::driver_xf86dga(const video_mode &mode)
// Allocate memory for frame buffer (SIZE is extended to page-boundary)
the_host_buffer = the_buffer;
the_buffer_size = page_extend((height + 2) * bytes_per_row);
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size);
the_buffer_copy = (uint8 *)malloc(the_buffer_size);
the_buffer = (uint8 *)vm_acquire(the_buffer_size);
}
#else
@ -1256,15 +1234,6 @@ driver_xf86dga::~driver_xf86dga()
else {
// don't free() the screen buffer in driver_base dtor
the_host_buffer = NULL;
if (the_buffer_copy != VM_MAP_FAILED) {
vm_release(the_buffer_copy, the_buffer_size);
the_buffer_copy = NULL;
}
if (the_buffer != VM_MAP_FAILED) {
vm_release(the_buffer, the_buffer_size);
the_buffer = NULL;
}
}
#endif
#ifdef ENABLE_XF86_VIDMODE

View File

@ -162,17 +162,18 @@ int vm_release(void * addr, size_t size)
return 0;
#ifdef HAVE_MACH_VM
int ret_code = vm_deallocate(mach_task_self(), (vm_address_t)addr, size);
return ret_code == KERN_SUCCESS ? 0 : -1;
if (vm_deallocate(mach_task_self(), (vm_address_t)addr, size) != KERN_SUCCESS)
return -1;
#else
#ifdef HAVE_MMAP_VM
int ret_code = munmap(addr, size);
return ret_code == 0 ? 0 : -1;
if (munmap(addr, size) != 0)
return -1;
#else
free(addr);
#endif
#endif
return 0;
#endif
#endif
}
/* Change the memory protection of the region starting at ADDR and