#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
MODULE_AUTHOR("Tan xujia");
MODULE_LICENSE("Dual BSD/GPL");
struct aligned1 {
char a8;
u16 lun;
};
struct aligned2 {
char a8;
u16 lun;
}__attribute__((packed));
struct aligned1 i;
struct aligned2 j;
static
int __init hello_init (void)
{
printk("i.a8 = %d, i.lun = %d\n", i.a8, i.lun);
printk("j.a8 = %d, j.lun = %d\n", j.a8, j.lun);
printk("sizeof(i) = %d\n", sizeof(i));
printk("sizeof(i) = %d\n", sizeof(j));
printk("hello_init\n");
return 0;
}
static
void __exit hello_exit (void)
{
printk("hello_exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m :=aligned.o
all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.* .tmp_versions *.mod *.order *.symvers *.dwo
![在这里插入图片描述](https://img-blog.csdnimg.cn/bb1f7959a33c4616abf7e70d0314be62.png)