Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filelock is not unlocked #42

Closed
wants to merge 852 commits into from
Closed

filelock is not unlocked #42

wants to merge 852 commits into from

Conversation

296995966
Copy link

If the lock is not unlocked, it will be deadlocked

Gregg Lewis Smith and others added 30 commits November 17, 2016 09:34
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1770134 13f79535-47bb-0310-9956-ffa450edef68
Fix build on non-Unix.

This test was never implemented if !APR_HAS_FORK, but the
capability check was error prone. 



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1770138 13f79535-47bb-0310-9956-ffa450edef68
  (APR_SOURCES): Add poll/unix/wakeup.c.

git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1772478 13f79535-47bb-0310-9956-ffa450edef68
poll/unix/wakeup.c
   fix typo

include/apr_cstr.h, strings/apr_cstr.c
   Backport r1767019

apr.dsp, apr.mak, libapr.dsp, libapr.mak, makefile.win, test/makefile.win, 
   Add strings/apr_cstr.c
   Remove Win9x targets




git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1772487 13f79535-47bb-0310-9956-ffa450edef68
proc_mutex_pthread: simplify (shorten) methods' names by removing
the second/double proc_ (consistently with other mechanisms).



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1775072 13f79535-47bb-0310-9956-ffa450edef68
* Optimize apr_file_info_get(APR_FINFO_SIZE) on Windows.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1775154 13f79535-47bb-0310-9956-ffa450edef68
Backport of r1776994 from trunk.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1776995 13f79535-47bb-0310-9956-ffa450edef68
Not all pthread implementations have mutex_timedlock(),
like Solaris 8, so proc_mutex_proc_pthread_timedacquire()
can return APR_ENOTIMPL.

Backport of r1774973 from trunk.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1778111 13f79535-47bb-0310-9956-ffa450edef68
…from

2007.  Assuming FIXED, WONTFIX, or just overtaken by events.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1787592 13f79535-47bb-0310-9956-ffa450edef68
apr_allocator: Provide apr_allocator_align() to get the true size that
would be allocated for the given size (including the header and alignment).


Follow up to r1788334: better apr_allocator_align() description.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1788449 13f79535-47bb-0310-9956-ffa450edef68
Avoid remaking gen_test_char and the library unnecessarily.

Submitted by: trawick


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1788493 13f79535-47bb-0310-9956-ffa450edef68
Follow up to r1788334: apr_allocator_align() should take an allocator as
argument, for better scalability of the API.

Suggested by ivan.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1789951 13f79535-47bb-0310-9956-ffa450edef68
Follow up to r1733694: proc-pthreads have their own child_init() now.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790046 13f79535-47bb-0310-9956-ffa450edef68
Follow up to r1667900: don't fail test{proc,global}mutex if
APR_LOCK_DEFAULT_TIMED is not implemented (e.g. MacOS).


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790047 13f79535-47bb-0310-9956-ffa450edef68
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790104 13f79535-47bb-0310-9956-ffa450edef68
osx/macos that don't have it. Be a bit more generous in the test

git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1790105 13f79535-47bb-0310-9956-ffa450edef68
ylavic and others added 27 commits January 5, 2022 18:58
testatomic: Silence -Wmissing-prototypes warning.

Submitted by: brane


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896728 13f79535-47bb-0310-9956-ffa450edef68
apr_ring: Don't break strict-aliasing rules in APR_RING_SPLICE_{HEAD,TAIL}().

GCC-11 complains (see [1]) about apr_brigade_split_ex() seemingly issuing an
out of bounds access, the cause being that APR_RING_SPLICE_{HEAD,TAIL}() is
dereferencing an APR_RING_SENTINEL() and the cast there in not very aliasing
friendly (see [2] for a great explanation by Martin Sebor).

The APR (and user code) should never dereference APR_RING_SENTINEL(), it's fine
as a pointer only (i.e. for comparing pointers). So this commit modifies the
APR_RING_SPLICE_{HEAD,TAIL}() and APR_RING_{CONCAT,PREPEND}() macros to use the
passed in APR_RING_HEAD's prev/next pointers directly instead of passing the
APR_RING_SENTINEL() to APR_RING_SPLICE_{BEFORE,AFTER}().

