wine/ipc/shm_main_blk.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

273 lines
6.8 KiB
C

/***************************************************************************
* Copyright 1995, Technion, Israel Institute of Technology
* Electrical Eng, Software Lab.
* Author: Michael Veksler.
***************************************************************************
* File: shm_main_blk.c
* Purpose: Main Wine's shared memory block
***************************************************************************
*/
#ifdef CONFIG_IPC
#define inline __inline__
#include <sys/types.h>
#include <sys/sem.h>
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include "debug.h"
#include "shm_fragment.h"
#include "shm_block.h"
#include "shm_main_blk.h"
#include "shm_semaph.h"
#define WineKey ( 'W'+((int)'i'<<8)+((int)'n'<<16)+((int)'e'<<24) )
#define SHM_KEY_RANGE 8
/* main block (set during initialization) */
struct shm_main_block *main_block=NULL;
static char *shm_header="Wine - Windows emulator DDE mechanism";
static int main_shm_id;
static void shm_main_refresh();
/* for debugging only */
static void print_perm(struct ipc_perm *perm)
{
printf("Permission:\n");
/* FIXME: not portable
printf("\tKey=%d, mode=%03o, sequence #=%d\n",
(int)perm->key,perm->mode, perm->seq);
*/
printf("\towner: uid=%d, gid=%d ;" ,perm->uid, perm->gid);
printf(" creator: uid=%d, gid=%d\n",perm->cuid,perm->cgid);
}
/* for debugging only */
/* print_shm_info: print shared memory descriptor info */
static void print_shm_info(int shm_id)
{
struct shmid_ds ds;
shmctl(shm_id, IPC_STAT, &ds );
printf("shm_id=%d, Size=0x%08x , Number of attaches=%d\n",
shm_id, ds.shm_segsz, (int)ds.shm_nattch);
if (ds.shm_atime)
printf("Last attach=%s",ctime(&ds.shm_atime));
if (ds.shm_dtime)
printf("Last detach=%s",ctime(&ds.shm_dtime));
printf("Last change=%s",ctime(&ds.shm_ctime));
printf("pid: creator=%d, last operator=%d\n",
(int)ds.shm_cpid,(int)ds.shm_lpid);
print_perm( &ds.shm_perm);
}
int proc_exist(pid_t pid)
{
if ( kill(pid,0) == 0) /* dummy signal to test existence */
return 1;
else if (errno==ESRCH) /* "no such process" */
return 0;
else
return 1;
}
/* setup a new main shm block (only construct a shm block object). */
static void shm_setup_main_block()
{
TRACE(shm,"creating data structure\n");
main_block->build_lock=1;
strcpy(main_block->magic, shm_header);
shm_setup_block(&main_block->block,sizeof(*main_block),SHM_MINBLOCK);
dde_proc_init(main_block->proc);
ATOM_GlobalInit();
shm_sem_init(&main_block->sem);
/* main block set and data structure is stable now */
main_block->build_lock=0;
}
/* Delete everything related to main_block */
void shm_delete_all(int shmid)
{
int proc_idx;
if (shmid == -1)
shmid= main_shm_id;
shmctl( shmid, IPC_RMID, NULL);
for (proc_idx= 0 ; proc_idx < DDE_PROCS ; proc_idx++)
dde_proc_done( &main_block->proc[proc_idx] );
shm_sem_done(&main_block->sem);
shmdt( (void *) main_block);
main_block= NULL;
}
int DDE_no_of_attached()
{
struct shmid_ds shm_info;
if (shmctl(main_shm_id, IPC_STAT, &shm_info) == -1)
return -1;
return shm_info.shm_nattch;
}
/*
** Test if shm_id is MainBlock and attach it (if it is),
** Return 1 if ok, 0 otherwise.
*/
static int attach_MainBlock(int shm_id)
{
struct shmid_ds shm_info;
if (shmctl(shm_id, IPC_STAT, &shm_info) == -1)
return 0;
/* Make sure we don't work on somebody else's block */
if (shm_info.shm_perm.cuid != getuid()) { /* creator is not me */
WARN(shm, "Creator is not me!\n");
return 0;
}
TRACE(shm,"shared memory exist, attaching anywhere\n");
main_block=(struct shm_main_block *)shmat(shm_id, 0, 0);
if ( (int)main_block==-1) {
WARN(shm, "Attach failed\n");
return 0;
}
if (strcmp(main_block->magic, shm_header) != 0) {
TRACE(shm,"Detaching, wrong magic\n");
shmdt((void *)main_block);
return 0;
}
if (TRACE_ON(shm))
print_shm_info(shm_id);
/* Is it an old unused block ? */
if (shm_info.shm_nattch == 0) {
TRACE(shm,"No attaches, deleting old data\n");
shm_delete_all(shm_id);
return 0;
}
/* Wait for data structure to stabilize */
while (main_block->build_lock)
usleep(10000);
main_shm_id= shm_id;
shm_main_refresh();
return 1;
}
/* (Function used by the constructor)
* Try to get existing shared memory with key="Wine", size=SHM_MINBLOCK
* complete user permission.
* If such block is found - return true (1), else return false (0)
*/
static int shm_locate_MainBlock(key_t shm_key)
{
int shm_id; /* Descriptor to this shared memory */
int i;
TRACE(shm,"trying to attach, key=0x%x\n",
shm_key);
for (i=0 ; i < SHM_KEY_RANGE ; i++) {
TRACE(shm,"iteration=%d\n", i);
shm_id= shmget ( shm_key+i, SHM_MINBLOCK ,0700);
if (shm_id != -1) {
if ( attach_MainBlock(shm_id) ) {
return 1; /* success! */
}
} else {
switch(errno) {
#ifdef EIDRM
case EIDRM: /* segment destroyed */
#endif
case EACCES: /* no user permision */
break;
case ENOMEM: /* no free memory */
case ENOENT: /* this key does not exist */
default :
WARN(shm,"shmget failed, errno=%d, %s\n",
errno, strerror(errno) );
return 0; /* Failed */
}
} /* if .. else */
} /* for */
return 0;
}
/* (Function used by the constructor)
* Try to allocate new shared memory with key="Wine", size=SHM_MINBLOCK
* with complete user permission.
* If allocation succeeds - return true (1), else return false (0)
*/
static int shm_create_MainBlock(key_t MainShmKey)
{
int shm_id;
int flags= 0700 | IPC_CREAT | IPC_EXCL;
int i;
TRACE(shm,"creating shared memory\n");
/* try to allocate shared memory with key="Wine", size=SHM_MINBLOCK, */
/* complete user permission */
for (i=0 ; i < SHM_KEY_RANGE ; i++) {
shm_id= shmget ( (key_t) MainShmKey, SHM_MINBLOCK, flags);
if (shm_id != -1)
break;
}
if (shm_id == -1) {
WARN(shm, "failed to create shared memory\n");
return 0;
}
TRACE(shm,"shared memory created, attaching\n");
main_block=(struct shm_main_block*) shmat(shm_id, 0,0);
if (TRACE_ON(shm))
print_shm_info(shm_id);
main_shm_id= shm_id;
shm_setup_main_block();
dde_wnd_setup();
return 1;
}
/* link to the dde shared memory block */
/* RETURN: 0 on success, non zero on failure */
int shm_init(void)
{
if ( !shm_locate_MainBlock(WineKey)
&& !shm_create_MainBlock(WineKey)) {
fflush(stdout);
fprintf(stderr,"shm_init: failed to init main shm block\n");
exit(1);
}
dde_proc_add(main_block->proc);
return 0;
}
static void shm_main_refresh()
{
int proc_idx;
for (proc_idx= 0 ; proc_idx < DDE_PROCS ; proc_idx++)
dde_proc_refresh( &main_block->proc[proc_idx] );
}
#endif /* CONFIG_IPC */