6.10 初探

新增配置项

详细信息

一堆驱动。。。

drm

drm_panic

为 Kernel Panic 提供显示支持(???)。

MEM_ALLOC_PROFILING

低开销(未测试)统计内存分配信息。

系统调用

mseal

用于保护某段内存的映射关系(mmap)不被改变,保护 VMA(管理虚拟内存的结构)。

原型

long mseal(void *addr,size_t len,unsigned long flags);

addr 内存开始位置。

len 内存长度。

flags 目前无意义,保留。

效果

无法对该段内存各种搞 mmap,munmap,mremap 之类的,具体来说:

  • munmap(),mremap()。

  • mmap(MAP_FIXED)。

  • mprotect(),pkey_mprotect()

  • madvice(MADV_DONTNEED) 等等修改无写入权限匿名内存使其更改,比如清 0 。

测试

#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/stat.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
long mseal(void *addr,size_t len,unsigned long flags){
	return syscall(__NR_mseal,addr,len,flags);
}
struct stat buf;
int main(){
	int fd=open("/home/wxt/a.txt",O_RDWR);
	if(fd<0){
		printf("file open error: %d",fd);
		return fd;
	}
	int ret=stat("/home/wxt/a.txt",&buf);
	char *MMap=mmap(NULL,buf.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
	if(MMap==MAP_FAILED){
		close(fd);
		printf("mmap failed error: %p",MMap);
		return -1;
	}
  printf("the file is: %s",MMap);
  MMap[0]=getchar();
  printf("the file is: %s",MMap);
  ret=mseal(MMap,buf.st_size,0);
  if(ret<0){
    printf("mseal failed error: %d",ret);
    return ret;
  }
  ret=munmap(MMap,buf.st_size);
  if(ret<0){
    printf("munmap failed error: %d",ret);//it failed
    return ret;
  }
	return 0;
}