English 中文(简体)
当我执行 AIX 内核扩展程序时出错
原标题:errors when I excute AIX kernel extension program

Im newbie at AIX. I got many errors when I compiled kernel extension. After then, finally I compiled and Linked.

但当我执行二进制时,我犯了这个错误。

bash# ./sysconfig_1 load ./question.exp
Could not load program ./sysconfig_1:
        The program does not have an entry point or 
           the o_snentry field in the auxiliary haeder is invalid.
Examine file headers with the  dump -ohv  command

有人能帮我吗?

//sysconfig_1.c
#include <sys/types.h>
#include <sys/sysconfig.h>
#include <sys/device.h>
#include <sys/errno.h>

main(int argc, char *argv[])
{
    struct cfg_load cl;
    struct cfg_kmod ck;
    int rc;
    int act = -1;
    if (argc == 3)
    {
        if ((strcmp(argv[1], "load")) == 0)
            act = SYS_KLOAD;
        else if (strcmp(argv[1], "unload") == 0)
            act = SYS_KULOAD;
    }

    if (act == -1)
    {
        printf("usage: %s load|unload <kmod>
, argv[0]");
        exit(1);
    }

    cl.path =argv[2];
    cl.libpath = NULL;

    if (act == SYS_KLOAD)
    {
        /* Load Kernel Module */
        rc = sysconfig(SYS_KLOAD, &cl, sizeof(struct cfg_load));
        if (rc == CONF_SUCC)
            printf("kload returns %d, kmid = %x
", rc, cl.kmid);
        else
            printf("kload returns %d, errno = %d
", rc); //, errno);

        if ((rc == CONF_SUCC) && (cl.kmid != 0))
        {
            /*
             * Invoke entry point (kmod) or config routine (dd)
             * for kernel extension with CFG_INIT parameter.
             */
            ck.kmid = cl.kmid;
            ck.cmd = CFG_INIT;
            rc = sysconfig(SYS_CFGKMOD, &ck, sizeof(struct cfg_kmod));
            if (rc == CONF_SUCC)
                printf("cfgkmod returns %d, kmid = %x
", rc, cl.kmid);
            else 
                printf("cfgkmod returns %d, errno = %d
", rc); // , errno);
        }
    } else {
        /* Query to determine if kernel module is loaded. */
        rc = sysconfig(SYS_QUERYLOAD, &cl, sizeof(struct cfg_load));
        if (rc == CONF_SUCC)
            printf("queryload returns %d, kmid = %x
", rc, cl.kmid);
        else
            printf("queryload returns %d, errno = %x
", rc); // , errno);

        if ((rc == 0) && (cl.kmid != 0))
        {
            /*
             * Invoke entry point (kmod) or config routine (dd)
             * for kernel extension with CGW_TERM parameter.
             */
            ck.kmid = cl.kmid;
            ck.cmd = CFG_TERM;
            ck.mdiptr = 0;
            ck.mdilen = 0;
            rc = sysconfig(SYS_CFGKMOD, &ck, sizeof(struct cfg_kmod));
            if (rc == CONF_SUCC)
                printf("cfgkmod returns %d, kmid =%x
", rc, cl.kmid);
            else
            {
                printf("cfgkmod returns %d, errno =%d
, rc); //, errno");
                exit(rc);
            }
            /* Unconfigure kernel module. */
            rc = sysconfig(SYS_KULOAD, &cl, sizeof(struct cfg_load));
            if (rc == CONF_SUCC)
                printf("unload returns %d, kmid =%x
", rc, cl.kmid);
            else
                printf("unload returns %d, errno =%d
", rc); // , errno);
        }
    }
    exit(rc);
}

//question.c
#include <stdio.h>
#include <sys/device.h>
question_init(int cmd, struct uio *uio)
{
    switch(cmd) {
        case CFG_INIT: {
            printf("question_init: command=CFW_INIT 
");
            break;
            } 
        case CFG_TERM: {
            printf("question_init:command=CFG_TERM 
");
            break;
            }
        default:
            printf("question_init:command=%d
", cmd);
    }
    return 0;
}

question()
{
    return 42;
}

我编成这样,我误解了什么?

bash# gcc -D_KERNEL -Wall -g -pipe -maix64 -ffreestanding -msoft-float -c sysconfig_1.c
bash# gcc -D_KERNEL -Wall -g -pipe -maix64 -ffreestanding -msoft-float -c question.c
bash# /usr/bin/ld -o sysconfig_1 -b64 -K -bI:/usr/lib/kernex.exp -lsys -lcsys -lc_r sysconfig_1.o
最佳回答

您的程序并不打算在一个独立的环境中运行, 所以我猜这就是造成问题的 < code>- fredepty 选项。 < code> main 函数显然被视为普通函数, 而不是切入点 。

问题回答

暂无回答




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签