[NSWI004] Stuck on syscall return

Vojtech Horky horky at d3s.mff.cuni.cz
Sun Feb 16 17:27:26 CET 2020


Hello.

Dne 16. 02. 20 v 17:12 Patrik Smelik napsal(a):
> ne 16. 2. 2020 o 16:47 Vojtech Horky <horky at d3s.mff.cuni.cz 
> >    Looking at your code, I do not see where you distinguish between puts
> >    and putc in libc syscalls.. 
> 
> Do you mean puts and putchar? Well I've implemented it together, so that 
> we won't use several syscalls for basically the same thing. But now that 
> I've tried it, it worked so i guess that was the mistake :D It isn't 
> possible to pass a single char to a function that takes pointer to char 
> as argument? I thought since it was passed as int, it didn't really 
> matter what you cast it as after it gets to handle syscall.

Arguments of char and char * types are different (value and pointer to 
starting address of multiple values). In C, you can typecast almost any 
type to any type as long as you know what you are doing. And that is by 
design (well, sort of).


Not sure about your uncommitted changes, but

int c = ...;
syscall(WRITE, (unative_t) c)

together with

char *s = ...
syscall(WRITE, (unative_t) s)

is simply wrong. It can work only by accident as there will be some 
zeroes on the stack...


- VH


More information about the NSWI004 mailing list