Commit Graph

37 Commits

Author SHA1 Message Date
Jacques Germishuys
bc48bcdcb3 Make the Visual Studio compiler happy 2014-11-03 14:23:13 +02:00
Edward Thomson
50aae0007b global: clean up openssl_locks on shutdown 2014-10-26 22:27:52 -04:00
Carlos Martín Nieto
f0f9737094 ssl: dump the SSL ciphers in favour of TLS
All versions of SSL are considered deprecated now, so let's ask OpenSSl
to only use TLSv1. We still ask it to load those ciphers for
compatibility with servers which want to use an older hello but will use
TLS for encryption.

For good measure we also disable compression, which can be exploitable,
if the OpenSSL version supports it.
2014-10-23 15:56:29 +02:00
Carlos Martín Nieto
fdea219a86 global: free the error message when exiting a thread
When we free the global state at thread termination, we must also free
the error message in order not to leak the string once per thread.
2014-09-14 00:39:07 +02:00
Jacques Germishuys
f59a34d2e6 Only create openssl_locks if thread support is enabled 2014-07-13 16:23:17 +02:00
Carlos Martín Nieto
e6b0ae7a13 ssl: init only once without threads
The OpenSSL library-loading functions do not expect to be called
multiple times. Add a flag in the non-threaded libgit2 init so we only
call once.

This fixes #2446.
2014-06-30 09:29:54 +02:00
Vicent Marti
e93206e0f5 Merge pull request #2421 from libgit2/cmn/init-ssl-once
netops: init OpenSSL once under lock
2014-06-14 12:58:03 +02:00
Carlos Martín Nieto
081e76bac2 ssl: init everything all the time
Bring together all of the OpenSSL initialization to
git_threads_init() so it's together and doesn't need locks.

Moving it here also gives us libssh2 thread safety (when built against
openssl).
2014-06-12 16:58:25 +02:00
Carlos Martín Nieto
8f897b6f2f ssl: init also without threads 2014-06-12 14:50:08 +02:00
Carlos Martín Nieto
cf15ac8aa9 ssl: cargo-cult thread safety
OpenSSL's tests init everything in the main thread, so let's do that.
2014-06-12 14:37:03 +02:00
Carlos Martín Nieto
1d3364ac9d netops: init OpenSSL once under lock
The OpenSSL init functions are not reentrant, which means that running
multiple fetches in parallel can cause us to crash.

Use a mutex to init OpenSSL, and since we're adding this extra checks,
init it only once.
2014-06-11 20:54:42 +02:00
Philip Kelley
fb5917679d Win32: Fix object::cache::threadmania test on x64 2014-06-07 12:51:48 -04:00
Vicent Marti
138af33717 Merge pull request #2303 from jacquesg/mingw-lseek
WIP: Windows fixes
2014-05-19 12:20:31 +02:00
Anurag Gupta
0bf5430dc7 Fix the issues in git_shutdown
1) Call to git_shutdown results in setting git__n_shutdown_callbacks
to -1. Next call to git__on_shutdown results in ABW (Array Bound Write)
for array git__shutdown_callbacks. In the current Implementation,
git_atomic_dec is called git__n_shutdown_callbacks + 1 times. I have
modified it to a for loop so that it is more readable. It would not
set git__n_shutdown_callbacks to a negative number and reset the
elements of git__shutdown_callbacks to NULL.