Semantically, this also clarifies that APR_RING_{SPLICE,INSERT}_{BEFORE,AFTER}()
should be called for an APR_RING_ENTRY while APR_RING_SPLICE_{HEAD,TAIL}() and
APR_RING_{CONCAT,PREPEND}() are to be called with an APR_RING_HEAD.

[1]
In file included from ./include/apr_mmap.h:28,
                 from ./include/apr_buckets.h:32,
                 from buckets/apr_brigade.c:22:
buckets/apr_brigade.c: In function ‘apr_brigade_split’:
./include/apr_ring.h:177:43: error: array subscript ‘struct apr_bucket[0]’ is partly outside array bounds of ‘unsigned char[32]’ [-Werror=array-bounds]
  177 | #define APR_RING_NEXT(ep, link) (ep)->link.next
      |                                 ~~~~~~~~~~^~~~~
./include/apr_ring.h:247:38: note: in expansion of macro ‘APR_RING_NEXT’
  247 |         APR_RING_NEXT((epN), link) = APR_RING_NEXT((lep), link);        \
      |                                      ^~~~~~~~~~~~~
./include/apr_ring.h:287:9: note: in expansion of macro ‘APR_RING_SPLICE_AFTER’
  287 |         APR_RING_SPLICE_AFTER(APR_RING_SENTINEL((hp), elem, link),      \
      |         ^~~~~~~~~~~~~~~~~~~~~
buckets/apr_brigade.c:118:9: note: in expansion of macro ‘APR_RING_SPLICE_HEAD’
  118 |         APR_RING_SPLICE_HEAD(&a->list, e, f, apr_bucket, link);
      |         ^~~~~~~~~~~~~~~~~~~~
buckets/apr_brigade.c:90:9: note: referencing an object of size 32 allocated by ‘apr_palloc’
   90 |     b = apr_palloc(p, sizeof(*b));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~

[2] https://bugzilla.redhat.com/show_bug.cgi?id=1957353#c2
(Note that the original comment from Martin Sebor talks about the struct
 "_direntry" and the global variable "anchor" which relate to some httpd
 code using an APR_RING in a similar way than apr_bucket_brigade does. So
 below I allowed myself to edit the original comment to replace "_direntry"
 by "apr_bucket" and "anchor" by "list" (the apr_bucket_brigade's member used
 as the head of the ring) to make the link with the above commit message)
"
The message is a bit cryptic but it says that the code accesses an object
(list) of some anonymous type as it was struct apr_bucket.  That's invalid
because objects can only be accessed by lvalues of compatible types (or char).

The APR_RING_ENTRY macro is defined like so:

#define APR_RING_ENTRY(elem)						\
    struct {								\
	struct elem * volatile next;					\
	struct elem * volatile prev;					\
    }

so given the definition:

APR_RING_ENTRY(apr_bucket) list;

list can only be accessed by lvalues of its (anonymous) type but the
APR_RING_SENTINEL() macro defined like so:

#define APR_RING_SENTINEL(hp, elem, link)				\
    (struct elem *)((char *)(&(hp)->next) - APR_OFFSETOF(struct elem, link))

casts the address of list's next member minus some constant to a pointer to
struct apr_bucket and that pointer is then used to access the prev pointer.
The anonymous struct and struct apr_bucket are unrelated and cannot be used
each other's members even if the corresponding members have the same type and
are at the same offset within the bounds of the object.
"


apr_ring: Follow up to r1896535: Use APR_RING_{FIRST,LAST} macros.

hp->{next,prev} are APR_RING_{FIRST,LAST}(hp), so use them to make
APR_RING_SPLICE_{HEAD,TAIL}() read better.


Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896748 13f79535-47bb-0310-9956-ffa450edef68
Fix typo

Submitted by: mturk


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896808 13f79535-47bb-0310-9956-ffa450edef68
Avoids the scenario;
gcc  tools/gen_test_char.c -o tools/gen_test_char
gcc: error: tools/gen_test_char.c: No such file or directory
gcc: fatal error: no input files

Substitute the source tree path to this file rather that the target tree.

Backports: r1896933


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896934 13f79535-47bb-0310-9956-ffa450edef68
apr_sockaddr_ip_getbuf: Follow up to r1883728.

Return APR_ENOSPC if returned buf is truncated for an AF_UNIX.

Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896958 13f79535-47bb-0310-9956-ffa450edef68
apr_atomic_set64: Follow up to r1868129.

Like for apr_atomic_read64() in r1868502, use direct memory write on x86_x64.

Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896960 13f79535-47bb-0310-9956-ffa450edef68
testatomic: Fix gcc-11 warnings.

Not sure why it wants the "a" local variable to point to something since
we only use its pointer, but that's how it is..  While at it let's initialize
"b" too.

Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896962 13f79535-47bb-0310-9956-ffa450edef68
Add GCC 10 build to Travis config.

Since bionic is the default, switch one -Werror build to xenial.



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896966 13f79535-47bb-0310-9956-ffa450edef68
Add Asan builds to travis.

Disable odbc tests with ASan for now, dlclose() leaks memory somehow.

Move misplaced comment.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1896996 13f79535-47bb-0310-9956-ffa450edef68
test: fix memory leaks of the test framework at exit.

To please memory leak analysers..

Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1897005 13f79535-47bb-0310-9956-ffa450edef68
Begin 1.8.x development from here, with no need to roll anything back
from this branch. The 1.7.x branch will need breaking backports all
rolled back.



git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897021 13f79535-47bb-0310-9956-ffa450edef68
…nces.

The new versions [1] compile to a shorter/faster assembly than the previous
ones [2], no functionnal change.

[1] apr_cstr_casecmp() after this commit:
Dump of assembler code for function apr_cstr_casecmp:
   0x0000000000049fc0 <+0>:     movzbl (%rdi),%eax
   0x0000000000049fc3 <+3>:     movzbl (%rsi),%edx
   0x0000000000049fc6 <+6>:     lea    0x3d573(%rip),%r8        # 0x87540 <ucharmap>
   0x0000000000049fcd <+13>:    movzbl (%r8,%rax,1),%eax
   0x0000000000049fd2 <+18>:    movzbl (%r8,%rdx,1),%ecx
   0x0000000000049fd7 <+23>:    cmp    %ecx,%eax
   0x0000000000049fd9 <+25>:    jne    0x49ffe <apr_cstr_casecmp+62>
   0x0000000000049fdb <+27>:    xor    %edx,%edx
   0x0000000000049fdd <+29>:    jmp    0x49ffa <apr_cstr_casecmp+58>
   0x0000000000049fdf <+31>:    nop
   0x0000000000049fe0 <+32>:    add    $0x1,%rdx
   0x0000000000049fe4 <+36>:    movzbl (%rdi,%rdx,1),%eax
   0x0000000000049fe8 <+40>:    movzbl (%rsi,%rdx,1),%ecx
   0x0000000000049fec <+44>:    movzbl (%r8,%rax,1),%eax
   0x0000000000049ff1 <+49>:    movzbl (%r8,%rcx,1),%ecx
   0x0000000000049ff6 <+54>:    cmp    %ecx,%eax
   0x0000000000049ff8 <+56>:    jne    0x49ffe <apr_cstr_casecmp+62>
   0x0000000000049ffa <+58>:    test   %eax,%eax
   0x0000000000049ffc <+60>:    jne    0x49fe0 <apr_cstr_casecmp+32>
   0x0000000000049ffe <+62>:    sub    %ecx,%eax
   0x000000000004a000 <+64>:    ret   
End of assembler dump.

[2] apr_cstr_casecmp() before this commit:
Dump of assembler code for function apr_cstr_casecmp:
   0x000000000004a000 <+0>:     movzbl (%rdi),%eax
   0x000000000004a003 <+3>:     movzbl (%rsi),%edx
   0x000000000004a006 <+6>:     lea    0x3d533(%rip),%r8        # 0x87540 <ucharmap>
   0x000000000004a00d <+13>:    mov    %rdi,%r9
   0x000000000004a010 <+16>:    mov    %rax,%rcx
   0x000000000004a013 <+19>:    movswl (%r8,%rdx,2),%edx
   0x000000000004a018 <+24>:    movswl (%r8,%rax,2),%eax
   0x000000000004a01d <+29>:    sub    %edx,%eax
   0x000000000004a01f <+31>:    jne    0x4a052 <apr_cstr_casecmp+82>
   0x000000000004a021 <+33>:    mov    $0x1,%edx
   0x000000000004a026 <+38>:    test   %ecx,%ecx
   0x000000000004a028 <+40>:    je     0x4a052 <apr_cstr_casecmp+82>
   0x000000000004a02a <+42>:    nopw   0x0(%rax,%rax,1)
   0x000000000004a030 <+48>:    movzbl (%r9,%rdx,1),%eax
   0x000000000004a035 <+53>:    movzbl (%rsi,%rdx,1),%ecx
   0x000000000004a039 <+57>:    add    $0x1,%rdx
   0x000000000004a03d <+61>:    mov    %rax,%rdi
   0x000000000004a040 <+64>:    movswl (%r8,%rcx,2),%ecx
   0x000000000004a045 <+69>:    movswl (%r8,%rax,2),%eax
   0x000000000004a04a <+74>:    sub    %ecx,%eax
   0x000000000004a04c <+76>:    jne    0x4a052 <apr_cstr_casecmp+82>
   0x000000000004a04e <+78>:    test   %edi,%edi
   0x000000000004a050 <+80>:    jne    0x4a030 <apr_cstr_casecmp+48>
   0x000000000004a052 <+82>:    ret   
End of assembler dump.


Merge r1897102 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897103 13f79535-47bb-0310-9956-ffa450edef68
This ones have a shorter prologue and epilogue (-O2 still).

Dump of assembler code for function apr_cstr_casecmp:
   0x0000000000049fd0 <+0>:     xor    %edx,%edx
   0x0000000000049fd2 <+2>:     lea    0x3d567(%rip),%r8        # 0x87540 <ucharmap>
   0x0000000000049fd9 <+9>:     nopl   0x0(%rax)
   0x0000000000049fe0 <+16>:    movzbl (%rsi,%rdx,1),%eax
   0x0000000000049fe4 <+20>:    movzbl (%r8,%rax,1),%ecx
   0x0000000000049fe9 <+25>:    movzbl (%rdi,%rdx,1),%eax
   0x0000000000049fed <+29>:    add    $0x1,%rdx
   0x0000000000049ff1 <+33>:    movzbl (%r8,%rax,1),%eax
   0x0000000000049ff6 <+38>:    sub    %ecx,%eax
   0x0000000000049ff8 <+40>:    jne    0x49ffe <apr_cstr_casecmp+46>
   0x0000000000049ffa <+42>:    test   %ecx,%ecx
   0x0000000000049ffc <+44>:    jne    0x49fe0 <apr_cstr_casecmp+16>
   0x0000000000049ffe <+46>:    ret   
End of assembler dump.

Merge r1897121 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897122 13f79535-47bb-0310-9956-ffa450edef68
…ds too.

r1884078 fixed lifetime issues with detached threads by using unmanaged pool
destroyed by the thread itself on exit, with no binding to the parent pool.

This commit makes use of unmanaged pools for attached threads too, they needed
their own allocator anyway due to apr_thread_detach() being callable anytime
later. apr__pool_unmanage() was a hack to detach a subpool from its parent, but
if a subpool needs its own allocator for this to work correctly there is no
point in creating a subpool for threads (no memory reuse on destroy for short
living threads for instance).

Since an attached thread has its own lifetime now, apr_thread_join() must be
called to free its resources/pool, though it's no different than before when
destroying the parent pool was UB if the thread was still running (i.e.  not
joined yet).

Let's acknoledge that threads want no binding with the pool passed to them at
creation time, besides the abort_fn which they can steal :)


