[NSWI004] Adding print prevents exception 5

Tomáš Drozdík drozdik.tomas at gmail.com
Sat Jan 4 21:15:48 CET 2020


Hi,

I've encountered an interesting problem that I cannot really reason about.

As I was dealing with counting references to an address space my code
suddenly started throwing Exception 5. Via debug prints I was able to
track down when this exception is thrown. What came as a surprise is
that if a place a print right before this instruction everything works
properly (i.e. tests which should pass pass). Moving this print
anywhere else ruins it and exception is thrown.

This is a little snippet from thread_create function:
```
printk("REMOVE THIS PRINT AND EXCEPTION 5 IS THROWN\n");
++thread->as->reference_counter;
```
I've looked up that Exception 5 is an store to illegal address. What
does it have to do with print is beyond me, obviously adding print
does shift code in the memory and so it may get aligned or something.
But alignment of code is compilers job. Therefore illegal address
should be in memory, possibly in as_t structure but that contains just
4 integers.
I don't know how much code I can paste here and even if I could I'm
not even remotely aware of what can cause such behavior.

Link to repo: https://gitlab.mff.cuni.cz/teaching/nswi004/winter-2019-20/team-i_cant_c/tree/as5
Commit hash: 80761a068cd7f342d42e7786eaf5611419ac0487

Any help would be really appreciated.
Thanks in advance.

Sincerly
Tomáš Drozdík


More information about the NSWI004 mailing list