Tag: 内核

在Linux内核源代码中实现系统调用/陷阱

我目前正在学习操作系统使用陷阱来促进Linux内核中的系统调用。 我在traps.c中找到了陷阱表,并在entry.S中实现了许多陷阱。 但是,我被指示在Linux内核中找到两个系统调用的实现,它使用陷阱来实现系统调用。 虽然我可以找到陷阱本身的定义,但我不确定内核中的其中一个陷阱的“调用”是什么样的。 因此,我正在努力寻找这种行为的一个例子。 在有人问之前,是的,这是家庭作业。 作为一个注释,我正在使用Github浏览内核源代码,因为kernel.org已关闭: https : //github.com/torvalds/linux/

如何在用户空间程序中使用内核libcrc32c(或相同的函数)?

我想在我自己的用户空间程序中进行一些CRC检查。 我发现内核加密lib已经在系统中,并且支持SSE4.2。 我试着直接#include 并用-I/usr/src/linux/include/运行gcc。 但是,它不起作用。 有什么办法可以使用某种libcrc32c吗?

netlink_kernel_create无法使用最新的Linux内核

我在编译使用netlink函数的旧kernel模块时遇到编译器错误。 int init_module() { /* Initialize the Netlink kernel interface */ nl_sk = netlink_kernel_create(&init_net, 17, 0, recv_cmd, NULL, THIS_MODULE); if(!nl_sk) { printk(KERN_INFO “failed to initialize system (error: 1001)\n”); return -ENOMEM; } …. 以前它工作正常,但现在我收到此错误。 error: too many arguments to function ‘netlink_kernel_create’ OS信息 uname -a Linux ibrar-ahmed 3.8.0-17-generic #27-Ubuntu SMP Sun Apr 7 19:39:35 UTC 2013 x86_64 […]

如何使用内核创建可启动CD映像?

我有一个内核,要启动我正在使用命令qemu-system-i386 -kernel kernel.bin 。 有没有办法用qemu-system-i386 -cdrom CD.iso创建可引导的磁盘映像? 我在linux中用这些命令编译的代码: nasm -f elf32 kernel.asm -o kernelasm.o gcc -m32 -c kernel.c -o kernelc.o ld -m elf_i386 -T link.ld -o kernel.bin kernelasm.o kernelc.o 然后使用qemu-system-i386 -kernel kernel.bin 代码:kernel.asm: [BITS 32] SECTION .text align 4 dd 0x1BADB002 dd 0x00 dd – (0x1BADB002 + 0x00) global start global keyboard_handler global read_port global […]

如何在rmmod上停止Linux内核线程?

我编写了以下代码来创建内核线程: #include #include #include #include #include struct task_struct *task; int data; int ret; int thread_function(void *data) { int var; var = 10; return var; } static int kernel_init(void) { data = 20; printk(KERN_INFO”——————————————–“); task = kthread_create(&thread_function,(void *)data,”pradeep”); task = kthread_run(&thread_function,(void *)data,”pradeep”); printk(KERN_INFO”Kernel Thread : %s\n”,task->comm); return 0; } static void kernel_exit(void) { ret = kthread_stop(task); […]

Jiffies – 如何计算秒数?

我有一段代码,我想以秒计算时间..虽然我在jiffies有时间,我怎么能在几秒钟内转换它? 这是我的内核代码: #include #include #include #include unsigned long js, je, tet; int netblock_init_module(void){ js = jiffies; printk(“\n[Jiffies start Time : %lu]\nModule Started.\n”, js); return 0; } void netblock_cleanup_module(void) { je = jiffies; printk(“\n[Jiffies End Time : %lu]\nModule Removed.\n”, je); tet = je – js; printk(“\nEnd Time [%lu] – Start Time [%lu]: \nTotlal elapsed Time [%lu]\n”,js,je, […]

C内核 – 在VM上工作正常但不是真正的计算机吗?

我正在制作一个基本的C内核。 (由汇编程序加载)我正在用Windows的i686-elf交叉编译器编译它。 我的C代码如下: void cls(); void drawhappy(); void main(){ char *vidptr = (char *)0xb8000; cls(); drawhappy(); } void cls(){ char *vidptr = (char *)0xb8000; unsigned int j = 0; while(j < 80*2*25){ vidptr[j] = ' '; vidptr[j+1] = 0x07; j = j+2; } } void drawhappy(){ char *vidptr = (char *)0xb8000; const unsigned int linewidth […]

如何在内核源文件中包含math.h #include ?

我想在我的Linux内核模块中包含math.h。 如果我用, #include ‘/usr/include/math.h’ 它给我以下错误: error: features.h: No such file or directory error: bits/huge_val.h: No such file or directory error: bits/mathdef.h: No such file or directory error: bits/mathcalls.h: No such file or directory 为什么是这样?

C – Linux – 内核模块 – TCP标头

我正在尝试创建linux内核模块,它将检查传入的数据包。 目前,我正在提取数据包的TCP头并读取源和目标端口 – >但是我得到的值不正确。 我有钩function: unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)) { struct iphdr *ipp = (struct iphdr *)skb_network_header(skb); struct tcphdr *hdr; /* Using this to filter data from another machine */ unsigned long ok_ip = 2396891328; /* Some problem, empty […]

如何在Linux内核中将char 字符串转换为int?

如何在linux内核中将char []转换为int validation输入的文本实际上是一个int? int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) { char procfs_buffer[PROCFS_MAX_SIZE]; /* get buffer size */ unsigned long procfs_buffer_size = count; if (procfs_buffer_size > PROCFS_MAX_SIZE ) { procfs_buffer_size = PROCFS_MAX_SIZE; } /* write data to the buffer */ if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { return -EFAULT; } […]