aboutsummaryrefslogtreecommitdiffstats
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 ();
78#define O_WRONLY 1 78#define O_WRONLY 1
79#endif 79#endif
80 80
81#ifdef WINDOWSNT
82#include <fcntl.h>
83#include "w32.h"
84#endif
85
81#ifdef DOUG_LEA_MALLOC 86#ifdef DOUG_LEA_MALLOC
82 87
83#include <malloc.h> 88#include <malloc.h>
@@ -125,17 +130,17 @@ static pthread_mutex_t alloc_mutex;
125#define BLOCK_INPUT_ALLOC \ 130#define BLOCK_INPUT_ALLOC \
126 do \ 131 do \
127 { \ 132 { \
128 pthread_mutex_lock (&alloc_mutex); \ 133 if (pthread_self () == main_thread) \
129 if (pthread_self () == main_thread) \ 134 BLOCK_INPUT; \
130 BLOCK_INPUT; \ 135 pthread_mutex_lock (&alloc_mutex); \
131 } \ 136 } \
132 while (0) 137 while (0)
133#define UNBLOCK_INPUT_ALLOC \ 138#define UNBLOCK_INPUT_ALLOC \
134 do \ 139 do \
135 { \ 140 { \
136 if (pthread_self () == main_thread) \ 141 pthread_mutex_unlock (&alloc_mutex); \
137 UNBLOCK_INPUT; \ 142 if (pthread_self () == main_thread) \
138 pthread_mutex_unlock (&alloc_mutex); \ 143 UNBLOCK_INPUT; \
139 } \ 144 } \
140 while (0) 145 while (0)
141 146
@@ -4608,6 +4613,32 @@ mark_stack ()
4608#endif /* GC_MARK_STACK != 0 */ 4613#endif /* GC_MARK_STACK != 0 */
4609 4614
4610 4615
4616/* Determine whether it is safe to access memory at address P. */
4617int
4618valid_pointer_p (p)
4619 void *p;
4620{
4621#ifdef WINDOWSNT
4622 return w32_valid_pointer_p (p, 16);
4623#else
4624 int fd;
4625
4626 /* Obviously, we cannot just access it (we would SEGV trying), so we
4627 trick the o/s to tell us whether p is a valid pointer.
4628 Unfortunately, we cannot use NULL_DEVICE here, as emacs_write may
4629 not validate p in that case. */
4630
4631 if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0)
4632 {
4633 int valid = (emacs_write (fd, (char *)p, 16) == 16);
4634 emacs_close (fd);
4635 unlink ("__Valid__Lisp__Object__");
4636 return valid;
4637 }
4638
4639 return -1;
4640#endif
4641}
4611 4642
4612/* Return 1 if OBJ is a valid lisp object. 4643/* Return 1 if OBJ is a valid lisp object.
4613 Return 0 if OBJ is NOT a valid lisp object. 4644 Return 0 if OBJ is NOT a valid lisp object.
@@ -4620,9 +4651,7 @@ valid_lisp_object_p (obj)
4620 Lisp_Object obj; 4651 Lisp_Object obj;
4621{ 4652{
4622 void *p; 4653 void *p;
4623#if !GC_MARK_STACK 4654#if GC_MARK_STACK
4624 int fd;
4625#else
4626 struct mem_node *m; 4655 struct mem_node *m;
4627#endif 4656#endif
4628 4657
@@ -4634,26 +4663,22 @@ valid_lisp_object_p (obj)
4634 return 1; 4663 return 1;
4635 4664
4636#if !GC_MARK_STACK 4665#if !GC_MARK_STACK
4637 /* We need to determine whether it is safe to access memory at 4666 return valid_pointer_p (p);
4638 address P. Obviously, we cannot just access it (we would SEGV
4639 trying), so we trick the o/s to tell us whether p is a valid
4640 pointer. Unfortunately, we cannot use NULL_DEVICE here, as
4641 emacs_write may not validate p in that case. */
4642 if ((fd = emacs_open ("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0)
4643 {
4644 int valid = (emacs_write (fd, (char *)p, 16) == 16);
4645 emacs_close (fd);
4646 unlink ("__Valid__Lisp__Object__");
4647 return valid;
4648 }
4649
4650 return -1;
4651#else 4667#else
4652 4668
4653 m = mem_find (p); 4669 m = mem_find (p);
4654 4670
4655 if (m == MEM_NIL) 4671 if (m == MEM_NIL)
4656 return 0; 4672 {
4673 int valid = valid_pointer_p (p);
4674 if (valid <= 0)
4675 return valid;
4676
4677 if (SUBRP (obj))
4678 return 1;
4679
4680 return 0;
4681 }
4657 4682
4658 switch (m->type) 4683 switch (m->type)
4659 { 4684 {