wine/ipc/shm_fragment.c
Alexandre Julliard b7258befe0 Release 950901
Thu Aug 31 17:19:57 1995  Alexandre Julliard  <julliard@sunsite.unc.edu>

	* [Configure]
	Added compile-time option for IPC.

	* [configure.in]
	Added command-line options for language, IPC and malloc
	debugging.

	* [controls/menu.c]
	WM_MENUSELECT was sometimes sent to the wrong window.

	* [debugger/break.c]
	For the 'next' command, only step over instruction that require
	it. This allows 'next' to do the right thing with jmp and ret
	instructions.

	* [ipc/*.c] [memory/atom.c] [memory/global.c]
	IPC can now be configured out at compile-time.

	* [loader/task.c]
	Bug fix in TASK_Reschedule() that could cause a task to be deleted
	twice.

	* [miscemu/dosmem.c] (New file)
	Partial emulation of the BIOS data segment.

	* [miscemu/instr.c]
	Trap attempts to access selector 0x40 and remap the access to
	segment __0040H.

	* [tools/build.c]
	Fixed bug in CallTo32_LargeStack() that caused problems when
	compiling Wine with the -fomit-frame-pointer option.

	* [windows/message.c]
	Fixed bug in hardware event handling that could cause some events
	to get ignored.

Sat Aug 26 13:12:59 IST 1995 Michael Veksler <mveksler@vnet.ibm.com>

	* [ipc/README] [ipc/dde.tex]
	LaTeX documentation for the ipc and DDE stuff.

Wed Aug 23 22:01:23 GMT 1995 Michael Veksler <mveksler@vnet.ibm.com>

	* [ipc/Imakefile] [ipc/wine_test_stub.c]
	Fixed IPC testing. Now it can be compiled with "make tests"

Wed Aug 23 21:04:14 1995  Fons Botman  <botman@wab-tis.rabobank.nl>

	* [if1632/kernel.spec] [include/windows.h] [misc/main.c]
	Added GetWinDebugInfo/SetWinDebugInfo stub for player.exe

Sun Aug  20 13:49:42 1995  Marcus Meissner  <msmeissn@faui01.informatik.uni-erlangen.de>

	* [miscemu/int21.c]
	Misc fix to int21,ah=40 (write) to match _lwrite().
	AX=0x440A (check if handle is remote) added.

	* [multimedia/mmsystem.c]
	Moved mciSendString to mcistring.c.

	* [multimedia/mcistring.c]
	New file, string interface for MCI (not complete, not thoroughly
	tested).

	* [multimedia/audio.c]
	IOCTL prints errors; one paranoid check disabled.

	* [misc/file.c]
	Misc operator precedence fixes.

	* [if1632/gdi.spec] [objects/bitblt.c]
	Stub for FastWindowFrame (parameters not correct).

Sat Aug 19 01:31:23 1995  Graham Menhennitt <gfm@werple.mira.net.au>

	* [loader/ne_image.c]
	Preliminary support for iterated segments.

Sat Aug 19 00:43:04 1995  Andrew Taylor  (andrew@riscan.com)

	* [windows/mapping.c]
	In function MAPPING_FixIsotropic(), VportExt[XY] is multiplied by
 	the absolute value of (ydim / xdim) or (xdim / ydim).

Thu Aug 15 23:00:16  Gregory Trubetskoy  <grisha@mira.com>

	* [objects/oembitmap.c]
	Added some includes for Windows 95.

	* [include/sysmetrics.h]
	Added some sysmetrics for Windows 95.

	* [include/bitmaps/*95]
	New files: obm_close_95, obm_closed_95, obm_reduce_95, obm_reduced_95
	obm_zoom_95, obm_zoomd_95 - these are some pixmaps for Windows 95.

Thu Aug 10 12:00:00 1995  Jan Willamowius  (jan@janhh.shnet.org)

	* [misc/shell.c] [rc/sysres*.rc]
	The caption of the ShellAbout dialog box is language specific and
 	should be defined in the resources.
1995-09-01 15:57:28 +00:00

183 lines
5.3 KiB
C

/***************************************************************************
* Copyright 1995, Technion, Israel Institute of Technology
* Electrical Eng, Software Lab.
* Author: Michael Veksler.
***************************************************************************
* File: shm_fragment.c
* Purpose: Data fragments and free list items. Allocate and free blocks.
***************************************************************************
*/
#ifdef CONFIG_IPC
#include <stdio.h> /* for debugging only */
#include <stddebug.h>
#include <debug.h> /* for "stddeb" */
#include "shm_fragment.h"
#include "shm_block.h"
/******************************************************************************
*
* Free list: all fragments are ordered according to memory location.
* new fragments are inserted in this way.
*
******************************************************************************
*/
#define FRAG_PTR(block,ofs) ((struct shm_fragment *) ((char *) block + ofs) )
#define NEXT_FRAG(block,ofs) ( FRAG_PTR(block,ofs)->info.next )
/* setup first item in the free list */
void shm_FragmentInit(struct shm_block *block,int first, int size)
{
struct shm_fragment *fragment;
/* round up to nearest 16 byte boundary */
first=(first+15)& ~15;
block->free_list=first;
/* make all the block (exluding the header) free */
fragment= FRAG_PTR(block, first);
block->free= fragment->size= size-first;
fragment->info.next=0;
}
void shm_FragPtrFree(struct shm_block *block, void *ptr)
{
/* ptr points to fragment->info.data, find pointer to fragment,
* find the offset of this pointer in block.
*/
if (ptr)
shm_FragmentFree(block, PTR2REL(block, ptr));
}
void shm_FragmentFree(struct shm_block *block, int fragment_ofs)
{
struct shm_fragment *fragment=NULL;
int prev;
int next;
fragment_ofs-=(int )&fragment->info.data;
fragment= FRAG_PTR(block, fragment_ofs);
block->free+=fragment->size;
/* scan free list to find candidates for merging with fragment */
for (prev=0, next=block->free_list;
(next!=0) && (fragment_ofs > next) ;
prev=next, next=NEXT_FRAG(block,next) )
;
/* insert fragment between, prev and next
* prev==0: fragment will be the first item in free list
* next==0: fragment will be the last item in free list
*/
/* update fragment (point to next, or merge with next) */
if ( fragment_ofs+fragment->size == next ) {
/* merge with the next free block */
fragment->size+= FRAG_PTR(block,next)->size;
fragment->info.next=FRAG_PTR(block,next)->info.next;
} else
/* fragment should be inserted before the next fragment or end of */
/* list. (not merged) */
fragment->info.next=next;
/* now fragment has all the information about the rest of the list */
/* upate prev fragment (point or merge with fragment) */
if (prev==0) /* first item in free list */
block->free_list=fragment_ofs;
else if ( prev+FRAG_PTR(block,prev)->size == fragment_ofs ) {
/* merge fragment with previous fragment */
FRAG_PTR(block,prev)->size+= fragment->size;
FRAG_PTR(block,prev)->info.next=fragment->info.next;
} else
/* insert fragment after previous fragment */
FRAG_PTR(block,prev)->info.next=fragment_ofs;
}
/* use "first fit" algorithm,
* return: offset to data in fragment.
*/
int shm_FragmentAlloc(struct shm_block *block, int size)
{
int prev;
int candidate;
struct shm_fragment *fragment;
struct shm_fragment *ret_fragment;
if (size <= 0)
return NIL;
/* add size of "fragment->size" */
size+= (char *)&fragment->info.data - (char *)fragment ;
/* round "size" to nearest 16 byte value */
size= (size+15) & ~15;
if (size > block->free)
return NIL;
/* scan free list to find candidates for allocation */
for (prev=0, candidate=block->free_list;
candidate!=0 ;
prev=candidate, candidate= fragment->info.next )
{
fragment=FRAG_PTR(block,candidate);
if (fragment->size >= size)
break;
}
if (candidate == 0)
return NIL;
block->free-=size;
if (fragment->size == size) {
if (prev == 0)
block->free_list= fragment->info.next;
else
FRAG_PTR(block,prev)->info.next= fragment->info.next;
return PTR2REL(block, &fragment->info.data);
}
/* fragment->size > size */
/* Split fragment in two, return one part, put the other in free list. */
/* The part that starts at the old location - will stay in the free list. */
fragment->size -= size;
ret_fragment=FRAG_PTR(block, candidate + fragment->size);
ret_fragment->size= size;
return PTR2REL(block, ret_fragment->info.data);
}
/* like shm_FragmentAlloc, returns pointer instead of offset */
char *shm_FragPtrAlloc(struct shm_block *block, int size)
{
int ofs;
ofs= shm_FragmentAlloc(block,size);
if (ofs == NIL)
return NULL;
else
return (char *) REL2PTR(block, ofs);
}
/* This is used for debugging only */
void shm_print_free_list(struct shm_block *block)
{
struct shm_fragment *fragment;
int item;
item=block->free_list;
if (item==0) {
fprintf(stddeb,"no free fragments");
} else {
for (; item ; item=fragment->info.next) {
fragment=FRAG_PTR(block,item);
fprintf(stddeb,"{0x%04x,0x%04x} ",item,fragment->size);
}
}
fprintf(stddeb," [total free=%04x]\n",block->free);
fflush(stddeb);
}
#endif /* CONFIG_IPC */