Mercurial > emacs
comparison src/alloc.c @ 67216:fc58516afccd
Include fcntl.h. Define O_WRONLY if not defined.
(valid_lisp_object_p) [!GC_MARK_STACK]: Validate pointer by
passing it to `emacs_write'.
| author | Kim F. Storm <storm@cua.dk> |
|---|---|
| date | Wed, 30 Nov 2005 00:04:51 +0000 |
| parents | e485868e3caf |
| children | 28fd92314a04 1955a4462bf9 |
comparison
equal
deleted
inserted
replaced
| 67215:c84d59e9c018 | 67216:fc58516afccd |
|---|---|
| 62 | 62 |
| 63 #ifdef HAVE_UNISTD_H | 63 #ifdef HAVE_UNISTD_H |
| 64 #include <unistd.h> | 64 #include <unistd.h> |
| 65 #else | 65 #else |
| 66 extern POINTER_TYPE *sbrk (); | 66 extern POINTER_TYPE *sbrk (); |
| 67 #endif | |
| 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 | |
| 67 #endif | 75 #endif |
| 68 | 76 |
| 69 #ifdef DOUG_LEA_MALLOC | 77 #ifdef DOUG_LEA_MALLOC |
| 70 | 78 |
| 71 #include <malloc.h> | 79 #include <malloc.h> |
| 4495 | 4503 |
| 4496 int | 4504 int |
| 4497 valid_lisp_object_p (obj) | 4505 valid_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; |
| 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 | |
| 4514 | 4538 |
| 4515 m = mem_find (p); | 4539 m = mem_find (p); |
| 4516 | 4540 |
| 4517 if (m == MEM_NIL) | 4541 if (m == MEM_NIL) |
| 4518 return 0; | 4542 return 0; |