Merge r1897179 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897220 13f79535-47bb-0310-9956-ffa450edef68
apr_thread_create() was allocating the created apr_thread_t on the given pool,
which caused e.g. short-living threads to leak memory on that pool without a
way to clear it (while some threads are still running).

Change this by allocating the apr_thread_t on the thread's pool itself, which
is safe in the implementations of all archs because none uses the apr_thread_t
after the thread exits, and it's safe for the users provided they don't use the
apr_thread_t for detached threads or for attached threads after the call to
apr_thread_join(). These are hardly new requirements though.


apr_thread: Follow up to r1897197: Safer apr_thread_join().

Make sure apr_thread_join() behaves correctly w.r.t. the returned value
and pool destroy for all archs.


Merge r1897197, r1897198 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897221 13f79535-47bb-0310-9956-ffa450edef68
…inter.

All modern compilers provide a Thread Local Storage keyword that allows to
store per-thread data efficiently (C++11 's thread_local, C11's _Thread_local,
gcc/clang's __thread or MSVC's __declspec(thread)).

Use that to have an apr_thread_t pointer associated with each thread created
by apr_thread_create() or any native thread (like the process' initial thread)
that registered itself with the new apr_thread_current_create() function.

This mechanism allows to implement apr_thread_current() quite efficiently, if
available, otherwise the function returns NULL.

If available APR_HAS_THREAD_LOCAL is #define'd to 1 and the APR_THREAD_LOCAL
macro is the keyword usable to register TLS variables natively.
Both APR_HAS_THREAD_LOCAL and APR_THREAD_LOCAL are #undef'ined if the compiler
does not provide the mechanism.
This allows to test for the functionality at compile time.

When APR_HAS_THREAD_LOCAL, the user can load his/her own TLS data with:
    apr_thread_data_get(&my_data, my_key, apr_thread_current());

and store them with:
    apr_thread_data_set(my_data, my_key, my_data_cleanup,
                        apr_thread_current());

which can be nice to avoid the proliferation of native TLS keys.


Merge r1897207 from trunk:
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897223 13f79535-47bb-0310-9956-ffa450edef68
… failure.

Merge r1897419 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897420 13f79535-47bb-0310-9956-ffa450edef68
It's not needed, when the thread exits it's not accessible anyway.


Merge r1897445 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897446 13f79535-47bb-0310-9956-ffa450edef68
.. rather than a defined().


Merge r1897447 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897448 13f79535-47bb-0310-9956-ffa450edef68
…ork().

thread_local variables are not (always?) reset on fork(), so APR (and the
user) needs a way to set the current_thread to NULL.

Use apr_thread_current_after_fork() in apr_proc_fork()'s child process.


Merge r1897470 from trunk.
Submitted by: ylavic
Reviewed by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897471 13f79535-47bb-0310-9956-ffa450edef68
…ort it.

epoll has EPOLLEXCLUSIVE, start with that.


poll: Follow up to r1897521: struct epoll_event's events field is unsigned int.

EPOLLEXCLUSIVE is 1u << 28 so it doesn't fit in an int16_t, use unsigned for
the native epoll events type.


poll: Follow up to r1897521: Clarify what APR_POLLEXCL means.

This is to avoid the thundering herd issue when multiple threads/processes
poll on the same descriptor (usually listening/to-be-accept()ed descriptors).


Merge r1897521, r1897548, r1897549 from trunk.
Submitted by: ylavic
Reviewed by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897550 13f79535-47bb-0310-9956-ffa450edef68
…ation.

Fix compilation of apr_thread_current_create() for OS/2 and Windows.
Set *current to NULL on failure.


Merge r1897879 from trunk.
Submitted by: ylavic


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897880 13f79535-47bb-0310-9956-ffa450edef68
Fix various harmless cases of undefined behaviour, and add a Travis
job testing under UBSan.

* poll/unix/poll.c (apr_poll): For the on-stack array allocation use
  num+1 since allocating a 0-length array is undefined behaviour.

* tables/apr_skiplist.c (get_b_rand): Use unsigned integers to avoid
  signed integer overflow in the left shift.
  (skiplist_qpush): Avoid calling memcpy(,NULL,0).

* random/unix/apr_random.c (apr_random_add_entropy): Avoid calling
  memcpy(,NULL,0).

* test/teststr.c (overflow_strfsize): Avoid signed integer overflow.




git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1898099 13f79535-47bb-0310-9956-ffa450edef68
If the lock is not unlocked, it will be deadlocked
@asfgit asfgit closed this in 96f9855 Mar 13, 2024
@ylavic
Copy link
Member

ylavic commented Mar 13, 2024

Thanks for the patch, now in 96f9855 (https://svn.apache.org/repos/asf/apr/apr/trunk@1916276)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants