CVS: winex/server macosx.c, 1.3, 1.4 main.c, 1.18, 1.19 Makefile.in, 1.21, 1.22 process.c, 1.44, 1.45 protocol.def, 1.44, 1.45 server_memory.h, 1.13, 1.14 shm.c, 1.19, 1.20 trace.c, 1.45, 1.46
[email protected] 31 Jul 2007 20:06:25 -0000
| Newsgroups | gmane.comp.emulators.winex.cvs |
|---|---|
| Message-ID | <[email protected]> |
Subject: winex/server macosx.c,1.3,1.4 main.c,1.18,1.19 Makefile.in,1.21,1.22 process.c,1.44,1.45 protocol.def,1.44,1.45 server_memory.h,1.13,1.14 shm.c,1.19,1.20 trace.c,1.45,1.46Update of /var/lib/cvsd/cvsroot/winex/server
In directory agravaine:/tmp/cvs-serv3468/server
Modified Files:
macosx.c main.c Makefile.in process.c protocol.def
server_memory.h shm.c trace.c
Log Message:
Refactor SHM server to handle both POSIX and SYSV IPC.
Add support for SHM server on Mac OS X.
Index: macosx.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/macosx.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- macosx.c 31 Jul 2007 19:56:20 -0000 1.3
+++ macosx.c 31 Jul 2007 20:06:23 -0000 1.4
@@ -53,6 +53,13 @@
if (Err != MACH_MSG_SUCCESS)
fprintf (stderr, "Warn: suspending thread port 0x%x failed: 0x%x\n",
thread->thread_port, Err);
+ else
+ {
+ Err = thread_abort (thread->thread_port);
+ if ((Err != MACH_MSG_SUCCESS) && debug_level)
+ fprintf (stderr, "Warn: aborting thread port 0x%x failed: 0x%x\n",
+ thread->thread_port, Err);
+ }
}
/* make a thread continue (at the Unix level) */
Index: main.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/main.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- main.c 30 Mar 2007 15:55:03 -0000 1.18
+++ main.c 31 Jul 2007 20:06:23 -0000 1.19
@@ -36,11 +36,7 @@
extern int debug_level;
extern int persistent_server;
extern int wineserver_is_daemon;
-#ifndef __APPLE__
static int shared_memory_server = 1; /* PH: FIXME: Temp */
-#else
-static int shared_memory_server = 0; /* PH: FIXME: Temp */
-#endif
/* this symbol is exported.
* The preloader will locate it and set it to point to
* a NULL terminated list of mmap reserved areas.
Index: Makefile.in
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/Makefile.in,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- Makefile.in 31 Jul 2007 18:00:22 -0000 1.21
+++ Makefile.in 31 Jul 2007 20:06:23 -0000 1.22
@@ -72,7 +72,7 @@
@MAKE_RULES@
$(SONAME): $(LIB_OBJS)
- $(LDSHARED) $(LIB_OBJS) -o $@
+ $(LDSHARED) $(LIB_OBJS) -o $@ @POSIX_SHM_LIB_NAME@
LDEXECFLAGS = @LDEXECFLAGS@
wineserver: $(SERVER_OBJS) $(SONAME)
@@ -96,5 +96,5 @@
cd $(libdir) && $(RM) $(SONAME) $(SONAME).$(SOVERSION)
install:: all $(LIBEXT:%=install_%)
-
+
### Dependencies:
Index: process.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/process.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- process.c 31 Jul 2007 19:58:52 -0000 1.44
+++ process.c 31 Jul 2007 20:06:23 -0000 1.45
@@ -898,6 +898,7 @@
reply->shm_server = SERVER_GLOBAL_VARIABLE( shared_memory_server );
reply->shm_size = SERVER_GLOBAL_VARIABLE( shared_memory_server_size );
reply->shm_addr = SERVER_GLOBAL_VARIABLE( shared_memory_server_addr );
+ reply->shm_type = SERVER_GLOBAL_VARIABLE( shared_memory_server_type );
initschedule( current, current->suspend + current->process->suspend );
}
Index: protocol.def
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/protocol.def,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- protocol.def 31 Jul 2007 19:58:30 -0000 1.44
+++ protocol.def 31 Jul 2007 20:06:23 -0000 1.45
@@ -248,8 +248,9 @@
@REPLY
int debugged; /* being debugged? */
int shm_server; /* If the wineserver can support this process through SHM */
- size_t shm_size;/* Size of shared segment */
+ size_t shm_size; /* Size of shared segment */
void* shm_addr; /* Address of shared segment */
+ int shm_type; /* Type of shm being used */
@END
Index: server_memory.h
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/server_memory.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- server_memory.h 30 Mar 2007 15:55:03 -0000 1.13
+++ server_memory.h 31 Jul 2007 20:06:23 -0000 1.14
@@ -72,6 +72,7 @@
int shared_memory_server;
size_t shared_memory_server_size;
void *shared_memory_server_addr;
+ int shared_memory_server_type;
/* serverdir */
char* serverdir;
Index: shm.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/shm.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- shm.c 31 Jul 2007 18:00:22 -0000 1.19
+++ shm.c 31 Jul 2007 20:06:23 -0000 1.20
@@ -1,7 +1,7 @@
/*
* Shared Memory WineServer stuff.
*
- * Copyright (C) 2002,2004 TransGaming Technologies
+ * Copyright (C) 2002,2004,2006-2007 TransGaming Technologies
*/
#include "config.h"
@@ -12,6 +12,9 @@
#ifdef HAVE_SYS_IPC_H
# include <sys/ipc.h>
#endif
+#ifdef HAVE_SEMAPHORE_H
+# include <semaphore.h>
+#endif
#ifdef HAVE_SYS_SHM_H
# include <sys/shm.h>
#endif
@@ -46,7 +49,7 @@
/* Data area pointer */
server_memory_area* server_memory_block = NULL;
-static off_t allocated_shm_size = 0;
+static size_t allocated_shm_size = 0;
/* this is set by wineserver (the binary) if wine_main_preload_info has been
* set by the preloader.
@@ -71,14 +74,19 @@
#define shared_memory_address 0x90000000 /* FIXME DH: to go away (can almost go now) */
#else
/* On the Mac, the 0x90000000 address is reserved */
- #define shared_memory_address 0xB0000000 /* FIXME DH: to go away (can almost go now) */
+ #define shared_memory_address 0xF0000000 /* FIXME DH: to go away (can almost go now) */
#endif
#define PAGESIZE getpagesize()
#define USE_CSRI_MALLOC
-#if defined( HAVE_SEMOP ) && defined( HAVE_SHMGET ) && defined( HAVE_FTOK )
+#if defined (HAVE_SEMAPHORE_H) && defined (HAVE_SHM_OPEN)
+# define USE_POSIX_IPC
+#endif
+
+/* SYSV IPC is fundamentally broken on Mac OS X, at least as of 10.4 */
+#if defined (HAVE_SEMOP) && defined (HAVE_SHMGET) && defined (HAVE_FTOK) && !defined(__APPLE__)
# define USE_SYSV_IPC
#endif
@@ -194,57 +202,319 @@
}
-static const int shared_memory_project_id = 0x54477758; /* "TGwX" in ascii. */
+/* Function pointer definitions for shm/sem callbacks */
+typedef void (*sem_open_t) (BOOL Create);
+typedef void (*sem_destroy_t) ();
+typedef void (*sem_acquire_t) ();
+typedef void (*sem_release_t) ();
+typedef BOOL (*shm_open_t) (const char *pName);
+typedef void (*shm_destroy_t) ();
+typedef void* (*shm_map_t) (BOOL Create, void *Addr, size_t Len);
-#if defined( USE_SYSV_IPC )
+typedef struct {
+ sem_open_t sem_open;
+ sem_destroy_t sem_destroy;
+ sem_acquire_t sem_acquire;
+ sem_release_t sem_release;
+ shm_open_t shm_open;
+ shm_destroy_t shm_destroy;
+ shm_map_t shm_map;
+} shm_ops_t;
+
+static shm_ops_t shm_ops;
+
+typedef enum {SHM_USING_NONE, SHM_USING_POSIX, SHM_USING_SYSV} shm_using_t;
+static shm_using_t shm_type = SHM_USING_NONE;
+
+#ifdef USE_POSIX_IPC
+
+static char *shm_path;
+static int shm_fd = -1;
+static sem_t *shm_sem = (sem_t *)SEM_FAILED;
+
+static int create_shm_path (const char *pathname)
+{
+ size_t len, i;
+
+ shm_path = strdup (pathname);
+ if (!shm_path)
+ {
+ perror ("Unable to copy shm path");
+ return 0;
+ }
+
+ /* For portability, need to ensure it starts with a / and doesn't
+ contain any others */
+ if (shm_path[0] != '/')
+ shm_path[0] = '/';
+
+ len = strlen (shm_path);
+ for (i = 1; i < len; i++)
+ {
+ if (shm_path[i] == '/')
+ shm_path[i] = '_';
+ }
+
+#ifdef __APPLE__
+ /* Apple doesn't like the name to be very long! */
+ shm_path[30] = 0;
+#endif
+
+ return 1;
+}
+
+static void posix_sem_destroy ()
+{
+ if (sem_close (shm_sem))
+ perror ("Error closing semaphore");
+ if (sem_unlink (shm_path))
+ perror ("Error unlinking semaphore");
+}
+
+static void posix_sem_open (BOOL Create)
+{
+ /* Ensure semaphore doesn't already exist */
+ if (Create)
+ sem_unlink (shm_path);
+
+ /* Create our semaphore */
+ if (Create)
+ shm_sem = sem_open (shm_path, O_CREAT | O_EXCL, 0600, 0);
+ else
+ shm_sem = sem_open (shm_path, 0);
+ if (shm_sem == (sem_t *)SEM_FAILED)
+ fatal_perror ("sem_open failed");
+}
+
+static void posix_sem_acquire ()
+{
+ while (sem_wait (shm_sem))
+ {
+ if (errno == EINTR)
+ continue;
+
+ fatal_perror ("sem_wait failed");
+ }
+}
+
+static void posix_sem_release ()
+{
+ if (sem_post (shm_sem))
+ fatal_perror ("sem_post failed");
+}
+
+static void posix_shm_destroy ()
+{
+ close (shm_fd);
+ if (shm_unlink (shm_path))
+ perror ("Failed to destory shared memory\n");
+}
+
+static BOOL posix_shm_create (const char *pName)
+{
+ if (!create_shm_path (pName))
+ {
+ perror ("Unable to copy shm path");
+ return FALSE;
+ }
+
+ /* Ensure it doesn't already exist */
+ shm_unlink (shm_path);
+
+ if (debug_level > 2)
+ fprintf (stderr,"shm_path: %s\n", shm_path);
+
+ shm_fd = shm_open (shm_path, O_CREAT | O_EXCL | O_RDWR, S_IRWXU);
+ if (shm_fd < 0)
+ {
+ perror ("Unable to create POSIX shm segment");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static BOOL posix_shm_open (const char *pName)
+{
+ if (!create_shm_path (pName))
+ {
+ perror ("Unable to copy shm path");
+ return FALSE;
+ }
+
+ shm_fd = shm_open (shm_path, O_RDWR, 0);
+ if (shm_fd < 0)
+ {
+ perror ("Unable to open POSIX shm segment");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void *posix_shm_map (BOOL Create, void *Addr, size_t Len)
+{
+ if (Create)
+ {
+ /* Set the shm entry size */
+ if (ftruncate (shm_fd, Len))
+ {
+ perror ("Unable to set POSIX shm segment size");
+ return (void *)-1;
+ }
+ }
+ return mmap (Addr, Len, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
+}
+
+static void posix_initialize_ops ()
+{
+ shm_type = SHM_USING_POSIX;
+ shm_ops.sem_open = posix_sem_open;
+ shm_ops.sem_destroy = posix_sem_destroy;
+ shm_ops.sem_acquire = posix_sem_acquire;
+ shm_ops.sem_release = posix_sem_release;
+ shm_ops.shm_open = posix_shm_open;
+ shm_ops.shm_destroy = posix_shm_destroy;
+ shm_ops.shm_map = posix_shm_map;
+}
+
+#endif /* USE_POSIX_IPC */
+
+#ifdef USE_SYSV_IPC
+
+static const int shared_memory_project_id = 0x54477758; /* "TGwX" in ascii. */
static int shm_sema_id = 0;
+static int shmid_server;
+static key_t shmkey;
#if defined( _SEM_SEMUN_UNDEFINED )
union semun {
- int val;
- struct semid_ds *buf;
- ushort * array;
- };
+ int val;
+ struct semid_ds *buf;
+ ushort * array;
+};
#endif /* _SEM_SEMUN_UNDEFINED */
-static void atexit_destroy_semaphore(void)
+static void sysv_sem_destroy ()
{
- if( debug_level ) fprintf( stderr, "atexit destroy of semaphore\n" );
- if( semctl( shm_sema_id, 0, IPC_RMID ) == -1 )
- {
- perror( "Unable to destroy semaphore" );
- }
+ if (semctl (shm_sema_id, 0, IPC_RMID) == -1)
+ perror ("Error closing semaphore");
}
-static void create_server_semaphore( key_t key )
+static void sysv_sem_open (BOOL Create)
{
- union semun argument;
-
- argument.val = 0; /* Initially the semaphore is not available */
+ union semun argument;
- shm_sema_id = semget( key, 1, IPC_CREAT | SHM_R | SHM_W );
- if( shm_sema_id == -1 )
- {
- fatal_perror( "sema create fail" );
- }
-
- /* Set the semaphore as available to start with */
- if( semctl( shm_sema_id, 0, SETVAL, argument ) < 0 )
- {
- fatal_perror( "Can't set value for new sema" );
- }
-
- atexit( atexit_destroy_semaphore );
+ argument.val = 0; /* Initially the semaphore is not available */
+
+ if (Create)
+ shm_sema_id = semget (shmkey, 1, IPC_CREAT | SHM_R | SHM_W);
+ else
+ shm_sema_id = semget (shmkey, 1, SHM_R | SHM_W);
+
+ if (shm_sema_id == -1)
+ fatal_perror ("semget fail");
+
+ /* Set the semaphore as available to start with */
+ if (Create)
+ {
+ if (semctl (shm_sema_id, 0, SETVAL, argument) < 0)
+ fatal_perror ("Can't set value for new semaphore");
+ }
}
-static void get_server_semaphore( key_t key )
+static void sysv_sem_acquire ()
{
- shm_sema_id = semget (key, 1, SHM_R | SHM_W );
- if( shm_sema_id == -1 )
- {
- fatal_perror( "sema get fail" );
- }
+ static struct sembuf acquire_operation = {0, -1, 0};
+
+ while (semop (shm_sema_id, &acquire_operation, 1) == -1)
+ {
+ if (errno == EINTR)
+ continue;
+
+ fatal_perror ("semop acquire failed");
+ }
+}
+
+static void sysv_sem_release ()
+{
+ static struct sembuf release_operation = {0, 1, 0};
+
+ while (semop (shm_sema_id, &release_operation, 1) == -1)
+ {
+ if (errno == EINTR)
+ continue;
+
+ fatal_perror ("semop release failed");
+ }
+}
+
+static void sysv_shm_destroy ()
+{
+ if (shmctl (shmid_server, IPC_RMID, 0) == -1)
+ perror ("Failed to destory shared memory\n");
+}
+
+static BOOL sysv_shm_create (const char *pName)
+{
+ shmkey = ftok (pName, shared_memory_project_id);
+ if (shmkey == -1)
+ {
+ perror ("can't create key_t for SYSV shm");
+ return FALSE;
+ }
+
+ if (debug_level > 2)
+ fprintf (stderr, "Key is 0x%x\n", shmkey);
+
+ return TRUE;
+}
+
+static void *sysv_shm_map (BOOL Create, void *Addr, size_t Len)
+{
+ int flags = SHM_R | SHM_W;
+
+ if (Create)
+ flags |= IPC_CREAT;
+
+ shmid_server = shmget (shmkey, Len, flags);
+ if (shmid_server == -1)
+ return (void *)-1;
+
+ return shmat (shmid_server, Addr, 0);
+}
+
+static void sysv_initialize_ops ()
+{
+ shm_type = SHM_USING_SYSV;
+ shm_ops.sem_open = sysv_sem_open;
+ shm_ops.sem_destroy = sysv_sem_destroy;
+ shm_ops.sem_acquire = sysv_sem_acquire;
+ shm_ops.sem_release = sysv_sem_release;
+ shm_ops.shm_open = sysv_shm_create;
+ shm_ops.shm_destroy = sysv_shm_destroy;
+ shm_ops.shm_map = sysv_shm_map;
+}
+
+#endif /* USE_SYSV_IPC */
+
+static void atexit_destroy_semaphore(void)
+{
+ if (debug_level)
+ fprintf (stderr, "atexit destroy of semaphore\n");
+ shm_ops.sem_destroy ();
+}
+
+static void create_server_semaphore ()
+{
+ shm_ops.sem_open (TRUE);
+ atexit (atexit_destroy_semaphore);
+}
+
+static void get_server_semaphore ()
+{
+ shm_ops.sem_open (FALSE);
}
#if defined( CRITSECTION_SEMA ) && defined( __i386__ )
@@ -315,7 +585,6 @@
/* Called prior to performing anything on shared data */
void acquire_shm_server_semaphore_exclusive(void)
{
- static struct sembuf acquire_operation = { 0, -1, 0 };
pid_t pid,tid;
/* Don't do anything if we're not running as a shared memory server */
@@ -342,14 +611,9 @@
else
#endif
{
- if( debug_level > DEBUG_LEVEL ) fprintf( stderr, "%d - Taking slow path\n", tid );
-
- while( semop( shm_sema_id, &acquire_operation, 1 ) == -1 )
- {
- if( errno == EINTR ) continue;
-
- fatal_perror( "sema acquire fail" );
- }
+ if (debug_level > DEBUG_LEVEL)
+ fprintf (stderr, "%d - Taking slow path\n", tid);
+ shm_ops.sem_acquire ();
}
#if defined( CRITSECTION_SEMA )
@@ -369,8 +633,6 @@
/* Call to release */
void release_shm_server_semaphore(void)
{
- static struct sembuf release_operation = { 0, 1, 0 };
-
/* Don't do anything if we're not running as a shared memory server */
if( !SERVER_GLOBAL_VARIABLE( shared_memory_server ) )
return;
@@ -392,14 +654,7 @@
if( interlocked_dec( &SERVER_GLOBAL_VARIABLE( sema_lock_count ) ) >= 0 )
{
#endif
-
- while( semop( shm_sema_id, &release_operation, 1 ) == -1 )
- {
- if( errno == EINTR ) continue;
-
- fatal_perror( "sema release fail" );
- }
-
+ shm_ops.sem_release ();
#if defined( CRITSECTION_SEMA )
}
#endif
@@ -408,24 +663,18 @@
}
#endif /* RECURIVE_CRITSECION_SEMA */
- if( debug_level > DEBUG_LEVEL ) fprintf( stderr, "%d - Released sema\n", wine_gettid_or_pid() );
+ if( debug_level > DEBUG_LEVEL ) fprintf( stderr, "%d - Released sema\n", wine_get_inprocess_tid() );
}
-static int shmid_server;
-
static void atexit_destroy_shared_memory(void)
{
- if( debug_level ) fprintf( stderr, "atexit destroy of shared_memory\n" );
- if( shmctl( shmid_server, IPC_RMID, 0 ) == -1 )
- {
- perror( "Failed to destory shared memory\n" );
- }
+ if (debug_level)
+ fprintf (stderr, "atexit destroy of shared_memory\n");
+ shm_ops.shm_destroy ();
}
-#endif /* defined( USE_SYSV_IPC ) */
-
void* regular_memory_alloc( const char* pathname, int reg_size )
{
@@ -445,8 +694,8 @@
void* create_server_shared_memory_area( const char* pathname, int reg_size )
{
void *shm_addr, *shm_get_addr;
- key_t shmkey;
size_t shm_size = initial_size + reg_size;
+ BOOL ShmInitialized = FALSE;
/* If we've already established the segment for this process, there's not need to
* repeat.
@@ -473,128 +722,129 @@
return NULL;
}
-#if defined( USE_SYSV_IPC )
- shmkey = ftok( pathname, shared_memory_project_id );
- if( shmkey == -1 )
+#ifdef USE_POSIX_IPC
+ ShmInitialized = posix_shm_create (pathname);
+ if (ShmInitialized)
+ posix_initialize_ops ();
+#endif
+#if defined(USE_SYSV_IPC)
+ if (!ShmInitialized)
{
- perror( "can't create key_t for shm" );
- return NULL;
+ ShmInitialized = sysv_shm_create (pathname);
+ if (ShmInitialized)
+ sysv_initialize_ops ();
}
+#endif
- if( debug_level > 2 ) fprintf( stderr, "Key is 0x%x\n", shmkey );
+ if (!ShmInitialized)
+ return NULL;
- /* NOTE: It's alright if it already exists from an unnatural death previously since
- * we're just going to reiintialize it...
- */
- while( shm_size > 0 )
+ /* Try full size first; if no luck, keep trying smaller sizes until
+ we succeed or hit 0 */
+ while (shm_size > 0)
{
- shmid_server = shmget( shmkey, shm_size, IPC_CREAT | SHM_R | SHM_W);
- if( shmid_server != -1 ) break;
- shm_size -= 2*PAGESIZE;
+ shm_addr = shm_ops.shm_map (TRUE, shm_get_addr, shm_size);
+ if (shm_addr != (void *)-1)
+ break;
+
+ if (shm_size <= 2 * PAGESIZE)
+ shm_size = 0;
+ else
+ shm_size -= 2 * PAGESIZE;
}
- if( shm_size <= 0 )
+ if (shm_size == 0)
{
- fprintf( stderr, "Unable to allocate any shared memory. Is SYSV shm supported/broken on your system?\n" );
+ fprintf (stderr,
+ "Unable to allocate any shared memory. Is shm supported on your system?\n");
+ shm_ops.shm_destroy ();
return NULL;
}
- else if( shm_size < initial_size + reg_size )
+ else if (shm_size < (initial_size + reg_size))
{
- if( shm_size < (reg_size + 0.5*initial_size) )
+ if (shm_size < (reg_size + 0.5 * initial_size))
{
- /* Probably not enough memory so don't use shm */
- fprintf( stderr, "A less than optimial amount of shared memory was available (%lu vs %d).\n"
- "Perhaps your registry is too large?\n", (unsigned long)shm_size,
- initial_size + reg_size );
- shmctl( shmid_server, IPC_RMID, 0 );
- return NULL;
+ /* Probably not enough memory so don't use shm */
+ fprintf (stderr,
+ "A less than optimial amount of shared memory was available (%lu vs %d).\n"
+ "Perhaps your registry is too large?\n",
+ (unsigned long)shm_size, initial_size + reg_size);
+ shm_ops.shm_destroy ();
+ return NULL;
}
- if( debug_level )
- fprintf( stderr, "Using shm with less than ideal shm(%lu vs %d).\n",
- (unsigned long)shm_size, initial_size + reg_size );
+ if (debug_level)
+ fprintf (stderr, "Using shm with less than ideal shm (%lu vs %d).\n",
+ (unsigned long)shm_size, initial_size + reg_size);
}
- if( debug_level > 1 )
- fprintf( stderr, "Allocated %lu with min_size %d and initial size %d\n",
- (unsigned long)shm_size, reg_size, initial_size );
-
- /* Get the segment */
- shm_addr = shmat( shmid_server, (void*)shm_get_addr/* FIXME dh: configureable */, 0 );
- if( shm_addr == (void*)-1 )
- {
- perror( "can't map memory? (server)" );
- return NULL;
- }
+ if (debug_level > 1)
+ fprintf (stderr, "Allocated %lu with min_size %d and initial size %d\n",
+ (unsigned long)shm_size, reg_size, initial_size);
/* Setup for this process */
server_memory_block = shm_addr;
allocated_shm_size = shm_size;
- /* Other processes cannot attach if we delete immediately. Mark for destruction on exit. */
- atexit( atexit_destroy_shared_memory );
-#endif /* defined( USE_SYSV_IPC ) */
+ /* Other processes cannot attach if we delete immediately. Mark for
+ destruction on exit. */
+ atexit (atexit_destroy_shared_memory);
/* Initialize the memory */
memset( server_memory_block, 0xff, allocated_shm_size );
- create_server_semaphore( shmkey );
+ create_server_semaphore ();
setup_shm_malloc();
return shm_addr;
}
-void* get_server_shared_memory_area( const char* pathname, size_t shm_size, void *shm_get_addr,
- size_t shm_res_size, void *shm_res_addr )
+void* get_server_shared_memory_area(shm_using_t shm_server_type,
+ const char* pathname, size_t shm_size,
+ void *shm_get_addr, size_t shm_res_size,
+ void *shm_res_addr )
{
- int shmid;
void* shm_addr;
- key_t shmkey;
- /* If we've already established the segment for this process, there's not need to
- * repeat.
- */
+ /* If we've already established the segment for this process, there's no
+ need to repeat */
if( server_memory_block )
return server_memory_block;
- /* PH: FIXME: Should probably make sure we destroy everything first if this is the wineserver starting. */
-
- shmkey = ftok( pathname, shared_memory_project_id );
- if( shmkey == -1 )
- {
- perror( "can't create key_t for shm" );
- return NULL;
- }
-
- if( debug_level > 2 ) fprintf( stderr, "Key is 0x%x\n", shmkey );
+#ifdef USE_POSIX_IPC
+ if (shm_server_type == SHM_USING_POSIX)
+ posix_initialize_ops ();
+#endif
+#ifdef USE_SYSV_IPC
+ if (shm_server_type == SHM_USING_SYSV)
+ sysv_initialize_ops ();
+#endif
+ if (shm_type == SHM_USING_NONE)
+ return NULL;
- shmid = shmget( shmkey, shm_size, SHM_R | SHM_W );
- if( shmid == -1 )
- {
- perror( "unable to create/get shared memory segment" );
- return NULL;
- }
+ if (!shm_ops.shm_open (pathname))
+ return NULL;
/* if the preloader has reserved memory memory for us, free it here
* just before the attach.*/
- if (shm_res_size && (shm_res_addr != shm_res_addr || shm_res_size < shm_size))
- {
- fprintf(stderr,
- "the memory reserved for the shm server by the preloader does not match "
- "the memory that the server is using. will use the servers addr, but it may "
- "fail to allocate\n");
- }
- if (shm_size)
+ if (shm_res_size &&
+ ((shm_res_addr != shm_get_addr) || (shm_res_size < shm_size)))
+ fprintf (stderr,
+ "the memory reserved for the shm server by the preloader does\n"
+ "not match the memory that the server is using. Will use the\n"
+ "servers addr, but it may fail to allocate\n");
+
+ if (shm_res_size)
{
- if (debug_level > 2)
- fprintf(stderr, "unmapping reserved area of %p (0x%lx)\n", shm_res_addr,
- (unsigned long)shm_res_size);
- munmap(shm_res_addr, shm_res_size);
+ if (debug_level > 2)
+ fprintf (stderr, "Unmapping reserved area of %p (0x%lx)\n",
+ shm_res_addr, (unsigned long)shm_res_size);
+ munmap (shm_res_addr, shm_res_size);
}
/* Get the segment */
- shm_addr = shmat( shmid, (void*)shm_get_addr, 0 );
+ shm_addr = shm_ops.shm_map (FALSE, shm_get_addr, shm_size);
if( shm_addr == (void*)-1 )
{
perror( "can't map memory (client)?" );
@@ -609,7 +859,7 @@
/* PH: FIXME: I think that this needs to turn into an atexit( shmdt... */
//shmctl( shmid, IPC_RMID, 0 );
- get_server_semaphore( shmkey );
+ get_server_semaphore ();
setup_shm_malloc();
@@ -662,6 +912,7 @@
SERVER_GLOBAL_VARIABLE( shared_memory_server ) = shm;
SERVER_GLOBAL_VARIABLE( shared_memory_server_size ) = allocated_shm_size;
SERVER_GLOBAL_VARIABLE( shared_memory_server_addr ) = server_memory_block;
+ SERVER_GLOBAL_VARIABLE( shared_memory_server_type ) = shm_type;
SERVER_GLOBAL_VARIABLE( serverdir ) = NULL;
SERVER_GLOBAL_VARIABLE( sema_lock_count ) = 0; /* We start locked for wineserver */
#if defined( RECURIVE_CRITSECION_SEMA )
@@ -705,12 +956,12 @@
else
{
/* Not enough memory available for the request */
- fatal_error( "not enough memory for allocation of %d bytes\n"
+ fatal_error( "not enough memory for allocation of %u bytes\n"
"start=%p present=%p total=0x%x\n",
- size,
- DYN_MEM_AREA(server_memory_block)->start,
- DYN_MEM_AREA(server_memory_block)->free,
- DYN_MEM_AREA(server_memory_block)->size );
+ (unsigned int)size,
+ DYN_MEM_AREA(server_memory_block)->start,
+ DYN_MEM_AREA(server_memory_block)->free,
+ (unsigned int)DYN_MEM_AREA(server_memory_block)->size );
new_area = (void*)-1;
}
Index: trace.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/server/trace.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- trace.c 31 Jul 2007 19:58:30 -0000 1.45
+++ trace.c 31 Jul 2007 20:06:23 -0000 1.46
@@ -398,7 +398,8 @@
fprintf( stderr, " debugged=%d,", req->debugged );
fprintf( stderr, " shm_server=%d,", req->shm_server );
fprintf( stderr, " shm_size=%d,", req->shm_size );
- fprintf( stderr, " shm_addr=%p", req->shm_addr );
+ fprintf( stderr, " shm_addr=%p,", req->shm_addr );
+ fprintf( stderr, " shm_type=%d", req->shm_type );
}
static void dump_init_thread_request( const struct init_thread_request *req )