# ;; dmesg.s # the documentation on syslog(2) seems to be slightly different # than what I observe from on strace. strace shows # a call to syslog(0xa,0,0) to apparently retrieve the size of the # buffer (?) and then a call to syslog(3,buffer,bufflen) to actually # retrieve data # something's wrong with the heap allocation --- if I use a fixed buffer, works fine! #include .data _syslog_bytes: .long 0 _heap_bottom: .long 0 _heap_top: .long 0 .file "dmesg.s" .globl dmesg dmesg: mov $0xa,%ebx # find out how many bytes? I guess -- 0xa is definitely not documented! mov $0,%ecx mov $0,%edx mov $__NR_syslog,%eax int $0x80 mov %eax,_syslog_bytes # save the number of bytes mov $0,%ebx # find the bottom of the heap mov $__NR_brk,%eax # int $0x80 mov %eax,_heap_bottom # and save the bottom of heap in %r14 mov %eax,_heap_top # %r13 will keep the top of the heap mov _syslog_bytes,%eax add %eax,_heap_top mov _heap_top,%ebx # now ask to extend heap mov $__NR_brk,%eax int $0x80 mov $3,%ebx # do the actual call to syslog(2) mov _heap_bottom,%ecx mov _syslog_bytes,%edx mov $__NR_syslog,%eax int $0x80 mov %eax,_syslog_bytes # actual number of bytes remaining # to write, and of course begins with what # syslog(2) returned... write_loop: mov $1,%ebx mov _heap_bottom,%ecx mov _syslog_bytes,%edx mov $__NR_write,%eax int $0x80 add %eax,_heap_bottom sub %eax,_syslog_bytes jnz write_loop mov $0,%ebx mov $__NR_exit,%eax int $0x80