Skip to content
Snippets Groups Projects
  1. Oct 16, 2013
  2. Oct 14, 2013
  3. Oct 11, 2013
  4. Oct 08, 2013
    • Nadav Har'El's avatar
      Use same version in <linux/version.h> and uname() · e2554eaf
      Nadav Har'El authored
      
      We had a different Linux version compiled into uname() (3.7.0) than
      we had compiled into other code (via <linux/version.h>).
      
      This patch makes them both pretend to be 3.7.0 - arbitrarily chosen
      as the current Linux version at the time OSv was created. The new code
      verifies with a static assertion that both files contain the same version,
      so if they diverge, uname.c will fail compilation.
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      e2554eaf
  5. Oct 07, 2013
  6. Oct 06, 2013
  7. Oct 05, 2013
    • Benoît Canet's avatar
      pthread: initialize earlier · 0cb87a5d
      Benoît Canet authored
      
      boost's asio.hpp module init() function was calling pthread_key_create which
      tried to manipulate some libc/pthread.cc unitialized objects.
      
      pthread_key_create then returned -ENOMEM so an exception was thrown by boost
      causing the loader's premain() function to fail and the boot to loop.
      
      This patch lower the priority of the initialization of the libc/pthread.cc
      objects so they are ready when premain is calling the boost module init()
      function.
      
      Signed-off-by: default avatarBenoit Canet <benoit@irqsave.net>
      Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
      0cb87a5d
  8. Oct 03, 2013
  9. Sep 29, 2013
    • Nadav Har'El's avatar
      Support alarm() · ee88c900
      Nadav Har'El authored
      
      This patch adds support for Linux's alarm(2) system call.
      
      alarm() is needed in some ancient Unix software, like netperf :(
      
      This implementation is fully compatible with Linux's alarm(), but please
      note that what alarm() does when the alarm times out is a kill(SIGALRM) -
      so all the caveats mentioned in the previous patch regarding kill(),
      will also apply here.
      
      Alarm() is implemented by running one "alarm thread", started on the
      first alarm() call. This alarm-thread waits for the alarm to expire,
      or for instructions to change the alarm. When an alarm expires the
      alarm thread does a kill(0,SIGALRM).
      
      tst-kill.cc (from the previous patch) includes a test to see that
      alarm() really sends a SIGALRM signal on time, and also that we can
      cancel a pending alarm and not receive a signal.
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      ee88c900
    • Nadav Har'El's avatar
      Add kill() support - sort of · b9ed15c2
      Nadav Har'El authored
      
      This patch adds support for the Linux kill(2) function.
      The next patch will add alarm(2) support, which uses kill(2).
      
      To be honest, we sort-of implement kill(). This implementation is
      compatible with the API, but the semantics are somewhat different:
      While in Linux kill() causes the signal handler to run on one of the
      existing threads, in this implementation, the signal handler is run in a
      *new* thread.
      
      Implementing the exact Linux semantics in OSv would require tracking when
      OSv runs kernel code (i.e., code in the main executable, not a shared
      object) so we can delay running the signal handler until returning to the
      user code. Moreover, we'll need to be able to interrupt sleeping kernel
      code. This is complicated and adds overhead even if signals aren't used
      (and they aren't used in most modern code).
      
      I expect that this code will be "good enough" in many use cases.
      This code will *not* be good in enough in programs that expect one of the
      following:
      
      1. A program that by using Posix Thread's "signal masks" tried to ensure
         that the signal is delivered to one specific thread, and not to an
         arbitrary thread.
      
      2. A program that used kill() or alarm() not intending to run a signal
         handler, but rather intending to interrupt a sleeping system call
         like sleep() or read(). Our kill() does not interrupt sleeping OSv
         function calls, which will continue to sleep on the thread they run
         on.
      
      The support in this patch (and see next patch, for alarm()) is good
      enough for netperf's use of alarm().
      
      P.S. kill() can be used only to send a signal to the current process, the
      only process we have in OSv (you can also use pid=0 and pid=-1 to achieve
      the same results).
      
      This patch also adds a test for kill() and alarm(). The alarm() test
      will fail until the next patch :-)
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      b9ed15c2
  10. Sep 25, 2013
  11. Sep 24, 2013
    • Nadav Har'El's avatar
      Change pipe event from POLLRDHUP to POLLERR|POLLOUT · f6d134bc
      Nadav Har'El authored
      
      We used to return the POLLRDHUP event when polling a write-side of a pipe
      whose reader is closed, but Linux returns POLLERR|POLLOUT, so let's do
      the same.
      
      Linux's behavior can be explained in that when the reader is closed, a write
      will return immediately (and hence POLLOUT) but moreover, will return with
      an error (EPIPE). And since a read will also cause an error (EBADF when
      reading on the write side of the pipe), a POLLERR makes sense and says
      that any operation on this fd will now result in an error.
      
      This patch also adds a test for this case.
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      f6d134bc
    • Nadav Har'El's avatar
      Fix POLLHUP in pipes · 35117245
      Nadav Har'El authored
      
      The code in pipe_buffer.cc had the meaning of POLLHUP and POLLRDHUP
      reversed, and as a result POLLHUP wasn't correctly returned when polling
      a read-end of the pipe whose write-end is closed.
      
      This fixes the mixup, and as a result the test added to tst-pipe.cc in
      the previous commit, and also another one added in this patch, all pass.
      
      We are still incompatible with Linux with what we do regarding POLLRDHUP.
      This will be a separate patch.
      
      Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
      35117245
  12. Sep 15, 2013
    • Nadav Har'El's avatar
      Add copyright statements in libc/ · bec69a62
      Nadav Har'El authored
      Add Cloudius copyright statements in libc/.
      
      One unfortunate problem we have in libc/ is that most of the code there was copied
      from Musl, and Musl is copyrighted and licensed, but individual files do not carry
      any statements - Rich Felker explains in Musl's COPYRIGHT file: "The decision to
      exclude such comments is intentional, as it should be possible to carry around the
      complete source code on tiny storage media."
      
      In the future, we should find all the Musl files and add to each one the line
      Copyright (C) 2005-2013 Rich Felker. But we'll need to do it carefully so as not
      to wrongly attribute non-Musl code to Musl. In the meantime, if we just have
      documentation/LICENSE-musl, and don't claim our own copyright on the musl files,
      I think we're playing fair.
      bec69a62
  13. Sep 12, 2013
    • Guy Zana's avatar
      getnameinfo: try to find entry in /etc/hosts first · 2c7f0a58
      Guy Zana authored
      the musl implementation immidiately issues a DNS query, instead of looking
      first at the /etc/hosts file, this patch fixes it.
      
      As a side effect, the long boot duration is shortened by 3-4 seconds.
      2c7f0a58
  14. Sep 03, 2013
    • Pekka Enberg's avatar
      dlfcn: Fix dlopen() error handling · a83cdf85
      Pekka Enberg authored
      If "-javaagent" option is enabled, the JVM page faults:
      
        (gdb) bt
        #0  0x000000000033d432 in halt_no_interrupts () at ../../arch/x64/processor.hh:232
        #1  osv::halt () at ../../core/power.cc:20
        #2  0x0000000000214d82 in abort (msg=msg@entry=0x57ea90 "page fault outside application") at ../../runtime.cc:98
        #3  0x00000000002fd4d8 in page_fault (ef=0xffffc0003ffe6008) at ../../core/mmu.cc:943
        #4  <signal handler called>
        #5  0x0000000000373169 in __stpncpy (d=d@entry=0x2000001fe7f0 "dlsym: symbol JVM_begin_signal_setting not found", s=0x0, n=1023)
            at ../../libc/string/stpncpy.c:19
        #6  0x0000000000373ad1 in strncpy (d=0x2000001fe7f0 "dlsym: symbol JVM_begin_signal_setting not found", s=<optimized out>,
            n=<optimized out>) at ../../libc/string/strncpy.c:7
        #7  0x0000100000b0ab67 in os::dll_load (filename=filename@entry=0x2000001febf0 "libinstrument.so",
            ebuf=ebuf@entry=0x2000001fe7f0 "dlsym: symbol JVM_begin_signal_setting not found", ebuflen=ebuflen@entry=1024)
            at /usr/src/debug/java-1.7.0-openjdk-1.7.0.25-2.3.12.3.fc19.x86_64/openjdk/hotspot/src/os/linux/vm/os_linux.cpp:1841
        #8  0x0000100000c247eb in lookup_on_load (agent=agent@entry=0xffffc0003976ccc0,
            on_load_symbols=on_load_symbols@entry=0x2000001ffd40, num_symbol_entries=1)
            at /usr/src/debug/java-1.7.0-openjdk-1.7.0.25-2.3.12.3.fc19.x86_64/openjdk/hotspot/src/share/vm/runtime/thread.cpp:3585
        #9  0x0000100000c2a64f in lookup_agent_on_load (agent=0xffffc0003976ccc0)
            at /usr/src/debug/java-1.7.0-openjdk-1.7.0.25-2.3.12.3.fc19.x86_64/openjdk/hotspot/src/share/vm/runtime/thread.cpp:3617
        #10 create_vm_init_agents ()
            at /usr/src/debug/java-1.7.0-openjdk-1.7.0.25-2.3.12.3.fc19.x86_64/openjdk/hotspot/src/share/vm/runtime/thread.cpp:3656
        #11 Threads::create_vm (args=<optimized out>, canTryAgain=canTryAgain@entry=0x2000001ffdb0)
            at /usr/src/debug/java-1.7.0-openjdk-1.7.0.25-2.3.12.3.fc19.x86_64/openjdk/hotspot/src/share/vm/runtime/thread.cpp:3177
        #12 0x000010000094d7b0 in JNI_CreateJavaVM (vm=0x2000001ffe58, penv=0x2000001ffe60, args=<optimized out>)
            at /usr/src/debug/java-1.7.0-openjdk-1.7.0.25-2.3.12.3.fc19.x86_64/openjdk/hotspot/src/share/vm/prims/jni.cpp:5127
        #13 0x0000100000007b3b in main (argc=<optimized out>, argv=0xffffc0003fff2008) at ../../java/java.cc:73
        #14 0x0000000000208ac8 in run_main (prog=<optimized out>, args=args@entry=0xffffc0003fe9bfa0) at ../../loader.cc:196
        #15 0x0000000000208c68 in do_main_thread (_args=0xffffc0003fe9bfa0) at ../../loader.cc:217
        #16 0x0000000000376d36 in operator() (__closure=0xffffc0003b5e2a00) at ../../libc/pthread.cc:59
        #17 std::_Function_handler<void(), pthread_private::pthread::pthread(void* (*)(void*), void*, sigset_t, const pthread_private::thread_attr*)::__lambda0>::_M_invoke(const std::_Any_data &) (__functor=...) at ../../external/gcc.bin/usr/include/c++/4.8.1/functional:2071
        #18 0x000000000032ed6b in main (this=0xffffc0003a807010) at ../../core/sched.cc:536
        #19 sched::thread_main_c (t=0xffffc0003a807010) at ../../arch/x64/arch-switch.hh:133
        #20 0x000000000031873e in thread_main () at ../../arch/x64/entry.S:101
        Backtrace stopped: frame did not save the PC
      
      This is caused by the JVM expecting dlerror() to return an error string
      if dlopen() fails. Fix that up.
      a83cdf85
  15. Sep 02, 2013
  16. Sep 01, 2013
    • Pekka Enberg's avatar
      mman: Fix missing libc.hh include · 584c1737
      Pekka Enberg authored
      Fixes the following build brekage caused by commit a7d6b269 ("mman: Use
      libc_error() in mprotect()"):
      
      ../../libc/mman.cc: In function ‘int mprotect(void*, size_t, int)’:
      ../../libc/mman.cc:36:33: error: ‘libc_error’ was not declared in this scope
               return libc_error(EINVAL);
                                       ^
      ../../libc/mman.cc:41:33: error: ‘libc_error’ was not declared in this scope
               return libc_error(ENOMEM);
                                       ^
        CXX libc/pipe_buffer.o
        CXX libc/pipe.o
      make[1]: *** [libc/mman.o] Error 1
      584c1737
    • Pekka Enberg's avatar
      mman: Use libc_error() in mprotect() · a7d6b269
      Pekka Enberg authored
      a7d6b269
  17. Aug 29, 2013
  18. Aug 26, 2013
    • Nadav Har'El's avatar
      Avoid including elf.hh from sched.hh · 714d313a
      Nadav Har'El authored
      sched.hh included elf.hh, just so it can refer to the elf::tls_data
      type. But now that we have rcu.hh which includes sched.hh and therefore
      elf.hh, if we wish to use rcu in elf.hh (we'll do this in a later patch),
      we have an include loop mess.
      
      So better not include elf.hh from sched.hh, and just declare the one
      struct we need.
      
      After sched.hh no longer includes elf.hh and the dozen includes that
      it further included, we need to add missing includes to some of the
      code that included sched.hh and relied on its implict includes.
      714d313a
  19. Aug 21, 2013
  20. Aug 14, 2013
    • Avi Kivity's avatar
      libc: define __pthread_key_create · da3e7b76
      Avi Kivity authored
      libstdc++ switched to relying on this symbol for the gthread machinery,
      define it so it works.
      
      Fixes std::thread used in mpsc queue tests.
      da3e7b76
  21. Aug 12, 2013
  22. Aug 08, 2013
    • Nadav Har'El's avatar
      dl_iterate_phdr: Don't pass pointers on the stack to callback · a26fe58c
      Nadav Har'El authored
      This patch fixes the exception handling bug seen in tst-except.so.
      
      The callback given dl_iterate_phdr (such as _Unwind_IteratePhdrCallback
      in libgcc_eh.a used to implement exceptions) may decide to cache previous
      information we gave it, as long as the "adds" and "subs" fields are
      unchanged.
      
      The bug was that we passed to the callback a on-stack *copy* of the
      obj->_phdrs vector, and if the callback saved pointers to that in its
      cache, they became invalid on the next call. We need the pointers to
      remain valid as long as adds/subs do not change. So we need to pass
      the actual obj->_phdrs (which doesn't change after the object's load),
      NOT a copy.
      
      Note there's a locking issue remaining here - if someone dlclose()s
      an object while the callback is running (and already checked adds/subs)
      it can use a stale pointer. This should be fixed separately, probably
      by using reference counting on objects.
      a26fe58c
    • Nadav Har'El's avatar
      dl_iterate_phdr: fill missing adds and subs field · 4d8353ac
      Nadav Har'El authored
      The callback function passed to dl_iterate_phdr, such as
      _UnWind_IteratePhdrCallback (used in libgcc_eh.a to implement exceptions),
      may want to cache previous lookups, and wants to know when the list of
      iterated modules hasn't changed since the last call to dl_iterate_phdr.
      For this, dl_iterate_phdr() is supposed to fill two fields, dlpi_adds
      and dlpi_subs, counting the number of times objects were loaded or
      unloaded from the program. If both dlpi_subs and dlpi_adds are unchanged,
      the callback is guaranteed the list of objects is unchanged.
      
      In the existing code, we forgot to set these two fields, so they got
      random values which caused the exception unwinding code to sometimes
      cache, and sometime not cache, depending on the phase of the moon.
      
      This patch adds the counting of the correct "subs" and "adds" counters,
      and after it exception unwinding will always use its cache (as long
      as the list of objects doesn't change).
      
      Note that this does NOT fix the crash in tst-except.so. That is a bug
      which appears when caching is enabled (which before this patch happend
      randomly), and will be fixed by the next patch.
      4d8353ac
    • Pekka Enberg's avatar
      dlfcn: dlerror() support · 31751201
      Pekka Enberg authored
      dlerror is needed when an application is started on the JVM with the
      "-javaagent" option defined.
      31751201
  23. Jul 28, 2013
  24. Jul 22, 2013
  25. Jul 18, 2013
Loading