<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/libgit2.git/src/global.c, branch ethomson/test_https</title>
<subtitle>github.com: libgit2/libgit2.git
</subtitle>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/'/>
<entry>
<title>Rename global.c to libgit2.c</title>
<updated>2020-10-11T19:13:06+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-07-11T11:25:51+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=1ec4702a51b1074fb7109a841dc95a192feb8525'/>
<id>1ec4702a51b1074fb7109a841dc95a192feb8525</id>
<content type='text'>
Now that we've identified that our global settings really aren't global
at all, and refactored the library to match that, change global.c to
libgit2.c, which is especially nice since the prefix of the functions
matches the filename.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Now that we've identified that our global settings really aren't global
at all, and refactored the library to match that, change global.c to
libgit2.c, which is especially nice since the prefix of the functions
matches the filename.
</pre>
</div>
</content>
</entry>
<entry>
<title>runtime: move init/shutdown into the "runtime"</title>
<updated>2020-10-11T19:13:04+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-05-15T10:47:09+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=e316b0d3d64eb8f65f4109c1565d929b29e1d33a'/>
<id>e316b0d3d64eb8f65f4109c1565d929b29e1d33a</id>
<content type='text'>
Provide a mechanism for system components to register for initialization
and shutdown of the libgit2 runtime.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Provide a mechanism for system components to register for initialization
and shutdown of the libgit2 runtime.
</pre>
</div>
</content>
</entry>
<entry>
<title>global: separate global state from thread-local state</title>
<updated>2020-10-11T19:06:15+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-05-14T09:36:35+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=4853d94ca47a6f1ecaa7c24b9034ededcb7e5bff'/>
<id>4853d94ca47a6f1ecaa7c24b9034ededcb7e5bff</id>
<content type='text'>
Our "global initialization" has accumulated some debris over the years.
It was previously responsible for both running the various global
initializers (that set up various subsystems) _and_ setting up the
"global state", which is actually the thread-local state for things
like error reporting.

Separate the thread local state out into "threadstate".  Use the normal
subsystem initialization functions that we already have to set it up.
This makes both the global initialization system and the threadstate
system simpler to reason about.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Our "global initialization" has accumulated some debris over the years.
It was previously responsible for both running the various global
initializers (that set up various subsystems) _and_ setting up the
"global state", which is actually the thread-local state for things
like error reporting.

