From 7ffb6955ce67ed159ae2386b053df929d6220725 Mon Sep 17 00:00:00 2001 From: Kim F. Storm Date: Fri, 28 Jul 2006 11:12:23 +0000 Subject: (valid_pointer_p): New function (from valid_lisp_object_p). (valid_lisp_object_p): Use it to check for valid SUBRP obj. --- src/alloc.c | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index b058b29c697..a861504ab89 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4606,6 +4606,27 @@ 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; +{ + 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; +} /* Return 1 if OBJ is a valid lisp object. Return 0 if OBJ is NOT a valid lisp object. @@ -4618,9 +4639,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 @@ -4632,26 +4651,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) { -- cgit v1.2.1 From 69b9efaa09b5fe495b5520af1a44f7f84dfd6b90 Mon Sep 17 00:00:00 2001 From: Richard M. Stallman Date: Sat, 29 Jul 2006 01:53:31 +0000 Subject: Whitespace change. --- src/alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index a861504ab89..4c1a81e7c92 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -4607,7 +4607,8 @@ mark_stack () /* Determine whether it is safe to access memory at address P. */ -int valid_pointer_p (p) +int +valid_pointer_p (p) void *p; { int fd; -- cgit v1.2.1 From 69666f776a28c398808c3a6c8004a5c831f84b7d Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 29 Jul 2006 10:18:48 +0000 Subject: [WINDOWSNT]: Include fcntl.h, to fix last change. --- src/alloc.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 4c1a81e7c92..e5735e03fd9 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -78,6 +78,10 @@ extern POINTER_TYPE *sbrk (); #define O_WRONLY 1 #endif +#ifdef WINDOWSNT +#include +#endif + #ifdef DOUG_LEA_MALLOC #include -- cgit v1.2.1 From f892cf9c9d14e5920ad5c8ce236bd660f18c0816 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 5 Aug 2006 13:01:50 +0000 Subject: Include w32.h. (valid_lisp_object_p) [WINDOWSNT]: Call w32_valid_pointer_p to do the job. --- src/alloc.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index e5735e03fd9..eb7acfd649f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -80,6 +80,7 @@ extern POINTER_TYPE *sbrk (); #ifdef WINDOWSNT #include +#include "w32.h" #endif #ifdef DOUG_LEA_MALLOC @@ -4615,6 +4616,9 @@ 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 @@ -4631,6 +4635,7 @@ valid_pointer_p (p) } return -1; +#endif } /* Return 1 if OBJ is a valid lisp object. -- cgit v1.2.1 From 0d3e774694d20e3cf496204fad3447bac9f13d55 Mon Sep 17 00:00:00 2001 From: Jan Djärv Date: Thu, 10 Aug 2006 06:09:30 +0000 Subject: * alloc.c (UNBLOCK_INPUT_ALLOC, BLOCK_INPUT_ALLOC): Use in_sighandler to check if mutex should be locked or not. --- src/alloc.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index eb7acfd649f..192b974196f 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -130,17 +130,27 @@ static pthread_mutex_t alloc_mutex; #define BLOCK_INPUT_ALLOC \ do \ { \ - pthread_mutex_lock (&alloc_mutex); \ - if (pthread_self () == main_thread) \ - BLOCK_INPUT; \ + if (!in_sighandler) \ + { \ + pthread_mutex_lock (&alloc_mutex); \ + if (pthread_self () == main_thread) \ + BLOCK_INPUT; \ + else \ + sigblock (sigmask (SIGIO)); \ + } \ } \ while (0) #define UNBLOCK_INPUT_ALLOC \ do \ { \ - if (pthread_self () == main_thread) \ - UNBLOCK_INPUT; \ - pthread_mutex_unlock (&alloc_mutex); \ + if (!in_sighandler) \ + { \ + pthread_mutex_unlock (&alloc_mutex); \ + if (pthread_self () == main_thread) \ + UNBLOCK_INPUT; \ + else \ + sigunblock (sigmask (SIGIO)); \ + } \ } \ while (0) -- cgit v1.2.1 From f3c4a0e1d28dcf59bf9b59ba040b361ad44adad3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Sun, 27 Aug 2006 07:08:31 +0000 Subject: (BLOCK_INPUT_ALLOC, UNBLOCK_INPUT_ALLOC): Undo previous change. Move mutex lock/unlock operations inside BLOCK_INPUT. --- src/alloc.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/alloc.c') diff --git a/src/alloc.c b/src/alloc.c index 192b974196f..2fd50009649 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -130,27 +130,17 @@ static pthread_mutex_t alloc_mutex; #define BLOCK_INPUT_ALLOC \ do \ { \ - if (!in_sighandler) \ - { \ - pthread_mutex_lock (&alloc_mutex); \ - if (pthread_self () == main_thread) \ - BLOCK_INPUT; \ - else \ - sigblock (sigmask (SIGIO)); \ - } \ + if (pthread_self () == main_thread) \ + BLOCK_INPUT; \ + pthread_mutex_lock (&alloc_mutex); \ } \ while (0) #define UNBLOCK_INPUT_ALLOC \ do \ { \ - if (!in_sighandler) \ - { \ - pthread_mutex_unlock (&alloc_mutex); \ - if (pthread_self () == main_thread) \ - UNBLOCK_INPUT; \ - else \ - sigunblock (sigmask (SIGIO)); \ - } \ + pthread_mutex_unlock (&alloc_mutex); \ + if (pthread_self () == main_thread) \ + UNBLOCK_INPUT; \ } \ while (0) -- cgit v1.2.1