Compare commits

...

2 Commits

Author SHA1 Message Date
Juhani Krekelä 0b5fd0d84e Deallocate program memory only at end of event dispatch
Previously programs deallocated their memory before forwarding a
message. If the forwarded message made another program allocate, this
could cause the program code to be overwritten while it is still
running.
2023-03-29 13:24:28 +03:00
Juhani Krekelä 3f5d4ebd16 Fix typo that broke builds 2023-03-29 13:23:06 +03:00
2 changed files with 24 additions and 10 deletions

View File

@ -88,9 +88,17 @@ process_event:
jne .not_open_file
call event_open_file
jmp .end
.not_opend_file:
.not_open_file:
.end:
cmp byte [exiting], 0
je .not_exiting
; Once we have deallocated our own memory, we may not call any
; external functions that might allocate. Safest place to do the
; deallocation is just before returning control to our caller
call deallocate_own_memory
.not_exiting:
pop es
pop ds
pop bp
@ -289,10 +297,7 @@ event_click:
jne .not_close
.close:
call unhook_self_from_window_chain
; Nothing can call into us again after we unhook
; the window, so deallocate the memory we have
; reserved
call deallocate_own_memory
mov byte [exiting], 1
; We don't need to call request_redraw here, since
; it will be called unconditionally above
jmp .title_bar_end
@ -672,6 +677,8 @@ request_redraw:
; Variables
; ------------------------------------------------------------------
exiting db 0
window_title db 'Hello'
.end:
WINDOW_TITLE_LEN equ window_title.end - window_title

View File

@ -76,9 +76,17 @@ process_event:
jne .not_open_file
call event_open_file
jmp .end
.not_opend_file:
.not_open_file:
.end:
cmp byte [exiting], 0
je .not_exiting
; Once we have deallocated our own memory, we may not call any
; external functions that might allocate. Safest place to do the
; deallocation is just before returning control to our caller
call deallocate_own_memory
.not_exiting:
pop es
pop ds
pop bp
@ -273,10 +281,7 @@ event_click:
jne .not_close
.close:
call unhook_self_from_window_chain
; Nothing can call into us again after we unhook
; the window, so deallocate the memory we have
; reserved
call deallocate_own_memory
mov byte [exiting], 1
; We don't need to call request_redraw here, since
; it will be called unconditionally above
jmp .title_bar_end
@ -554,6 +559,8 @@ request_redraw:
; Variables
; ------------------------------------------------------------------
exiting db 0
window_next dw 0xffff
window_x dw 65
window_y dw 3