1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2022 Huawei Device Co., Ltd. 4 */ 5 6#include <linux/ptrace.h> 7#include <linux/sched/mm.h> 8#include "internal.h" 9 10#define XPM_REGION_LEN 48 11static int xpm_region_open(struct inode *inode, struct file *file) 12{ 13 struct mm_struct *mm = proc_mem_open(inode, PTRACE_MODE_READ); 14 15 if (IS_ERR(mm)) 16 return PTR_ERR(mm); 17 18 file->private_data = mm; 19 return 0; 20} 21 22static ssize_t xpm_region_read(struct file *file, char __user *buf, 23 size_t count, loff_t *pos) 24{ 25 struct mm_struct *mm = file->private_data; 26 char xpm_region[XPM_REGION_LEN] = {0}; 27 size_t len; 28 29 if (!mm) 30 return 0; 31 32 len = snprintf(xpm_region, XPM_REGION_LEN - 1, "%lx-%lx", 33 mm->xpm_region.addr_start, 34 mm->xpm_region.addr_end); 35 36 return simple_read_from_buffer(buf, count, pos, xpm_region, len); 37} 38 39static int xpm_region_release(struct inode *inode, struct file *file) 40{ 41 struct mm_struct *mm = file->private_data; 42 43 if (mm) 44 mmdrop(mm); 45 46 return 0; 47} 48 49const struct file_operations proc_xpm_region_operations = { 50 .open = xpm_region_open, 51 .read = xpm_region_read, 52 .llseek = generic_file_llseek, 53 .release = xpm_region_release, 54};