aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32notify.c
diff options
context:
space:
mode:
authorEli Zaretskii2012-10-18 07:13:29 +0200
committerEli Zaretskii2012-10-18 07:13:29 +0200
commit0b86d359eb52cef840345f7fd09b5f4342aede03 (patch)
treecf6f40a1e99685727a2004930bfab592724478dd /src/w32notify.c
parent9a85d8539c1685b90599a77c5b7872c8ce1a86c2 (diff)
downloademacs-0b86d359eb52cef840345f7fd09b5f4342aede03.tar.gz
emacs-0b86d359eb52cef840345f7fd09b5f4342aede03.zip
Use XIL/XLI instead of make_number/XINT for converting descriptor to a ptr.
More safety checks in using the pointer obtained from descriptor. Not tested yet.
Diffstat (limited to 'src/w32notify.c')
-rw-r--r--src/w32notify.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/w32notify.c b/src/w32notify.c
index 244b0b872bf..f14621001a8 100644
--- a/src/w32notify.c
+++ b/src/w32notify.c
@@ -103,12 +103,12 @@ struct notification {
103 char *watchee; /* the file we are interested in */ 103 char *watchee; /* the file we are interested in */
104 HANDLE dir; /* handle to the watched directory */ 104 HANDLE dir; /* handle to the watched directory */
105 HANDLE thr; /* handle to the thread that watches */ 105 HANDLE thr; /* handle to the thread that watches */
106 int terminate; /* if non-zero, request for the thread to terminate */ 106 volatile int terminate; /* if non-zero, request for the thread to terminate */
107 unsigned signature; 107 unsigned signature;
108}; 108};
109 109
110/* Used for communicating notifications to the main thread. */ 110/* Used for communicating notifications to the main thread. */
111int notification_buffer_in_use; 111volatile int notification_buffer_in_use;
112BYTE file_notifications[16384]; 112BYTE file_notifications[16384];
113DWORD notifications_size; 113DWORD notifications_size;
114void *notifications_desc; 114void *notifications_desc;
@@ -120,7 +120,8 @@ static Lisp_Object Qsecurity_desc, Qsubtree, watch_list;
120/* Signal to the main thread that we have file notifications for it to 120/* Signal to the main thread that we have file notifications for it to
121 process. */ 121 process. */
122static void 122static void
123send_notifications (BYTE *info, DWORD info_size, void *desc, int *terminate) 123send_notifications (BYTE *info, DWORD info_size, void *desc,
124 volatile int *terminate)
124{ 125{
125 int done = 0; 126 int done = 0;
126 FRAME_PTR f = SELECTED_FRAME (); 127 FRAME_PTR f = SELECTED_FRAME ();
@@ -557,7 +558,7 @@ FILE is the name of the file whose event is being reported. */)
557 report_file_error ("Cannot watch file", Fcons (file, Qnil)); 558 report_file_error ("Cannot watch file", Fcons (file, Qnil));
558 } 559 }
559 /* Store watch object in watch list. */ 560 /* Store watch object in watch list. */
560 watch_descriptor = make_number (dirwatch); 561 watch_descriptor = XIL ((EMACS_INT)dirwatch);
561 watch_object = Fcons (watch_descriptor, callback); 562 watch_object = Fcons (watch_descriptor, callback);
562 watch_list = Fcons (watch_object, watch_list); 563 watch_list = Fcons (watch_object, watch_list);
563 564
@@ -572,17 +573,22 @@ WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'. */)
572 (Lisp_Object watch_descriptor) 573 (Lisp_Object watch_descriptor)
573{ 574{
574 Lisp_Object watch_object; 575 Lisp_Object watch_object;
575 struct notification *dirwatch = 576 struct notification *dirwatch;
576 (struct notification *)XINT (watch_descriptor); 577 int status = -1;
577 578
578 /* Remove the watch object from watch list. Do this before freeing 579 /* Remove the watch object from watch list. Do this before freeing
579 the object, do that even if we fail to free it, watch_list is 580 the object, do that even if we fail to free it, watch_list is
580 kept free of junk. */ 581 kept free of junk. */
581 watch_object = Fassoc (watch_descriptor, watch_list); 582 watch_object = Fassoc (watch_descriptor, watch_list);
582 if (!NILP (watch_object)) 583 if (!NILP (watch_object))
583 watch_list = Fdelete (watch_object, watch_list); 584 {
585 watch_list = Fdelete (watch_object, watch_list);
586 dirwatch = (struct notification *)XLI (watch_descriptor);
587 if (w32_valid_pointer_p (dirwatch, sizeof(struct notification)))
588 status = remove_watch (dirwatch);
589 }
584 590
585 if (remove_watch (dirwatch) == -1) 591 if (status == -1)
586 report_file_error ("Invalid watch descriptor", Fcons (watch_descriptor, 592 report_file_error ("Invalid watch descriptor", Fcons (watch_descriptor,
587 Qnil)); 593 Qnil));
588 594
@@ -590,9 +596,13 @@ WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'. */)
590} 596}
591 597
592Lisp_Object 598Lisp_Object
593w32_get_watch_object (Lisp_Object desc) 599w32_get_watch_object (void *desc)
594{ 600{
595 return NILP (watch_list) ? Qnil : assoc_no_quit (desc, watch_list); 601 Lisp_Object descriptor = XIL ((EMACS_INT)desc);
602
603 /* This is called from the input queue handling code, so we cannot
604 possibly QUIT if watch_list is not in the right condition. */
605 return NILP (watch_list) ? Qnil : assoc_no_quit (descriptor, watch_list);
596} 606}
597 607
598void 608void