kernel

function with variable arguments in kernel mode

核能气质少年 提交于 2020-01-07 05:42:08
问题 I am trying to implement function with variable params in kernel mode. call to function: a,b,c are integer variables WriteLogFile("test of trace logs=%d =%d =%d \n",a,b,c); Function: NTSTATUS WriteLogFile(const char* str,...) { va_list vl; va_start(vl,str); RtlStringCbPrintfA(buffer, sizeof(buffer), str,vl); then i am using zwwriteffile to write usermode text file. va_end(vl); } output: test of trace logs=1953719889=-1681971698 =1953719668 I am getting some garbage values. why? 来源: https:/

#内核里的神函数# 之 hweight32

我们两清 提交于 2020-01-07 05:20:32
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在阅读iptables内核模块的代码时,我遇到了这样一个函数hweight32: unsigned int hweight32(unsigned int w) { unsigned int res = w - ((w >> 1) & 0x55555555); res = (res & 0x33333333) + ((res >> 2) & 0x33333333); res = (res + (res >> 4)) & 0x0F0F0F0F; res = res + (res >> 8); return (res + (res >> 16)) & 0x000000FF; } 乍看起来,似乎很难理解这段代码的功能,其实它就完成了“统计给定数字中值为1的bit位个数”的功能,怎么样,是不是有点风马牛不相及的感觉。 下面我们先看网络上的一篇分析 文章 : ============转载:华丽的分割线============ 在 linux 内核里,在计算 CPU 个数时用到了 hweight32 这个函数,这个函数就是汉明重量的计算方法。对于二进制串来说,它就是计算这个二进制串里含有多少个 1 。hweight32() 函数实现如下: /*代码如上*/ 下面先对一个任意的二进制串中 1 的数量的计算推出上面的公式: 1.

“'errno' undeclared” when compile Linux kernel

坚强是说给别人听的谎言 提交于 2020-01-07 02:58:03
问题 I'm trying to compile and I keep getting the following error: enter image description here I've included the asm-i386/errno.h once and it didn't work. Also I've tried including linux/errno.h and it didn't work ether. What file should I include? 回答1: There is no errno variable in Linux kernel: this variable lives in user space only. If kernel function wants to report about the error and specify the error code, it encapsulates the error code into the returning value. There are 3 possibilities

Write module of kernel (Linux), which to save the page of process from removing to the swap

て烟熏妆下的殇ゞ 提交于 2020-01-06 19:59:09
问题 Need to save the page of process (the user part!) from removing to the swap. I need to do it in the kernel, only. (language C I know) (Maybe insert hook in shrink_page_list?) I have IDs of processes, which need to save and threshold amount of physical memory in the system (We fill, while it isn't filled). IDs and threshold write in /proc, /dev or /sys. How to approach this? What files to look at? What tutorials to read? Maybe there are examples that are somehow are related with this task.

Error compilation kernel

半城伤御伤魂 提交于 2020-01-06 18:36:21
问题 Trying to compile a linux kernel on Ubuntu 16.04 for an embedded board and I have this error during make : fatal error: mach/cputype.h: No such file or directory compilation terminated. The board I use is the TMDSLCDK138 integrating the OMAPL138. I installed the TI SDK from here http://software-dl.ti.com/sdoemb/sdoemb_public_sw/mcsdk/latest1/index_FDS.html and in the installation folder there is a custom linux SDK called "linux-3.3-psp03.22.00.06.sdk". This is what I did so far : sudo make O=

Linux Kernel Check VID / PID Number?

随声附和 提交于 2020-01-06 14:06:16
问题 What I am looking for is the command to check the live USB disks serial number from within a kernel module. from within the kernel, lsusb won't work. TMI Clause: I am developing a live USB device for a client, and this will be a current part of our copy protection. 回答1: Your program would be querying the serial number via the operating system. And you know what, your client has the ability to alter the operating system, so your program would not be able to completely trust the information

why does `synchronize_rcu()` not deadlock when beening called inside a read lock block?

安稳与你 提交于 2020-01-06 09:06:42
问题 synchronize_rcu() is used to waits only for ongoing RCU read-side critical sections to complete. If so, it should been blocked forever when beening called inside a read block. However, the following code works well on my linux kernel, why? void port_range_clean( void ) { struct port_range *p; redo: rcu_read_lock(); list_for_each_entry_rcu(p, &port_rt->ports, list) { list_del_rcu(&p->list); synchronize_rcu(); rcu_read_unlock(); kfree(p); goto redo; } } 来源: https://stackoverflow.com/questions

why does `synchronize_rcu()` not deadlock when beening called inside a read lock block?

删除回忆录丶 提交于 2020-01-06 09:05:21
问题 synchronize_rcu() is used to waits only for ongoing RCU read-side critical sections to complete. If so, it should been blocked forever when beening called inside a read block. However, the following code works well on my linux kernel, why? void port_range_clean( void ) { struct port_range *p; redo: rcu_read_lock(); list_for_each_entry_rcu(p, &port_rt->ports, list) { list_del_rcu(&p->list); synchronize_rcu(); rcu_read_unlock(); kfree(p); goto redo; } } 来源: https://stackoverflow.com/questions

Reach kernel session space from kernel driver

穿精又带淫゛_ 提交于 2020-01-06 04:36:09
问题 I'm writing a kernel driver, which should read (and in some cases, also write) some memory addresses in kernel session space (win32k.sys). I've read in another topic that for example in Windbg I should change the context to a random user process to read the memory of kernel session space (with .process /p). How can I do that in a kernel driver? Should I create a user process which communicate with the driver (that's my idea now, but I hope that there is a better solution) or there is a more

Android read CPU time in states for multicore devices

最后都变了- 提交于 2020-01-06 03:33:12
问题 I'm trying to have my app show time spent by the CPU at each frequency. The main issue is when a CPU goes offline (due to hotplugging or deep sleep) the file /CPUN/cpufreq/stats/time_in_state gets removed and times reset to all 0s. So this limits me to only be able to show the times on CPU 0. What I've Tried Use FileObserver service to monitor the creation/deletion of the file This should work in theory but for whatever reason when the device goes into deep sleep it fails to report the