The current design won't swap out the stack page of a process. So, the stack page won't change.
However, the scenario can come with the heap page. If I don't miss something, this is probably a design flaw.
It can be fixed if the PID of the process issuing read is passed as an additional argument to buffered read.
(Now, by dividing by 512 and checking the page table of the process, one can validate the physical address.
If the physical address is on the stack page, the address will be valid.
Otherwise, if it is a heap page, the page table can be checked for the correct page number.
Before writing data. Buffered_Read may have to first swap back the page (if swapped out)).
I think Buffered Read should have been designed with PID and logical address as arguments rather than physical address.
Did I miss a point somewhere? Any of the seniors? It is a nice catch anyway!
Murali