Chapter 4. Max value for exit sys call in Linux

Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Chapter 4. Max value for exit sys call in Linux

pgubook-readers mailing list

My name is Anton.

Firstly, thank you very much for such a great book!
Reading it right now and trying to do exercises.

Secondly, just wanted to share my finding, may be a note about this problem will be added to the book sometime and will save some time for new readers.

When I was testing program with square function I noticed that at some input values program's exit codes were not correct (program was returning squared value by return code of exit system call).

Here is the listing:

.section .text
.globl _start
pushl $30
call square
addl $4, %esp
movl %eax, %ebx
movl $1, %eax
int $0x80

pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
imull %eax, %eax
movl %ebp, %esp
popl %ebp

return code was 127 (0x84), but it should be 900 (0x384).

And the problem was that it is limitation of bash (only 1 byte for exit codes - 0-255) and more accurately described at link below:

Sincerely yours,
Pgubook-readers mailing list
[hidden email]