首页 \ 问答 \ 如何使@NotNull抛出运行时异常?(How to make @NotNull throw runtime exception?)

如何使@NotNull抛出运行时异常?(How to make @NotNull throw runtime exception?)

如果我将null作为参数传递给@NotNull注释,是否有任何框架可以引发异常? 我不是指静态分析,而是运行时检查。

如果没有,如何实施呢?


Is there any framework that can throw exception if I pass null as parameter to @NotNull annotation? I don't mean static analysis but run-time checks.

If not, how to implement it?


原文:https://stackoverflow.com/questions/26393129
更新时间:2023-08-26 12:08

最满意答案

你在linux/mm.h寻找linux/mm.h

/* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);

这应该是诀窍:

struct vm_area_struct *vma = find_vma(task->mm, 0x13000);
if (vma == NULL)
    return -EFAULT;
if (0x13000 >= vma->vm_end)
    return -EFAULT;

You're looking for find_vma in linux/mm.h.

/* Look up the first VMA which satisfies  addr < vm_end,  NULL if none. */
extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr);

This should do the trick:

struct vm_area_struct *vma = find_vma(task->mm, 0x13000);
if (vma == NULL)
    return -EFAULT;
if (0x13000 >= vma->vm_end)
    return -EFAULT;

相关问答

更多
  • find
  • 内核确实希望位于特定位置。 该位置是特定于架构的。 您可以重新配置并重新编译内核以进行调整。 我最近正在为x86 / x86_64进行研究,这是有据可查的 。 我希望在那里找到Sparc文档,虽然它不会跳出来。 但是,有些信息可以在这里找到。 相关的一点似乎是: 加载的引导扇区是您在Linux-Sparc系统中的/boot/first.b中找到的,并且是512字节。 它被加载到0x4000地址,它的作用是从磁盘/boot/second.b中检索并将其放入地址0x280000(2.5兆); 选择该地址是因为S ...
  • 对不起,我的源代码另一部分(过程)发生内核恐慌。 以上代码运行良好。 抱歉。 Sorry, my source code another part(procedure) occured kernel panic. Above code works well. sorry.
  • 要访问页面,需要将其映射到当前的虚拟地址空间。 因此,如果内核想要访问用户页面,则有两种解决方案: 在我们当前的地址空间,内核的地址空间中映射页面,并确保两个页面表条目保持一致(您不必严格保持一致,但您真的想要)。 切换到已映射该页面的地址空间,即用户自己的地址空间 你的内核似乎在挑选选项1,这对性能来说是一件好事。 切换到另一个地址空间并返回需要相当多的时间。 它可以选择选项2,并在每次想要访问用户页面时切换到用户的地址空间,这可能会通过避免一些簿记使代码更简单,但这将非常慢。 To access a p ...
  • 您使用哪种方法取决于您要完成的任务。 (1)设备驱动程序是内核的一部分,因此区分这种方式并没有多大意义。 对于这些情况,设备驱动程序要求从整个内核可用的(物理)内存资源中为自己的内存分配内存。 使用(a),正在分配物理上连续的空间。 如果有一些外部硬件(例如PCI设备)将读取或写入该内存,则可以执行此操作。 kmalloc的返回值已经映射到内核虚拟地址空间。 remap_pfn_range用于将页面映射到当前进程的用户虚拟地址空间。 对于(b),正在分配几乎连续的空间。 如果没有涉及外部硬件,这就是您通常使 ...
  • 大多数系统定义内核和用户地址空间的逻辑地址范围。 在某些系统上,范围完全取决于操作系统(如何设置页表),而其他系统则由硬件完成。 对于前者,页表通常是嵌套的。 在这种情况下,多个页表共享相同的entires。 对于后者,通常有用户和内核地址空间的单独页表。 如果ELF定义了虚拟地址空间,那么ELF是否也定义了内核虚拟地址空间? 怎么样? [我假设内核虚拟地址空间在运行时动态映射?] 可执行文件仅定义用户地址空间的初始布局。 如果内核地址空间映射到进程地址空间那么为什么进程大小(虚拟)也不包括内核大小呢? 这 ...
  • 经过一些折磨之后,我们意识到这很可能是内存控制器的硬件问题,因此很难理解其中存在的是什么以及发生了什么,因为它是随机内存损坏。 After some torture we have realized that this was most likely a hardware issue with memory controller, so the reason why it is very hard to understand what's there and what is happening is tha ...
  • 传统上,可编译器在编译时被分配固定的虚拟地址映射。 然而,近年来,显而易见的是,这对于安全性是不利的 - 攻击者可以利用他们对内存中事物的确切知识作为漏洞利用的一部分。 为了帮助缓解这种情况,可以使用与位置无关或可重定位的可执行文件来允许加载地址随机化(至少在Linux上)。 但是,这有一个缺点 - 启动程序需要更多时间,因为动态加载程序必须执行重定位(或者在运行时从位置无关的机器代码中存在额外的开销)。 对于OS内核,与其余的引导时间相比,额外的开销是微不足道的; 实际上,Windows内核实际上动态地链 ...
  • 仅供记录。 我深入研究了内核代码,发现它只能在那里使用一些特定的加密算法(根据IPSec RFC),并且添加新的块加密算法也会涉及操纵IKE(例如Racoon)。 顺便说一句,只有一个RFC草案用于为IPSec ESP使用流密码(如salsa20),因此使用它们将涉及在其他修改之上实现RFC草案。 Just for record. I dig into the kernel code and found that it's only possible to use some specific encrypt ...
  • 你在linux/mm.h寻找linux/mm.h 。 /* Look up the first VMA which satisfies addr < vm_end, NULL if none. */ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr); 这应该是诀窍: struct vm_area_struct *vma = find_vma(task->mm, 0x13000); if ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。