• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "napi/native_api.h"
16 #include <cstdio>
17 #include <js_native_api.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/pr.h>
21 #include <malloc.h>
22 #include <node_api.h>
23 #include <sys/xattr.h>
24 
25 #define DEFAULT_VALUE 0
26 #define BUFSIZ 128
27 #define PARAM_0 0
28 #define PARAM_1 1
29 #define PARAM_2 2
30 #define PARAM_5 5
31 #define PARAM_UNNORMAL (-1)
32 #define ERRON_0 0
33 extern "C" int init_module(void *module_image, unsigned long len, const char *param_values);
34 
InitModule(napi_env env,napi_callback_info info)35 static napi_value InitModule(napi_env env, napi_callback_info info)
36 {
37     void *param;
38     int ret = init_module(param, PARAM_5, "0");
39     napi_value result = nullptr;
40     if (ret == PARAM_UNNORMAL) {
41         napi_create_int32(env, PARAM_UNNORMAL, &result);
42     } else {
43         napi_create_int32(env, DEFAULT_VALUE, &result);
44     }
45     return result;
46 }
47 
48 EXTERN_C_START
Init(napi_env env,napi_value exports)49 static napi_value Init(napi_env env, napi_value exports)
50 {
51     napi_property_descriptor desc[] = {
52         {"initModule", nullptr, InitModule, nullptr, nullptr, nullptr, napi_default, nullptr},
53     };
54     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
55     return exports;
56 }
57 EXTERN_C_END
58 
59 static napi_module demoModule = {
60     .nm_version = 1,
61     .nm_flags = 0,
62     .nm_filename = nullptr,
63     .nm_register_func = Init,
64     .nm_modname = "wchar",
65     .nm_priv = ((void *)0),
66     .reserved = {0},
67 };
68 
RegisterEntryModule(void)69 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
70