Bubble android client. Fork of https://git.zx2c4.com/wireguard-android/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

150 rivejä
4.1 KiB

  1. From 6f345a38d9533db388009d91d29981673dcf95b4 Mon Sep 17 00:00:00 2001
  2. From: Jason A. Donenfeld <Jason@zx2c4.com>
  3. Date: Fri, 04 May 2018 03:48:23 +0200
  4. Subject: [PATCH] runtime: use CLOCK_BOOTTIME in nanotime on Linux
  5. This makes timers account for having expired while a computer was
  6. asleep, which is quite common on mobile devices. Note that BOOTTIME is
  7. identical to MONOTONIC, except that it takes into account time spent
  8. in suspend. In Linux 4.17, the kernel will actually make MONOTONIC act
  9. like BOOTTIME anyway, so this switch will additionally unify the
  10. timer behavior across kernels.
  11. BOOTTIME was introduced into Linux 2.6.39-rc1 with 70a08cca1227d in
  12. 2011.
  13. Fixes #24595
  14. Change-Id: I7b2a6ca0c5bc5fce57ec0eeafe7b68270b429321
  15. ---
  16. diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s
  17. index 8d5a4ff..bfad064 100644
  18. --- a/src/runtime/sys_linux_386.s
  19. +++ b/src/runtime/sys_linux_386.s
  20. @@ -285,13 +285,13 @@
  21. LEAL 8(SP), BX // &ts (struct timespec)
  22. MOVL BX, 4(SP)
  23. - MOVL $1, 0(SP) // CLOCK_MONOTONIC
  24. + MOVL $7, 0(SP) // CLOCK_BOOTTIME
  25. CALL AX
  26. JMP finish
  27. fallback:
  28. MOVL $SYS_clock_gettime, AX
  29. - MOVL $1, BX // CLOCK_MONOTONIC
  30. + MOVL $7, BX // CLOCK_BOOTTIME
  31. LEAL 8(SP), CX
  32. INVOKE_SYSCALL
  33. diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s
  34. index 62d8024..8510be4 100644
  35. --- a/src/runtime/sys_linux_amd64.s
  36. +++ b/src/runtime/sys_linux_amd64.s
  37. @@ -257,7 +257,7 @@
  38. MOVQ runtime·vdsoClockgettimeSym(SB), AX
  39. CMPQ AX, $0
  40. JEQ fallback
  41. - MOVL $1, DI // CLOCK_MONOTONIC
  42. + MOVL $7, DI // CLOCK_BOOTTIME
  43. LEAQ 0(SP), SI
  44. CALL AX
  45. MOVQ 0(SP), AX // sec
  46. diff --git a/src/runtime/sys_linux_arm.s b/src/runtime/sys_linux_arm.s
  47. index aa39732..d29cb88 100644
  48. --- a/src/runtime/sys_linux_arm.s
  49. +++ b/src/runtime/sys_linux_arm.s
  50. @@ -11,7 +11,7 @@
  51. #include "textflag.h"
  52. #define CLOCK_REALTIME 0
  53. -#define CLOCK_MONOTONIC 1
  54. +#define CLOCK_BOOTTIME 7
  55. // for EABI, as we don't support OABI
  56. #define SYS_BASE 0x0
  57. @@ -287,7 +287,7 @@
  58. SUB $24, R13 // Space for results
  59. BIC $0x7, R13 // Align for C code
  60. - MOVW $CLOCK_MONOTONIC, R0
  61. + MOVW $CLOCK_BOOTTIME, R0
  62. MOVW $8(R13), R1 // timespec
  63. MOVW runtime·vdsoClockgettimeSym(SB), R11
  64. CMP $0, R11
  65. diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s
  66. index c6afd76..24294e8 100644
  67. --- a/src/runtime/sys_linux_arm64.s
  68. +++ b/src/runtime/sys_linux_arm64.s
  69. @@ -13,7 +13,7 @@
  70. #define AT_FDCWD -100
  71. #define CLOCK_REALTIME 0
  72. -#define CLOCK_MONOTONIC 1
  73. +#define CLOCK_BOOTTIME 7
  74. #define SYS_exit 93
  75. #define SYS_read 63
  76. @@ -243,7 +243,7 @@
  77. BIC $15, R1
  78. MOVD R1, RSP
  79. - MOVW $CLOCK_MONOTONIC, R0
  80. + MOVW $CLOCK_BOOTTIME, R0
  81. MOVD runtime·vdsoClockgettimeSym(SB), R2
  82. CBZ R2, fallback
  83. BL (R2)
  84. diff --git a/src/runtime/sys_linux_mips64x.s b/src/runtime/sys_linux_mips64x.s
  85. index 8e64f1c..521062f 100644
  86. --- a/src/runtime/sys_linux_mips64x.s
  87. +++ b/src/runtime/sys_linux_mips64x.s
  88. @@ -185,7 +185,7 @@
  89. RET
  90. TEXT runtime·nanotime(SB),NOSPLIT,$16
  91. - MOVW $1, R4 // CLOCK_MONOTONIC
  92. + MOVW $7, R4 // CLOCK_BOOTTIME
  93. MOVV $0(R29), R5
  94. MOVV $SYS_clock_gettime, R2
  95. SYSCALL
  96. diff --git a/src/runtime/sys_linux_mipsx.s b/src/runtime/sys_linux_mipsx.s
  97. index a6bca3b..920ed9a 100644
  98. --- a/src/runtime/sys_linux_mipsx.s
  99. +++ b/src/runtime/sys_linux_mipsx.s
  100. @@ -189,7 +189,7 @@
  101. RET
  102. TEXT runtime·nanotime(SB),NOSPLIT,$8-8
  103. - MOVW $1, R4 // CLOCK_MONOTONIC
  104. + MOVW $7, R4 // CLOCK_BOOTTIME
  105. MOVW $4(R29), R5
  106. MOVW $SYS_clock_gettime, R2
  107. SYSCALL
  108. diff --git a/src/runtime/sys_linux_ppc64x.s b/src/runtime/sys_linux_ppc64x.s
  109. index 483cb8e..11f3c49 100644
  110. --- a/src/runtime/sys_linux_ppc64x.s
  111. +++ b/src/runtime/sys_linux_ppc64x.s
  112. @@ -164,7 +164,7 @@
  113. RET
  114. TEXT runtime·nanotime(SB),NOSPLIT,$16
  115. - MOVW $1, R3 // CLOCK_MONOTONIC
  116. + MOVW $7, R3 // CLOCK_BOOTTIME
  117. MOVD $0(R1), R4
  118. SYSCALL $SYS_clock_gettime
  119. MOVD 0(R1), R3 // sec
  120. diff --git a/src/runtime/sys_linux_s390x.s b/src/runtime/sys_linux_s390x.s
  121. index 1ff110c..e9049e0 100644
  122. --- a/src/runtime/sys_linux_s390x.s
  123. +++ b/src/runtime/sys_linux_s390x.s
  124. @@ -176,7 +176,7 @@
  125. RET
  126. TEXT runtime·nanotime(SB),NOSPLIT,$16
  127. - MOVW $1, R2 // CLOCK_MONOTONIC
  128. + MOVW $7, R2 // CLOCK_BOOTTIME
  129. MOVD $tp-16(SP), R3
  130. MOVW $SYS_clock_gettime, R1
  131. SYSCALL