1 /*
2 * kdatasize.c -- print the size of common data items from kernel space
3 * This runs with any Linux kernel (not any Unix, because of <linux/types.h>)
4 *
5 * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
6 * Copyright (C) 2001 O'Reilly & Associates
7 *
8 * The source code in this file can be freely used, adapted,
9 * and redistributed in source or binary form, so long as an
10 * acknowledgment appears in derived source files. The citation
11 * should list that the code comes from the book "Linux Device
12 * Drivers" by Alessandro Rubini and Jonathan Corbet, published
13 * by O'Reilly & Associates. No warranty is attached;
14 * we cannot take responsibility for errors or fitness for use.
15 */
16
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/types.h>
20 #include <linux/utsname.h>
21 #include <linux/errno.h>
22
23 /*
24 * Define several data structures, all of them start with a lone char
25 * in order to present an unaligned offset for the next field
26 */
27 struct c {char c; char t;} c;
28 struct s {char c; short t;} s;
29 struct i {char c; int t;} i;
30 struct l {char c; long t;} l;
31 struct ll {char c; long long t;} ll;
32 struct p {char c; void * t;} p;
33 struct u1b {char c; __u8 t;} u1b;
34 struct u2b {char c; __u16 t;} u2b;
35 struct u4b {char c; __u32 t;} u4b;
36 struct u8b {char c; __u64 t;} u8b;
37
38 static void data_cleanup(void)
39 {
40 /* never called */
41 }
42
43 static int data_init(void)
44 {
45 /* print information and return an error */
46 printk("arch Align: char short int long ptr long-long "
47 " u8 u16 u32 u64\n");
48 printk("%-12s %3i %3i %3i %3i %3i %3i "
49 "%3i %3i %3i %3i\n",
50 init_uts_ns.name.machine,
51 /* note that gcc can subtract void * values, but it's not ansi */
52 (int)((void *)(&c.t) - (void *)&c),
53 (int)((void *)(&s.t) - (void *)&s),
54 (int)((void *)(&i.t) - (void *)&i),
55 (int)((void *)(&l.t) - (void *)&l),
56 (int)((void *)(&p.t) - (void *)&p),
57 (int)((void *)(&ll.t) - (void *)&ll),
58 (int)((void *)(&u1b.t) - (void *)&u1b),
59 (int)((void *)(&u2b.t) - (void *)&u2b),
60 (int)((void *)(&u4b.t) - (void *)&u4b),
61 (int)((void *)(&u8b.t) - (void *)&u8b));
62 return -ENODEV;
63 }
64
65 module_init(data_init);
66 module_exit(data_cleanup);
67
68 MODULE_LICENSE("Dual BSD/GPL");
69
|
This page was automatically generated by the
LXR engine.
|