wine/ipc/shm_block.c
Alexandre Julliard a69b88b2f2 Release 980315
Sun Mar 15 03:46:50 1998  Dimitrie O. Paun  <dimi@mail.cs.toronto.edu>

	* [*/*]
	Fixed some dprintf_ such that there is one and only one
	new line for each dprintf and that new line occurs at the end.
	Transformed some fprintfs into proper debug statements.
	Removed much redundancy from most of the debug statements. The
	redundancy appeared because now the component and function
	name is output automatically. Most debug statements also used to
	output the name of the function.
	All these changes prepared the source to switch completely to
	the new debugging interface.
	For more info, refer to ./documentation/debug-msg

Sat Mar 14 19:45:23 1997  Andreas Mohr <100.30936@germany.net>

	* [misc/shell.c] [if1632/kernel.spec]
	Changed parameters of FUNC004() to fix a crash.
	Not sure if this fix is correct (doc wanted).

	* [windows/user.c] [if1632/user.spec] [include/user.h]
	Implemented UserSeeUserDo.

	* [msdos/int21.c] [include/msdos.h]
	Added "GET LIST OF LISTS" (INT 21/52h).

Sat Mar 14 15:48:02 1998  Douglas Ridgway <ridgway@gmcl.com>

	* [include/windows.h] [relay32/gdi32.spec] [objects/enhmetafile.c]
	Beginnings of enhanced metafile support.

Fri Mar 13 20:53:09 1998  John Richardson <jrichard@zko.dec.com>

	* [win32/console.c]
	Restart interrupted console writes.

Fri Mar 13 18:59:24 1998  Matthew Becker <mbecker@glasscity.net>

	* [*/*.c]
	Updated documentation for API manpages.

	* [windows/dce.c]
	ReleaseDC16: Fixed cast.

	* [include/windows.h] [memory/virtual.c]
	VirtualQuery{Ex} should return DWORD instead of BOOL32.

