diff options
| author | Eli Zaretskii | 2012-10-18 07:13:29 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2012-10-18 07:13:29 +0200 |
| commit | 0b86d359eb52cef840345f7fd09b5f4342aede03 (patch) | |
| tree | cf6f40a1e99685727a2004930bfab592724478dd /src | |
| parent | 9a85d8539c1685b90599a77c5b7872c8ce1a86c2 (diff) | |
| download | emacs-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')
| -rw-r--r-- | src/w32inevt.c | 2 | ||||
| -rw-r--r-- | src/w32notify.c | 30 | ||||
| -rw-r--r-- | src/w32term.c | 2 | ||||
| -rw-r--r-- | src/w32term.h | 4 |
4 files changed, 24 insertions, 14 deletions
diff --git a/src/w32inevt.c b/src/w32inevt.c index 878106d7070..06629d37cf6 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c | |||
| @@ -599,7 +599,7 @@ handle_file_notifications (struct input_event *hold_quit) | |||
| 599 | { | 599 | { |
| 600 | DWORD info_size = notifications_size; | 600 | DWORD info_size = notifications_size; |
| 601 | Lisp_Object cs = intern ("utf-16le"); | 601 | Lisp_Object cs = intern ("utf-16le"); |
| 602 | Lisp_Object obj = w32_get_watch_object (make_number (notifications_desc)); | 602 | Lisp_Object obj = w32_get_watch_object (notifications_desc); |
| 603 | 603 | ||
| 604 | /* notifications_size could be zero when the buffer of | 604 | /* notifications_size could be zero when the buffer of |
| 605 | notifications overflowed on the OS level, or when the | 605 | notifications overflowed on the OS level, or when the |
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. */ |
| 111 | int notification_buffer_in_use; | 111 | volatile int notification_buffer_in_use; |
| 112 | BYTE file_notifications[16384]; | 112 | BYTE file_notifications[16384]; |
| 113 | DWORD notifications_size; | 113 | DWORD notifications_size; |
| 114 | void *notifications_desc; | 114 | void *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. */ |
| 122 | static void | 122 | static void |
| 123 | send_notifications (BYTE *info, DWORD info_size, void *desc, int *terminate) | 123 | send_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 | ||
| 592 | Lisp_Object | 598 | Lisp_Object |
| 593 | w32_get_watch_object (Lisp_Object desc) | 599 | w32_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 | ||
| 598 | void | 608 | void |
diff --git a/src/w32term.c b/src/w32term.c index 1285b5a06f6..c00bbe0f3cd 100644 --- a/src/w32term.c +++ b/src/w32term.c | |||
| @@ -3282,7 +3282,7 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f, | |||
| 3282 | { | 3282 | { |
| 3283 | DWORD info_size = notifications_size; | 3283 | DWORD info_size = notifications_size; |
| 3284 | Lisp_Object cs = intern ("utf-16le"); | 3284 | Lisp_Object cs = intern ("utf-16le"); |
| 3285 | Lisp_Object obj = w32_get_watch_object (make_number (notifications_desc)); | 3285 | Lisp_Object obj = w32_get_watch_object (notifications_desc); |
| 3286 | 3286 | ||
| 3287 | /* notifications_size could be zero when the buffer of | 3287 | /* notifications_size could be zero when the buffer of |
| 3288 | notifications overflowed on the OS level, or when the | 3288 | notifications overflowed on the OS level, or when the |
diff --git a/src/w32term.h b/src/w32term.h index 94ef9624351..14b3d1ffc42 100644 --- a/src/w32term.h +++ b/src/w32term.h | |||
| @@ -683,11 +683,11 @@ extern BOOL parse_button (int, int, int *, int *); | |||
| 683 | extern void w32_sys_ring_bell (struct frame *f); | 683 | extern void w32_sys_ring_bell (struct frame *f); |
| 684 | extern void x_delete_display (struct w32_display_info *dpyinfo); | 684 | extern void x_delete_display (struct w32_display_info *dpyinfo); |
| 685 | 685 | ||
| 686 | extern int notification_buffer_in_use; | 686 | extern volatile int notification_buffer_in_use; |
| 687 | extern BYTE file_notifications[16384]; | 687 | extern BYTE file_notifications[16384]; |
| 688 | extern DWORD notifications_size; | 688 | extern DWORD notifications_size; |
| 689 | extern void *notifications_desc; | 689 | extern void *notifications_desc; |
| 690 | extern Lisp_Object w32_get_watch_object (Lisp_Object); | 690 | extern Lisp_Object w32_get_watch_object (void *); |
| 691 | extern Lisp_Object lispy_file_action (DWORD); | 691 | extern Lisp_Object lispy_file_action (DWORD); |
| 692 | 692 | ||
| 693 | extern void w32_initialize_display_info (Lisp_Object); | 693 | extern void w32_initialize_display_info (Lisp_Object); |