• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * SPDX-License-Identifier: GPL-2.0
4  *
5  * Legacy blkg rwstat helpers enabled by CONFIG_BLK_CGROUP_RWSTAT.
6  * Do not use in new code.
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  */
14 
15 #include <cstdio>
16 #include <cstdint>
17 #include <unistd.h>
18 #include <fcntl.h>
19 
20 namespace OHOS {
ForceShrinkAnonFuzzer(const uint8_t * data,size_t size)21 bool ForceShrinkAnonFuzzer(const uint8_t *data, size_t size)
22 {
23     const char *forceShrinkAnon = "/dev/memcg/memory.force_shrink_anon";
24     int fd = open(forceShrinkAnon, O_RDWR);
25     if (fd < 0) {
26         return false;
27     }
28 
29     int ret = write(fd, data, size);
30     if (ret < 0) {
31         printf("%s write fail\n", forceShrinkAnon);
32         close(fd);
33         return false;
34     }
35 
36     close(fd);
37     return true;
38 }
39 } // namespace OHOS
40 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
42 {
43     OHOS::ForceShrinkAnonFuzzer(data, size);
44     return 0;
45 }
46