How to get use count from Linux kernel module?
module_refcount()
will give you the use count of the module passed.
How Can I Count malloc in linux kernel with kprobe
This is not possible with kprobes because, as you said, malloc
is not a system call.
You can, however, use USDTs to trace userspace processes. The bcc tools contain an example with uobjnew
. It traces object allocations in the given process:
$ ./uobjnew -h
usage: uobjnew.py [-h] [-l {java,ruby,c}] [-C TOP_COUNT] [-S TOP_SIZE] [-v]
pid [interval]
Summarize object allocations in high-level languages.
positional arguments:
pid process id to attach to
interval print every specified number of seconds
optional arguments:
-h, --help show this help message and exit
-l {java,ruby,c}, --language {java,ruby,c}
language to trace
-C TOP_COUNT, --top-count TOP_COUNT
number of most frequently allocated types to print
-S TOP_SIZE, --top-size TOP_SIZE
number of largest types by allocated bytes to print
-v, --verbose verbose mode: print the BPF program (for debugging
purposes)
examples:
./uobjnew -l java 145 # summarize Java allocations in process 145
./uobjnew -l c 2020 1 # grab malloc() sizes and print every second
./uobjnew -l ruby 6712 -C 10 # top 10 Ruby types by number of allocations
./uobjnew -l ruby 6712 -S 10 # top 10 Ruby types by total size
printing number of processes in kernel module
If anyone is still looking how to do this, I solved this sometime ago, Here is the solution.
This works for debian Linux 3.16 version. If you want to take look at the code which is here.
https://github.com/st0rmi/rootkit_programming/blob/master/assignment01/assignment01_mod.c
Related Topics
Find Based Filename Autocomplete in Bash Script
Webdrivererror Error: Chrome Failed to Start: Exited Abnormally
How Does Ltrace (Library Tracing Tool) Work
How to Use Awk to Test If a Column Value Is in Another File
Why Are Both "True" and "False" Tests True
Make Bash Differentiate Between Ctrl-<Letter> and Ctrl-Shift-<Letter>
Scp Command Between 2 Servers with 2 Different .Pem Keys
Exactly When Tasklet Runs After It Is Schedule by Isr
Sending Command to Process Using /Proc
How to Give Password in Shell Script
Bash Script Command to Wait Until Docker-Compose Process Has Finished Before Moving On
Oracle Instant Client: Ora-28759: Failure to Open File
Unix Unzip: How to Batch Unzip Zip Files in a Folder and Save in Subfolders
Shipping Gnu/Linux Firefox Plugin with Shared Libraries (For Installation with No Root Access)
Run Any Linux Terminal Command from Typescript
How Does Linux Kernel Creates Sysfs