第36部分-Linux x86 64位汇编 sysinfo系统调用

第36部分-Linux x86 64位汇编 sysinfo系统调用

Sysinfo可以返回关于系统配置的资源信息。

通过man 查看如下:

NAME

       sysinfo - return system information

 

SYNOPSIS

       #include

       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 */

};

通过查看文件arch/x86/entry/syscalls/syscall_64.tbl

知道系统调用号是99.

示例

.section .data
result:
uptime:
   .int 0,0
load1:
   .int 0,0
load5:
   .int 0,0
load15:
   .int 0,0
totalram:
   .int 0,0
freeram:
   .int 0,0
sharedram:
   .int 0,0
bufferram:
   .int 0,0
totalswap:
   .int 0,0
freeswap:
   .int 0,0
procs:
   .byte 0x00, 0x00
.section .text
.globl _start
_start:
   nop
   movq $result, %rdi
   movq $99, %rax
   syscall

   movq $0, %rbx
   movq $60, %rax
   syscall

as -g -o sysinfo.o sysinfo.s

ld -o sysinfo sysinfo.o

在执行过程中进行查看如下:

(gdb) x /d &load5

0x6000e1:   23584

(gdb) x /d &load15

0x6000e9:   10656

(gdb) x /d &totalram

0x6000f1:   -467349504

(gdb) x /ud &totalram

0x6000f1:   -467349504

(gdb) x /u &totalram

0x6000f1:   3827617792

(gdb) x /u &procs

0x600121:   1565

(gdb) x /u &totalswap

0x600111:   999288832

(gdb) x /u &freeswap

0x600119:   999288832

(gdb)

你可能感兴趣的:(X86处理器汇编技术系列)