setlevel line 30 error

错误 :  
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寄存器全面检查系统调用表 如
更多精彩 用 超级搜索引擎
速谷歌    http://www.sugoogle.com

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)


解决办法:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/syscall.h>
#include <linux/unistd.h>


int syslog(int type,char *bufp,int len)
 {
     long __res;
     __asm__ volatile ("int $0x80":"=a"(__res):"0"(103),"b"((long)(type)),"c"    ((long)(bufp)),"d"((long)(len)));
 
     if ((unsigned long)(__res) >= (unsigned long)(-125)){
         errno = -(__res);
         __res = -1;
     }
     return (int)(__res);
 }




 int main(int argc, char **argv)
 {
     int level;


     if (argc==2) {
     level = atoi(argv[1]); /* the chosen console */
     } else {
        fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1);
     }
     if (syslog(8,NULL,level) < 0) {
                 argv[0],strerror(errno));
        exit(1);
     }
     exit(0);
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值