Skip to content

Latest commit

 

History

History
418 lines (391 loc) · 17.5 KB

Linux.org

File metadata and controls

418 lines (391 loc) · 17.5 KB

Linux Notes

1 Kernel

1.1 Kernel startup (for X86 and ARM)

1.2 Scheduler

1.3 MM

1.4 Network

1.5 Video

1.6 Devices

1.6.1 USB

1.6.2 TTY

1.7 syscall (x86)

  • syscall initialization procedure
    • setup()
      • startp_32()
        • start_kernel() (from init/main.c)
          • trap_init()
            • set_system_trap_gate(SYSCALL_VECTOR, &system_call);
              • arch/x86/include/asm/irq_vectors.h # define SYSCALL_VECTOR 0x80
    • Or do a syscall using sysenter, syscall etc (vdso, AT_SYSINFO, __kernel_vsyscall …)
      • linux-2.6/arch/x86/vdso/vdso32-setup.c
      • linux-2.6/arch/x86/vdso/vdso32/{syscall,sysenter,int80}.S
      • linux-2.6/arch/x86/vdso/vdso32/vdso32.lds.S
  • syscall flow for execve
    • sys_execve() (from arch/x86/kernel/process.c)
      • do_execve(filename, argv, envp, regs)
        • Sanity checks
        • open_exec(filename)
        • prepare_binprm(bprm) Reads permission and stuff
        • copy_strings() Copy environment, args etc
        • search_binary_handler(bprm,regs) Search for the executable type and its handler
          • load_elf_binary()
            • Do some sanity checks
            • Read in all the elf sections
            • Map the read elf sections
            • load_elf_interp()
              • Loads the interpreter mentioned in the elf (for example /lib/ld-linux.so)
            • start_thread()
              • Sets up the USER_CS. Sets IP and SP to be that of the interpreter’s entry points (in our case it is _dl_start() of ld-linux.so)
      • RTLD_START (glibc/sysdeps/i386/dl-machine.h)
        • _dl_start() (glibc/elf/rtld.c)
          • elf_machine_load_address ()
            • Runtime load address of the linker
          • Read the linker’s own header
          • Allocate TLS
          • ELF_DYNAMIC_RELOCATE ()
            • elf_machine_runtime_setup () (glibc/sysdeps/i386/dl-machine.h)
              • If we are doing “lazy” on-demand binding, setup the appropriate handlers (_dl_runtime_resolve or _dl_runtime_profile)
            • ELF_DYNAMIC_DO_REL () (glibc/elf/dynamic-link.h)
              • elf_dynamic_do_rel()
                • If laze relocation, call elf_machine_lazy_rel() (at glibc/sysdeps/i386/dl-machine.h). Set up to call _dl_runtime_resolve.
            • ELF_DYNAMIC_DO_RELA () (glibc/elf/dynamic-link.h)
          • _dl_start_final()
            • Record the startup time
            • __builtin_frame_address (0)
            • _dl_sysdep_start() (glibc/elf/dl-sysdep.c)
              • Initialize user entry point i.e., ENTRY_POINT (which is nothing but _start). It will be updated to a value specified by AT_ENTRY if one was supplied by the elf binary
              • dl_main() (from glibc/elf/rtld.c)
                • process_envvars()
                • See if the ld.so was run directly (rather than being invoked on behalf of an elf’s PT_INTERP section). If so, support the “ld.so programname args” kind of invocation. Loaded program’s PT_INTERP would be ignored, as we are the interpreter.
                • Or else: call _dl_new_object() Create a link map for executable
                • Scan through the header looking for dynamic section and initialize appropriate values in the create map object.
                • elf_get_dynamic_info ()
                • _dl_setup_hash ()
                • If we were just called to verify (“–verify”), exit now
                • _dl_init_paths
                • Load debug sections, setup debugging (for self as well)
                • Load all the objects, including LD_PRELOADS and DT_NEEDED objects
                • _dl_receive_error () for reporting missing dependencies
                • If we were just called to list the libraries (“–list”), list them and call it quits
                • If we are prelinked, update the conflicts and do call _dl_resolve_conflicts()
                • Else
                  • For each library object in the list
                    • Call _dl_relocate_object() which will do the relocation as needed (lazy etc - _dl_runtime_resolve() is the one that is of interest here). And also mprotect’ing of segments are done here.
              • return user_entry
            • Return what ever value _dl_sysdep_start() returned (that is the starting address of the binary)
          • Return the user start address
        • Setup the stack
        • Call _dl_init_internal_*()
        • Jump to the user start address
          • Setup stack
          • __libc_start_main() (glibc/csu/libc-start.c)
            • INIT_ARGV_and_ENVIRON
            • _dl_aux_init ()
            • __libc_csu_irel ()
            • __pthread_initialize_minimal ()
            • _dl_setup_stack_chk_guard ()
            • __cxa_atexit (…rtld_fini, ....)
              • Register destructor call back of the dynamic linker if any
            • __libc_init_first (argc, argv, __environ)
            • __cxa_atexit (… fini, …)
              • Register destructor call back of the program if any
            • __libc_check_standard_fds ()
            • init (argc, argv, __environ MAIN_AUXVEC_PARAM)
            • result = main (argc, argv, __environ MAIN_AUXVEC_PARAM)
              • Life revolves around here
            • exit (result)
              • __run_exit_handlers (status, &__exit_funcs, true)
                • Call the functions that were registered with “atexit()” and “onexit()”. Cleanup stdio.
                • RUN_HOOK (__libc_atexit, ())
                • _exit()
                  • syscall for __NR_exit_group

1.8 To Read

2 XServer

2.1 To Read

