I have integrated a C++ codebase which uses minimalistic features of c
and followed the guidelines in
to integrate with an existing C linux kernel module.
It all works fine except for occassional very very weird NULL pointer
The problem that I am facing is , I get NULL pointer exceptions while
the C++ code access local variables in the program stack.
The same functions in which the null pointer exceptions occur have
executed correctly several times before such an exception occurs.
The null pointer exceptions that I get and the corresponding code
where this occurs are below.
Any help / clues/ pointers on how to go about debugging this are very welcome !
Relevant details :
void Address::from_long(ssd::ulong longval)
page = longval % BLOCK_SIZE;
longval /= BLOCK_SIZE;
block = longval % PLANE_SIZE;
longval /= PLANE_SIZE;
plane = longval % DIE_SIZE;
<============ Null pointer Exception in this line
longval /= DIE_SIZE;
die = longval % PACKAGE_SIZE;
longval /= PACKAGE_SIZE;
package = longval % SSD_SIZE;
valid = PAGE;
(/root/compressions/Compressions/psu_ssd/sba.c, 888): process_request:
process request : block 64 rw 1 sectors : 8calling get_next_free_addr
(flashsim/flashsim.cpp, 32): issue_request: issue request lba 0 size 1 dir 1
BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
IP: [<ffffffffa01c3373>] _ZN3ssd7Address9from_longEm+0xa3/0x12c [SBA]
PGD 1f6ebc067 PUD 21d440067 PMD 0
Oops: 0002 [#1] SMP
last sysfs file: /sys/devices/virtual/block/sba0/range
Pid: 2349, comm: disksimulator0
Not tainted 2.6.33.yy #71 0GM819/OptiPlex 755
RIP: 0010:[<ffffffffa01c3373>] [<ffffffffa01c3373>]
RSP: 0018:ffff88022c49bbe0 EFLAGS: 00010296
RAX: 0000000000000018 ...
Wild guess: Stack overflow. In the kernel the stack is very limited
(depends on the configuration and IIRC on the archtecture, but 4K is the
minimum IIRC) and in C++ it's possible and common to put larger objects
on the stack.
However, C++ isn't supported by the kernel developers and you're on your
own. Rewrite the code to use plain C.