diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..978618f6ccb2fab4f0c8a1fe54188aa07aa12adb --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +build/ +linux* +debian* +.hello-1* +*.o +*.cmd +*.ko +*.mod +*.symvers +*.orders \ No newline at end of file diff --git a/kvm-mylinux.sh b/kvm-mykernel.sh similarity index 55% rename from kvm-mylinux.sh rename to kvm-mykernel.sh index eed53d5d4d38474eca11147d65f2dca9a7ab1808..d058b0daa4e44ca086687dbc6b374a5101dc4d02 100755 --- a/kvm-mylinux.sh +++ b/kvm-mykernel.sh @@ -1,10 +1,10 @@ #!/bin/bash -KERNEL=${1-/home/lipari/Documents/corsi/2023-2024/ASEE/prova/build/kvm/arch/x86/boot/bzImage} +KERNEL=${1-build/kvm/arch/x86/boot/bzImage} SMP=${2-2} kvm -smp $SMP -m 1G -boot c --enable-kvm \ -kernel $KERNEL -append "root=/dev/sda1 console=ttyS0 rw" \ -hda debian.qcow \ - -net user,hostfwd=tcp::10022-:22 -net nic + -net user,hostfwd=tcp::10022-:22 -net nic \ -serial mon:stdio diff --git a/lkmpg b/lkmpg new file mode 160000 index 0000000000000000000000000000000000000000..c6b02adc982382044c86fa11dcaf012fbe78715e --- /dev/null +++ b/lkmpg @@ -0,0 +1 @@ +Subproject commit c6b02adc982382044c86fa11dcaf012fbe78715e diff --git a/work/hello-1/Makefile b/work/hello-1/Makefile index b06c2df0f45277c58b081c12be911d4e2507cd05..1f08f62d2a2a516450d55ef5ba503248d5cb88cf 100644 --- a/work/hello-1/Makefile +++ b/work/hello-1/Makefile @@ -4,6 +4,7 @@ obj-m += hello-1.o obj-m += hello-2.o obj-m += hello-3.o obj-m += hello-5.o +obj-m += hello-sysfs.o PWD := $(CURDIR) all: diff --git a/work/hello-1/hello-sysfs.c b/work/hello-1/hello-sysfs.c new file mode 100644 index 0000000000000000000000000000000000000000..7900a6238093bacaab2303edc24015256f3ecccc --- /dev/null +++ b/work/hello-1/hello-sysfs.c @@ -0,0 +1,61 @@ +/* + * hello-sysfs.c sysfs example + */ +#include <linux/fs.h> +#include <linux/init.h> +#include <linux/kobject.h> +#include <linux/module.h> +#include <linux/string.h> +#include <linux/sysfs.h> + +static struct kobject *mymodule; + +/* the variable you want to be able to change */ +static int myvariable = 0; + +static ssize_t myvariable_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", myvariable); +} + +static ssize_t myvariable_store(struct kobject *kobj, + struct kobj_attribute *attr, char *buf, + size_t count) +{ + sscanf(buf, "%du", &myvariable); + return count; +} + +static struct kobj_attribute myvariable_attribute = + __ATTR(myvariable, 0660, myvariable_show, (void *)myvariable_store); + +static int __init mymodule_init(void) +{ + int error = 0; + + pr_info("mymodule: initialised\n"); + + mymodule = kobject_create_and_add("mymodule", kernel_kobj); + if (!mymodule) + return -ENOMEM; + + error = sysfs_create_file(mymodule, &myvariable_attribute.attr); + if (error) { + pr_info("failed to create the myvariable file " + "in /sys/kernel/mymodule\n"); + } + + return error; +} + +static void __exit mymodule_exit(void) +{ + pr_info("mymodule: Exit success\n"); + kobject_put(mymodule); +} + +module_init(mymodule_init); +module_exit(mymodule_exit); + +MODULE_LICENSE("GPL"); \ No newline at end of file diff --git a/work/hello-1/hello-sysfs.mod.c b/work/hello-1/hello-sysfs.mod.c new file mode 100644 index 0000000000000000000000000000000000000000..101c8b5f8194104fe232acef61a5361b9f7876ef --- /dev/null +++ b/work/hello-1/hello-sysfs.mod.c @@ -0,0 +1,53 @@ +#include <linux/module.h> +#define INCLUDE_VERMAGIC +#include <linux/build-salt.h> +#include <linux/elfnote-lto.h> +#include <linux/export-internal.h> +#include <linux/vermagic.h> +#include <linux/compiler.h> + +#ifdef CONFIG_UNWINDER_ORC +#include <asm/orc_header.h> +ORC_HEADER; +#endif + +BUILD_SALT; +BUILD_LTO_INFO; + +MODULE_INFO(vermagic, VERMAGIC_STRING); +MODULE_INFO(name, KBUILD_MODNAME); + +__visible struct module __this_module +__section(".gnu.linkonce.this_module") = { + .name = KBUILD_MODNAME, + .init = init_module, +#ifdef CONFIG_MODULE_UNLOAD + .exit = cleanup_module, +#endif + .arch = MODULE_ARCH_INIT, +}; + +#ifdef CONFIG_RETPOLINE +MODULE_INFO(retpoline, "Y"); +#endif + + + +static const struct modversion_info ____versions[] +__used __section("__versions") = { + { 0x122c3a7e, "_printk" }, + { 0xa6ef1646, "kernel_kobj" }, + { 0x10bd90f2, "kobject_create_and_add" }, + { 0xa3efd5d1, "sysfs_create_file_ns" }, + { 0xecc78457, "kobject_put" }, + { 0xbdfb6dbb, "__fentry__" }, + { 0xbcab6ee6, "sscanf" }, + { 0x5b8239ca, "__x86_return_thunk" }, + { 0x3c3ff9fd, "sprintf" }, + { 0x76800044, "module_layout" }, +}; + +MODULE_INFO(depends, ""); + + +MODULE_INFO(srcversion, "6C30BA4EA53200F485C730C"); diff --git a/work/hello-1/modules.order b/work/hello-1/modules.order index 07bfd4243bf37eeca62142db31ac55ef9c9cce84..1715a2600e96ca86f70f36b74466a9003fb5ecaf 100644 --- a/work/hello-1/modules.order +++ b/work/hello-1/modules.order @@ -2,3 +2,4 @@ /root/Desktop/asee/work/hello-1/hello-2.o /root/Desktop/asee/work/hello-1/hello-3.o /root/Desktop/asee/work/hello-1/hello-5.o +/root/Desktop/asee/work/hello-1/hello-sysfs.o