2.2 Xorg general architecture

2.3 Xorg and OpenGL

2.3.1 TinyGL

2.4 Intumo

2.4.1 to-be-checked

2.4.1.2 Native widget drawing in canvas - QGraphicsView

2.4.1.3 Physics engine:

2.4.1.3.1 @Simon: “poorer” in which sense? have you tried writing a demo like TAT’s? have you tried using shaders? a physics engine? Clutter is already a competitive mobile UI tool.
2.4.1.3.2 @krh, yep - also see box2d and chipmonk. Pippin has been playing with them all (http://www.murrayc.com/blog/permalink/2008/03/03/clutter-tutorial-done-for-now/)

2.4.2 clutter

2.4.2.1 Q: Offscreen rendering support?

2.4.3 xserver

2.4.4 QUESTIONS:

2.4.4.1 Why not use Qt and custom widgets on top of it?

2.4.4.2 Why not use GTK and custom widgets on top of it?

2.4.4.4 what is libggi?

2.4.4.4.1 comment from somewhere: Lucas wrote: A good compromise I found for a touchscreen based POS system (using one of those VIA mini-ATX boards) was libggi. It allows to develop and test on X and have the same binary run under fb.

2.4.4.5 what is this http://xynth.org/ ?

2.4.4.6 check qtopia

2.4.4.10 check clutter

2.4.4.11 check cocoa

2.4.4.12 read X11 log in computer/laptop

2.4.4.16 http://fltk.org - Fast Light ToolKit

3 Miscellaneous

3.1 Tinyelf

[suresh@linux-vrse tt]$ cat | gcc -nostdlib -x c - -o helloworld
#define SYS_exit  1
#define SYS_write 4
#define stdout    1

int strlen(const char *str)
{
  long len = 0;
  while (str && *str++)
  {
      len++;
  }
  
  return len;
}


void print(const char *str) 
{
    int len = strlen(str);

    long ret;

    /* Can't touch ebx directly, PIC uses it */
    __asm__ __volatile__ ("pushl %%ebx\n"
                          "movl  %%esi, %%ebx\n"
                          "int	 $0x80\n;"
                          "popl  %%ebx"
                          :
                          : "a" (SYS_write),
                            "S" ((long) stdout),
                            "c" ((long) str),
                            "d" ((long) len));
    return;
}

void _start()
{
  main();

  __asm__ __volatile__ (
       "xorl %%ebx, %%ebx\n"
       "int $0x80\n"
       :
       : "a" (SYS_exit));
}

int main()
{
  print("Hello World\n");
  return 0;
}

[suresh@linux-vrse tt]$ strip -R .comment -R .comment.SUSE.OPTs -R .note.gnu.build-id helloworld
[suresh@linux-vrse tt]$ ll helloworld 
-rwxr-xr-x 1 suresh users 540 2010-07-21 13:19 helloworld

[suresh@linux-vrse tt]$ ./helloworld 
Hello World

3.2 VDSO

Dump of VDSO related stuff

[suresh@linux-vrse tmp]$ ldd /bin/cat 
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0xb7e65000)
        /lib/ld-linux.so.2 (0xb7fe0000)

[suresh@linux-vrse tmp]$ LD_SHOW_AUXV=1 /bin/cat | grep AT_SYSINFO
AT_SYSINFO:      0xffffe414
AT_SYSINFO_EHDR: 0xffffe000

[suresh@linux-vrse tmp]$ cat /proc/self/maps  | grep vdso
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]


[suresh@linux-vrse tmp]$ dd if=/proc/self/mem of=vdso skip=$((0xffffe000/0x1000)) count=1 bs=$((0x1000))
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 4.3047e-05 s, 95.2 MB/s

[suresh@linux-vrse tmp]$ objdump -d --start-address=0xffffe000 ./vdso 

/tmp/vdso:     file format elf32-i386


Disassembly of section .text:

ffffe400 <__kernel_sigreturn>:
ffffe400:       58                      pop    %eax
ffffe401:       b8 77 00 00 00          mov    $0x77,%eax
ffffe406:       cd 80                   int    $0x80
ffffe408:       90                      nop    
ffffe409:       8d 76 00                lea    0x0(%esi),%esi

ffffe40c <__kernel_rt_sigreturn>:
ffffe40c:       b8 ad 00 00 00          mov    $0xad,%eax
ffffe411:       cd 80                   int    $0x80
ffffe413:       90                      nop    

ffffe414 <__kernel_vsyscall>:
ffffe414:       51                      push   %ecx
ffffe415:       52                      push   %edx
ffffe416:       55                      push   %ebp
ffffe417:       89 e5                   mov    %esp,%ebp
ffffe419:       0f 34                   sysenter 
ffffe41b:       90                      nop    
ffffe41c:       90                      nop    
ffffe41d:       90                      nop    
ffffe41e:       90                      nop    
ffffe41f:       90                      nop    
ffffe420:       90                      nop    
ffffe421:       90                      nop    
ffffe422:       eb f3                   jmp    ffffe417
<__kernel_vsyscall+0x3>
ffffe424:       5d                      pop    %ebp
ffffe425:       5a                      pop    %edx
ffffe426:       59                      pop    %ecx
ffffe427:       c3                      ret    

[suresh@linux-vrse tmp]$ # or we can use
[suresh@linux-vrse tmp]$ dd if=/proc/self/mem of=- skip=$((0x`cat /proc/self/maps | grep vdso | cut -d'-' -f1`/0x1000)) count=1 bs=$((0x1000)) | objdump -d --start-address=0xffffe000 - 

3.3 ELF format

3.4 Stack

3.5 BIOS

3.5.1 Coreboot