Skip to contentSkip to conversation

creating own syscall on 2.6.37.3 and getting error on compilaton...

DISCUSSION rgonzale at darkterminal.net 2 participants 4 messages Oct 21, 2012 – Oct 23, 2012 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

I'm trying to implement my own system call on Linux kernel 2.6.37.3 using this guide.

http://enzam.wordpress.com/2011/03/2...nel-ubuntu-os/

Here's the code that I have for kernel/mysystemcalls.c
It just takes an int for an argument and then spits out the PIDs for the process that is running on that CPU. Code:

#include<linux/linkage.h>
#include<linux/cpumask.h>

asmlinkage long sys_current_pid(int i)  {
	struct rq *rq;
	int num_cpu;
	num_cpu = num_online_cpus();
	if(i <= 0 || i > num_cpu)
		return -1;

	rq = cpu_rq(i);
	if(rq->curr != NULL)
		return rq->curr->pid;
	else
		return -1;
}

But on kernel compilation I get this.
Code:

kernel/mysystemcalls.c: In function 'sys_current_pid':
kernel/mysystemcalls.c:12: error: implicit declaration of function 'cpu_rq' kernel/mysystemcalls.c:12: warning: assignment makes pointer from integer without a cast kernel/mysystemcalls.c:13: error: dereferencing pointer to incomplete type kernel/mysystemcalls.c:14: error: dereferencing pointer to incomplete type make[1]: *** [kernel/mysystemcalls.o] Error 1
make[1]: *** Waiting for unfinished jobs....

The definition for cpu_rq() is in kernel/sched.c. Here's the pertinent piece of Makefile in kernel/Makefile Code:

#
# Makefile for the linux kernel.
#

obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
				cpu.o exit.o itimer.o time.o softirq.o resource.o \
				sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
				signal.o sys.o kmod.o workqueue.o pid.o \
				rcupdate.o extable.o params.o posix-timers.o \
				kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
				hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
				notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \
				async.o range.o jump_label.o
				obj-y += mysystemcalls.o

				I would think that since sched.o(the first c file that gets compiled) has the definition for the cpu_rq() then mysystemcalls.c should be able to see that function. What am I missing?

-Tristan

#2 lore raw
In reply to a message not in the archive
Quoted 35 lines · On 21 October 2012 21:28, <[email protected]> wrote:

I'm trying to implement my own system call on Linux kernel 2.6.37.3 using this guide.

http://enzam.wordpress.com/2011/03/2...nel-ubuntu-os/

Here's the code that I have for kernel/mysystemcalls.c
It just takes an int for an argument and then spits out the PIDs for the process that is running on that CPU. Code:

#include<linux/linkage.h>
#include<linux/cpumask.h>

asmlinkage long sys_current_pid(int i)  {
        struct rq *rq;
        int num_cpu;
        num_cpu = num_online_cpus();
        if(i <= 0 || i > num_cpu)
                return -1;

        rq = cpu_rq(i);
        if(rq->curr != NULL)
                return rq->curr->pid;
        else
                return -1;
}

But on kernel compilation I get this.
Code:

kernel/mysystemcalls.c: In function 'sys_current_pid':
kernel/mysystemcalls.c:12: error: implicit declaration of function 'cpu_rq' kernel/mysystemcalls.c:12: warning: assignment makes pointer from integer without a cast kernel/mysystemcalls.c:13: error: dereferencing pointer to incomplete type kernel/mysystemcalls.c:14: error: dereferencing pointer to incomplete type make[1]: *** [kernel/mysystemcalls.o] Error 1
make[1]: *** Waiting for unfinished jobs....

Quoted 1 line

The definition for cpu_rq() is in kernel/sched.c.

sched.c contains the implementation, the definition is in sched/sched.h, you should #include that header.

Quoted 7 lines

Here's the pertinent piece of Makefile in kernel/Makefile Code:

#
# Makefile for the linux kernel.
#

