Update Marl to 49602432d

Changes:
    49602432d Add PA and BTI to Marl (#204)
    7f0c24af2 Double the `fiberStackSize` for OSFiber tests (#202)
    f25e48ee3 add explanation of the code (#200)
    5e1b007cc Suppress MemorySanitizer false-positive (#198)
    21e05796c ignore auto generated clion files (#197)
    4c1b662da changed alignemt to alignment (spelling mistake)
    e82d1a7b8 Fix macOS arm64 cross compiling.
    12bbbbe3e examples/fractal.cpp: Fix BMP header writing
    d7a43845f Update README.md
    1fda31658 Implement support for ppc64 ELFv1 (#193)
    938e919f4 Add Apache-2.0 to the list of licenses
    40209e952 Fix extra ';' warning emitted by some compilers
    0182eb968 ConditionVariable::notify_one should notify one waiter

Commands:
    ./third_party/update-marl.sh --squash

Bug: b/140546382
Change-Id: Ie69ca856a3a9d30f4b91304d83d89ea303a95581
diff --git a/third_party/marl/.gitignore b/third_party/marl/.gitignore
index cae5b93..4c7dc22 100644
--- a/third_party/marl/.gitignore
+++ b/third_party/marl/.gitignore
@@ -1,6 +1,8 @@
 /.vs/
 /.vscode/
 /build/
+/cmake-build-*/
 /out/
 bazel-*
-CMakeSettings.json
\ No newline at end of file
+CMakeSettings.json
+/.idea/
diff --git a/third_party/marl/README.md b/third_party/marl/README.md
index 3adaf40..1c1778b 100644
--- a/third_party/marl/README.md
+++ b/third_party/marl/README.md
@@ -8,7 +8,7 @@
 
 Marl uses a combination of fibers and threads to allow efficient execution of tasks that can block, while keeping a fixed number of hardware threads.
 
-Marl supports Windows, macOS, Linux, FreeBSD, Fuchsia, Android and iOS (arm, aarch64, mips64, ppc64 (ELFv2), x86 and x64).
+Marl supports Windows, macOS, Linux, FreeBSD, Fuchsia, Android and iOS (arm, aarch64, mips64, ppc64, x86 and x64).
 
 Marl has no dependencies on other libraries (with an exception on googletest for building the optional unit tests).
 
diff --git a/third_party/marl/examples/fractal.cpp b/third_party/marl/examples/fractal.cpp
index b741f44..b95a49e 100644
--- a/third_party/marl/examples/fractal.cpp
+++ b/third_party/marl/examples/fractal.cpp
@@ -91,9 +91,11 @@
   defer(fclose(file));
 
   bool ok = true;
-  auto put4 = [&](uint32_t val) { ok = ok && fwrite(&val, 1, 4, file) == 4; };
-  auto put2 = [&](uint16_t val) { ok = ok && fwrite(&val, 1, 2, file) == 2; };
   auto put1 = [&](uint8_t val) { ok = ok && fwrite(&val, 1, 1, file) == 1; };
+  auto put2 = [&](uint16_t val) { put1(static_cast<uint8_t>(val));
+				  put1(static_cast<uint8_t>(val >> 8)); };
+  auto put4 = [&](uint32_t val) { put2(static_cast<uint16_t>(val));
+				  put2(static_cast<uint16_t>(val >> 16)); };
 
   const uint32_t padding = -(3 * width) & 3U;   // in bytes
   const uint32_t stride = 3 * width + padding;  // in bytes
@@ -102,8 +104,8 @@
   // Bitmap file header
   put1('B');  // header field
   put1('M');
-  put4(offset + stride * height * 3);  // size in bytes
-  put4(0);                             // reserved
+  put4(offset + stride * height);  // size in bytes
+  put4(0);                         // reserved
   put4(offset);
 
   // BITMAPINFOHEADER
diff --git a/third_party/marl/include/marl/conditionvariable.h b/third_party/marl/include/marl/conditionvariable.h
index 4788363..bafb37e 100644
--- a/third_party/marl/include/marl/conditionvariable.h
+++ b/third_party/marl/include/marl/conditionvariable.h
@@ -95,6 +95,7 @@
     marl::lock lock(mutex);
     if (waiting.size() > 0) {
       (*waiting.begin())->notify();  // Only wake one fiber.
+      return;
     }
   }
   if (numWaitingOnCondition > 0) {
diff --git a/third_party/marl/include/marl/memory.h b/third_party/marl/include/marl/memory.h
index d80e592..d645ccb 100644
--- a/third_party/marl/include/marl/memory.h
+++ b/third_party/marl/include/marl/memory.h
@@ -131,18 +131,18 @@
   inline void destroy(T* object);
 
   // make_unique() returns a new object allocated from the allocator wrapped
-  // in a unique_ptr that respects the alignemnt of the type.
+  // in a unique_ptr that respects the alignment of the type.
   template <typename T, typename... ARGS>
   inline unique_ptr<T> make_unique(ARGS&&... args);
 
   // make_unique_n() returns an array of n new objects allocated from the
-  // allocator wrapped in a unique_ptr that respects the alignemnt of the
+  // allocator wrapped in a unique_ptr that respects the alignment of the
   // type.
   template <typename T, typename... ARGS>
   inline unique_ptr<T> make_unique_n(size_t n, ARGS&&... args);
 
   // make_shared() returns a new object allocated from the allocator
-  // wrapped in a std::shared_ptr that respects the alignemnt of the type.
+  // wrapped in a std::shared_ptr that respects the alignment of the type.
   template <typename T, typename... ARGS>
   inline std::shared_ptr<T> make_shared(ARGS&&... args);
 
diff --git a/third_party/marl/license-checker.cfg b/third_party/marl/license-checker.cfg
index f72c6df..e46ec1b 100644
--- a/third_party/marl/license-checker.cfg
+++ b/third_party/marl/license-checker.cfg
@@ -1,5 +1,6 @@
 {
     "licenses": [
+        "Apache-2.0",
         "Apache-2.0-Header"
     ],
     "paths": [
diff --git a/third_party/marl/src/osfiber_asm_aarch64.S b/third_party/marl/src/osfiber_asm_aarch64.S
index 04db6de..b689f80 100644
--- a/third_party/marl/src/osfiber_asm_aarch64.S
+++ b/third_party/marl/src/osfiber_asm_aarch64.S
@@ -17,6 +17,48 @@
 #define MARL_BUILD_ASM 1
 #include "osfiber_asm_aarch64.h"
 
+
+#if defined(__ARM_FEATURE_PAC_DEFAULT) && __ARM_FEATURE_PAC_DEFAULT
+// ENABLE_PAUTH must be defined to 1 since this value will be used in
+// bitwise-shift later!
+#define ENABLE_PAUTH 1
+
+#if ((__ARM_FEATURE_PAC_DEFAULT & ((1 << 0) | (1 << 1))) == 0)
+#error Pointer authentication defines no valid key!
+#endif
+#else
+#define ENABLE_PAUTH 0
+#endif
+
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+// ENABLE_BTI must be defined to 1 since this value will be used in
+// bitwise-shift later!
+#define ENABLE_BTI 1
+#else
+#define ENABLE_BTI 0
+#endif
+
+// Although Pointer Authentication and Branch Target Instructions are
+// technically seperate features they work together, i.e. the paciasp and
+// pacibsp instructions serve as BTI landing pads. Therefore PA-instructions are
+// enabled when PA _or_ BTI is enabled!
+#if ENABLE_PAUTH || ENABLE_BTI
+// See section "Pointer Authentication" of
+// https://developer.arm.com/documentation/101028/0012/5--Feature-test-macros
+// for details how to interpret __ARM_FEATURE_PAC_DEFAULT
+#if (__ARM_FEATURE_PAC_DEFAULT & (1 << 0))
+#define PAUTH_SIGN_SP paciasp
+#define PAUTH_AUTH_SP autiasp
+#else
+#define PAUTH_SIGN_SP pacibsp
+#define PAUTH_AUTH_SP autibsp
+#endif
+#else
+#define PAUTH_SIGN_SP
+#define PAUTH_AUTH_SP
+#endif
+
+
 // void marl_fiber_swap(marl_fiber_context* from, const marl_fiber_context* to)
 // x0: from
 // x1: to
@@ -28,6 +70,8 @@
     // Save context 'from'
     // TODO: pairs of str can be combined with stp.
 
+    PAUTH_SIGN_SP
+
     // Store special purpose registers
     str x16, [x0, #MARL_REG_r16]
     str x17, [x0, #MARL_REG_r17]
@@ -99,6 +143,24 @@
     ldr x2,  [x7, #MARL_REG_SP]
     mov sp, x2
 
+    PAUTH_AUTH_SP
+
     ret
 
+#if ENABLE_PAUTH || ENABLE_BTI
+// see
+// https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#program-property
+.pushsection .note.gnu.property, "a";
+    .balign 8
+    .long 4
+    .long 0x10
+    .long 0x5
+    .asciz "GNU"
+    .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
+    .long 4
+    .long ((ENABLE_PAUTH)<<1) | ((ENABLE_BTI)<<0) /* PAuth and BTI */
+    .long 0
+.popsection
+#endif
+
 #endif // defined(__aarch64__)
diff --git a/third_party/marl/src/osfiber_asm_ppc64.S b/third_party/marl/src/osfiber_asm_ppc64.S
index afc143d..6c0ba5a 100644
--- a/third_party/marl/src/osfiber_asm_ppc64.S
+++ b/third_party/marl/src/osfiber_asm_ppc64.S
@@ -23,8 +23,20 @@
 .text
 .global marl_fiber_swap
 .align 4
+#if !defined(_CALL_ELF) || (_CALL_ELF != 2)
+.global .marl_fiber_swap
+.pushsection ".opd","aw"
+marl_fiber_swap:
+.quad .marl_fiber_swap
+.quad .TOC.@tocbase
+.quad 0
+.popsection
+.type .marl_fiber_swap,@function
+.marl_fiber_swap:
+#else
 .type marl_fiber_swap @function
 marl_fiber_swap:
+#endif
 
     // Store non-volatile registers
     std 1, MARL_REG_R1(3)
diff --git a/third_party/marl/src/osfiber_asm_ppc64.h b/third_party/marl/src/osfiber_asm_ppc64.h
index 402bece..f4d20a9 100644
--- a/third_party/marl/src/osfiber_asm_ppc64.h
+++ b/third_party/marl/src/osfiber_asm_ppc64.h
@@ -123,11 +123,6 @@
   uintptr_t vmx[12 * 2];
 };
 
-// Only the ELFv2 ABI is supported for now.
-#if !defined(_CALL_ELF) || (_CALL_ELF != 2)
-#error "Only the ppc64 ELFv2 ABI is supported."
-#endif
-
 #ifdef __cplusplus
 #include <cstddef>
 static_assert(offsetof(marl_fiber_context, r1) == MARL_REG_R1,
diff --git a/third_party/marl/src/osfiber_ppc64.c b/third_party/marl/src/osfiber_ppc64.c
index c325d7d..48c4d9a 100644
--- a/third_party/marl/src/osfiber_ppc64.c
+++ b/third_party/marl/src/osfiber_ppc64.c
@@ -29,19 +29,29 @@
                            uint32_t stack_size,
                            void (*target)(void*),
                            void* arg) {
-  uintptr_t stack_top = (uintptr_t)((uint8_t*)(stack) + stack_size);
+  uintptr_t stack_top = (uintptr_t)((uint8_t*)(stack) + stack_size - sizeof(uintptr_t));
   if ((stack_top % 16) != 0) {
     stack_top -= (stack_top % 16);
   }
 
-  // Write a backchain and subtract a minimum stack frame size (32)
+  // Write a backchain and subtract a minimum stack frame size (32/48)
   *(uintptr_t*)stack_top = 0;
+#if !defined(_CALL_ELF) || (_CALL_ELF != 2)
+  stack_top -= 48;
+  *(uintptr_t*)stack_top = stack_top + 48;
+#else
   stack_top -= 32;
   *(uintptr_t*)stack_top = stack_top + 32;
+#endif
 
   // Load registers
   ctx->r1 = stack_top;
+#if !defined(_CALL_ELF) || (_CALL_ELF != 2)
+  ctx->lr = ((const uintptr_t *)marl_fiber_trampoline)[0];
+  ctx->r2 = ((const uintptr_t *)marl_fiber_trampoline)[1];
+#else
   ctx->lr = (uintptr_t)marl_fiber_trampoline;
+#endif
   ctx->r3 = (uintptr_t)target;
   ctx->r4 = (uintptr_t)arg;
 
diff --git a/third_party/marl/src/osfiber_test.cpp b/third_party/marl/src/osfiber_test.cpp
index d31b3a8..4b881ed 100644
--- a/third_party/marl/src/osfiber_test.cpp
+++ b/third_party/marl/src/osfiber_test.cpp
@@ -18,7 +18,10 @@
 
 namespace {
 
-auto constexpr fiberStackSize = 8 * 1024;
+// A custom, small stack size for the fibers in these tests.
+// Note: Stack sizes less than 16KB may cause issues on some platforms.
+// See: https://github.com/google/marl/issues/201
+constexpr size_t fiberStackSize = 16 * 1024;
 
 }  // anonymous namespace
 
diff --git a/third_party/marl/src/osfiber_x64.c b/third_party/marl/src/osfiber_x64.c
index 0533076..3cc09c1 100644
--- a/third_party/marl/src/osfiber_x64.c
+++ b/third_party/marl/src/osfiber_x64.c
@@ -18,6 +18,8 @@
 
 #include "marl/export.h"
 
+//You can find an explanation of this code here: https://github.com/google/marl/issues/199
+
 MARL_EXPORT
 void marl_fiber_trampoline(void (*target)(void*), void* arg) {
   target(arg);