I'm trying to read the output of sysinfo
system call from an assembly program but it seems that the system call leaves the sysinfo
struct unchanged
.section .data
result:
uptime:
.quad 00
loads:
.quad 00
total_ram:
.quad 00
free_ram:
.quad 00
shared_ram:
.quad 00, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.section .bss
.section .text
.globl main
main:
nop
movq $99, %rax
leaq result(%rip), %rdi
syscall
nop
strace shows that sysinfo is called correctly but using gdb to view the result after the syscall
shows that all are still unchanged(0). Also rax
is 0 which means that syscall
is called successfully. So why did syscall
didnt modify the result
struct although it works normally using C so why did this happen.
/********************* Debugging part *************************/
gdb at last nop
instruction ((gdb) x/9dg &result
:
0x7ffff7faad80 <result>: 0 0
0x7ffff7faad90 <result+16>: 0 0
0x7ffff7faada0 <result+32>: 0 0
0x7ffff7faadb0 <result+48>: 0 0
0x7ffff7faadc0 <result+64>: 0
man page of sysinfo
(man 2 sysinfo
):
int sysinfo(struct sysinfo *info);
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* Swap space still available */
unsigned short procs; /* Number of current processes */
char _f[22]; /* Pads structure to 64 bytes */
};
running strace ./sysinfo
shows this line
sysinfo({uptime=21623, loads=[134496, 128288, 129056], totalram=6125535232, freeram=231415808, sharedram=593993728, bufferram=306745344, totalswap=2147479552, freeswap=2056269824, procs=887, totalhigh=0, freehigh=0, mem_unit=1}) = 0