summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscottc <scottc>2002-07-11 21:49:07 +0000
committerscottc <scottc>2002-07-11 21:49:07 +0000
commitb79d9992003b74630bbea305e7e9e29d56bdaca2 (patch)
tree7226fa3bc5d841a439ad2a6304f51532e9f02290
parent1812384213f7320efb4ad46b40ac9637f5f0931c (diff)
downloadgdb-b79d9992003b74630bbea305e7e9e29d56bdaca2.tar.gz
* safe_memory.h: New file extracted from "woutsup.h".
* woutsup.h: Move the "safe" new/delete macros into the new "safe_memory.h" header file and include that here. * cygserver_client.cc: Explicitly include "safe_memory.h" for client-side code. (client_request::make_request): Use the "safe" new/delete macros unconditionally, i.e. use them on the client side as well as on the server side. * cygserver_transport.cc: Explicitly include "safe_memory.h" for client-side code. (create_server_transport): Use the "safe" new/delete macros unconditionally, i.e. use them on the client side as well as on the server side. * shm.cc: Include "safe_memory.h". (client_shmmgr::instance): Use the "safe" new/delete macros. (client_shmmgr::shmdt): Ditto. (client_shmmgr::new_segment): Ditto.
-rw-r--r--winsup/cygserver/woutsup.h34
-rw-r--r--winsup/cygwin/ChangeLog20
-rwxr-xr-xwinsup/cygwin/cygserver_client.cc9
-rwxr-xr-xwinsup/cygwin/cygserver_transport.cc9
-rw-r--r--winsup/cygwin/safe_memory.h48
-rw-r--r--winsup/cygwin/shm.cc8
-rw-r--r--winsup/cygwin/woutsup.h34
7 files changed, 78 insertions, 84 deletions
diff --git a/winsup/cygserver/woutsup.h b/winsup/cygserver/woutsup.h
index e93a2586c3d..e66a694ad18 100644
--- a/winsup/cygserver/woutsup.h
+++ b/winsup/cygserver/woutsup.h
@@ -107,36 +107,4 @@ extern "C" void __cygserver__printf (const char *, const char *, ...);
#define thread_printf __noop_printf
#endif
-/*****************************************************************************/
-
-/* Temporary hack to get around the thread-unsafe new/delete in cygwin
- * gcc 2.95.3. This should all be binned at the first opportunity,
- * e.g. gcc 3.1 or sooner.
- *
- * The trick here is to do contruction via malloc(3) and then the
- * placement new operator, and destruction via an explicit call to the
- * destructor and then free(3).
- */
-
-#include <new.h>
-#include <stdlib.h>
-
-#define safe_new0(T) (new (malloc (sizeof (T))) T)
-
-#ifdef NEW_MACRO_VARARGS
-
-#define safe_new(T, ...) \
- (new (malloc (sizeof (T))) T (__VA_ARGS__))
-
-#else /* !NEW_MACRO_VARARGS */
-
-#define safe_new(T, args...) \
- (new (malloc (sizeof (T))) T (## args))
-
-#endif /* !NEW_MACRO_VARARGS */
-
-#define safe_delete(T, O) \
-{ \
- (O)->~ ## T (); \
- free (O); \
-}
+#include "safe_memory.h"
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 424fec52112..8a6eb4b76c2 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,25 @@
2002-07-11 Conrad Scott <conrad.scott@dsl.pipex.com>
+ * safe_memory.h: New file extracted from "woutsup.h".
+ * woutsup.h: Move the "safe" new/delete macros into the new
+ "safe_memory.h" header file and include that here.
+ * cygserver_client.cc: Explicitly include "safe_memory.h" for
+ client-side code.
+ (client_request::make_request): Use the "safe" new/delete macros
+ unconditionally, i.e. use them on the client side as well as on
+ the server side.
+ * cygserver_transport.cc: Explicitly include "safe_memory.h" for
+ client-side code.
+ (create_server_transport): Use the "safe" new/delete macros
+ unconditionally, i.e. use them on the client side as well as on
+ the server side.
+ * shm.cc: Include "safe_memory.h".
+ (client_shmmgr::instance): Use the "safe" new/delete macros.
+ (client_shmmgr::shmdt): Ditto.
+ (client_shmmgr::new_segment): Ditto.
+
+2002-07-11 Conrad Scott <conrad.scott@dsl.pipex.com>
+
* cygserver_process (process::process): Add the client's cygpid
and winpid to all tracing statements as appropriate.
(process::exit_code): Ditto.
diff --git a/winsup/cygwin/cygserver_client.cc b/winsup/cygwin/cygserver_client.cc
index 2b81d446e43..9ae7f6ba4ee 100755
--- a/winsup/cygwin/cygserver_client.cc
+++ b/winsup/cygwin/cygserver_client.cc
@@ -24,6 +24,7 @@ details. */
#include "cygerrno.h"
#include "cygserver_shm.h"
+#include "safe_memory.h"
#include "cygwin/cygserver.h"
#include "cygwin/cygserver_transport.h"
@@ -355,11 +356,7 @@ client_request::make_request ()
error_code (errno);
else
error_code (ENOSYS);
-#ifdef safe_delete
safe_delete (transport_layer_base, transport);
-#else
- delete transport;
-#endif
return -1;
}
@@ -367,11 +364,7 @@ client_request::make_request ()
send (transport);
-#ifdef safe_delete
safe_delete (transport_layer_base, transport);
-#else
- delete transport;
-#endif
return 0;
}
diff --git a/winsup/cygwin/cygserver_transport.cc b/winsup/cygwin/cygserver_transport.cc
index bcf36cc1cf4..8684a6148f6 100755
--- a/winsup/cygwin/cygserver_transport.cc
+++ b/winsup/cygwin/cygserver_transport.cc
@@ -19,6 +19,8 @@ details. */
#include <sys/socket.h>
+#include "safe_memory.h"
+
#include "cygwin/cygserver_transport.h"
#include "cygwin/cygserver_transport_pipes.h"
#include "cygwin/cygserver_transport_sockets.h"
@@ -27,17 +29,10 @@ details. */
transport_layer_base *
create_server_transport ()
{
-#ifdef safe_new0
if (wincap.is_winnt ())
return safe_new0 (transport_layer_pipes);
else
return safe_new0 (transport_layer_sockets);
-#else
- if (wincap.is_winnt ())
- return new transport_layer_pipes;
- else
- return new transport_layer_sockets;
-#endif
}
#ifndef __INSIDE_CYGWIN__
diff --git a/winsup/cygwin/safe_memory.h b/winsup/cygwin/safe_memory.h
new file mode 100644
index 00000000000..bcfc9452e09
--- /dev/null
+++ b/winsup/cygwin/safe_memory.h
@@ -0,0 +1,48 @@
+/* safe_memory.h
+
+ Copyright 2002 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef __SAFE_MEMORY_H__
+#define __SAFE_MEMORY_H__
+
+/*****************************************************************************/
+
+/* Temporary hack to get around the thread-unsafe new/delete in cygwin
+ * gcc 2.95.3. This should all be binned at the first opportunity,
+ * e.g. gcc 3.1 or sooner.
+ *
+ * The trick here is to do contruction via malloc(3) and then the
+ * placement new operator, and destruction via an explicit call to the
+ * destructor and then free(3).
+ */
+
+#include <new.h>
+#include <stdlib.h>
+
+#define safe_new0(T) (new (malloc (sizeof (T))) T)
+
+#ifdef NEW_MACRO_VARARGS
+
+#define safe_new(T, ...) \
+ (new (malloc (sizeof (T))) T (__VA_ARGS__))
+
+#else /* !NEW_MACRO_VARARGS */
+
+#define safe_new(T, args...) \
+ (new (malloc (sizeof (T))) T (## args))
+
+#endif /* !NEW_MACRO_VARARGS */
+
+#define safe_delete(T, O) \
+{ \
+ (O)->~ ## T (); \
+ free (O); \
+}
+
+#endif /* __SAFE_MEMORY_H__ */
diff --git a/winsup/cygwin/shm.cc b/winsup/cygwin/shm.cc
index f4c6df54756..1813a23bab3 100644
--- a/winsup/cygwin/shm.cc
+++ b/winsup/cygwin/shm.cc
@@ -21,6 +21,7 @@ details. */
#include <unistd.h>
#include "cygerrno.h"
+#include "safe_memory.h"
#include "sigproc.h"
#include "cygserver_ipc.h"
@@ -145,7 +146,7 @@ client_shmmgr &
client_shmmgr::instance ()
{
if (!_instance)
- _instance = new client_shmmgr;
+ _instance = safe_new0 (client_shmmgr);
assert (_instance);
@@ -358,7 +359,7 @@ client_shmmgr::shmdt (const void *const shmaddr)
segptr->shmid, segptr->hFileMap,
strerror (request.error_code ()));
- delete segptr;
+ safe_delete (segment_t, segptr);
syscall_printf ("0 = shmdt (shmaddr = 0x%p)", shmaddr);
@@ -582,7 +583,8 @@ client_shmmgr::new_segment (const int shmid,
? (!previous->next || previous->next->shmaddr > shmaddr) \
: (!_segments_head || _segments_head->shmaddr > shmaddr));
- segment_t *const segptr = new segment_t (shmid, shmaddr, shmflg, hFileMap);
+ segment_t *const segptr =
+ safe_new (segment_t, shmid, shmaddr, shmflg, hFileMap);
assert (segptr);
diff --git a/winsup/cygwin/woutsup.h b/winsup/cygwin/woutsup.h
index e93a2586c3d..e66a694ad18 100644
--- a/winsup/cygwin/woutsup.h
+++ b/winsup/cygwin/woutsup.h
@@ -107,36 +107,4 @@ extern "C" void __cygserver__printf (const char *, const char *, ...);
#define thread_printf __noop_printf
#endif
-/*****************************************************************************/
-
-/* Temporary hack to get around the thread-unsafe new/delete in cygwin
- * gcc 2.95.3. This should all be binned at the first opportunity,
- * e.g. gcc 3.1 or sooner.
- *
- * The trick here is to do contruction via malloc(3) and then the
- * placement new operator, and destruction via an explicit call to the
- * destructor and then free(3).
- */
-
-#include <new.h>
-#include <stdlib.h>
-
-#define safe_new0(T) (new (malloc (sizeof (T))) T)
-
-#ifdef NEW_MACRO_VARARGS
-
-#define safe_new(T, ...) \
- (new (malloc (sizeof (T))) T (__VA_ARGS__))
-
-#else /* !NEW_MACRO_VARARGS */
-
-#define safe_new(T, args...) \
- (new (malloc (sizeof (T))) T (## args))
-
-#endif /* !NEW_MACRO_VARARGS */
-
-#define safe_delete(T, O) \
-{ \
- (O)->~ ## T (); \
- free (O); \
-}
+#include "safe_memory.h"