[Slackbuilds-users] Segmentation Fault help needed
414N
414N at slacky.it
Mon Mar 18 21:14:17 UTC 2024
Hello Antonio!
TL;DR: the error seems to be caused by the MAP_FIXED mmap flag used in
bbccon.c:1728.
You can find a patch attached that solves that issue, but I cannot
guarantee that the program will still work as intended with it. The
program seems to really want to allocate memory at a specific address
and removing that flag breaks that assumption.
The steps I followed to determine the source of the issue:
1. modify the src/console/makefile file to change every optimization
flag (i.e. gcc "-O2" or "-Os") to debug flags ("-O0 -g" for gcc, "-g"
for nasm) and removing any stripping instruction ("-Wl,-s")
2. recompile and run via gdb:
cd console/linux
make -f makefile
gdb ./bbcbasic
(gdb) run
Starting program: /tmp/BBCSDL/console/linux/bbcbasic
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x000
0x00000001003fffff in ?? ()
(gdb) bt
#0 0x00000001003fffff in ?? ()
#1 0x0000000000000001 in ?? ()
#2 0x0000000103ae75f6 in ?? ()
#3 0x0000000000000000 in ?? ()
(gdb)
3. as can be seen from the gdb backtrace (bt) output, no useful
information can be discerned
4. another way to catch the problem is by stepping one instruction at
a time from the main() function entrypoint (hoping that the error spawns
early in the program code ^_^), so, back in gdb (starting another
session)[1]:
(gdb) run
Starting program: /tmp/BBCSDL/console/linux/bbcbasic
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Breakpoint 1, main (argc=1, argv=0x7fffffffdf68) at ../../src
/bbccon.c:1683
1683 int exitcode = 0 ;
(gdb) next
1684 void *immediate = NULL ;
(gdb)
1715 pthread_t hThread = 0 ;
(gdb)
1717 platform = 1 ;
(gdb)
1719 void *base = NULL ;
(gdb)
1721 while ((MaximumRAM >= MINIMUM_RAM) && (NULL == (base
= mymap (MaximumRAM))))
(gdb)
1726 if (base != NULL)
(gdb)
1727 userRAM = mmap (base, MaximumRAM, PROT_EXEC
| PROT_READ | PROT_WRITE,
(gdb)
Program received signal SIGSEGV, Segmentation fault.
0x00000001003fffff in ?? ()
(gdb)
As can be seen, the SIGSEGV occurred after trying to step over the mmap
function call in bbccon.c at line 1727. By inspecting it in the source
file and by looking at the "mmap" man page, one can see that:
- the MAP_FIXED flag needs some care to be correctly used;
- the SIGSEGV signal can be the result of "Attempted write into a
region mapped as read-only."
I think this means that the "base" address returned by the "mymap"
function does not work well in the following "mmap" call with the
MAP_FIXED flag, probably due to some memory management kernel settings
that are different between Slackware and Debian, like
"/proc/sys/vm/mmap_min_addr" (if I remember correctly).
Hope to be helpful!
--
Alan Alberghini
SBo clone: https://github.com/414n/slackbuilds.org
[1]: after the first "next" instruction no command is echoed in the
following (gdb) prompts because I just pressed ENTER on the keyboard to
repeat the last command entered
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bbcsdl-no-SIGSEGV.patch
Type: text/x-patch
Size: 330 bytes
Desc: not available
URL: <http://lists.slackbuilds.org/pipermail/slackbuilds-users/attachments/20240318/febea89a/attachment.bin>
More information about the SlackBuilds-users
mailing list