kernel-module

install virtualbox modules from nixos-unstable in configuration.nix

自古美人都是妖i 提交于 2019-12-06 09:53:31
问题 It is possible to install packages from nixos-unstable in /etc/nixos/configuration.nix using the configuration from this answer. Here is an example of installing the htop packages from nixos-unstable: { config, pkgs, ... }: let unstableTarball = fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz; in { ... nixpkgs.config = { packageOverrides = pkgs: { unstable = import unstableTarball { config = config.nixpkgs.config; }; }; }; environment.systemPackages = with

How to use sysfs inside kernel module?

不想你离开。 提交于 2019-12-06 09:13:54
问题 In userspace I can just echo noop > /sys/block/sda/queue/scheduler . How to do the same inside a kernel module? I expect something like this (pseudocode): struct dentry* e = sysfs_get_root(); vfs_path_lookup(e, ????, "block/sda/queue/scheduler", ???); ????; struct something* q = ????; ????->store(q, "noop", 1); /* some cleanup */ How to implement it properly? My kernel module just registers SysRQ handler and should configure the io scheduler when that SysRQ is triggered (userspace programs

Create sysfs entry from kernel module

夙愿已清 提交于 2019-12-06 08:01:40
I want to pass a string > 1024 chars to my module (filesystem). As kernel parameters are limited to 1024 chars, someone recommended to use sysfs instead. I tried to include this example in my super.c class to create a string 'filename' & string 'code' entry in sysfs for my module. static decl_subsys(myfs, NULL, NULL); struct myfs_attr { struct attribute attr; char *value; }; static struct myfs_attr fname = { .attr.name="filename", .attr.owner = THIS_MODULE, .attr.mode = 0644, .value = "/my/test/path", }; static struct myfs_attr code = { .attr.name="code", .attr.owner = THIS_MODULE, .attr.mode

Touch gestures recognition while screen is off?

浪子不回头ぞ 提交于 2019-12-06 07:29:32
问题 I've been looking into on how to allow my phone to have it's screen off and allow it listen for touch gestures. I've thought of doing loading kernel modules but as I read more about it I found out that it would be troublesome to do since I'd have to write one for multiple different kernels. Does android sdk have anything that allows you to this easily? It would be really cool if you could just create a background service and listen for touch gestures even if the screen is off. I'm just

LKM: Last block written to device

∥☆過路亽.° 提交于 2019-12-06 06:38:46
I am trying to find a way, inside a module, to keep track of the last block written to a block device. The specific device I need is the one mounted at root (I know the /dev/ name ahead of time if that helps.) My original idea was to wrap the submit_bio function, since it has a logging function already if you "echo 1 > /proc/sys/vm/block_dump". Unfortunately it seems I'd need to modify the source code to make that function a pointer. I'd like to keep this all inside the module if at all possible. After that, I looked into finding the file system type, and wrapping the default file operations

Event-based sampling with the perf userland tool and PEBS

牧云@^-^@ 提交于 2019-12-06 05:31:37
问题 I'm doing event-based sampling with the perf userland tool: the objective being trying to find out where certain performance-impacting events like branch misses and cache misses are occurring on a larger system I'm working on. Now, something like perf record -a -e branch-misses:pp -- sleep 5 works perfectly: the PEBS counting mode trigerred by the 'pp' modifier is really accurate when collecting the IP in the samples. Unfortunately, when I try to do the same for cache-misses, i.e. perf record

Source code of keyboard driver of linux

有些话、适合烂在心里 提交于 2019-12-06 05:02:41
问题 I have been working on making my own keyboard driver for linux. So I came accross these two links: usbkbd.c and atkbd.c. Now I am confused which of these is the actual code driving my keyboard at the present. As I see it atkbd.c is quite gory and there is a conversion of scancodes to keycodes. So it should be the code, though I am not sure. If atkbd.c is the code, then what is the other code for? 回答1: This is easy to check. Let's take usbkbd.c. The corresponding Kconfig (http://lxr.free

perf cannot find external module symbols

时光总嘲笑我的痴心妄想 提交于 2019-12-06 02:21:41
问题 When running perf it finds the kernel symbols and symbols of my program but it does not find external module symbols. I have written a kernel module which I load using insmod how can I tell perf to find its symbols as well? I am running a 2.6.37.6 kernel (can't upgrade), my perf does not yet support the dwarf option but I think its a symbol issue. I have compiled everything with -g -fno-omit-frame-pointer 回答1: I had to make it a kernel module, then perf could find its symbols: IN_TREE_DIR=

How to get use count from Linux kernel module?

断了今生、忘了曾经 提交于 2019-12-06 00:40:36
问题 I have a problem with use count of kernel module being developed.I'd like to print it for debugging purpose. How can I obtain it from the module code? Kernel version in question - Linux 2.6.32 回答1: module_refcount() will give you the use count of the module passed. 回答2: /sbin/lsmod The third column will be the number of usages. 来源: https://stackoverflow.com/questions/3288282/how-to-get-use-count-from-linux-kernel-module

Hijacking sys calls

▼魔方 西西 提交于 2019-12-05 21:03:11
I'm writing a kernel module and I need to hijack/wrap some sys calls. I'm brute-forcing the sys_call_table address and I'm using cr0 to disable/enable page protection. So far so good (I'll make public the entire code once it's done, so I can update this question if somebody wants). Anyways, I have noticed that if I hijack __NR_sys_read I get a kernel oops when I unload the kernel module, and also all konsoles (KDE) crash. Note that this doesn't happen with __NR_sys_open or __NR_sys_write . I'm wondering why is this happening. Any ideas? PS: Please don't go the KProbes way, I already know about