linux-kernel

Virtual area to pages

In the Linux kernel, given the task_struct's mm I can access the process's list of vm_area_structs. Given these vm_area_structs, how do I get the struct pages which actually correspond to this vma? I tried looking for functions in mm/memory.c and the like, but I was at a loss. Edit: the idea is to find which pages in the vma are curre...

Is Linux kernel (or other low level stuff) a "good" example of how to write C

Following the "what's the best use for C" question. The Linux kernel seems to be a famous and very well thought of C program. But is it a good example of mainstream "best-practice" C? ...

Why do we need a swapper task in linux?

The idle task (a.k.a. swapper task) is chosen to run when no more runnable tasks in the run queue at the point of task scheduling. But what is the usage for this so special task? Another question is why i can't find this thread/process in the "ps aux" output (PID=0) from the userland? ...

What do I need to compile the kernel on Ubuntu Eee?

I'm trying follow a tutorial to create a custom USB driver in Linux and I hope to develop this thing on my Eee PC with Ubuntu Eee using g++. Unfortunately to follow the tutorial I need the linux/module.h header file. From what I understand I will need to compile the kernel to get this to work. I never compiled a kernel before and all ...

Getting the process id of a current process without unistd.h

I'm working on a deadlock detection algorithm and I'm only given kernel level libraries, i.e. #include <linux/somelibrary> and nothing else. Are there kernel-level facilities that will allow me to get the pid of the current process similar to getpid() of unistd.h? ...

PTP error in gphoto2 running against Linux kernel 2.6.21.3

In the hope that there is a gphoto or Linux kernel guru hanging around out there I am asking this question here. I am trying to build a custom front end to the Linux libgphoto2 library. For the moment I am using gphoto2 to call into the library. I am running this on an Etch (Debian 4.0) VM image as my testing machine. I pulled the source...

Timekeeping in Linux kernel 2.6

I've read chapter 7 in the 'Linux Device Drivers' (which can be found here) that time can be measured in 'jiffies'. The problem with the stock jiffies variable is that it wraps around quite frequently (especially if you have your CONFIG_HZ set to 1000). In my kernel module I'm saving a jiffies value that is set to some time in the futur...

why do we need zone_highmem on x86?

In linux kernel, mem_map is the array which holds all "struct page" descriptors. Those pages includes the 128MiB memory in lowmem for dynamically mapping highmem. Since the lowmem size is 1GiB, so the mem_map array has only 1GiB/4KiB=256KiB entries. If each entry size is 32 byte, then the mem_map memory size = 8MiB. But if we could use...

Linux - identify process owning a specific address in physical memory

Under Linux, how can I tell what specific process owns / is using a given address in physical memory? I understand that this may require writing a kernel module to access some kernel data structure and return the results to a user - I need to know how it can be done, regardless of how complicated it is. ...

IP Address from sk_buff

I am writing a kernel module which registers a netfilter hook. I am trying to get the ip address of the caller by using the sk_buff->saddr member. Is there a way I can get the IP in human readable i.e. x.x.x.x format? I found the function inet_ntop() but it doesn't seem to be available in kernel headers. How do I convert \xC0\xA8\x00\x...

How to create proc under /proc/driver?

I want to create a proc file under /proc/driver directory. I would like to use a macro like proc_root_driver (or something else provided) rather than use "driver/MODULE_NAME" explicitly. I use create_proc_entry : ... struct proc_dir_entry *simpleproc_fops_entry; simpleproc_fops_entry = create_proc_entry(MODULE_NAME, 0400, NULL /* proc...

Netfiler hook not getting called.

Hello, I am writing a kernel module which registers a hook with netfilter. The handler is not being called if I ssh/telnet into the machine where the module is loaded. struct nf_hook_ops my_hook_ops; my_hook_ops.hook = hook_handler; my_hook_ops.pf = PF_INET; my_hook_ops.hooknum = NF_INET_PRE_ROUTING; my_hook_ops.priority = NF_IP_PRI_F...

Prefered Editor for Linux Kernel Development Newbies

Before you answer vi... I'm looking to set a development environment for programmers with mainly Windows/Visual Studio background. Of course Emacs and Eclipse come to mind as IDEs, but I just want to make sure I'm not missing anything with relation to things like build tool integration etc. Thanks in advance ...

How to clean caches used by the Linux kernel

I want to force the Linux kernel to allocate more memory to applications after the cache starts taking up too much memory (as can be seen by the output of 'free'). I've run sudo sync; sudo sysctrl -w vm.drop_caches=3; free (to free both disc dentry/inode cache and page cache) and I see that only about half of the used cache was freed...

Direct Memory Access in Linux

I'm trying to access physical memory directly for an embedded Linux project, but I'm not sure how I can best designate memory for my use. If I boot my device regularly, and access /dev/mem, I can easily read and write to just about anywhere I want. However, in this, I'm accessing memory that can easily be allocated to any process; which...

How can I disable "demand paging" for one of my userspace programs ?

For an dedicated test I have to disable "demand paging" for exactly one of my userspace programs http://en.wikipedia.org/wiki/Demand_paging Any idea how I could do this ? (embedded linux appliance; 2.6 kernel) ...

Is it possible to compile Linux kernel with something other than gcc

I wonder if someone managed to compile the Linux kernel with some other compiler than gcc. Or if someone have ever tried? Question may seem to be silly or academic, but it arose when I thought about answers to: Are C++ int operations atomic on the mips architecture It seems that the atomicity of some operations depends not only on the ...

Non-GPL kernel modules using GPL ones

The company I work for is developing a closed source kernel module (.ko file). This module has to make calls to functions which are contained in a gpl2 module. Basically we have a situation like this: // GPL 2 kernel module (gpl.c -> gpl.ko) void a_function(void) { // ... } EXPORT_SYMBOL(a_function) // Closed Source module (closed.c ...

Kernel Scheduling for 1024 CPUs

Azul Systems has an appliance that supports thousands of cache coherent CPUs. I would love insight into what changes would need to occur to an operating system in order to schedule thousands of simultaneously running threads. ...

process descriptor in kernel modules

Is it possible to get a pointer to process descriptor of a process in a kernel module?If it is possible pls post how? I need to find all files opened by a process and their offset values of each file descriptor.... ...