1

I am working on a project that modifies part of the Android OS, and when I tried to implement a new system call to return the status of all the processes, I encountered the following error:

kernel/sys.c: error: array tpye has incomplete element type. 

What I did in sys.c is the following:

/***previous code in sys.c***/

SYSCALL_DEFINE2(new_syscall, struct info __user*, buf, int __user*, nr){
    if(!buf || !nr) return -EINVAL;

    int nr_copy;
    int success;

    success = copy_from_user(&nr_copy, nr, sizeof(int));
    if(success == 0) return -EINVAL;
    if(nr_copy < 1) return -EINVAL;

    struct info buf_copy[nr_copy];  /*************

    return 0;
}

Complier complained about the line marked with stars.

My info.h file looks like this:

    #ifndef __LINUX_INFO_H
    #define __LINUX_INFO_H

    struct info {
        long state;         
        pid_t pid;          
        pid_t parent_pid;       
    };

    #endif

I tried including the info.h in sys.c, but it didn't help at all. Can anyone provide me some directions on what I should look into?

Thanks

1

2 Answers 2

2

What compiler are you using? Dynamically sized arrays are a newish C feature that might not be supported. OTOH, they are allocated on the stack, and that is a very scarce commodity in-kernel. You should allocate memory for the array via kmalloc or one of its ilk.

Sign up to request clarification or add additional context in comments.

4 Comments

It's not dynamically allocated array, it's a fixed size array of length nr_copy. Good point for kmalloc
@user1926344, you are getting the size for the array the line above it's definition, unless my kernel-C is way off by now...
nr_copy is a variable declared as int, so buf_copy[nr_copy] is not a fixed size array at compile time.
oh i see the problem now. Thanks!
0

Have you tried explicitly declaring state as a long int.

long state; 

to

long int state;

4 Comments

There are two __user* pointers. info __user* and int __user*
Both long state and long int state mean exactly the same thing in C.
@vonbrand, Check that assumption with code. Depends on the hardware AND operating sytem: sizeof(int) on a 286 returns 2 sizeof(int) on a 16bitOS on a 386 returns 2, but 4 on a 32bit OS. sizeof(int) on my x86_64 returns 4, but sizeof(long int) returns 8.
completely irrelevant. As I said, in C long is exactly the same as long int, if you omit the type it defaults to int (yes, this comes from C's prehistory).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.