免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1308 | 回复: 8
打印 上一主题 下一主题

请教关于临界的用法(down up) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-28 13:36 |只看该作者 |倒序浏览
我用到了down up
但是编译以后总是提示:
/tmp/ccC0koWl.o(.text+0x25): In function `.text.lock.KBUILD_BASENAME':
: undefined reference to `__down_failed'
/tmp/ccC0koWl.o(.text+0x2c): In function `.text.lock.KBUILD_BASENAME':
: undefined reference to `__up_wakeup'
collect2: ld returned 1 exit status

我的源代码:
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif

#include <linux/config.h>;
#include <linux/mm.h>;
#include <linux/shm.h>;
#include <linux/init.h>;
#include <linux/msg.h>;
#include <linux/smp_lock.h>;
#include <linux/vmalloc.h>;
#include <linux/slab.h>;
#include <linux/highuid.h>;
#include <linux/wait.h>;
#include <asm/system.h>;
#include <asm/atomic.h>;
#include <asm/semaphore.h>;

#include <linux/kernel.h>;
#include <linux/sched.h>;
#include <linux/spinlock.h>;

struct ipc_ids {
int size;
int in_use;
int max_id;
unsigned short seq;
unsigned short seq_max;
struct semaphore sem;
spinlock_t ary;
struct ipc_id* entries;
};

static struct ipc_ids shm_ids;

asmlinkage long sys_shmget (key_t key, size_t size, int shmflg)
{
struct shmid_kernel *shp;
int err, id = 0;
down(&shm_ids.sem);
if (key == IPC_PRIVATE) {
//err = newseg(key, shmflg, size);
}
up(&shm_ids.sem);
return err;
}

int main()
{
return 0;
}

我的makefile:
#INCLUDE=-I/usr/src/linux/

#LIB=-L/data/oracle/product/9.2.0/lib/
#LINK=-ldl -lm -lpthread -lnsl -lirc

KERNELDIR =/usr/src/linux
include $(KERNELDIR)/.config
MODVERFILE = $(KERNELDIR)/include/linux/modversions.h
MODDEFS = -D__KERNEL__ -DMODULE -DMODVERSIONS
CFLAGS = -Wall -O2 -I$(KERNELDIR)/include -include $(MODVERFILE) -Wstrict-prototypes -fomit-frame-pointer -pipe -malign-loops=2 -malign-jumps=2 -malign-functions=2

SOURCE=$(wildcard *.c)
#SOURCE=main.c
CC=gcc
all:
$(CC) -w $(CFLAGS) $(MODDEFS) -o a.out $(SOURCE)
郁闷了我好多天 那位兄弟帮帮忙啊

论坛徽章:
0
2 [报告]
发表于 2005-06-28 13:48 |只看该作者

请教关于临界的用法(down up)

能不能说说你这个程序的目的先?

论坛徽章:
0
3 [报告]
发表于 2005-06-28 13:49 |只看该作者

请教关于临界的用法(down up)

这个是一段内核代码

论坛徽章:
0
4 [报告]
发表于 2005-06-28 13:51 |只看该作者

请教关于临界的用法(down up)

现在最主要的就是那个down(&shm_ids.sem);
up(&shm_ids.sem); 不能编译过去 如果把他们屏蔽掉了 就通过了
错误信息:
/tmp/ccC0koWl.o(.text+0x25): In function `.text.lock.KBUILD_BASENAME':
: undefined reference to `__down_failed'
/tmp/ccC0koWl.o(.text+0x2c): In function `.text.lock.KBUILD_BASENAME':
: undefined reference to `__up_wakeup'
collect2: ld returned 1 exit status

论坛徽章:
0
5 [报告]
发表于 2005-06-28 14:11 |只看该作者

请教关于临界的用法(down up)

呃。。。。。。。。。
kernel module不需要main
不需要ld的操作
你的程序有问题

论坛徽章:
0
6 [报告]
发表于 2005-06-28 14:18 |只看该作者

请教关于临界的用法(down up)

#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
不需要?那能编译过去?
那些多余的变量我是在其他的地方用的 为了搭建能够方便的看代码我把其他的都已经删除掉了,现在的问题不是集中在变量的问题上面 而是怎么能够消除下面的错误:
/tmp/ccC0koWl.o(.text+0x25): In function `.text.lock.KBUILD_BASENAME':
: undefined reference to `__down_failed'
/tmp/ccC0koWl.o(.text+0x2c): In function `.text.lock.KBUILD_BASENAME':
: undefined reference to `__up_wakeup'
collect2: ld returned 1 exit status

论坛徽章:
0
7 [报告]
发表于 2005-06-28 14:24 |只看该作者

请教关于临界的用法(down up)

我不知说什么好了
你先去找个kernel module的HelloWorld看看
然后你就晓得自己错在哪里了
从makefile到程序到module的概念都有错误阿

论坛徽章:
0
8 [报告]
发表于 2005-06-28 14:29 |只看该作者

请教关于临界的用法(down up)

哦 我明白你的意思:我程序的目的是把内核中的一段代码摘出来 我们自己用
我的qq:23030765   msn:zhangxiaoqi521@hotmail.com

邮箱:zhangxiaoqi@tomonline-inc.com

我们能够直接联系嘛 这种方式太慢了

论坛徽章:
0
9 [报告]
发表于 2005-06-28 15:15 |只看该作者

请教关于临界的用法(down up)

我们不能直接联系
在下的机器只能上web
这个问题不算很难的
自己看一下就明了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP