Skip to content

elksemu (sometimes) hangs running an ia16-gcc program #2412

@johnsonjh

Description

@johnsonjh

Greetings.

I was trying to port a program (errnum.c) to ELKS. The large majority of the program attempts to ensure that localized messages are always used in a way that is cross-platform aware, which is unnecessary on ELKS since there isn't any locale support, and neither does their exist strsignal, so in the end, the program ends up doing very little. The original program also used a 32K static buffer, but on ELKS we can safely assume that no error message will ever exceed 128 bytes.

Obviously, it would be better to just rewrite this program for ELKS, but, the minimal ELKS version is errnum_elks.c.

Running this program on Linux with elksemu results in random hangs at different points for me:

$ ia16-elf-gcc -melks errnum_elks.c -o errnum
$ while :; do seq 1 512 | xargs -I{} ~/src/build-ia16/build-elks/elksemu/elksemu errnum {}; done

It will always hang, and in different random spots.

I have a port of another program (I can provide it if need be) and this one, run running like:

while :; do elksemu ./mcmb -X mul 5 10 15; done

and it will run a few iterations and then elksemu will get a SIGSTOP:

[1]  + 2744420 suspended (signal)  elksemu ./mcmb -X mul 5 10 15

And then I can fg to continue it, and it will run millions of iterations without any pauses or hangs. But if I start the while loop over again, it will always get a SIGSTOP almost immediately, and require an fg to continue on.

I've not looked much further into the cause yet. I did try to run elksemu under strace on my system, it gets an immediate SIGSTOP every single time:

$ strace elksemu ./mcmb -X mul 5 10 15
execve("/home/jhj/src/build-ia16/build-elks/elksemu/elksemu", ["/home/jhj/src/build-ia16/build-e"..., "./mcmb", "-X", "mul", "5", "10", "15"], 0x7ffcb7f14e40
 /* 125 vars */) = 0                                                                                                                                         