Quoted 13 lines
obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
                                cpu.o exit.o itimer.o time.o softirq.o resource.o \
                                sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
                                signal.o sys.o kmod.o workqueue.o pid.o \
                                rcupdate.o extable.o params.o posix-timers.o \
                                kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
                                hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
                                notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \
                                async.o range.o jump_label.o
                                obj-y += mysystemcalls.o

                                I would think that since sched.o(the first c file that gets compiled) has the definition for the cpu_rq() then mysystemcalls.c should be able to see that function. What am I missing?

You don't have a *link* error. It is not that the linker can't find cpu_rq(). It is the compiler that does not understand the cpu_rq() definition. Try to include the header.

Cheers,
-Filipe

#4 lore raw
In reply to a message not in the archive
Quoted 73 lines · On 22 October 2012 01:10, <[email protected]> wrote:

Ah the kernel/sched directory was added in 3.3. I'm using 2.6.37.3.

-Tristan

Quoted 68 lines · Filipe Rinaldi
Quoted 35 lines · On 21 October 2012 21:28, <[email protected]> wrote:

I'm trying to implement my own system call on Linux kernel 2.6.37.3 using this guide.

http://enzam.wordpress.com/2011/03/2...nel-ubuntu-os/

Here's the code that I have for kernel/mysystemcalls.c
It just takes an int for an argument and then spits out the PIDs for the process that is running on that CPU. Code:

#include<linux/linkage.h>
#include<linux/cpumask.h>

asmlinkage long sys_current_pid(int i)  {
        struct rq *rq;
        int num_cpu;
        num_cpu = num_online_cpus();
        if(i <= 0 || i > num_cpu)
                return -1;

        rq = cpu_rq(i);
        if(rq->curr != NULL)
                return rq->curr->pid;
        else
                return -1;
}

But on kernel compilation I get this.
Code:

kernel/mysystemcalls.c: In function 'sys_current_pid':
kernel/mysystemcalls.c:12: error: implicit declaration of function 'cpu_rq' kernel/mysystemcalls.c:12: warning: assignment makes pointer from integer without a cast kernel/mysystemcalls.c:13: error: dereferencing pointer to incomplete type kernel/mysystemcalls.c:14: error: dereferencing pointer to incomplete type make[1]: *** [kernel/mysystemcalls.o] Error 1
make[1]: *** Waiting for unfinished jobs....

Quoted 1 line

The definition for cpu_rq() is in kernel/sched.c.

sched.c contains the implementation, the definition is in sched/sched.h, you should #include that header.

Quoted 7 lines

Here's the pertinent piece of Makefile in kernel/Makefile Code:

#
# Makefile for the linux kernel.
#

Quoted 13 lines
obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
                                cpu.o exit.o itimer.o time.o softirq.o resource.o \
                                sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
                                signal.o sys.o kmod.o workqueue.o pid.o \
                                rcupdate.o extable.o params.o posix-timers.o \
                                kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
                                hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
                                notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \
                                async.o range.o jump_label.o
                                obj-y += mysystemcalls.o

                                I would think that since sched.o(the first c file that gets compiled) has the definition for the cpu_rq() then mysystemcalls.c should be able to see that function. What am I missing?

You don't have a *link* error. It is not that the linker can't find cpu_rq(). It is the compiler that does not understand the cpu_rq() definition. Try to include the header.

Cheers,
-Filipe

Humm, on 2.6.37 this is a private macro in sched.c.

I suppose you could use "current->pid".
"current" is a macro that returns the current task's structure:
http://lxr.linux.no/linux+v2.6.37.3/arch/x86/include/asm/current.h#L17

-Filipe

#7 lore raw
In reply to a message not in the archive
Quoted 3 lines · Tristan

How can you tell that cpu_rq() is a private macro? Because there is no header for it? Be as specific as you can, I'd like to completely understand what the concept. I'll try the current macro. Thanks Filipe.

-Tristan

Hi Tristan,

By private I mean it was declared inside sched.c so only code from sched.c can access it.
Note also cpu_rq() uses "runqueues" which is also private (declared static) to sched.c.

Cheers,
-Filipe