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