首页 > 其他分享 >OS-Stack Monitoring

OS-Stack Monitoring

时间:2024-11-15 18:46:02浏览次数:3  
标签:Monitoring area overflow number method Stack stack OS check

The OS shall provide a stack monitoring which detects possible stack faults of Task(s)/Category 2 ISR(s). [SWS_Os_00067]

Stack Check Strategy

All OS stacks must be protected from overflowing. The OS shall offer different strategies to detect stack overflows or even to prevent stacks from overflowing.

In dependency of the configured scalability class there are the following strategies:

Scalability ClassStack check strategy
SC1 / SC2Software stack check (see below)
SC3 / SC4Stack supervision by memory protection unit (MPU) (Refer to "OS-Memory Protection")

How to detect a stack overflow (Software stack check)

The use of stack monitoring is specified by OsStackMonitoring at the time of configuration.

There are three methods for detecting stack overflow.

  • Stack pointer check method
  • Magic number check method
  • Stack remaining amount check method

The situation in which stack overflow can be detected differs depending on each method. Due to the specifications of each method, the stack monitoring function of the OS cannot always detect stack overflow.

Stack pointer check method

The stack pointer check method is a method for checking whether the stack pointer exceeds the range of the stack area of the target processing unit. At the time of checking the stack pointer, it can be detected if a stack overflow has occurred.

Magic number check method

The magic number check method is a method in which a special value (magic number) is written at the end of the stack area of each processing unit when the OS is started, and it is checked whether the magic number has been rewritten when the processing unit is switched. It can be detected when a stack overflow occurs during execution of a processing unit and it is written to the end of the stack area.

The magic number area in the magic number check method is allocated at the end of the stack assigned to each processing unit. The size assigned as a magic number to the stack of each processing unit is 4 bytes (eg. 0x5A5A5A5A).

Stack remaining amount check method

The stack remaining amount check method is a method to check whether the remaining stack size is sufficient by using the current stack pointer and the C2ISR stack size specified at the time of configuration when C2ISR is started by nested interrupts.

If CI2SR with medium interrupt priority is started while C2ISR with low interrupt priority is being executed, and if the total stack size used by CI2SR with medium interrupt priority or higher does not remain in the stack area for C2ISR, it is judged that the C2ISR with low interrupt priority has used more than the specified stack, and the stack overflows. Since stacks for C2ISR with different interrupt priorities are allocated in one stack area, the stack pointer check method and the magic number method can detect only when the stack overflows to the entire allocated stack area. Therefore, the stack remaining amount check method makes it possible to check whether the C2ISR that has been executed up to that point is using the stack too much when nested interrupts occur.

Cases when stack overflow cannot be detected

Even if stack monitoring is performed, stack overflow cannot be detected if the stack pointer returns to the range of the stack area without rewriting the magic number area after the stack overflow occurs. In other words, even if stack overflow is not detected, there is a possibility that an area different from the magic number area has been rewritten.

In addition, the memory area outside the stack range is destroyed by stack overflow, which may cause a malfunction before the timing when stack monitoring operates.

Operation timing of stack monitoring

The OS should perform stack monitoring at the timing shown below.

 TimingCheck contentsUsage method
When task dispatch occursCheck whether the task (TASK1) that was in the running state exceeds the set stack size.Stack pointer check method
Magic number check method
When an interrupt occursCheck whether the task (TASK2) that was in the running state exceeds the set stack size.Stack pointer check method
Magic number check method
When nested interrupts occurCheck whether the C2ISR (ISR1) that was in the running state exceeds the set stack size.Stack remaining amount check method
Magic number check method
When an interrupt endsCheck whether the C2ISR (ISR2/ISR1) that was in the running state exceeds the set stack size.Magic number check method
-When a trust function endsCheck whether the stack used by the executed trust function exceeds the stack size.Magic number check method

In the following cases, stack monitoring is performed in the same way as the timing of ①.

  • When a task in the running state transitions to the suspended state by invoking the API TerminateTask or ChainTask.
  • When a task in the running state is forcibly terminated.

If the PostTaskHook is enabled, stack monitoring is performed after calling the PostTaskHook. Since task dispatch occurs due to the expiration process by executing the IncrementCounter, a stack overflow may be detected during the execution of the IncrementCounter as in the timing of ①.

For the timings ③ and ④, the stack used by the hook routines and C2ISR is allocated in one area, so stack monitoring is performed for the stack area used in all these processing units. Therefore, even if the hook routines cause a stack overflow, there is a possibility that the stack overflow will be detected by the magic number check method of ③ and ④.

Note that there may be an overflow in the OS stack when returning from the hook routine, as there is no timing to monitor the overflow in the hook routine.

Behavior at stack overflow

Behavior on SC1

If a stack overflow is detected, the OS shall call the ShutdownOS service with the status E_OS_STACKFAULT. [SWS_Os_00068]

Behavior on SC3

If a stack overflow is detected, AND

  • no ProtectionHook is configured, the OS shall call the ShutdownOS service with the status E_OS_STACKFAULT. [SWS_Os_00068]
  • a ProtectionHook is configured, the OS shall call the ProtectionHook with the status E_OS_STACKFAULT. [SWS_Os_00396]

Precautions for use

Note that the stack monitoring function cannot always detect stack overflow due to its specifications. To improve the effectiveness of stack monitoring, it is recommended not to place static variables above the stack area (in the direction in which the stack grows). If it is unavoidable due to memory allocation, a sufficient margin must be provided between the stack area and static variables.

标签:Monitoring,area,overflow,number,method,Stack,stack,OS,check
From: https://blog.csdn.net/erroror/article/details/143769941

相关文章

  • 洛谷 P1365 WJMZBMR打osu! / Easy 做题记录
    设\(len\)表示当前的期望连击数,设\(ans\)为当前的答案,我们分类讨论来更新\(ans\):当现在打到了这个音符,那么\(ans\toans+(len+1)^2-len^2=ans+len\times2+1\)。当现在没打到这个音符,那么\(ans\)不变。当现在不知道打没打到,那么\(ans\toans+\frac{(len\times2......
  • AutoSAR CP DoIP规范导读
    主要功能和用途诊断通信协议实现遵循标准:遵循ISO13400-2标准,实现了诊断通信在IP网络上的传输协议和网络层服务,包括数据封装、传输、路由等功能。多种消息支持车辆识别与公告:能够进行车辆识别请求和响应,发送车辆公告信息,包括车辆标识、实体标识、组标识等......
  • 为什么 Vue3 封装 Table 组件丢失 expose 方法呢?
    在实际开发中,我们通常会将某些常见组件进行二次封装,以便更好地实现特定的业务需求。然而,在封装Table组件时,遇到一个问题:Table内部暴露的方法,在封装之后的组件获取不到。代码展示为:constMyTable=defineComponent({name:'MyTable',props:ElTable.props,emits:......
  • Axios 拦截器示例(JWT 登录与自动刷新)
    1.安装axios首先,确保你已经安装了axios:npminstallaxios2.设置Axios拦截器importaxiosfrom'axios';//创建一个axios实例constaxiosInstance=axios.create({baseURL:'http://localhost:8000/',//后端API地址timeout:10000,//设置超时时间......
  • docker compose网络
    基本概念默认情况下,Compose会为我们的应用创建一个网络,服务的每个容器都会加入该网络中。这样,容器就可被该网络中的其他容器访问,不仅如此,该容器还能以服务名称作为hostname被其他容器访问。默认情况下,应用程序的网络名称基于Compose的工程名称,而项目名称基于docker-compose.yml......
  • centos7.9安装zabbix6.0
    一.安装zabbix1.官网下载tar包,下载链接:https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.35.tar.gz右键复制链接到linux终端使用wget命令下载,或者下载到本地再上传到linux服务器2.解压下载好的tar包创建虚拟用户和组,使用zabbix用户运行服务 1groupa......
  • Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider,
     macm1启动项目,报错,“Unabletoloadio.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider,fallbacktosystemdefaults.ThismayresultinincorrectDNSresolutionsonMacOS.”,出现这个问题是因为使用了spring-cloud-starter-gateway依赖,这需要额外安装......
  • 【Chapter 4】Machine Learning Regression Case_Second hand Car Price Prediction-X
    文章目录一、XGBoostAlgorithm二、ComparisonofalgorithmimplementationbetweenPythoncodeandSentosa_DSMLcommunityedition(1)Datareadingandstatisticalanalysis(2)dataprocessing(三)Featureselectionandcorrelationanalysis(4)Samplepartit......
  • 联想 进入bios u盘启动
    先插入u盘,再选择选项thinkpade485, f12快速选择启动选项 ,f1  进入bios    其他 联想进入bios设置u盘启动,网上的博客资料中有这样一句话:“7、在Startup栏目中,找到“UEFI/LegacyBoot”选项,设置为“LegacyOnly”,并将“CSMSupport”设置为“YES”,然后找到“B......
  • php- strpos(). substr()
    在PHP中,如果你想要以第一个引号(")为分隔符来分割字符串,并获取第一个分割部分,你可以使用strpos()和substr()函数组合来实现。下面是一个示例:<?php$urlString='https://app3"type="application/vnd.apple.mpegurl"';//找到第一个引号的位置$quotePosition=strpo......