Skip to content

Commit 32d04a0

Browse files
Pataterbulislaw
authored andcommitted
RTX5: uVisor: Add OsEventObserver
Add the OsEventObserver mechanism. A client interested in receiving notifications on certain OS events can register to receive notifications with osRegisterForOsEvents. This is useful for clients like the secure memory allocator, which observes thread switching events in order to swap in and out different memory allocator objects.
1 parent 86b91be commit 32d04a0

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2013-2016 ARM Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* -----------------------------------------------------------------------------
19+
*
20+
* Project: CMSIS-RTOS RTX
21+
* Title: OS Event Observer
22+
*
23+
* -----------------------------------------------------------------------------
24+
*/
25+
#include "rt_OsEventObserver.h"
26+
27+
/*
28+
* _____ _____ ____ __ _____
29+
* | ___|_ _\ \/ / \/ | ____|
30+
* | |_ | | \ /| |\/| | _|
31+
* | _| | | / \| | | | |___
32+
* |_| |___/_/\_\_| |_|_____|
33+
*
34+
* FIXME:
35+
* The osEventObs variable must be in protected memory. If not every box
36+
* and box 0 can modify osEventObs to point to any handler to run code
37+
* privileged. This issue is tracked at
38+
* <https://github.com/ARMmbed/uvisor/issues/235>.
39+
*/
40+
const OsEventObserver *osEventObs;
41+
42+
void osRegisterForOsEvents(const OsEventObserver *observer)
43+
{
44+
static uint8_t has_been_called = 0;
45+
if (has_been_called) {
46+
return;
47+
}
48+
has_been_called = 1;
49+
50+
osEventObs = observer;
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2013-2016 ARM Limited. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the License); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
14+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* -----------------------------------------------------------------------------
19+
*
20+
* Project: CMSIS-RTOS RTX
21+
* Title: OS Event Observer
22+
*
23+
* -----------------------------------------------------------------------------
24+
*/
25+
#ifndef _RT_OS_EVENT_OBSERVER_H
26+
#define _RT_OS_EVENT_OBSERVER_H
27+
28+
#include <stdint.h>
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
typedef struct {
35+
uint32_t version;
36+
void (*pre_start)(void);
37+
void *(*thread_create)(int thread_id, void *context);
38+
void (*thread_destroy)(void *context);
39+
void (*thread_switch)(void *context);
40+
} OsEventObserver;
41+
extern const OsEventObserver *osEventObs;
42+
43+
void osRegisterForOsEvents(const OsEventObserver *observer);
44+
45+
#ifdef __cplusplus
46+
};
47+
#endif
48+
49+
#endif
50+
51+
/** @}*/

0 commit comments

Comments
 (0)