Hi.

Previously, I encountered

this problem, at first it scared me, but the problem was that the esp for the problem was calculated as follows: esp = stack_bottom + stack_size, as a result, the first addition of data to the stack overwritten the data outside it.

To solve this problem, I changed the esp calculation formula to this: esp = stack_bottom + stack_size - X

And I had a question about what number should I substitute instead of X?

Since my kernel is designed to run in protected mode on x86 processors, that means x = 4 bytes(word size), right?

And what if they try to add 6 bytes of data to the stack at the start, then 2 bytes will get out of the stack border? Or will the first 4 bytes be added first, then 4 bytes will be subtracted from the esp and 4 bytes will be added again?