brk(NULL)                               = 0x2db61000                                                                                                         
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x153bf19ac000                                                                    
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)                                                                              
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3                                                                                                 
fstat(3, {st_mode=S_IFREG|0644, st_size=334839, ...}) = 0                                                                                                    
mmap(NULL, 334839, PROT_READ, MAP_PRIVATE, 3, 0) = 0x153bf195a000                                                                                            
close(3)                                = 0                                                                                                                  
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3                                                                                                 
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\00007\0\0\0\0\0\0"..., 832) = 832                                                                      
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784                                                                
fstat(3, {st_mode=S_IFREG|0755, st_size=2447520, ...}) = 0                                                                                                   
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784                                                                
mmap(NULL, 2038832, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x153bf1768000                                                                   
mmap(0x153bf18d7000, 479232, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16f000) = 0x153bf18d7000                                                   
mmap(0x153bf194c000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e3000) = 0x153bf194c000                                         
mmap(0x153bf1952000, 31792, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x153bf1952000                                               
close(3)                                = 0                                   
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x153bf1765000                                                                   
arch_prctl(ARCH_SET_FS, 0x153bf1765740) = 0                                   
set_tid_address(0x153bf1765a10)         = 2830309                                                                                                            
set_robust_list(0x153bf1765a20, 24)     = 0                                                                                                                  
rseq(0x153bf1765680, 0x20, 0, 0x53053053) = 0                                                                                                                
mprotect(0x153bf194c000, 16384, PROT_READ) = 0                                                                                                               
mprotect(0x408000, 4096, PROT_READ)     = 0                                   
mprotect(0x153bf19e8000, 8192, PROT_READ) = 0                                                                                                                
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=RLIM64_INFINITY, rlim_max=RLIM64_INFINITY}) = 0                                                                   
munmap(0x153bf195a000, 334839)          = 0                                                                                                                  
access("./mcmb", X_OK)                  = 0                                                                                                                  
openat(AT_FDCWD, "./mcmb", O_RDONLY)    = 3                                                                                                                  
fstat(3, {st_mode=S_IFREG|0755, st_size=51776, ...}) = 0                                                                                                     
getuid()                                = 1000                                
getgid()                                = 1000                                                                                                               
setregid(1000, 1000)                    = 0                                                                                                                  
setreuid(1000, 1000)                    = 0                                                                                                                  
modify_ldt(0, 0x7ffcffabfeb0, 65536)    = 0                                                                                                                  
modify_ldt(1, {entry_number=0, base_addr=0x001000, limit=0x000fff, seg_32bit=0, contents=2, read_exec_only=0, limit_in_pages=0, seg_not_present=0, useable=1, lm=0}, 16) = 0                                                                                                                                              
modify_ldt(1, {entry_number=1, base_addr=0x001000, limit=0x000fff, seg_32bit=0, contents=2, read_exec_only=0, limit_in_pages=0, seg_not_present=0, useable=1, lm=0}, 16) = 0                                                                                                                                              
modify_ldt(1, {entry_number=2, base_addr=0x001000, limit=0x000fff, seg_32bit=0, contents=0, read_exec_only=0, limit_in_pages=0, seg_not_present=0, useable=1, lm=0}, 16) = 0                                                                                                                                              
mmap(NULL, 200704, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|MAP_32BIT, -1, 0) = 0x41eed000                                                  
mprotect(0x41f1d000, 4096, PROT_NONE)   = 0                                                                                                                  
read(3, "\1\0030\4 \0\1\0p\300\0\0\260\t\0\0\260\f\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32) = 32                                                                    
read(3, "Y\211\343QU\211\345\211\310@\321\340\1\330PSQ\276\364\10\375\255\374\221\343\4\377\321\353\366\350r"..., 49264) = 49264                             
read(3, "", 0)                          = 0                                                                                                                  
read(3, "\0\0\0\0\0\0%s \0002120.6.03-dps\0libcmb 3"..., 2480) = 2480                                                                                        
modify_ldt(1, {entry_number=0, base_addr=0x41eed000, limit=0x00c06f, seg_32bit=0, contents=2, read_exec_only=0, limit_in_pages=0, seg_not_present=0, useable=0, lm=0}, 16) = 0                                                                                                                                            
modify_ldt(1, {entry_number=1, base_addr=0x41efd000, limit=0xffffffff, seg_32bit=0, contents=2, read_exec_only=0, limit_in_pages=0, seg_not_present=1, useable=0, lm=0}, 16) = 0                                                                                                                                          
modify_ldt(1, {entry_number=2, base_addr=0x41f0d000, limit=0x005895, seg_32bit=0, contents=0, read_exec_only=0, limit_in_pages=0, seg_not_present=0, useable=0, lm=0}, 16) = 0                                                                                                                                            
close(3)                                = 0                                                                                                                  
clone(child_stack=0x41f10650, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_IO) = 2830310                                                                        
ptrace(PTRACE_ATTACH, 2830310)          = 0                                                                                                                  
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_STOPPED, si_pid=2830310, si_uid=1000, si_status=SIGSTOP, si_utime=0, si_stime=0} ---                              
wait4(2830310, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGSTOP}], __WALL, NULL) = 2830310                                                                          
ptrace(PTRACE_SETREGS, 2830310, {r15=0, r14=0, r13=0, r12=0, rbp=0, rbx=0, r11=0, r10=0, r9=0, r8=0, rax=0, rcx=0, rdx=0, rsi=0, rdi=0, orig_rax=0xf, rip=0, cs=0x7, eflags=0, rsp=0x3660, ss=0x17, fs_base=0, gs_base=0, ds=0x17, es=0x17, fs=0, gs=0}) = 0                                                              
ptrace(PTRACE_GETREGS, 2830310, {r15=0, r14=0, r13=0, r12=0, rbp=0, rbx=0, r11=0, r10=0, r9=0, r8=0, rax=0, rcx=0, rdx=0, rsi=0, rdi=0, orig_rax=0xf, rip=0, cs=0x7, eflags=0x202, rsp=0x3660, ss=0x17, fs_base=0, gs_base=0, ds=0x17, es=0x17, fs=0, gs=0}) = 0                                                          
ptrace(PTRACE_SYSEMU, 2830310, NULL, 0) = 0                                                                                                                  
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_TRAPPED, si_pid=2830310, si_uid=1000, si_status=SIGSTOP, si_utime=0, si_stime=0} ---                              
wait4(2830310, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGSTOP}], __WALL, NULL) = 2830310                                                                          
ptrace(PTRACE_GETREGS, 2830310, {r15=0, r14=0, r13=0, r12=0, rbp=0, rbx=0, r11=0, r10=0, r9=0, r8=0, rax=0, rcx=0, rdx=0, rsi=0, rdi=0, orig_rax=0xf, rip=0, cs=0x7, eflags=0x202, rsp=0x3660, ss=0x17, fs_base=0, gs_base=0, ds=0x17, es=0x17, fs=0, gs=0}) = 0                                                          
gettid()                                = 2830309                                                                                                            
getpid()                                = 2830309                                                                                                            
tgkill(2830309, 2830309, SIGSTOP)       = 0                                                                                                                  
--- SIGSTOP {si_signo=SIGSTOP, si_code=SI_TKILL, si_pid=2830309, si_uid=1000} ---                                                                            
--- stopped by SIGSTOP ---                                                                                                                                   

And of course, giving it a SIGCONT makes it go.

So this seems to be something going on with elksemu and how the ptrace code works. It's a minor inconvenience interactively, but its breaking my ability to do any automated testing.

Before I did further in, any suggestions?

Edit: It seems like this would have to be a Linux bug, no?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDefect in the product

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions