nibblebits / PeachOS

Simple kernel designed for a online course
GNU General Public License v2.0
133 stars 55 forks source link

struct registers should be __attribute__((packed)) #21

Closed TheWire closed 1 year ago

TheWire commented 1 year ago

I noticed a bug in my own PeachOS code which turned out to be to do with the order of registers in task.h struct registers. The order of cause matters because struct registers gets passed to assembly functions: task_return and restore_general_purpose_registers.

It follows if the order in memory matters then struct registers should be attribute((packed)) to ensure no compiler optimisations.

singul4ri7y commented 1 year ago

Hi, Do you mean the registers order, like which one comes before which one? I am not sure. Please bother to clarify. But the attribute((packed)) has nothing to do with it, as all the values are unsigned 32-bit integers and has no need of data padding or alignment, as it's already been aligned. You can research on structure data padding and alignment for more clarification.

nibblebits commented 1 year ago

I am closing this issue because the structure is already aligned therefore packing the structure is not so important. Thank you anyway it does not hurt to add it to the structure to be more clear about it but it is not so important.