1 /*
2 * Copyright (c) 2024 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 "form_memmgr_client.h"
17
18 #include <functional>
19 #include <dlfcn.h>
20 #include <unistd.h>
21 #include "fms_log_wrapper.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 constexpr int32_t FORM_RENDER_SERVICE_SAID = -1;
26
FormMemmgrClient()27 FormMemmgrClient::FormMemmgrClient()
28 {}
29
~FormMemmgrClient()30 FormMemmgrClient::~FormMemmgrClient()
31 {}
32
SetCritical(bool critical)33 void FormMemmgrClient::SetCritical(bool critical)
34 {
35 int32_t pid = getprocpid();
36 HILOG_INFO("pid:%{public}" PRId32 ", critical:%{public}d", pid, critical);
37
38 void *libMemmgrClientHandle = dlopen("libmemmgrclient.z.so", RTLD_NOW);
39 if (!libMemmgrClientHandle) {
40 HILOG_ERROR("dlopen libmemmgrclient fail");
41 return;
42 }
43
44 void *setCritical = (dlsym(libMemmgrClientHandle, "set_critical"));
45 if (!setCritical) {
46 HILOG_ERROR("dlsym set_critical fail");
47 dlclose(libMemmgrClientHandle);
48 return;
49 }
50
51 auto setCriticalFunc = reinterpret_cast<int32_t(*)(int32_t, bool, int32_t)>(setCritical);
52 if (setCriticalFunc(pid, critical, FORM_RENDER_SERVICE_SAID) != 0) {
53 HILOG_ERROR("setCriticalFunc fail");
54 }
55 dlclose(libMemmgrClientHandle);
56 }
57 } // namespace AppExecFwk
58 } // namespace OHOS
59