1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "napi/native_api.h"
17 #include <cerrno>
18 #include <cstdio>
19 #include <cstdlib>
20 #include <ctime>
21 #include <dlfcn.h>
22 #include <fcntl.h>
23 #include <fnmatch.h>
24 #include <js_native_api_types.h>
25 #include <netinet/in.h>
26 #include <poll.h>
27 #include <pthread.h>
28 #include <semaphore.h>
29 #include <sys/resource.h>
30 #include <sys/sem.h>
31 #include <sys/socket.h>
32 #include <sys/stat.h>
33 #include <sys/timerfd.h>
34 #include <sys/timex.h>
35 #include <sys/wait.h>
36 #include <threads.h>
37 #include <unistd.h>
38 #include <utime.h>
39 #include <securec.h>
40
41 #define PARAM_5 5
42 #define PARAM_0 0
43 #define PARAM_1 1
44 #define PARAM_UNNORMAL (-1)
45 #define PARAM_1999 1999
46 #define PARAM_12 12
47 #define PARAM_17 17
48 #define PARAM_06 06
49 #define PARAM_30 30
50 #define PARAM_23 23
51 #define PARAM_1900 1900
52 #define PARAM_02 02
53 #define PARAM_07 07
54 #define PARAM_16 16
55 #define PARAM_15 15
56 #define PARAM_20 20
57 #define SUCCESS 1
58 #define SIZE_64 64
59 #define SIZE_10 10
60 #define SEC_TIME 123840
61 #define FAIL (-1)
62 #define MPARAM_1 (-1)
63 #define TEST_SIZE 2
64 #define MICROSECONDS (1000000)
65 #define TEST_FILE "/data/storage/el2/base/files/test.txt"
66 #define PARAM_0777 0777
67 #define PATH "/data/storage/el2/base/files/utime64.txt"
68 #define TEST_FILE_NAME "test.txt"
69 #define TEST_FILE_PATH "/data/storage/el2/base/files/"
70 #define PARAM_0666 0666
71
FnMatch(napi_env env, napi_callback_info info)72 static napi_value FnMatch(napi_env env, napi_callback_info info)
73 {
74 char firstStr[] = "video_???_test.txt";
75 char secondStr[] = "video_010_test.txt";
76 int backParam = fnmatch(firstStr, secondStr, FNM_NOESCAPE);
77 napi_value result = nullptr;
78 napi_create_int32(env, backParam, &result);
79 return result;
80 }
81
82 extern "C" int __clock_gettime64(clockid_t, struct timespec *);
clock_getTime64(napi_env env, napi_callback_info info)83 static napi_value clock_getTime64(napi_env env, napi_callback_info info)
84 {
85 int returnParam = PARAM_1;
86 struct timespec timeSpec {};
87 returnParam = __clock_gettime64(CLOCK_REALTIME, &timeSpec);
88 napi_value result = nullptr;
89 napi_create_int32(env, returnParam, &result);
90 return result;
91 }
92
93 extern "C" int __pthread_cond_timedwait_time64(pthread_cond_t *__restrict, pthread_mutex_t *__restrict,
94 const struct timespec *__restrict);
PThread_cond_timedWait_time64(napi_env env, napi_callback_info info)95 static napi_value PThread_cond_timedWait_time64(napi_env env, napi_callback_info info)
96 {
97 int returnParam = PARAM_1;
98 pthread_cond_t pCond = PTHREAD_COND_INITIALIZER;
99 pthread_mutex_t pMutex = PTHREAD_MUTEX_INITIALIZER;
100 const struct timespec timeSpec {};
101 returnParam = __pthread_cond_timedwait_time64(&pCond, &pMutex, &timeSpec);
102 napi_value result = nullptr;
103 napi_create_int32(env, returnParam, &result);
104 return result;
105 }
106
107 extern "C" int __nanosleep_time64(const struct timespec *, struct timespec *);
NanoSleep_time64(napi_env env, napi_callback_info info)108 static napi_value NanoSleep_time64(napi_env env, napi_callback_info info)
109 {
110 int returnParam = PARAM_1;
111 struct timespec timeSpec {
112 PARAM_0, PARAM_0
113 };
114 timeSpec.tv_sec = PARAM_5;
115 timeSpec.tv_nsec = PARAM_0;
116 returnParam = __nanosleep_time64(&timeSpec, &timeSpec);
117 napi_value result = nullptr;
118 napi_create_int32(env, returnParam, &result);
119 return result;
120 }
121
122 extern "C" int __fstat_time64(int, struct stat *);
FStat_time64(napi_env env, napi_callback_info info)123 static napi_value FStat_time64(napi_env env, napi_callback_info info)
124 {
125 int returnParam = PARAM_1;
126 int fileDescribe = open("/data/storage/el2/base/files/Fzl.txt", O_CREAT);
127 struct stat stat {};
128 returnParam = __fstat_time64(fileDescribe, &stat);
129 napi_value result = nullptr;
130 close(fileDescribe);
131 napi_create_int32(env, returnParam, &result);
132 return result;
133 }
134
135 extern "C" int __lstat_time64(const char *__restrict, struct stat *__restrict);
LStat_time64(napi_env env, napi_callback_info info)136 static napi_value LStat_time64(napi_env env, napi_callback_info info)
137 {
138 int returnParam = PARAM_1;
139 const char *test = "/data/storage/el2/base/files/Fzl.txt";
140 struct stat stat {};
141 returnParam = __lstat_time64(test, &stat);
142 napi_value result = nullptr;
143 napi_create_int32(env, returnParam, &result);
144 return result;
145 }
146
147 extern "C" int __stat_time64(const char *__restrict, struct stat *__restrict);
Stat_time64(napi_env env, napi_callback_info info)148 static napi_value Stat_time64(napi_env env, napi_callback_info info)
149 {
150 int returnParam = PARAM_1;
151 const char *firstParam = "/data/storage/el2/base/files/Fzl.txt";
152 struct stat stat {};
153 returnParam = __stat_time64(firstParam, &stat);
154 napi_value result = nullptr;
155 napi_create_int32(env, returnParam, &result);
156 return result;
157 }
158
159 extern "C" int __utimensat_time64(int, const char *, const struct timespec[2], int);
UTimeNsAt_time64(napi_env env, napi_callback_info info)160 static napi_value UTimeNsAt_time64(napi_env env, napi_callback_info info)
161 {
162 size_t argc = PARAM_1;
163 napi_value args[1] = {nullptr};
164 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
165 int toCppResult = FAIL;
166 size_t length = SIZE_64, stresult = PARAM_0;
167 char path[SIZE_64] = {PARAM_0};
168 napi_get_value_string_utf8(env, args[0], path, length, &stresult);
169 int fileDescribe = open(path, O_CREAT);
170 const long sec = SEC_TIME;
171 struct timespec times[] = {{.tv_sec = PARAM_0}, {.tv_sec = sec}};
172 int utimensatValue = __utimensat_time64(fileDescribe, path, times, PARAM_0);
173 close(fileDescribe);
174 struct stat statbuf = {PARAM_0};
175 utimensatValue = stat(path, &statbuf);
176 if (utimensatValue == PARAM_0 && statbuf.st_mtim.tv_sec == sec) {
177 toCppResult = SUCCESS;
178 }
179 remove(path);
180 napi_value result = nullptr;
181 napi_create_int32(env, toCppResult, &result);
182 return result;
183 }
184
185 extern "C" int __clock_getres_time64(clockid_t, struct timespec *);
Clock_getRes_time64(napi_env env, napi_callback_info info)186 static napi_value Clock_getRes_time64(napi_env env, napi_callback_info info)
187 {
188 int returnParam = PARAM_1;
189 clockid_t firstParam = PARAM_1;
190 struct timespec secondParam {};
191 returnParam = __clock_getres_time64(firstParam, &secondParam);
192 napi_value result = nullptr;
193 napi_create_int32(env, returnParam, &result);
194 return result;
195 }
196
197 extern "C" int __clock_nanosleep_time64(clockid_t, int, const struct timespec *, struct timespec *);
Clock_nanoSleep_time64(napi_env env, napi_callback_info info)198 static napi_value Clock_nanoSleep_time64(napi_env env, napi_callback_info info)
199 {
200 int returnParam = PARAM_1, secondParam = PARAM_1;
201 clockid_t firstParam = PARAM_1;
202 const struct timespec thirdParam {};
203 struct timespec fourthParam {};
204 returnParam = __clock_nanosleep_time64(firstParam, secondParam, &thirdParam, &fourthParam);
205 napi_value result = nullptr;
206 napi_create_int32(env, returnParam, &result);
207 return result;
208 }
209
210 extern "C" int __clock_settime64(clockid_t, const struct timespec *);
Clock_setTime64(napi_env env, napi_callback_info info)211 static napi_value Clock_setTime64(napi_env env, napi_callback_info info)
212 {
213 int returnParam = PARAM_1;
214 struct timespec firstParam {};
215 clock_gettime(CLOCK_REALTIME, &firstParam);
216 returnParam = __clock_settime64(CLOCK_REALTIME, &firstParam);
217 napi_value result = nullptr;
218 napi_create_int32(env, returnParam, &result);
219 return result;
220 }
221
222 extern "C" int __cnd_timedwait_time64(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict);
Cnd_timedWait_time64(napi_env env, napi_callback_info info)223 static napi_value Cnd_timedWait_time64(napi_env env, napi_callback_info info)
224 {
225 int returnParam = PARAM_1;
226 cnd_t firstParam;
227 mtx_t secondParam;
228 cnd_init(&firstParam);
229 mtx_lock(&secondParam);
230 struct timespec thirdParam {};
231 returnParam = __cnd_timedwait_time64(&firstParam, &secondParam, &thirdParam);
232 napi_value result = nullptr;
233 napi_create_int32(env, returnParam, &result);
234 return result;
235 }
236
237 extern "C" char *__ctime64(const time_t *);
CTime64(napi_env env, napi_callback_info info)238 static napi_value CTime64(napi_env env, napi_callback_info info)
239 {
240 char *checkParam = nullptr;
241 int returnParam = PARAM_1;
242 const time_t time = PARAM_0;
243 checkParam = __ctime64(&time);
244 if (checkParam != nullptr) {
245 returnParam = PARAM_0;
246 }
247 napi_value result = nullptr;
248 napi_create_int32(env, returnParam, &result);
249 return result;
250 }
251
252 extern "C" char *__ctime64_r(const time_t *, char *);
CTime64_r(napi_env env, napi_callback_info info)253 static napi_value CTime64_r(napi_env env, napi_callback_info info)
254 {
255 char *checkParam = nullptr;
256 int returnParam = PARAM_1;
257 const time_t time = PARAM_0;
258 char secondParam[32];
259 checkParam = __ctime64_r(&time, secondParam);
260 if (checkParam != nullptr) {
261 returnParam = PARAM_0;
262 }
263 napi_value result = nullptr;
264 napi_create_int32(env, returnParam, &result);
265 return result;
266 }
267
268 extern "C" double __difftime64(time_t, time_t);
DiffTime64(napi_env env, napi_callback_info info)269 static napi_value DiffTime64(napi_env env, napi_callback_info info)
270 {
271 double checkParam;
272 int returnParam = PARAM_1;
273 time_t now;
274 struct tm newyear;
275 time(&now);
276 newyear = *localtime(&now);
277 newyear.tm_hour = PARAM_0;
278 newyear.tm_min = PARAM_0;
279 newyear.tm_sec = PARAM_0;
280 newyear.tm_mon = PARAM_0;
281 newyear.tm_mday = PARAM_1;
282 time_t firstTime = PARAM_1999 - PARAM_12 - PARAM_17 - PARAM_06 - PARAM_30 - PARAM_23;
283 time_t secondTime = PARAM_1900 - PARAM_02 - PARAM_07 - PARAM_16 - PARAM_15 - PARAM_20;
284 checkParam = __difftime64(firstTime, secondTime);
285 if (checkParam) {
286 returnParam = PARAM_0;
287 }
288 napi_value result = nullptr;
289 napi_create_double(env, returnParam, &result);
290 return result;
291 }
292
293 extern "C" void *__dlsym_time64(void *__restrict, const char *__restrict);
DlSym_time64(napi_env env, napi_callback_info info)294 static napi_value DlSym_time64(napi_env env, napi_callback_info info)
295 {
296 const char *path = "/system/lib/extensionability/libstatic_subscriber_extension_module.z.so";
297 void *ptr = dlopen(path, RTLD_LAZY);
298 errno = PARAM_0;
299 __dlsym_time64(ptr, "OHOS_EXTENSION_GetExtensionModule");
300 napi_value result = nullptr;
301 napi_create_int32(env, errno, &result);
302 return result;
303 }
304
305 extern "C" int __futimens_time64(int, const struct timespec[2]);
FuTimeNs_time64(napi_env env, napi_callback_info info)306 static napi_value FuTimeNs_time64(napi_env env, napi_callback_info info)
307 {
308 int fileDescribe = open(PATH, O_CREAT);
309 int ret = __futimens_time64(fileDescribe, ((struct timespec[2]){{.tv_nsec = UTIME_OMIT}, {.tv_nsec = UTIME_OMIT}}));
310 napi_value result;
311 napi_create_int32(env, ret, &result);
312 close(fileDescribe);
313 remove(PATH);
314 return result;
315 }
316
317 extern "C" int __futimes_time64(int, const struct timeval[2]);
FuTimes_time64(napi_env env, napi_callback_info info)318 static napi_value FuTimes_time64(napi_env env, napi_callback_info info)
319 {
320 struct stat s;
321 static struct timeval tv[2];
322 tv[0].tv_sec = s.st_atime;
323 tv[0].tv_usec = PARAM_0;
324 tv[1].tv_sec = s.st_mtime;
325 tv[1].tv_usec = PARAM_0;
326 int ret = MPARAM_1;
327 int fileDescribe = open(TEST_FILE, O_RDWR | O_CREAT, PARAM_0777);
328 if (fileDescribe != MPARAM_1) {
329 ret = __futimes_time64(fileDescribe, tv);
330 }
331 napi_value result = nullptr;
332 napi_create_int32(env, ret, &result);
333 remove(TEST_FILE);
334 return result;
335 }
336
337 extern "C" int __futimesat_time64(int, const char *, const struct timeval[2]);
FuTimesAt_time64(napi_env env, napi_callback_info info)338 static napi_value FuTimesAt_time64(napi_env env, napi_callback_info info)
339 {
340 int dir_fd = open(TEST_FILE_PATH, O_RDONLY | O_DIRECTORY);
341 int fileDescribe = openat(dir_fd, TEST_FILE_NAME, O_CREAT | O_RDWR | O_EXCL, PARAM_0666);
342 const char *msg = "helloworld";
343 write(fileDescribe, "msg", sizeof(msg));
344 struct timeval tv[2];
345 struct stat st;
346 fstat(fileDescribe, &st);
347 close(fileDescribe);
348 tv[0].tv_sec = st.st_atime + PARAM_1;
349 tv[0].tv_usec = PARAM_0;
350 tv[1].tv_sec = st.st_mtime + PARAM_1;
351 tv[1].tv_usec = PARAM_0;
352 int ret = __futimesat_time64(dir_fd, TEST_FILE_NAME, tv);
353 unlinkat(dir_fd, TEST_FILE_NAME, PARAM_0);
354 close(dir_fd);
355 remove(TEST_FILE);
356 napi_value result;
357 napi_create_int32(env, ret, &result);
358 return result;
359 }
360
361 extern "C" struct tm *__gmtime64(const time_t *);
GmTime64(napi_env env, napi_callback_info info)362 static napi_value GmTime64(napi_env env, napi_callback_info info)
363 {
364 int backParam = PARAM_UNNORMAL;
365 struct tm *checkParam{};
366 const time_t firstParam = PARAM_0;
367 checkParam = __gmtime64(&firstParam);
368 if (checkParam != nullptr) {
369 backParam = PARAM_0;
370 }
371 napi_value result = nullptr;
372 napi_create_int32(env, backParam, &result);
373 return result;
374 }
375
376 extern "C" struct tm *__gmtime64_r(const time_t *__restrict, struct tm *__restrict);
GmTime64_r(napi_env env, napi_callback_info info)377 static napi_value GmTime64_r(napi_env env, napi_callback_info info)
378 {
379 int backParam = PARAM_UNNORMAL;
380 struct tm *checkParam{};
381 const time_t firstParam = PARAM_0;
382 struct tm secondParam {};
383 checkParam = __gmtime64_r(&firstParam, &secondParam);
384 if (checkParam != nullptr) {
385 backParam = PARAM_0;
386 }
387 napi_value result = nullptr;
388 napi_create_int32(env, backParam, &result);
389 return result;
390 }
391
392 extern "C" struct tm *__localtime64(const time_t *);
Localtime64(napi_env env, napi_callback_info info)393 static napi_value Localtime64(napi_env env, napi_callback_info info)
394 {
395 int backParam = PARAM_UNNORMAL;
396 struct tm *checkParam{};
397 const time_t firstParam = PARAM_0;
398 checkParam = __localtime64(&firstParam);
399 if (checkParam != nullptr) {
400 backParam = PARAM_0;
401 }
402 napi_value result = nullptr;
403 napi_create_int32(env, backParam, &result);
404 return result;
405 }
406
407 extern "C" struct tm *__localtime64_r(const time_t *__restrict, struct tm *__restrict);
Localtime64_r(napi_env env, napi_callback_info info)408 static napi_value Localtime64_r(napi_env env, napi_callback_info info)
409 {
410 int backParam = PARAM_UNNORMAL;
411 struct tm *checkParam{};
412 const time_t firstParam = PARAM_0;
413 struct tm secondParam {};
414 checkParam = __localtime64_r(&firstParam, &secondParam);
415 if (checkParam != nullptr) {
416 backParam = PARAM_0;
417 }
418 napi_value result = nullptr;
419 napi_create_int32(env, backParam, &result);
420 return result;
421 }
422
423 extern "C" int __lutimes_time64(const char *, const struct timeval[2]);
LuTimes_time64(napi_env env, napi_callback_info info)424 static napi_value LuTimes_time64(napi_env env, napi_callback_info info)
425 {
426 int ret;
427 struct stat s;
428 static struct timeval tv[TEST_SIZE] = {{0L, 0L}, {0L, 0L}};
429 tv[0].tv_sec = s.st_atime;
430 tv[0].tv_usec = PARAM_0;
431 tv[1].tv_sec = s.st_mtime;
432 tv[1].tv_usec = PARAM_0;
433 int fd = open("/data/storage/el2/base/files/Fzl.txt", O_RDWR | O_CREAT, PARAM_0666);
434 close(fd);
435 ret = __lutimes_time64("/data/storage/el2/base/files/Fzl.txt", tv);
436 napi_value result;
437 if (ret == FAIL) {
438 napi_create_int32(env, FAIL, &result);
439 } else {
440 napi_create_int32(env, PARAM_0, &result);
441 }
442 return result;
443 }
444
445 extern "C" time_t __mktime64(struct tm *);
MkTime64(napi_env env, napi_callback_info info)446 static napi_value MkTime64(napi_env env, napi_callback_info info)
447 {
448 time_t checkParam = PARAM_UNNORMAL;
449 int backParam = PARAM_1;
450 struct tm firstParam {};
451 checkParam = __mktime64(&firstParam);
452 if (checkParam != PARAM_UNNORMAL) {
453 backParam = PARAM_0;
454 }
455 napi_value result = nullptr;
456 napi_create_int32(env, backParam, &result);
457 return result;
458 }
459
460 extern "C" int __mtx_timedlock_time64(mtx_t *__restrict, const struct timespec *__restrict);
Mtx_timedLock_time64(napi_env env, napi_callback_info info)461 static napi_value Mtx_timedLock_time64(napi_env env, napi_callback_info info)
462 {
463 int backParam = PARAM_UNNORMAL;
464 mtx_t firstParam;
465 mtx_init(&firstParam, mtx_timed);
466 struct timespec secondParam;
467 secondParam.tv_sec = PARAM_02;
468 secondParam.tv_nsec = PARAM_0;
469 backParam = __mtx_timedlock_time64(&firstParam, &secondParam);
470 mtx_unlock(&firstParam);
471 napi_value result = nullptr;
472 napi_create_int32(env, backParam, &result);
473 return result;
474 }
475
476 extern "C" int __ppoll_time64(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *);
PPoll_time64(napi_env env, napi_callback_info info)477 static napi_value PPoll_time64(napi_env env, napi_callback_info info)
478 {
479 int backParam = PARAM_UNNORMAL;
480 struct pollfd *firstParam{};
481 nfds_t secondParam = PARAM_0;
482 struct timespec thirdParam {};
483 const sigset_t *fourthParam = nullptr;
484 backParam = __ppoll_time64(firstParam, secondParam, &thirdParam, fourthParam);
485 napi_value result = nullptr;
486 napi_create_int32(env, backParam, &result);
487 return result;
488 }
489
490 extern "C" int __pthread_mutex_timedlock_time64(pthread_mutex_t *__restrict, const struct timespec *__restrict);
PThread_mutex_timedLock_time64(napi_env env, napi_callback_info info)491 static napi_value PThread_mutex_timedLock_time64(napi_env env, napi_callback_info info)
492 {
493 int backParam = PARAM_UNNORMAL;
494 pthread_mutex_t firstParam = PTHREAD_MUTEX_INITIALIZER;
495 struct timespec secondParam {};
496 backParam = pthread_mutex_timedlock(&firstParam, &secondParam);
497 napi_value result = nullptr;
498 napi_create_int32(env, backParam, &result);
499 return result;
500 }
501
502 extern "C" int __pthread_rwlock_timedrdlock_time64(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
PThread_rwLock_timedrdLock_time64(napi_env env, napi_callback_info info)503 static napi_value PThread_rwLock_timedrdLock_time64(napi_env env, napi_callback_info info)
504 {
505 int backParam = PARAM_UNNORMAL;
506 pthread_rwlock_t firstParam = PTHREAD_RWLOCK_INITIALIZER;
507 struct timespec secondParam {};
508 backParam = __pthread_rwlock_timedrdlock_time64(&firstParam, &secondParam);
509 napi_value result = nullptr;
510 napi_create_int32(env, backParam, &result);
511 return result;
512 }
513
514 extern "C" int __pthread_rwlock_timedwrlock_time64(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
PThread_rwLock_timedWrLock_time64(napi_env env, napi_callback_info info)515 static napi_value PThread_rwLock_timedWrLock_time64(napi_env env, napi_callback_info info)
516 {
517 int backParam = PARAM_UNNORMAL;
518 pthread_rwlock_t firstParam = PTHREAD_RWLOCK_INITIALIZER;
519 const struct timespec *secondParam{};
520 backParam = __pthread_rwlock_timedwrlock_time64(&firstParam, secondParam);
521 napi_value result = nullptr;
522 napi_create_int32(env, backParam, &result);
523 return result;
524 }
525
526 extern "C" int __recvmmsg_time64(int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
ReCvmMsg_time64(napi_env env, napi_callback_info info)527 static napi_value ReCvmMsg_time64(napi_env env, napi_callback_info info)
528 {
529 #define BUFSIZE 200
530 int resultValue = FAIL;
531 pid_t pid = fork();
532 if (pid > PARAM_0) {
533 struct mmsghdr msgs[SIZE_10];
534 struct iovec iovecs[SIZE_10];
535 char bufs[SIZE_10][BUFSIZE + PARAM_1];
536 struct sockaddr_in addr;
537 int sockfd = socket(AF_INET, SOCK_DGRAM, PARAM_0);
538 addr.sin_family = AF_INET;
539 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
540 addr.sin_port = htons(PARAM_1999);
541 if (bind(sockfd, reinterpret_cast<sockaddr *>(static_cast<struct sockaddr_in *>(&addr)), sizeof(addr)) ==
542 FAIL) {
543 resultValue = PARAM_30;
544 } else {
545 memset(msgs, PARAM_0, sizeof(msgs));
546 for (int i = 0; i < SIZE_10; i++) {
547 iovecs[i].iov_base = bufs[i];
548 iovecs[i].iov_len = BUFSIZE;
549 msgs[i].msg_hdr.msg_iov = &iovecs[i];
550 msgs[i].msg_hdr.msg_iovlen = PARAM_1;
551 }
552 struct timespec timeout;
553 timeout.tv_sec = PARAM_1;
554 timeout.tv_nsec = PARAM_0;
555 resultValue = __recvmmsg_time64(sockfd, msgs, SIZE_10, PARAM_0, &timeout);
556 }
557 close(sockfd);
558 } else if (pid == PARAM_0) {
559 sleep(PARAM_1);
560 int sockfd;
561 struct sockaddr_in addr;
562 struct mmsghdr msg[PARAM_1];
563 struct iovec msg1[PARAM_1];
564
565 sockfd = socket(AF_INET, SOCK_DGRAM, PARAM_0);
566
567 addr.sin_family = AF_INET;
568 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
569 addr.sin_port = htons(PARAM_1999);
570 connect(sockfd, reinterpret_cast<sockaddr *>(static_cast<struct sockaddr_in *>(&addr)), sizeof(addr));
571 memset(msg1, PARAM_0, sizeof(msg1));
572 memset(msg, PARAM_0, sizeof(msg));
573 msg[PARAM_0].msg_hdr.msg_iov = msg1;
574 msg[PARAM_0].msg_hdr.msg_iovlen = PARAM_1;
575
576 sendmmsg(sockfd, msg, PARAM_1, PARAM_0);
577 close(sockfd);
578 _exit(PARAM_0);
579 }
580
581 napi_value result = nullptr;
582 napi_create_int32(env, resultValue, &result);
583 return result;
584 }
585
586 extern "C" int __sched_rr_get_interval_time64(pid_t, struct timespec *);
SchEd_rr_get_interval_time64(napi_env env, napi_callback_info info)587 static napi_value SchEd_rr_get_interval_time64(napi_env env, napi_callback_info info)
588 {
589 int backParam = PARAM_UNNORMAL;
590 pid_t firstParam = getpid();
591 struct timespec secondParam {};
592 backParam = __sched_rr_get_interval_time64(firstParam, &secondParam);
593 napi_value result = nullptr;
594 napi_create_int32(env, backParam, &result);
595 return result;
596 }
597
598 extern "C" int __select_time64(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict,
599 struct timeval *__restrict);
Select_time64(napi_env env, napi_callback_info info)600 static napi_value Select_time64(napi_env env, napi_callback_info info)
601 {
602 int backParam = PARAM_UNNORMAL, firstParam = PARAM_1;
603 fd_set secondParam, thirdParam, fourthParam;
604 FD_ZERO(&secondParam);
605 FD_ZERO(&thirdParam);
606 FD_ZERO(&fourthParam);
607 struct timeval fifthParam;
608 memset_s(&fifthParam, sizeof(fifthParam), 0, sizeof(fifthParam));
609 backParam = __select_time64(firstParam, &secondParam, &thirdParam, &fourthParam, &fifthParam);
610 napi_value result = nullptr;
611 napi_create_int32(env, backParam, &result);
612 return result;
613 }
614
615 extern "C" int __sem_timedwait_time64(sem_t *__restrict, const struct timespec *__restrict);
Sem_timedWait_time64(napi_env env, napi_callback_info info)616 static napi_value Sem_timedWait_time64(napi_env env, napi_callback_info info)
617 {
618 int backParam = PARAM_UNNORMAL;
619 sem_t firstParam;
620 struct timespec secondParam {};
621 backParam = __sem_timedwait_time64(&firstParam, &secondParam);
622 napi_value result = nullptr;
623 napi_create_int32(env, backParam, &result);
624 return result;
625 }
626
627 extern "C" int __semtimedop_time64(int, struct sembuf *, size_t, const struct timespec *);
SemTimeDop_time64(napi_env env, napi_callback_info info)628 static napi_value SemTimeDop_time64(napi_env env, napi_callback_info info)
629 {
630 int backParam = PARAM_UNNORMAL, firstParam = PARAM_UNNORMAL;
631 struct sembuf secondParam {};
632 size_t thirdParam = 256;
633 struct timespec fourthParam {};
634 backParam = __semtimedop_time64(firstParam, &secondParam, thirdParam, &fourthParam);
635 napi_value result = nullptr;
636 napi_create_int32(env, backParam, &result);
637 return result;
638 }
639
640 extern "C" int __settimeofday_time64(const struct timeval *, const struct timezone *);
SetTimeOfDay_time64(napi_env env, napi_callback_info info)641 static napi_value SetTimeOfDay_time64(napi_env env, napi_callback_info info)
642 {
643 int backParam = PARAM_UNNORMAL;
644 struct timeval firstParam {};
645 struct timezone secondParam {};
646 backParam = __settimeofday_time64(&firstParam, &secondParam);
647 napi_value result = nullptr;
648 napi_create_int32(env, backParam, &result);
649 return result;
650 }
651
652 extern "C" int __sigtimedwait_time64(const sigset_t *__restrict, siginfo_t *__restrict,
653 const struct timespec *__restrict);
SigTimedWait_time64(napi_env env, napi_callback_info info)654 static napi_value SigTimedWait_time64(napi_env env, napi_callback_info info)
655 {
656 int backParam = PARAM_UNNORMAL;
657 const sigset_t firstParam{};
658 siginfo_t secondParam;
659 struct timespec thirdParam {};
660 backParam = __sigtimedwait_time64(&firstParam, &secondParam, &thirdParam);
661 napi_value result = nullptr;
662 napi_create_int32(env, backParam, &result);
663 return result;
664 }
665
666 extern "C" int __thrd_sleep_time64(const struct timespec *, struct timespec *);
THrd_sleep_time64(napi_env env, napi_callback_info info)667 static napi_value THrd_sleep_time64(napi_env env, napi_callback_info info)
668 {
669 int backParam = PARAM_UNNORMAL;
670 struct timespec firstParam {};
671 struct timespec secondParam {};
672 backParam = __thrd_sleep_time64(&firstParam, &secondParam);
673 napi_value result = nullptr;
674 napi_create_int32(env, backParam, &result);
675 return result;
676 }
677
678 extern "C" time_t __time64(time_t *);
Time64(napi_env env, napi_callback_info info)679 static napi_value Time64(napi_env env, napi_callback_info info)
680 {
681 time_t checkParam;
682 int backParam = PARAM_1;
683 time_t firstParam;
684 checkParam = __time64(&firstParam);
685 if (checkParam != PARAM_UNNORMAL) {
686 backParam = PARAM_0;
687 }
688 napi_value result = nullptr;
689 napi_create_int32(env, backParam, &result);
690 return result;
691 }
692
693 extern "C" time_t __timegm_time64(struct tm *);
TimeGm_time64(napi_env env, napi_callback_info info)694 static napi_value TimeGm_time64(napi_env env, napi_callback_info info)
695 {
696 time_t checkParam = PARAM_0;
697 int backParam = PARAM_1;
698 struct tm firstParam {};
699 backParam = __timegm_time64(&firstParam);
700 if (checkParam != PARAM_UNNORMAL) {
701 backParam = PARAM_0;
702 }
703 napi_value result = nullptr;
704 napi_create_int32(env, backParam, &result);
705 return result;
706 }
707
708 extern "C" int __timerfd_gettime64(int, struct itimerspec *);
TimerFd_getTime64(napi_env env, napi_callback_info info)709 static napi_value TimerFd_getTime64(napi_env env, napi_callback_info info)
710 {
711 #define NANOSECOND (1000000000)
712 int backParam = PARAM_1;
713 int ret = PARAM_1;
714 struct itimerspec its = {{PARAM_0, PARAM_0}, {PARAM_02, PARAM_0}};
715 struct itimerspec val;
716 int fd;
717 fd = timerfd_create(CLOCK_REALTIME, PARAM_0);
718 timerfd_settime(fd, PARAM_0, &its, nullptr);
719 usleep(MICROSECONDS);
720 ret = __timerfd_gettime64(fd, &val);
721 if (ret == PARAM_0) {
722 if (val.it_value.tv_nsec <= NANOSECOND) {
723 backParam = PARAM_0;
724 }
725 }
726 napi_value result = nullptr;
727 napi_create_int32(env, backParam, &result);
728 return result;
729 }
730
731 extern "C" int __timerfd_settime64(int, int, const struct itimerspec *, struct itimerspec *);
TimerFd_setTime64(napi_env env, napi_callback_info info)732 static napi_value TimerFd_setTime64(napi_env env, napi_callback_info info)
733 {
734 struct itimerspec its = {{PARAM_0, PARAM_0}, {TEST_SIZE, PARAM_0}};
735 struct itimerspec val;
736 int fileDescribe, time_value;
737 fileDescribe = timerfd_create(CLOCK_REALTIME, PARAM_0);
738 time_value = __timerfd_settime64(fileDescribe, PARAM_0, &its, nullptr);
739 time_value = usleep(MICROSECONDS);
740 time_value = __timerfd_gettime64(fileDescribe, &val);
741 napi_value result = nullptr;
742 napi_create_int32(env, time_value, &result);
743 return result;
744 }
745
746 extern "C" int __timespec_get_time64(struct timespec *, int);
TimerSpec_get_time64(napi_env env, napi_callback_info info)747 static napi_value TimerSpec_get_time64(napi_env env, napi_callback_info info)
748 {
749 int backParam;
750 struct timespec firstParam {};
751 backParam = __timespec_get_time64(&firstParam, TIME_UTC);
752 napi_value result = nullptr;
753 napi_create_int32(env, backParam, &result);
754 return result;
755 }
756
757 extern "C" int __utime64(const char *, const struct utimbuf *);
UTime64(napi_env env, napi_callback_info info)758 static napi_value UTime64(napi_env env, napi_callback_info info)
759 {
760 size_t argc = PARAM_1;
761 napi_value args[PARAM_1] = {nullptr};
762 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
763 struct utimbuf ubuf;
764 struct stat statinfo;
765 int toCppResult = FAIL;
766 size_t length = SIZE_64, stresult = PARAM_0;
767 char strTemp[length];
768 napi_get_value_string_utf8(env, args[0], strTemp, length, &stresult);
769 int fileDescribe = open(strTemp, O_CREAT);
770 close(fileDescribe);
771 stat(strTemp, &statinfo);
772 ubuf.modtime = PARAM_0;
773 time(&ubuf.actime);
774 if (__utime64(strTemp, &ubuf) == PARAM_0) {
775 stat(strTemp, &statinfo);
776 if (statinfo.st_mtim.tv_sec == PARAM_0) {
777 toCppResult = PARAM_1;
778 }
779 }
780 napi_value result = nullptr;
781 napi_create_int32(env, toCppResult, &result);
782 return result;
783 }
784
785 extern "C" int __utimes_time64(const char *, const struct timeval[2]);
UTimes_time64(napi_env env, napi_callback_info info)786 static napi_value UTimes_time64(napi_env env, napi_callback_info info)
787 {
788 int fileDescribe = open(TEST_FILE, O_RDWR | O_RSYNC | O_CREAT);
789 close(fileDescribe);
790 struct timeval tv[2];
791 memset_s(tv, sizeof(tv), 0, sizeof(tv));
792 tv[0].tv_usec = PARAM_1;
793 int ret = __utimes_time64(TEST_FILE, tv);
794 napi_value result = nullptr;
795 napi_create_int32(env, ret, &result);
796 remove(TEST_FILE);
797 return result;
798 }
799
800 extern "C" pid_t __wait4_time64(pid_t, int *, int, struct rusage *);
Wait4_time64(napi_env env, napi_callback_info info)801 static napi_value Wait4_time64(napi_env env, napi_callback_info info)
802 {
803 pid_t backParam, firstParam;
804 int secondParam = PARAM_1;
805 int thirdParam = PARAM_1;
806 struct rusage fourthParam {};
807 firstParam = getpid();
808 backParam = __wait4_time64(firstParam, &secondParam, thirdParam, &fourthParam);
809 napi_value result = nullptr;
810 napi_create_int32(env, backParam, &result);
811 return result;
812 }
813
814 EXTERN_C_START
Init(napi_env env, napi_value exports)815 static napi_value Init(napi_env env, napi_value exports)
816 {
817 napi_property_descriptor desc[] = {
818 {"fnmatch", nullptr, FnMatch, nullptr, nullptr, nullptr, napi_default, nullptr},
819 {"__clock_gettime64", nullptr, clock_getTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
820 {"__pthread_cond_timedwait_time64", nullptr, PThread_cond_timedWait_time64, nullptr, nullptr, nullptr,
821 napi_default, nullptr},
822 {"__nanosleep_time64", nullptr, NanoSleep_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
823 {"__fstat_time64", nullptr, FStat_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
824 {"__lstat_time64", nullptr, LStat_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
825 {"__stat_time64", nullptr, Stat_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
826 {"__utimensat_time64", nullptr, UTimeNsAt_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
827 {"__clock_getres_time64", nullptr, Clock_getRes_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
828 {"__clock_nanosleep_time64", nullptr, Clock_nanoSleep_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
829 {"__clock_settime64", nullptr, Clock_setTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
830 {"__cnd_timedwait_time64", nullptr, Cnd_timedWait_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
831 {"__ctime64", nullptr, CTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
832 {"__ctime64_r", nullptr, CTime64_r, nullptr, nullptr, nullptr, napi_default, nullptr},
833 {"__difftime64", nullptr, DiffTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
834 {"__dlsym_time64", nullptr, DlSym_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
835 {"__futimens_time64", nullptr, FuTimeNs_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
836 {"__futimes_time64", nullptr, FuTimes_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
837 {"__futimesat_time64", nullptr, FuTimesAt_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
838 {"__gmtime64", nullptr, GmTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
839 {"__gmtime64_r", nullptr, GmTime64_r, nullptr, nullptr, nullptr, napi_default, nullptr},
840 {"__localtime64", nullptr, Localtime64, nullptr, nullptr, nullptr, napi_default, nullptr},
841 {"__localtime64_r", nullptr, Localtime64_r, nullptr, nullptr, nullptr, napi_default, nullptr},
842 {"__lutimes_time64", nullptr, LuTimes_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
843 {"__mktime64", nullptr, MkTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
844 {"__mtx_timedlock_time64", nullptr, Mtx_timedLock_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
845 {"__ppoll_time64", nullptr, PPoll_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
846 {"__pthread_mutex_timedlock_time64", nullptr, PThread_mutex_timedLock_time64, nullptr, nullptr, nullptr,
847 napi_default, nullptr},
848 {"__pthread_rwlock_timedrdlock_time64", nullptr, PThread_rwLock_timedrdLock_time64, nullptr, nullptr, nullptr,
849 napi_default, nullptr},
850 {"__pthread_rwlock_timedwrlock_time64", nullptr, PThread_rwLock_timedWrLock_time64, nullptr, nullptr, nullptr,
851 napi_default, nullptr},
852 {"__recvmmsg_time64", nullptr, ReCvmMsg_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
853 {"__sched_rr_get_interval_time64", nullptr, SchEd_rr_get_interval_time64, nullptr, nullptr, nullptr,
854 napi_default, nullptr},
855 {"__select_time64", nullptr, Select_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
856 {"__sem_timedwait_time64", nullptr, Sem_timedWait_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
857 {"__semtimedop_time64", nullptr, SemTimeDop_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
858 {"__settimeofday_time64", nullptr, SetTimeOfDay_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
859 {"__sigtimedwait_time64", nullptr, SigTimedWait_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
860 {"__thrd_sleep_time64", nullptr, THrd_sleep_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
861 {"__time64", nullptr, Time64, nullptr, nullptr, nullptr, napi_default, nullptr},
862 {"__timegm_time64", nullptr, TimeGm_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
863 {"__timerfd_gettime64", nullptr, TimerFd_getTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
864 {"__timerfd_settime64", nullptr, TimerFd_setTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
865 {"__timespec_get_time64", nullptr, TimerSpec_get_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
866 {"__utime64", nullptr, UTime64, nullptr, nullptr, nullptr, napi_default, nullptr},
867 {"__utimes_time64", nullptr, UTimes_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
868 {"__wait4_time64", nullptr, Wait4_time64, nullptr, nullptr, nullptr, napi_default, nullptr},
869 };
870 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
871 return exports;
872 }
873 EXTERN_C_END
874
875 static napi_module demoModule = {
876 .nm_version = 1,
877 .nm_flags = 0,
878 .nm_filename = nullptr,
879 .nm_register_func = Init,
880 .nm_modname = "libfnmatchndk",
881 .nm_priv = ((void *)0),
882 .reserved = {0},
883 };
884
RegisterModule(void)885 extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); }
886