aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKim F. Storm2005-11-30 00:04:51 +0000
committerKim F. Storm2005-11-30 00:04:51 +0000
commitde7124a7bda8ceeaf502775849f7aabf3a97c2be (patch)
tree6a3b0b2e0858dbc47820590bad7b7868d6fd57b6 /src
parent4269a2fd77bc80b11caacb55f7a101fc1cb21bdd (diff)
downloademacs-de7124a7bda8ceeaf502775849f7aabf3a97c2be.tar.gz
emacs-de7124a7bda8ceeaf502775849f7aabf3a97c2be.zip
Include fcntl.h. Define O_WRONLY if not defined.
(valid_lisp_object_p) [!GC_MARK_STACK]: Validate pointer by passing it to `emacs_write'.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 08bba475e76..f8d2f529bae 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -66,6 +66,14 @@ Boston, MA 02110-1301, USA. */
66extern POINTER_TYPE *sbrk (); 66extern POINTER_TYPE *sbrk ();
67#endif 67#endif
68 68
69#ifdef HAVE_FCNTL_H
70#define INCLUDED_FCNTL
71#include <fcntl.h>
72#endif
73#ifndef O_WRONLY
74#define O_WRONLY 1
75#endif
76
69#ifdef DOUG_LEA_MALLOC 77#ifdef DOUG_LEA_MALLOC
70 78
71#include <malloc.h> 79#include <malloc.h>
@@ -4497,21 +4505,37 @@ int
4497valid_lisp_object_p (obj) 4505valid_lisp_object_p (obj)
4498 Lisp_Object obj; 4506 Lisp_Object obj;
4499{ 4507{
4508 void *p;
4500#if !GC_MARK_STACK 4509#if !GC_MARK_STACK
4501 /* Cannot determine this. */ 4510 int fd;
4502 return -1;
4503#else 4511#else
4504 void *p;
4505 struct mem_node *m; 4512 struct mem_node *m;
4513#endif
4506 4514
4507 if (INTEGERP (obj)) 4515 if (INTEGERP (obj))
4508 return 1; 4516 return 1;
4509 4517
4510 p = (void *) XPNTR (obj); 4518 p = (void *) XPNTR (obj);
4511
4512 if (PURE_POINTER_P (p)) 4519 if (PURE_POINTER_P (p))
4513 return 1; 4520 return 1;
4514 4521
4522#if !GC_MARK_STACK
4523 /* We need to determine whether it is safe to access memory at
4524 address P. Obviously, we cannot just access it (we would SEGV
4525 trying), so we trick the o/s to tell us whether p is a valid
4526 pointer. Unfortunately, we cannot use NULL_DEVICE here, as
4527 emacs_write may not validate p in that case. */
4528 if ((fd = emacs_open("__Valid__Lisp__Object__", O_CREAT | O_WRONLY | O_TRUNC, 0666)) >= 0)
4529 {
4530 int valid = emacs_write(fd, (char *)p, 16) == 16;
4531 emacs_close(fd);
4532 unlink("__Valid__Lisp__Object__");
4533 return valid;
4534 }
4535
4536 return -1;
4537#else
4538
4515 m = mem_find (p); 4539 m = mem_find (p);
4516 4540
4517 if (m == MEM_NIL) 4541 if (m == MEM_NIL)