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.
This commit is contained in:
parent
3f5d4ebd16
commit
0b5fd0d84e
15
hello.asm
15
hello.asm
|
@ -91,6 +91,14 @@ process_event:
|
||||||
.not_open_file:
|
.not_open_file:
|
||||||
|
|
||||||
.end:
|
.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 es
|
||||||
pop ds
|
pop ds
|
||||||
pop bp
|
pop bp
|
||||||
|
@ -289,10 +297,7 @@ event_click:
|
||||||
jne .not_close
|
jne .not_close
|
||||||
.close:
|
.close:
|
||||||
call unhook_self_from_window_chain
|
call unhook_self_from_window_chain
|
||||||
; Nothing can call into us again after we unhook
|
mov byte [exiting], 1
|
||||||
; the window, so deallocate the memory we have
|
|
||||||
; reserved
|
|
||||||
call deallocate_own_memory
|
|
||||||
; We don't need to call request_redraw here, since
|
; We don't need to call request_redraw here, since
|
||||||
; it will be called unconditionally above
|
; it will be called unconditionally above
|
||||||
jmp .title_bar_end
|
jmp .title_bar_end
|
||||||
|
@ -672,6 +677,8 @@ request_redraw:
|
||||||
; Variables
|
; Variables
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
|
exiting db 0
|
||||||
|
|
||||||
window_title db 'Hello'
|
window_title db 'Hello'
|
||||||
.end:
|
.end:
|
||||||
WINDOW_TITLE_LEN equ window_title.end - window_title
|
WINDOW_TITLE_LEN equ window_title.end - window_title
|
||||||
|
|
15
memory.asm
15
memory.asm
|
@ -79,6 +79,14 @@ process_event:
|
||||||
.not_open_file:
|
.not_open_file:
|
||||||
|
|
||||||
.end:
|
.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 es
|
||||||
pop ds
|
pop ds
|
||||||
pop bp
|
pop bp
|
||||||
|
@ -273,10 +281,7 @@ event_click:
|
||||||
jne .not_close
|
jne .not_close
|
||||||
.close:
|
.close:
|
||||||
call unhook_self_from_window_chain
|
call unhook_self_from_window_chain
|
||||||
; Nothing can call into us again after we unhook
|
mov byte [exiting], 1
|
||||||
; the window, so deallocate the memory we have
|
|
||||||
; reserved
|
|
||||||
call deallocate_own_memory
|
|
||||||
; We don't need to call request_redraw here, since
|
; We don't need to call request_redraw here, since
|
||||||
; it will be called unconditionally above
|
; it will be called unconditionally above
|
||||||
jmp .title_bar_end
|
jmp .title_bar_end
|
||||||
|
@ -554,6 +559,8 @@ request_redraw:
|
||||||
; Variables
|
; Variables
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
|
exiting db 0
|
||||||
|
|
||||||
window_next dw 0xffff
|
window_next dw 0xffff
|
||||||
window_x dw 65
|
window_x dw 65
|
||||||
window_y dw 3
|
window_y dw 3
|
||||||
|
|
Loading…
Reference in New Issue