como usar cabeçalhos de kernel apropriadamente?

1

Eu escrevi um código-fonte muito simples de programação do kernel:

#include <linux/kernel.h>
#include <linux/fcntl.h>
#include <linux/init.h>

static int __init(void){
    sys_open("ee.c", O_RDONLY);

mas porque as fontes do kernel (que são realmente executadas agora) estão na pasta home, ocorreram erros abaixo. Mesmo que eu tenha feito links simbólicos assim.

rm -rf /usr/include/linux
rm -rf /usr/include/asm

ln -s /home/linux-2.6.21/include/linux /usr/include/linux
ln -s /home/linux-2.6.21/include/asm-i386 /usr/include/asm

In file included from /usr/include/asm/fcntl.h:1,  
             from /usr/include/linux/fcntl.h:4,  
             from v.c:2:  
/usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’  
/usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’  

O que eu preciso fazer antes de usar os cabeçalhos do kernel, que é uma pasta diferente com /usr/include e por que esse tipo de erro ocorreu?

eu também fiz

rm -rf /usr/include/asm
ln -s /home/linux-2.6.21/include/asm-i386 /usr/include/asm

e #include <linux/syscall.h> eu estava preso ...
que é uma mensagem de erro completa .. eu acho que os arquivos de cabeçalho do kernel são particularmente desinformados ..

In file included from /usr/include/linux/syscalls.h:61,
                 from vv.c:4:
/usr/include/linux/list.h:959:2: warning: #warning "don't include kernel headers in userspace"
In file included from /usr/include/asm/siginfo.h:4,
                 from /usr/include/linux/syscalls.h:64,
                 from vv.c:4:
/usr/include/asm-generic/siginfo.h:75: error: expected specifier-qualifier-list before ‘clock_t’
In file included from /usr/include/asm/signal.h:5,
                 from /usr/include/linux/syscalls.h:65,
                 from vv.c:4:
/usr/include/linux/time.h:12: error: redefinition of ‘struct timespec’
/usr/include/linux/time.h:18: error: redefinition of ‘struct timeval’
In file included from /usr/include/linux/syscalls.h:65,
                 from vv.c:4:
/usr/include/asm/signal.h:32: error: conflicting types for ‘sigset_t’
/usr/include/sys/select.h:38: error: previous declaration of ‘sigset_t’ was here
In file included from /usr/include/linux/syscalls.h:66,
                 from vv.c:4:
/usr/include/linux/quota.h:47: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dq_data_lock’
In file included from /usr/include/asm/processor.h:17,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/asm/msr.h:90: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:90: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:90: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h: In function ‘rdmsr_on_cpu’:
/usr/include/asm/msr.h:92: error: ‘l’ undeclared (first use in this function)
/usr/include/asm/msr.h:92: error: (Each undeclared identifier is reported only once
/usr/include/asm/msr.h:92: error: for each function it appears in.)
/usr/include/asm/msr.h:92: error: ‘h’ undeclared (first use in this function)
/usr/include/asm/msr.h:92: error: ‘msr_no’ undeclared (first use in this function)
/usr/include/asm/msr.h:92: error: invalid lvalue in asm output 0
/usr/include/asm/msr.h:92: error: invalid lvalue in asm output 1
/usr/include/asm/msr.h: At top level:
/usr/include/asm/msr.h:94: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:94: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h:94: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/msr.h: In function ‘wrmsr_on_cpu’:
/usr/include/asm/msr.h:96: error: ‘msr_no’ undeclared (first use in this function)
/usr/include/asm/msr.h:96: error: ‘l’ undeclared (first use in this function)
/usr/include/asm/msr.h:96: error: ‘h’ undeclared (first use in this function)
In file included from /usr/include/asm/processor.h:18,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/asm/system.h: At top level:
/usr/include/asm/system.h:346: error: expected declaration specifiers or ‘...’ before ‘u8’
/usr/include/asm/system.h:346: error: expected declaration specifiers or ‘...’ before ‘u8’
/usr/include/asm/system.h:347: error: expected declaration specifiers or ‘...’ before ‘u16’
/usr/include/asm/system.h:347: error: expected declaration specifiers or ‘...’ before ‘u16’
/usr/include/asm/system.h:348: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/system.h:348: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/asm/system.h: In function ‘cmpxchg_386’:
/usr/include/asm/system.h:355: error: too many arguments to function ‘cmpxchg_386_u8’
/usr/include/asm/system.h:357: error: too many arguments to function ‘cmpxchg_386_u16’
/usr/include/asm/system.h:359: error: too many arguments to function ‘cmpxchg_386_u32’
In file included from /usr/include/linux/cpumask.h:86,
                 from /usr/include/asm/processor.h:22,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/linux/bitmap.h: In function ‘bitmap_zero’:
/usr/include/linux/bitmap.h:134: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_fill’:
/usr/include/linux/bitmap.h:149: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_copy’:
/usr/include/linux/bitmap.h:155: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_and’:
/usr/include/linux/bitmap.h:166: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_or’:
/usr/include/linux/bitmap.h:175: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_xor’:
/usr/include/linux/bitmap.h:184: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_andnot’:
/usr/include/linux/bitmap.h:193: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_complement’:
/usr/include/linux/bitmap.h:202: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_equal’:
/usr/include/linux/bitmap.h:211: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_intersects’:
/usr/include/linux/bitmap.h:220: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_subset’:
/usr/include/linux/bitmap.h:229: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_empty’:
/usr/include/linux/bitmap.h:237: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_full’:
/usr/include/linux/bitmap.h:245: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_weight’:
/usr/include/linux/bitmap.h:253: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_shift_right’:
/usr/include/linux/bitmap.h:261: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function ‘bitmap_shift_left’:
/usr/include/linux/bitmap.h:270: error: ‘BITS_PER_LONG’ undeclared (first use in this function)
In file included from /usr/include/asm/processor.h:22,
                 from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:88: error: expected specifier-qualifier-list before ‘DECLARE_BITMAP’
/usr/include/linux/cpumask.h: In function ‘__cpu_set’:
/usr/include/linux/cpumask.h:94: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpu_clear’:
/usr/include/linux/cpumask.h:100: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_setall’:
/usr/include/linux/cpumask.h:106: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_clear’:
/usr/include/linux/cpumask.h:112: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpu_test_and_set’:
/usr/include/linux/cpumask.h:121: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_and’:
/usr/include/linux/cpumask.h:128: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:128: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:128: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_or’:
/usr/include/linux/cpumask.h:135: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:135: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:135: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_xor’:
/usr/include/linux/cpumask.h:142: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:142: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:142: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_andnot’:
/usr/include/linux/cpumask.h:150: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:150: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:150: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_complement’:
/usr/include/linux/cpumask.h:157: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:157: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_equal’:
/usr/include/linux/cpumask.h:164: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:164: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_intersects’:
/usr/include/linux/cpumask.h:171: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:171: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_subset’:
/usr/include/linux/cpumask.h:178: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:178: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_empty’:
/usr/include/linux/cpumask.h:184: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_full’:
/usr/include/linux/cpumask.h:190: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_weight’:
/usr/include/linux/cpumask.h:196: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_shift_right’:
/usr/include/linux/cpumask.h:204: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:204: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_shift_left’:
/usr/include/linux/cpumask.h:212: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:212: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpumask_scnprintf’:
/usr/include/linux/cpumask.h:273: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpumask_parse_user’:
/usr/include/linux/cpumask.h:281: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpulist_scnprintf’:
/usr/include/linux/cpumask.h:289: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpulist_parse’:
/usr/include/linux/cpumask.h:295: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpu_remap’:
/usr/include/linux/cpumask.h:303: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:303: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h: In function ‘__cpus_remap’:
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
/usr/include/linux/cpumask.h:311: error: ‘cpumask_t’ has no member named ‘bits’
In file included from /usr/include/asm/atomic.h:5,
                 from /usr/include/linux/key.h:22,
                 from /usr/include/linux/syscalls.h:67,
                 from vv.c:4:
/usr/include/asm/processor.h: At top level:
/usr/include/asm/processor.h:82: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
/usr/include/asm/processor.h:82: error: requested alignment is not a constant
In file included from vv.c:4:
/usr/include/linux/syscalls.h:114: error: expected ‘)’ before ‘*’ token
/usr/include/linux/syscalls.h:115: error: expected declaration specifiers or ‘...’ before ‘old_sigset_t’
/usr/include/linux/syscalls.h:116: error: expected declaration specifiers or ‘...’ before ‘old_sigset_t’
/usr/include/linux/syscalls.h:178: error: expected ‘)’ before ‘*’ token
/usr/include/linux/syscalls.h:394: error: expected ‘)’ before ‘cookie64’
/usr/include/linux/syscalls.h:474: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:475: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:476: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:477: error: expected ‘)’ before ‘mqdes’
/usr/include/linux/syscalls.h:507: error: expected declaration specifiers or ‘...’ before ‘key_serial_t’
/usr/include/linux/syscalls.h:512: error: expected declaration specifiers or ‘...’ before ‘key_serial_t’
/usr/include/linux/syscalls.h:546: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/include/linux/syscalls.h:547: error: expected declaration specifiers or ‘...’ before ‘u32’
vv.c: In function ‘init’:
vv.c:7: error: too few arguments to function ‘sys_open’
    
por KayKay 16.05.2011 / 04:42

1 resposta

5

Os cabeçalhos asm-generic também vêm do kernel do Linux, então você essencialmente misturou alguns dos cabeçalhos sanitizados de /usr/include com alguns da origem em seu diretório pessoal.

Se você está escrevendo um programa de espaço do usuário, pode também usar os cabeçalhos higienizados que vêm com a distribuição: as únicas informações que estão faltando são as partes necessárias para compilar o código que deve ser executado dentro do kernel. / p>

Para recuperar os arquivos excluídos, remova os dois links simbólicos criados e execute apt-get install --reinstall linux-libc-dev .

Como alternativa, se você precisar usar cabeçalhos de kernel não-aninhados para essa versão do kernel em particular, apenas passe -I/home/linux-2.6.21/include para o compilador para que ele escolha os cabeçalhos de preferência para os que estão instalados no sistema.

    
por James Henstridge 16.05.2011 / 09:25

Tags