Skip to content

Instantly share code, notes, and snippets.

@heatd
Created December 4, 2021 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heatd/17e365644a7ad9adf1a6d8d636704531 to your computer and use it in GitHub Desktop.
Save heatd/17e365644a7ad9adf1a6d8d636704531 to your computer and use it in GitHub Desktop.
Dump of assembler code for function _Z12process_exitj:
kernel/process.cpp:
831 {
0xffffffff801111d0 <+0>: push %rbp
0xffffffff801111d1 <+1>: mov %rsp,%rbp
0xffffffff801111d4 <+4>: push %r15
0xffffffff801111d6 <+6>: push %r14
0xffffffff801111d8 <+8>: push %r13
0xffffffff801111da <+10>: push %r12
0xffffffff801111dc <+12>: push %rbx
0xffffffff801111dd <+13>: sub $0x98,%rsp
0xffffffff801111e4 <+20>: mov %edi,%ebx
include/onyx/scheduler.h:
104 return get_per_cpu(current_thread);
0xffffffff801111e6 <+22>: mov %gs:0x7feef132(%rip),%r15 # 0x320 <current_thread>
0xffffffff801111ee <+30>: mov %gs:0x7feef12a(%rip),%rax # 0x320 <current_thread>
include/onyx/process.h:
261 return (thread == NULL) ? NULL : (struct process *) thread->owner;
0xffffffff801111f6 <+38>: test %rax,%rax
0xffffffff801111f9 <+41>: je 0xffffffff8011121e <_Z12process_exitj+78>
0xffffffff801111fb <+43>: mov 0x20(%rax),%r13
kernel/process.cpp:
835 if(current->get_pid() == 1)
0xffffffff801111ff <+47>: cmpl $0x1,0x188(%r13)
0xffffffff80111207 <+55>: jne 0xffffffff8011122b <_Z12process_exitj+91>
include/onyx/culstring.h:
255 return data_;
0xffffffff80111209 <+57>: mov 0x10(%r13),%rsi
kernel/process.cpp:
837 printk("Panic: %s exited with exit code %u!\n",
0xffffffff8011120d <+61>: mov $0xffffffff801a9af0,%rdi
0xffffffff80111214 <+68>: mov %ebx,%edx
0xffffffff80111216 <+70>: xor %eax,%eax
0xffffffff80111218 <+72>: call 0xffffffff801a4800 <printk(const char * __restrict__, ...)>
--Type <RET> for more, q to quit, c to continue without paging--c
include/onyx/x86/include/platform/irq.h:
45 __asm__ __volatile__("sti");
0xffffffff8011121d <+77>: sti
0xffffffff8011121e <+78>: xor %r13d,%r13d
kernel/process.cpp:
835 if(current->get_pid() == 1)
0xffffffff80111221 <+81>: cmpl $0x1,0x188(%r13)
0xffffffff80111229 <+89>: je 0xffffffff80111209 <_Z12process_exitj+57>
838 current->cmd_line.c_str(), exit_code);
839 irq_enable();
840 while(true);
841 }
842
843 process_kill_other_threads();
0xffffffff8011122b <+91>: call 0xffffffff801117f0 <_Z26process_kill_other_threadsv>
844
845 process_destroy_file_descriptors(current);
0xffffffff80111230 <+96>: mov %r13,%rdi
0xffffffff80111233 <+99>: call 0xffffffff8014e160 <_Z32process_destroy_file_descriptorsP7process>
846
847 current->signal_group_flags |= SIGNAL_GROUP_EXIT;
0xffffffff80111238 <+104>: orb $0x4,0xa00(%r13)
include/onyx/scheduler.h:
104 return get_per_cpu(current_thread);
0xffffffff80111240 <+112>: mov %gs:0x7feef0d8(%rip),%rax # 0x320 <current_thread>
include/onyx/process.h:
261 return (thread == NULL) ? NULL : (struct process *) thread->owner;
0xffffffff80111248 <+120>: test %rax,%rax
0xffffffff8011124b <+123>: mov %ebx,-0x2c(%rbp)
0xffffffff8011124e <+126>: je 0xffffffff80111256 <_Z12process_exitj+134>
0xffffffff80111250 <+128>: mov 0x20(%rax),%rdi
0xffffffff80111254 <+132>: jmp 0xffffffff80111258 <_Z12process_exitj+136>
0xffffffff80111256 <+134>: xor %edi,%edi
kernel/process.cpp:
704 vm_destroy_addr_space(&current->address_space);
0xffffffff80111258 <+136>: add $0x90,%rdi
0xffffffff8011125f <+143>: call 0xffffffff8012b060 <_Z21vm_destroy_addr_spaceP16mm_address_space>
705 }
706
707 void process_remove_from_list(process *proc)
708 {
709 {
710 scoped_lock g{process_list_lock};
711 /* TODO: Make the list a doubly-linked one, so we're able to tear it down more easily */
712 if(first_process == proc)
713 {
714 first_process = first_process->next;
715 if(process_tail == proc)
716 process_tail = first_process;
717 }
718 else
719 {
720 process *p;
721 for(p = first_process; p->next != proc && p->next; p = p->next);
722
723 assert(p->next != nullptr);
724
725 p->next = proc->next;
726
727 if(process_tail == proc)
728 process_tail = p;
729 }
730
731 }
732
733 /* Remove from the sibblings list */
734
735 scoped_lock g{proc->parent->children_lock};
736
737 if(proc->prev_sibbling)
738 proc->prev_sibbling->next_sibbling = proc->next_sibbling;
739 else
740 proc->parent->children = proc->next_sibbling;
741
742 if(proc->next_sibbling)
743 proc->next_sibbling->prev_sibbling = proc->prev_sibbling;
744 }
745
746 void process_wait_for_dead_threads(process *process)
747 {
748 while(process->nr_threads)
749 {
750 cpu_relax();
751 }
752 }
753
754 void process_end(process *process)
755 {
756 process_remove_from_list(process);
757
758 process_wait_for_dead_threads(process);
759
760 if(process->ctx.cwd)
761 fd_put(process->ctx.cwd);
762
763 delete process;
764 }
765
766 void kill_orphaned_pgrp(process *proc)
767 {
768 scoped_lock g{proc->pgrp_lock};
769
770 auto pgrp = proc->process_group;
771
772 if(pgrp->is_orphaned_and_has_stopped_jobs(proc))
773 {
774 pgrp->kill_pgrp(SIGHUP, 0, nullptr);
775 pgrp->kill_pgrp(SIGCONT, 0, nullptr);
776 }
777 }
778
779 void process_reparent_children(process *proc)
780 {
781 scoped_lock g{proc->children_lock};
0xffffffff80111264 <+148>: lea 0xb10(%r13),%r14
include/onyx/scoped_lock.h:
64 spin_lock(&internal_lock);
0xffffffff8011126b <+155>: mov %r14,%rdi
0xffffffff8011126e <+158>: call 0xffffffff80117a00 <spin_lock(spinlock*)>
kernel/process.cpp:
784 process *new_parent = first_process;
0xffffffff80111273 <+163>: mov 0xd81de(%rip),%rbx # 0xffffffff801e9458 <first_process>
785
786 // I think this is enough? I'm not sure though, Linux does it again on reparenting.
787 kill_orphaned_pgrp(proc);
0xffffffff8011127a <+170>: mov %r13,%rdi
0xffffffff8011127d <+173>: call 0xffffffff801116b0 <_Z18kill_orphaned_pgrpP7process>
788
789 if(!proc->children)
0xffffffff80111282 <+178>: mov 0xb18(%r13),%r12
0xffffffff80111289 <+185>: test %r12,%r12
0xffffffff8011128c <+188>: je 0xffffffff801112fc <_Z12process_exitj+300>
0xffffffff8011128e <+190>: mov %r15,-0x38(%rbp)
0xffffffff80111292 <+194>: mov %r12,%rax
0xffffffff80111295 <+197>: cs nopw 0x0(%rax,%rax,1)
0xffffffff8011129f <+207>: nop
795 c->parent = new_parent;
0xffffffff801112a0 <+208>: mov %rbx,0xa30(%rax)
794 for(process *c = proc->children; c != nullptr; c = c->next_sibbling)
0xffffffff801112a7 <+215>: mov 0xb28(%rax),%rax
0xffffffff801112ae <+222>: test %rax,%rax
0xffffffff801112b1 <+225>: jne 0xffffffff801112a0 <_Z12process_exitj+208>
55 scoped_lock g{parent->children_lock};
0xffffffff801112b3 <+227>: lea 0xb10(%rbx),%r15
include/onyx/scoped_lock.h:
64 spin_lock(&internal_lock);
0xffffffff801112ba <+234>: mov %r15,%rdi
0xffffffff801112bd <+237>: call 0xffffffff80117a00 <spin_lock(spinlock*)>
kernel/process.cpp:
57 process **pp = &parent->children;
0xffffffff801112c2 <+242>: add $0xb18,%rbx
0xffffffff801112c9 <+249>: xor %eax,%eax
0xffffffff801112cb <+251>: nopl 0x0(%rax,%rax,1)
0xffffffff801112d0 <+256>: mov %rax,%rcx
0xffffffff801112d3 <+259>: mov %rbx,%rdx
58 process *p = nullptr;
59
60 while(*pp)
0xffffffff801112d6 <+262>: mov (%rbx),%rax
61 {
62 p = *pp;
63 pp = &p->next_sibbling;
0xffffffff801112d9 <+265>: lea 0xb28(%rax),%rbx
60 while(*pp)
0xffffffff801112e0 <+272>: test %rax,%rax
0xffffffff801112e3 <+275>: jne 0xffffffff801112d0 <_Z12process_exitj+256>
64 }
65
66 *pp = children;
0xffffffff801112e5 <+277>: mov %r12,(%rdx)
67
68 children->prev_sibbling = p;
0xffffffff801112e8 <+280>: mov %rcx,0xb20(%r12)
include/onyx/scoped_lock.h:
73 spin_unlock(&internal_lock);
0xffffffff801112f0 <+288>: mov %r15,%rdi
0xffffffff801112f3 <+291>: call 0xffffffff80117a40 <spin_unlock(spinlock*)>
0xffffffff801112f8 <+296>: mov -0x38(%rbp),%r15
0xffffffff801112fc <+300>: mov %r14,%rdi
0xffffffff801112ff <+303>: call 0xffffffff80117a40 <spin_unlock(spinlock*)>
0xffffffff80111304 <+308>: mov 0xa88(%r13),%rax
kernel/process.cpp:
854 for(proc_event_sub *s = current->sub_queue; s; s = s->next)
0xffffffff8011130b <+315>: test %rax,%rax
0xffffffff8011130e <+318>: je 0xffffffff80111320 <_Z12process_exitj+336>
855 {
856 s->valid_sub = false;
0xffffffff80111310 <+320>: movb $0x0,0x10(%rax)
0xffffffff80111314 <+324>: mov 0x130(%rax),%rax
854 for(proc_event_sub *s = current->sub_queue; s; s = s->next)
0xffffffff8011131b <+331>: test %rax,%rax
0xffffffff8011131e <+334>: jne 0xffffffff80111310 <_Z12process_exitj+320>
857 }
858
859 /* Set this in this order exactly */
860 current_thread->flags = THREAD_IS_DYING;
0xffffffff80111320 <+336>: movl $0x4,0x30(%r15)
861 current_thread->status = THREAD_DEAD;
0xffffffff80111328 <+344>: movl $0x4,0x38(%r15)
862
863 {
864
865 scoped_lock g{current->signal_lock};
0xffffffff80111330 <+352>: lea 0x1d8(%r13),%r14
include/onyx/scoped_lock.h:
64 spin_lock(&internal_lock);
0xffffffff80111337 <+359>: mov %r14,%rdi
0xffffffff8011133a <+362>: call 0xffffffff80117a00 <spin_lock(spinlock*)>
0xffffffff8011133f <+367>: mov -0x2c(%rbp),%ebx
kernel/process.cpp:
866 current->exit_code = exit_code;
0xffffffff80111342 <+370>: mov %ebx,0xa20(%r13)
0xffffffff80111349 <+377>: mov $0xa08,%edi
867
868 /* Finally, wake up any possible concerned parents */
869 wait_queue_wake_all(&current->parent->wait_child_event);
0xffffffff8011134e <+382>: add 0xa30(%r13),%rdi
0xffffffff80111355 <+389>: call 0xffffffff80119130 <_Z19wait_queue_wake_allP10wait_queue>
include/onyx/scoped_lock.h:
73 spin_unlock(&internal_lock);
0xffffffff8011135a <+394>: mov %r14,%rdi
0xffffffff8011135d <+397>: call 0xffffffff80117a40 <spin_unlock(spinlock*)>
kernel/process.cpp:
873 siginfo_t info = {};
0xffffffff80111362 <+402>: movq $0x0,-0xb8(%rbp)
0xffffffff8011136d <+413>: movq $0x0,-0x40(%rbp)
0xffffffff80111375 <+421>: movq $0x0,-0x48(%rbp)
0xffffffff8011137d <+429>: movq $0x0,-0x50(%rbp)
0xffffffff80111385 <+437>: movq $0x0,-0x58(%rbp)
0xffffffff8011138d <+445>: movq $0x0,-0x60(%rbp)
0xffffffff80111395 <+453>: movq $0x0,-0x68(%rbp)
0xffffffff8011139d <+461>: movq $0x0,-0x70(%rbp)
0xffffffff801113a5 <+469>: movq $0x0,-0x78(%rbp)
0xffffffff801113ad <+477>: movq $0x0,-0x80(%rbp)
0xffffffff801113b5 <+485>: movq $0x0,-0x88(%rbp)
0xffffffff801113c0 <+496>: movq $0x0,-0x90(%rbp)
0xffffffff801113cb <+507>: movq $0x0,-0x98(%rbp)
0xffffffff801113d6 <+518>: movq $0x0,-0xa0(%rbp)
0xffffffff801113e1 <+529>: movq $0x0,-0xa8(%rbp)
0xffffffff801113ec <+540>: movq $0x0,-0xb0(%rbp)
874
875 info.si_signo = SIGCHLD;
0xffffffff801113f7 <+551>: movl $0x11,-0xb8(%rbp)
include/onyx/process.h:
171 return pid_;
0xffffffff80111401 <+561>: mov 0x188(%r13),%eax
kernel/process.cpp:
876 info.si_pid = current->get_pid();
0xffffffff80111408 <+568>: mov %eax,-0xa8(%rbp)
877 info.si_uid = current->cred.ruid;
0xffffffff8011140e <+574>: mov 0x1b0(%r13),%eax
0xffffffff80111415 <+581>: mov %eax,-0xa4(%rbp)
0xffffffff8011141b <+587>: movabs $0x431bde82d7b634db,%rcx
878 info.si_stime = current->system_time / NS_PER_MS;
0xffffffff80111425 <+597>: mov %rcx,%rax
0xffffffff80111428 <+600>: mulq 0xa68(%r13)
0xffffffff8011142f <+607>: shr $0x12,%rdx
0xffffffff80111433 <+611>: mov %rdx,-0x90(%rbp)
879 info.si_utime = current->user_time / NS_PER_MS;
0xffffffff8011143a <+618>: mov %rcx,%rax
0xffffffff8011143d <+621>: mulq 0xa60(%r13)
0xffffffff80111444 <+628>: shr $0x12,%rdx
0xffffffff80111448 <+632>: mov %rdx,-0x98(%rbp)
880
881 if(WIFEXITED(exit_code))
0xffffffff8011144f <+639>: mov %ebx,%eax
0xffffffff80111451 <+641>: and $0x7f,%eax
0xffffffff80111454 <+644>: je 0xffffffff80111470 <_Z12process_exitj+672>
885 }
886 else if(WIFSIGNALED(exit_code))
0xffffffff80111456 <+646>: movzwl %bx,%ecx
0xffffffff80111459 <+649>: add $0xffffffff,%ecx
0xffffffff8011145c <+652>: cmp $0xfe,%ecx
0xffffffff80111462 <+658>: ja 0xffffffff80111483 <_Z12process_exitj+691>
887 {
888 info.si_code = CLD_KILLED;
0xffffffff80111464 <+660>: movl $0x2,-0xb0(%rbp)
0xffffffff8011146e <+670>: jmp 0xffffffff8011147d <_Z12process_exitj+685>
883 info.si_code = CLD_EXITED;
0xffffffff80111470 <+672>: movl $0x1,-0xb0(%rbp)
884 info.si_status = WEXITSTATUS(exit_code);
0xffffffff8011147a <+682>: movzbl %bh,%eax
0xffffffff8011147d <+685>: mov %eax,-0xa0(%rbp)
889 info.si_status = WTERMSIG(exit_code);
890 }
891
892 kernel_raise_signal(SIGCHLD, current->parent, 0, &info);
0xffffffff80111483 <+691>: mov 0xa30(%r13),%rsi
0xffffffff8011148a <+698>: lea -0xb8(%rbp),%rcx
0xffffffff80111491 <+705>: mov $0x11,%edi
0xffffffff80111496 <+710>: xor %edx,%edx
0xffffffff80111498 <+712>: call 0xffffffff80114af0 <_Z19kernel_raise_signaliP7processjP9siginfo_t>
893
894 sched_yield();
0xffffffff8011149d <+717>: call 0xffffffff8015e1b0 <_Z11sched_yieldv>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment