@@ -30,12 +30,15 @@ diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort
3030index 3cfc92533..9c487ac45 100644
3131--- a/memory/mozalloc/mozalloc_abort.cpp
3232+++ b/memory/mozalloc/mozalloc_abort.cpp
33- @@ -9,6 +9,8 @@
33+ @@ -9,6 +9,11 @@
3434
3535 #ifdef ANDROID
3636 # include <android/log.h>
37- + #elif defined(OHOS)
38- + # include <hilog/log.h>
37+ + #elif defined(XP_OHOS)
38+ + extern "C" {
39+ + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
40+ + __attribute__((__format__(os_log, 5, 6)));
41+ + }
3942 #endif
4043 #ifdef MOZ_WIDGET_ANDROID
4144 # include "APKOpen.h"
@@ -46,8 +49,8 @@ index 3cfc92533..9c487ac45 100644
4649- #ifndef ANDROID
4750+ #ifdef ANDROID
4851+ __android_log_print(ANDROID_LOG_ERROR, "Gecko", "mozalloc_abort: %s", msg);
49- + #elif defined(OHOS )
50- + (void) OH_LOG_Print(LOG_APP, LOG_ERROR , 0, "Gecko",
52+ + #elif defined(XP_OHOS )
53+ + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "Gecko",
5154+ "mozalloc_abort: %{public}s\n", msg);
5255+ #else
5356 fputs(msg, stderr);
@@ -61,50 +64,58 @@ diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h
6164index 0b7395177..e84d76aba 100644
6265--- a/mfbt/Assertions.h
6366+++ b/mfbt/Assertions.h
64- @@ -88,6 +88,8 @@ MOZ_END_EXTERN_C
67+ @@ -88,6 +88,11 @@ MOZ_END_EXTERN_C
6568 #endif
6669 #ifdef ANDROID
6770 # include <android/log.h>
68- + #elif defined(OHOS)
69- + # include <hilog/log.h>
71+ + #elif defined(XP_OHOS)
72+ + MOZ_BEGIN_EXTERN_C
73+ + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
74+ + __attribute__((__format__(os_log, 5, 6)));
75+ + MOZ_END_EXTERN_C
7076 #endif
7177
7278 MOZ_BEGIN_EXTERN_C
7379@@ -120,6 +122,10 @@ MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename,
7480 MozWalkTheStackWithWriter(MOZ_ReportAssertionFailurePrintFrame, CallerPC(),
7581 /* aMaxFrames */ 0);
7682 # endif
77- + #elif defined(OHOS )
78- + (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_Assert",
83+ + #elif defined(XP_OHOS )
84+ + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "MOZ_Assert",
7985+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",
8086+ aStr, aFilename, aLine);
8187 #else
8288 # if defined(MOZ_BUFFER_STDERR)
8389 char msg[1024] = "";
84- @@ -144,6 +150,10 @@ MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
90+ @@ -144,8 +150,12 @@ MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
8591 __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH",
8692 "[%d] Hit MOZ_CRASH(%s) at %s:%d\n", MOZ_GET_PID(), aStr,
8793 aFilename, aLine);
88- + #elif defined(OHOS)
89- + (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_CRASH",
90- + "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
91- + aStr, aFilename, aLine);
9294 # if defined(MOZ_DUMP_ASSERTION_STACK)
9395 MozWalkTheStackWithWriter(MOZ_CrashPrintFrame, CallerPC(),
9496 /* aMaxFrames */ 0);
97+ # endif
98+ + #elif defined(XP_OHOS)
99+ + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "MOZ_CRASH",
100+ + "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
101+ + aStr, aFilename, aLine);
102+ #else
95103diff --git a/mfbt/DbgMacro.h b/mfbt/DbgMacro.h
96104index 3247b993c..c7039d5f8 100644
97105--- a/mfbt/DbgMacro.h
98106+++ b/mfbt/DbgMacro.h
99- @@ -18,8 +18,10 @@
107+ @@ -18,8 +18,13 @@
100108 template <typename T>
101109 class nsTSubstring;
102110
103111- #ifdef ANDROID
104112+ #if defined(ANDROID)
105113 # include <android/log.h>
106- + #elif defined(OHOS)
107- + # include <hilog/log.h>
114+ + #elif defined(XP_OHOS)
115+ + MOZ_BEGIN_EXTERN_C
116+ + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
117+ + __attribute__((__format__(os_log, 5, 6)));
118+ + MOZ_END_EXTERN_C
108119 #endif
109120
110121 namespace mozilla {
@@ -115,35 +126,41 @@ index 3247b993c..c7039d5f8 100644
115126- #ifdef ANDROID
116127+ #if defined(ANDROID)
117128 __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", s.str().c_str());
118- + #elif defined(OHOS )
119- + (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", "%{public}s\n", s.str().c_str());
129+ + #elif defined(XP_OHOS )
130+ + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */ , 0, "Gecko", "%{public}s\n", s.str().c_str());
120131 #else
121132 fputs(s.str().c_str(), stderr);
122133 #endif
123134diff --git a/mozglue/misc/Debug.cpp b/mozglue/misc/Debug.cpp
124135index c3a2ca89e..3fea33f4b 100644
125136--- a/mozglue/misc/Debug.cpp
126137+++ b/mozglue/misc/Debug.cpp
127- @@ -18,9 +18,11 @@
138+ @@ -18,9 +18,14 @@
128139
129140 #ifdef ANDROID
130141 # include <android/log.h>
131- + #elif defined(OHOS)
132- + # include <hilog/log.h>
142+ + #elif defined(XP_OHOS)
143+ + extern "C" {
144+ + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
145+ + __attribute__((__format__(os_log, 5, 6)));
146+ + }
133147 #endif
134148
135149- #ifndef ANDROID
136- + #if ! (defined(ANDROID) || defined(OHOS ))
150+ + #if ! (defined(ANDROID) || defined(XP_OHOS ))
137151 static void vprintf_stderr_buffered(const char* aFmt, va_list aArgs) {
138152 // Avoid interleaving by writing to an on-stack buffer and then writing in one
139153 // go with fputs, as long as the output fits into the buffer.
140- @@ -66,6 +68,10 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
154+ @@ -66,6 +68,13 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
141155 MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
142156 __android_log_vprint(ANDROID_LOG_INFO, "Gecko", aFmt, aArgs);
143157 }
144- + #elif defined(OHOS )
158+ + #elif defined(XP_OHOS )
145159+ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
146- + (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", aFmt, aArgs);
160+ + // OH_LOG_VPrint is available with API-level 18 (19?) or higher.
161+ + char buffer[1024];
162+ + VsprintfBuf(buffer, 1024, aFmt, aArgs);
163+ + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", "%{public}s", buffer);
147164+ }
148165 #elif defined(FUZZING_SNAPSHOT)
149166 MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
@@ -153,15 +170,15 @@ index c3a2ca89e..3fea33f4b 100644
153170
154171 MFBT_API void print_stderr(std::stringstream& aStr) {
155172- #if defined(ANDROID)
156- + #if defined(ANDROID) || defined(OHOS )
173+ + #if defined(ANDROID) || defined(XP_OHOS )
157174 // On Android logcat output is truncated to 1024 chars per line, and
158175 // we usually use std::stringstream to build up giant multi-line gobs
159176 // of output. So to avoid the truncation we find the newlines and
160177 // print the lines individually.
161178 std::string line;
162179 while (std::getline(aStr, line)) {
163- + # ifdef OHOS
164- + printf_stderr(" %{public}s\n ", line.c_str());
180+ + # ifdef XP_OHOS
181+ + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", " %{public}s", line.c_str());
165182+ # else
166183 printf_stderr("%s\n", line.c_str());
167184+ # endif
@@ -172,30 +189,31 @@ diff --git a/nsprpub/pr/src/io/prlog.c b/nsprpub/pr/src/io/prlog.c
172189index 52bd6abc5..781402d56 100644
173190--- a/nsprpub/pr/src/io/prlog.c
174191+++ b/nsprpub/pr/src/io/prlog.c
175- @@ -8,8 +8,10 @@
192+ @@ -8,8 +8,11 @@
176193 #include "prenv.h"
177194 #include "prprf.h"
178195 #include <string.h>
179196- #ifdef ANDROID
180197+ #if defined(ANDROID)
181198 # include <android/log.h>
182- + #elif defined(OHOS)
183- + # include <hilog/log.h>
199+ + #elif defined(XP_OHOS)
200+ + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
201+ + __attribute__((__format__(os_log, 5, 6)));
184202 #endif
185203
186204 /*
187205@@ -108,6 +110,19 @@ static void OutputDebugStringA(const char* msg) {
188206 PR_Write(fd, buf, nb); \
189207 } \
190208 PR_END_MACRO
191- + #elif defined(OHOS )
192- + #define _PUT_LOG(fd, buf, nb) \
209+ + #elif defined(XP_OHOS )
210+ + # define _PUT_LOG(fd, buf, nb) \
193211+ PR_BEGIN_MACRO \
194212+ if (fd == _pr_stderr) { \
195213+ char savebyte = buf[nb]; \
196214+ buf[nb] = '\0'; \
197- + (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "PRLog" , \
198- + "%{public}s\n", buf); \
215+ + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */ , \
216+ + 0, "PRLog", "%{public}s\n", buf); \
199217+ buf[nb] = savebyte; \
200218+ } else { \
201219+ PR_Write(fd, buf, nb); \
@@ -208,17 +226,17 @@ index 52bd6abc5..781402d56 100644
208226 PR_LogPrint("Aborting");
209227 #ifdef ANDROID
210228 __android_log_write(ANDROID_LOG_ERROR, "PRLog", "Aborting");
211- + #elif defined(OHOS )
212- + (void) OH_LOG_Print(LOG_APP, LOG_ERROR , 0, "PRLog", "Aborting\n");
229+ + #elif defined(XP_OHOS )
230+ + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "PRLog", "Aborting\n");
213231 #endif
214232 abort();
215233 }
216234@@ -567,6 +584,9 @@ PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
217235 #elif defined(ANDROID)
218236 __android_log_assert(NULL, "PRLog", "Assertion failure: %s, at %s:%d\n", s,
219237 file, ln);
220- + #elif defined(OHOS )
221- + (void) OH_LOG_Print(LOG_APP, LOG_ERROR , 0, "PRLog",
238+ + #elif defined(XP_OHOS )
239+ + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "PRLog",
222240+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",s, file, ln);
223241 #endif
224242 abort();
0 commit comments