2) In function git_sysdir_get, shutdown function is registered only if
git_sysdir__dirs_shutdown_set is set to 0. However, after this variable
is set to 1, it is never reset to 0. If git_sysdir_global_init is
called again from synchronized_threads_init it does not register
shutdown function for this subsystem.
2014-05-06 13:41:07 -07:00
Anurag Gupta
001befcdd5 Fix the issues in git__on_shutdown 2014-05-06 12:16:24 -07:00
Jacques Germishuys
6e94a1efbc _InterlockedExchange expects a volatile LONG 2014-05-01 10:49:51 +02:00
Russell Belfer
3816debc13 Fix threading tests when threads disabled 2014-04-17 14:43:46 -07:00
Jacques Germishuys
efaa342cbb Correct C90 warnings 2014-04-11 22:48:42 +02:00
Edward Thomson
83634d38be Move system directory cache out of utils 2014-02-24 17:52:38 -08:00
Ben Straub
2266144897 Don't use git_atomic as an integer 2013-10-04 19:35:32 -07:00
Philip Kelley
cdc95a0d93 Use InterlockedCompareExchange for the lock 2013-10-04 19:34:08 -07:00
Ben Straub
e411b74ebd Posix synchronized init, prototype win32 version 2013-10-04 19:33:48 -07:00
Russell Belfer
a3aa5f4d5d Add simple global shutdown hooks
Increasingly there are a number of components that want to do some
cleanup at global shutdown time (at least if there are not going
to be memory leaks).  This creates a very simple system of shutdown
hooks that will be invoked by git_threads_shutdown.  Right now, the
maximum number of hooks is hardcoded, but since adding a hook is
not a public API, it should be fine and I thought it was better to
start off with really simple code.
2013-09-17 09:31:45 -07:00
Russell Belfer
430953417f Load SRWLock APIs at runtime
This loads SRWLock APIs at runtime and in their absence (i.e. on
Windows before Vista) falls back on a regular CRITICAL_SECTION
that will not permit concurrent readers.
2013-08-26 14:56:31 -07:00
Edward Thomson
0a1c8f55b3 preload configuration paths 2013-07-11 17:17:53 -05:00
Russell Belfer
1a42dd17eb Mutex init can fail
It is obviously quite a serious problem if this happens, but mutex
initialization can fail and we should detect it.  It's a bit like
a memory allocation failure, in that you're probably pretty screwed
if this occurs, but at least we'll catch it.
2013-05-31 14:13:11 -07:00
Russell Belfer
5360786885 Further threading fixes
This builds on the earlier thread safety work to make it so that
setting the odb, index, refdb, or config for a repository is done
in a threadsafe manner with minimized locking time.  This is done
by adding a lock to the repository object and using it to guard
the assignment of the above listed pointers.  The lock is only
held to assign the pointer value.

This also contains some minor fixes to the other work with pack
files to reduce the time that locks are being held to and fix an
apparently memory leak.
2013-04-22 16:52:07 +02:00
Russell Belfer
41954a49c1 Switch search paths to classic delimited strings
This switches the APIs for setting and getting the global/system
search paths from using git_strarray to using a simple string with
GIT_PATH_LIST_SEPARATOR delimited paths, just as the environment
PATH variable would contain.  This makes it simpler to get and set
the value.

I also added code to expand "$PATH" when setting a new value to
embed the old value of the path.  This means that I no longer
require separate actions to PREPEND to the value.
2013-03-18 14:19:35 -07:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
Justin Spahr-Summers
c3320aca76 git__mwindow_mutex needs to be initialized even with pthreads
This could also use PTHREAD_MUTEX_INITIALIZER, but a dynamic initializer seems like a more portable concept, and we won't need another #define on top of git_mutex_init()
2012-12-09 02:22:50 -08:00
Edward Thomson
a8527429dc unload dll / destroy hash ctxs at shutdown 2012-11-13 14:48:10 -06:00
Edward Thomson
7ebefd22e7 move hash library func ptrs to global global 2012-11-13 10:23:05 -06:00
Vicent Marti
93b5fabcc0 threads: Assert that the global state is initialized 2012-10-01 17:59:04 +02:00
Carlos Martín Nieto
8cef828d8d Make the memory-window conrol structures global
Up to now, the idea was that the user would do all the operations for
one repository in the same thread. Thus we could have the
memory-mapped window information thread-local and avoid any locking.

This is not practical in a few environments, such as Apple's GCD which
allocates threads arbitrarily or the .NET CLR, where the OS-level
thread can change at any moment.

Make the control structure global and protect it with a mutex so we
don't depend on the thread currently executing the code.
2012-08-20 12:02:52 +02:00
Russell Belfer
2bc8fa0227 Implement git_pool paged memory allocator
This adds a `git_pool` object that can do simple paged memory
allocation with free for the entire pool at once.  Using this,
you can replace many small allocations with large blocks that
can then cheaply be doled out in small pieces.  This is best
used when you plan to free the small blocks all at once - for
example, if they represent the parsed state from a file or data
stream that are either all kept or all discarded.

There are two real patterns of usage for `git_pools`: either
for "string" allocation, where the item size is a single byte
and you end up just packing the allocations in together, or for
"fixed size" allocation where you are allocating a large object
(e.g. a `git_oid`) and you generally just allocation single
objects that can be tightly packed.  Of course, you can use it
for other things, but those two cases are the easiest.
2012-04-25 10:42:37 -07:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Vicent Marti
a15c550db8 threads: Fix the shared global state with TLS
See `global.c` for a description of what we're doing.

When libgit2 is built with GIT_THREADS support, the threading system
must be explicitly initialized with `git_threads_init()`.
2011-11-16 14:09:44 +01:00