错误 :
setlevel.c :30 :error: expected declaration sepecifiers of '...' before 'syslog'
setlevel.c :30 :error: expected declaration sepecifiers of '...' before 'type'
setlevel.c :30 :error: expected declaration sepecifiers of '...' before 'bufp'
setlevel.c :30 :error: expected declaration sepecifiers of '...' before 'len'
错误发生在
一个函数声明那里
_systecall3(int,syslog,int,type,char*,bufp,int,len);
看不出那里出错。 上goole了一下。发现这是内核版本的问题。systecall3 是在2.6.11以前 的版本才有定义,之後版本就取消了。我使用的是2.6.25.14 为了编译它们需要加上定义才可以
什么是System Call 呢??疑问出来了。
以下是网络上一个个解释:
所有的操作系统在其内核里都有一些内建的函数,这些函数可以用来完成一些系统级别的功能。Linux系统使用的这样的函数叫做“系统调用”,英文systemcall
系统支持的system call 文件位于 /usr/include/bits/syscall.h 内
每个系统调用都有一个定义好的数字,这些数字是用来构造这些系统调用的。内核通过0x80中断来管理这些系统调用。这些系统调用的对应的数字和一些参数都在调用的时候送到某些寄存器里面。并且%eax寄存器全面检查系统调用表 如
sc()
{
__asm__(
"movl $165,%eax
int $0x80"
);
}
以上是呼叫165这个 System Call
系统调用的数字实际上是一个序列号,表示其在系统的一个数组sys_call_table[165]中的地址。
下图是网络上找来的
下图是根据calltables数组会叫对应eax寄存器的值为序号的system call 下面是entry_32.s内的 system call 的汇编源码
# system call handler stub
ENTRY(system_call)
RING0_INT_FRAME # can't unwind into user space anyway
pushl %eax # save orig_eax 保存eax 入栈
CFI_ADJUST_CFA_OFFSET 4
SAVE_ALL //保存所有寄存器,所有入栈
GET_THREAD_INFO(%ebp) # system call tracing in operation / emulation 获取进程的信息 PCB (task_struct)
/* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
jnz syscall_trace_entry
cmpl $(nr_syscalls), %eax
jae syscall_badsys
syscall_call:
call *sys_call_table(,%eax,4)
movl %eax,PT_EAX(%esp) # store the return value
syscall_exit:
LOCKDEP_SYS_EXIT
DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
# setting need_resched or sigpending
# between sampling and the iret
TRACE_IRQS_OFF
testl $TF_MASK,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
jz no_singlestep
orl $_TIF_SINGLESTEP,TI_flags(%ebp)
no_singlestep:
movl TI_flags(%ebp), %ecx
testw $_TIF_ALLWORK_MASK, %cx # current->work
jne syscall_exit_work
restore_all:
movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
# Warning: PT_OLDSS(%esp) contains the wrong/random values if we
# are returning to the kernel.
# See comments in process.c:copy_thread() for details.
movb PT_OLDSS(%esp), %ah
movb PT_CS(%esp), %al
andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
CFI_REMEMBER_STATE
je ldt_ss # returning to user-space with LDT SS
restore_nocheck:
TRACE_IRQS_IRET
restore_nocheck_notrace:
RESTORE_REGS
addl $4, %esp # skip orig_eax/error_code
CFI_ADJUST_CFA_OFFSET -4
irq_return:
INTERRUPT_RETURN
.section .fixup,"ax"
iret_exc:
pushl $0 # no error code
pushl $do_iret_error
jmp error_code
.previous
.section __ex_table,"a"
.align 4
.long irq_return,iret_exc
.previous
CFI_RESTORE_STATE
ldt_ss:
larl PT_OLDSS(%esp), %eax
jnz restore_nocheck
testl $0x00400000, %eax # returning to 32bit stack?
jnz restore_nocheck # allright, normal return
#ifdef CONFIG_PARAVIRT
/*
* The kernel can't run on a non-flat stack if paravirt mode
* is active. Rather than try to fixup the high bits of
* ESP, bypass this code entirely. This may break DOSemu
* and/or Wine support in a paravirt VM, although the option
* is still available to implement the setting of the high
* 16-bits in the INTERRUPT_RETURN paravirt-op.
*/
cmpl $0, pv_info+PARAVIRT_enabled
jne restore_nocheck
#endif
/* If returning to userspace with 16bit stack,
* try to fix the higher word of ESP, as the CPU
* won't restore it.
* This is an "official" bug of all the x86-compatible
* CPUs, which we can try to work around to make
* dosemu and wine happy. */
movl PT_OLDESP(%esp), %eax
movl %esp, %edx
call patch_espfix_desc
pushl $__ESPFIX_SS
CFI_ADJUST_CFA_OFFSET 4
pushl %eax
CFI_ADJUST_CFA_OFFSET 4
DISABLE_INTERRUPTS(CLBR_EAX)
TRACE_IRQS_OFF
lss (%esp), %esp
CFI_ADJUST_CFA_OFFSET -8
jmp restore_nocheck
CFI_ENDPROC
ENDPROC(system_call)