Separate the thread local state out into "threadstate".  Use the normal
subsystem initialization functions that we already have to set it up.
This makes both the global initialization system and the threadstate
system simpler to reason about.
</pre>
</div>
</content>
</entry>
<entry>
<title>global init: check error message buffer allocation</title>
<updated>2020-10-11T13:43:37+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-07-11T11:14:26+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=bc3919abc716088cf7c33bc08d48ee2bc434c398'/>
<id>bc3919abc716088cf7c33bc08d48ee2bc434c398</id>
<content type='text'>
Ensure that we can allocate the error message buffer.  In keeping with
our typical policiess, we allow (small) memory leaks in the case where
we're out of memory.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Ensure that we can allocate the error message buffer.  In keeping with
our typical policiess, we allow (small) memory leaks in the case where
we're out of memory.
</pre>
</div>
</content>
</entry>
<entry>
<title>mwindow: localize mutex</title>
<updated>2020-10-11T13:43:37+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-05-13T09:48:13+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=8aa69f887afaced1389d1ae965d5f313b10da66b'/>
<id>8aa69f887afaced1389d1ae965d5f313b10da66b</id>
<content type='text'>
Move the mwindow mutex into the mwindow code itself, initializing it in
the mwindow global initialization function instead of in the global
initializer.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Move the mwindow mutex into the mwindow code itself, initializing it in
the mwindow global initialization function instead of in the global
initializer.
</pre>
</div>
</content>
</entry>
<entry>
<title>settings: localize global data</title>
<updated>2020-10-11T13:43:35+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-05-13T09:39:33+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=6554b40e42df831d7fc9c623d34b2738227dd8a2'/>
<id>6554b40e42df831d7fc9c623d34b2738227dd8a2</id>
<content type='text'>
Move the settings global data teardown into its own separate function,
instead of intermingled with the global state.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Move the settings global data teardown into its own separate function,
instead of intermingled with the global state.
</pre>
</div>
</content>
</entry>
<entry>
<title>win32: teach the allocator to deal with crtdbg</title>
<updated>2020-10-11T13:42:19+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-05-12T12:21:26+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=521aa8c1c04c25a57b82e1279a4e91d8a07436aa'/>
<id>521aa8c1c04c25a57b82e1279a4e91d8a07436aa</id>
<content type='text'>
Move the MSVC C runtime debugging bits into the allocator's global init
function.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Move the MSVC C runtime debugging bits into the allocator's global init
function.
</pre>
</div>
</content>
</entry>
<entry>
<title>init: move thread init to git_global_threads_init</title>
<updated>2020-10-11T13:42:19+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2020-05-12T12:08:22+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=fe12423a91015e6116773340a8936fece3251339'/>
<id>fe12423a91015e6116773340a8936fece3251339</id>
<content type='text'>
Instead of treating win32 thread initialization specially in the win32
git_libgit2_init function, add a git_global_threads_init function.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Instead of treating win32 thread initialization specially in the win32
git_libgit2_init function, add a git_global_threads_init function.
</pre>
</div>
</content>
</entry>
<entry>
<title>Avoid using atomics in pool.c</title>
<updated>2020-10-08T12:31:30+00:00</updated>
<author>
<name>lhchavez</name>
<email>lhchavez@lhchavez.com</email>
</author>
<published>2020-08-25T13:13:38+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=03c0938f5b389ef33946849636510fbc0c4388f4'/>
<id>03c0938f5b389ef33946849636510fbc0c4388f4</id>
<content type='text'>
Instead, globally initialize the system page size.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Instead, globally initialize the system page size.
</pre>
</div>
</content>
</entry>
<entry>
<title>global: convert to fiber-local storage to fix exit races</title>
<updated>2019-11-29T12:08:48+00:00</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2019-11-29T10:06:11+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/libgit2.git/commit/?id=5c6180b5a0e9f9bd1c82938137582720d7a2e6e6'/>
<id>5c6180b5a0e9f9bd1c82938137582720d7a2e6e6</id>
<content type='text'>
On Windows platforms, we automatically clean up the thread-local storage
upon detaching a thread via `DllMain()`. The thing is that this happens
for every thread of applications that link against the libgit2 DLL, even
those that don't have anything to do with libgit2 itself. As a result,
we cannot assume that these unsuspecting threads make use of our
`git_libgit2_init()` and `git_libgit2_shutdow()` reference counting,
which may lead to racy situations:

    Thread 1                    Thread 2

    git_libgit2_shutdown()
                                DllMain(DETACH_THREAD)
                                git__free_tls_data()
    git_atomic_dec() == 0
    git__free_tls_data()
    TlsFree(_tls_index)
                                TlsGetValue(_tls_index)

Due to the second thread never having executed `git_libgit2_init()`, the
first thread will clean up TLS data and as a result also free the
`_tls_index` variable. When detaching the second thread, we
unconditionally access the now-free'd `_tls_index` variable, which is
obviously not going to work out well.

Fix the issue by converting the code to use fiber-local storage instead
of thread-local storage. While FLS will behave the exact same as TLS if
no fibers are in use, it does allow us to specify a destructor similar
to the one that is accepted by pthread_key_create(3P). Like this, we do
not have to manually free indices anymore, but will let the FLS handle
calling the destructor. This allows us to get rid of `DllMain()`
completely, as we only used it to keep track of when threads were
exiting and results in an overall simplification of TLS cleanup.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
On Windows platforms, we automatically clean up the thread-local storage
upon detaching a thread via `DllMain()`. The thing is that this happens
for every thread of applications that link against the libgit2 DLL, even
those that don't have anything to do with libgit2 itself. As a result,
we cannot assume that these unsuspecting threads make use of our
`git_libgit2_init()` and `git_libgit2_shutdow()` reference counting,
which may lead to racy situations:

    Thread 1                    Thread 2

    git_libgit2_shutdown()
                                DllMain(DETACH_THREAD)
                                git__free_tls_data()
    git_atomic_dec() == 0
    git__free_tls_data()
    TlsFree(_tls_index)
                                TlsGetValue(_tls_index)

Due to the second thread never having executed `git_libgit2_init()`, the
first thread will clean up TLS data and as a result also free the
`_tls_index` variable. When detaching the second thread, we
unconditionally access the now-free'd `_tls_index` variable, which is
obviously not going to work out well.

Fix the issue by converting the code to use fiber-local storage instead
of thread-local storage. While FLS will behave the exact same as TLS if
no fibers are in use, it does allow us to specify a destructor similar
to the one that is accepted by pthread_key_create(3P). Like this, we do
not have to manually free indices anymore, but will let the FLS handle
calling the destructor. This allows us to get rid of `DllMain()`
completely, as we only used it to keep track of when threads were
exiting and results in an overall simplification of TLS cleanup.
</pre>
</div>
</content>
</entry>
</feed>
