summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c73
1 files changed, 49 insertions, 24 deletions
diff --git a/src/alloc.c b/src/alloc.c
index e3609292749..5cfcda2e1e0 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -78,6 +78,11 @@ extern POINTER_TYPE *sbrk ();
#define O_WRONLY 1
#endif
+#ifdef WINDOWSNT
+#include <fcntl.h>
+#include "w32.h"
+#endif
+
#ifdef DOUG_LEA_MALLOC
#include <malloc.h>
@@ -125,17 +130,17 @@ static pthread_mutex_t alloc_mutex;
#define BLOCK_INPUT_ALLOC \
do \
{ \
- pthread_mutex_lock (&alloc_mutex); \
- if (pthread_self () == main_thread) \
- BLOCK_INPUT; \
+ if (pthread_self () == main_thread) \
+ BLOCK_INPUT; \
+ pthread_mutex_lock (&alloc_mutex); \
} \
while (0)
#define UNBLOCK_INPUT_ALLOC \
do \
{ \
- if (pthread_self () == main_thread) \
- UNBLOCK_INPUT; \
- pthread_mutex_unlock (&alloc_mutex); \
+ pthread_mutex_unlock (&alloc_mutex); \
+ if (pthread_self () == main_thread) \
+ UNBLOCK_INPUT; \
} \
while (0)
@@ -4608,6 +4613,32 @@ mark_stack ()
#endif /* GC_MARK_STACK != 0 */
+/* Determine whether it is safe to access memory at address P. */
+int
+valid_pointer_p (p)
+ void *p;
+{
+#ifdef WINDOWSNT
+ return w32_valid_pointer_p (p, 16);
+#else
+ int fd;
+
+ /* Obviously, we cannot just access it (we would SEGV trying), so we
+ trick the o/s to tell us whether p is a valid pointer.
+ Unfortunately, we cannot use NULL_DEVICE here, as emacs_write may
+ not validate p in that case. */
+
+ if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0)
+ {
+ int valid = (emacs_write (fd, (char *)p, 16) == 16);
+ emacs_close (fd);
+ unlink ("__Valid__Lisp__Object__");
+ return valid;
+ }
+
+ return -1;
+#endif
+}
/* Return 1 if OBJ is a valid lisp object.
Return 0 if OBJ is NOT a valid lisp object.
@@ -4620,9 +4651,7 @@ valid_lisp_object_p (obj)
Lisp_Object obj;
{
void *p;
-#if !GC_MARK_STACK
- int fd;
-#else
+#if GC_MARK_STACK
struct mem_node *m;
#endif
@@ -4634,26 +4663,22 @@ valid_lisp_object_p (obj)
return 1;
#if !GC_MARK_STACK
- /* We need to determine whether it is safe to access memory at
- address P. Obviously, we cannot just access it (we would SEGV
- trying), so we trick the o/s to tell us whether p is a valid
- pointer. Unfortunately, we cannot use NULL_DEVICE here, as
- emacs_write may not validate p in that case. */
- if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0)
- {
- int valid = (emacs_write (fd, (char *)p, 16) == 16);
- emacs_close (fd);
- unlink ("__Valid__Lisp__Object__");
- return valid;
- }
-
- return -1;
+ return valid_pointer_p (p);
#else
m = mem_find (p);
if (m == MEM_NIL)
- return 0;
+ {
+ int valid = valid_pointer_p (p);
+ if (valid <= 0)
+ return valid;
+
+ if (SUBRP (obj))
+ return 1;
+
+ return 0;
+ }
switch (m->type)
{