Fri Mar 13 13:03:06 1998  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [README][documentation/status/]
	README updated, added lzexpand,version and multimedia
	status notes to new documentation/status directory.

	* [ole/*.c][if1632/typelib.spec]
	Added typelib stubs, several small additions and fixes.

	* [loader/pe_image.c]
	Fixed a small bug (fixup_imports got passed the wrong hModule in a
	remapcase).

	* [loader/signal.c][if1632/signal.c][misc/winsock_dns.c]
	  [loader/module.c]
	Fixed some recursive debugger crashes (caused by invalid FS).

	* [misc/registry.c]
	Two bugs fixed.

Fri Mar 13 04:55:01 1998  David Lee Lambert <lamber45@egr.msu.edu>

	* [include/winnt.h] [include/winnls.h]
	Moved LANG_xxx flags to winnls.h

	* [include/winnls.h]
	Added flags for GetDateFormat(); fixed validity of
	LOCALE_SYSTEM_DEFAULT.

	* [include/windows.h] 
	Added GetTimeFormat() prototypes.

	* [ole/ole2nls.c]
	Implemented ASCII date- and time-functions,  using an
	optimized common core;  added stubs for Unicode versions;  
	started work on a Unicode core.

	* [AUTHORS]
	Added my name.

Mon Mar  9 20:10:15 1998  Eric Kohl <ekohl@abo.rhein-zeitung.de>

	* [relay32/comctl32.spec] [include/imagelist.h]
	  [include/commctrl.h] [misc/imagelist.c] [misc/Makefile.in]
	First attempt at implementing ImageLists.

Sun Mar  8 20:19:49 1998  Uwe Bonnes  <bon@elektron.ikp.physik.tu-darmstadt.de>

	* [files/dos_fs.c] [configure.in]
	Try to get FileTimeToLocalFileTime,FileTimeToSystemTime and
	SystemTimeToFileTime right.
	Use timegm() where available.

	* [misc/lstr.c]
	Fix an off by one error in FormatMessage and handle the case 
	when args = NULL (used by programs to get the length of the 
	string).

	* [win32/console.c]
	Actual display a per-process Title string, better working
	attempt for WriteConsole32W and ReadConsole32W.

Fri Mar  6 20:33:45 1998  Slaven Rezic  <eserte@cs.tu-berlin.de>

	* [include/config.h.in][configure.in][multimedia/audio.c]
	  [multimedia/dsound.c]
	Added check for FreeBSD sound system.

Sun Mar  1 17:40:10 1998  Jason Schonberg <schon@mti.sgi.com>

	* [controls/edit.c] [include/ole.h] [include/shlobj.h]
	Removed final commas in enum types.

Mon Feb 23 07:52:18 1998  Luiz Otavio L. Zorzella  <zorzella@nr.conexware.com>

	* [multimedia/time.c]
	Workaround to avoid infinite recursion inside timeGetTime.

	* [multimedia/audio.c]
	WODM_GETNUMDEVS and WIDM_GETNUMDEVS only return 1 now if the
	SOUND_DEV can be opened, or if it's busy.
1998-03-15 20:29:56 +00:00

195 lines
5.3 KiB
C

/***************************************************************************
* Copyright 1995, Technion, Israel Institute of Technology
* Electrical Eng, Software Lab.
* Author: Michael Veksler.
***************************************************************************
* File: shm_block.c
* Purpose: Treat a shared memory block.
***************************************************************************
*/
#ifdef CONFIG_IPC
#define inline __inline__
#include <sys/types.h>
#include <sys/sem.h>
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include "debug.h"
#include "global.h"
#include "selectors.h"
#include "shm_fragment.h"
#include "shm_block.h"
#include "shm_semaph.h"
#include "dde_proc.h"
#include "xmalloc.h"
/* How each shmid is maped to local pointer */
/* Only attached shm blocks are in this construct */
struct local_shm_map *shm_map=NULL;
/* setup a new shm block (construct a shm block object).
* block: The pointer to the memory block (local mapping)
* first: The first data byte (excluding header stuff),
* if 0 (zero) Use the default.
* size: The size of the memory block.
*/
void shm_setup_block(struct shm_block *block, int first, int size)
{
TRACE(shm,"Setting up shm block at 0x%08x\n",(int )block);
/* setup block internal data structure */
if (first <= 0) {
first=sizeof(*block);
/* round up - so everything starts on cache line boundary
* (assume cache line=32 bytes, may be bigger/smaller for
* different processors and different L2 caches .)
*/
first=(first+0x1f) & ~0x1f;
}
block->free=size-first;
block->next_shm_id=-1; /* IPC shm ID (for initial linking) */
block->proc_idx= curr_proc_idx;
/* block->size is initialized in shm_FragmentInit */
shm_FragmentInit(block, first, size); /* first item in the free list */
TRACE(shm, "block was set up at 0x%08x, size=0x%04xKB, 1st usable=%02x\n",
(int )block,size/1024,first);
}
/* shm_attach_block: attach existing shm block, setup selectors
* shm_id - id of the block to attach.
* proc_idx - if not -1, puts this data into local mapping
* map - localy mapped info about this block.
*/
/* NOTE: there is no check if this block is already attached.
* Attaching the same block more than once - is possible
* In case of doubt use shm_locate_block.
*/
struct shm_block *shm_attach_block(int shm_id, int proc_idx,
struct local_shm_map *map)
{
struct shm_block *block;
struct shmid_ds ds;
struct local_shm_map *this;
shmctl(shm_id, IPC_STAT, &ds );
block=(struct shm_block*)shmat(shm_id, NULL, 0);
if (block==NULL || block == (struct shm_block*) -1) return NULL;
this=(struct local_shm_map *)xmalloc(sizeof(*this));
this->next= shm_map;
shm_map = this;
this->shm_id= shm_id;
this->ptr = block;
if (proc_idx < 0)
this->proc_idx=block->proc_idx;
else
this->proc_idx=proc_idx;
if (map != NULL) {
memcpy(map, this, sizeof(map));
map->next= NULL; /* don't pass private info */
}
return block;
}
struct shm_block *shm_create_block(int first, int size, int *shm_id)
{
struct shm_block *block;
if (size==0)
size=SHM_MINBLOCK;
else
/* round up size to a multiple of SHM_MINBLOCK */
size= (size+SHM_MINBLOCK-1) & ~(SHM_MINBLOCK-1);
*shm_id= shmget ( IPC_PRIVATE, size ,0700);
if (*shm_id==-1)
return NULL;
block=shm_attach_block(*shm_id, curr_proc_idx, NULL);
if (block!=NULL)
shm_setup_block(block, first, size);
return block;
}
/*
** Locate attached block. (return it, or NULL on failure)
** shm_id is the block we look for.
** *map - will get all the info related to this local map + proc_idx
** (may be NULL)
** *seg - will get the segment this block is attached to.
*/
struct shm_block *shm_locate_attached_block(int shm_id,
struct local_shm_map *map)
{
struct local_shm_map *curr;
for (curr= shm_map ; curr != NULL ; curr= curr->next) {
if (curr->shm_id == shm_id) {
if (map) {
memcpy(map, curr, sizeof(*curr) );
map->next = NULL; /* this is private info ! */
}
return curr->ptr;
}
}
/* block not found ! */
return 0;
}
/* shm_locate_block: see shm_attach_block.
In addition to shm_attach_block, make sure this
block is not already attached.
*/
struct shm_block *shm_locate_block(int shm_id, struct local_shm_map *map)
{
struct shm_block *ret;
ret= shm_locate_attached_block(shm_id, map);
if (ret!=NULL)
return ret;
/* block not found ! , try to attach */
return shm_attach_block(shm_id, -1, map);
}
static void forget_attached(int shmid)
{
struct local_shm_map *curr, **point_to_curr;
for (curr= shm_map, point_to_curr= &shm_map ;
curr != NULL ;
curr= curr->next, point_to_curr= &curr->next ) {
if (curr->shm_id == shmid) {
*point_to_curr= curr->next;
return;
}
}
}
/* delete chain of shm blocks (pointing to each other)
* Do it in reverse order. (This is what the recursion is for)
*/
void shm_delete_chain(int *shmid)
{
struct shm_block *block;
if (*shmid == -1)
return;
block= shm_locate_block(*shmid, NULL);
forget_attached( *shmid );
if (block == NULL)
return;
shm_delete_chain(&block->next_shm_id);
shmctl(*shmid, IPC_RMID, NULL);
*shmid=-1;
shmdt((char *)block);
}
#endif /* CONFIG_IPC */