Using notifications (notice_api.h)
The API is defined in the sysroot-*-kos/include/coresrv/handle/notice_api.h
header file from the KasperskyOS SDK.
The API can track events associated with (both system and user) resources, and inform other processes and threads about events involving user resources.
Information about API functions is provided in the table below.
Using the API
The notification mechanism uses an event mask. An event mask is a value whose bits are interpreted as events that should be tracked or that have already occurred. An event mask has a size of 32 bits and consists of a general part and a specialized part. The common part describes events that are not specific to any resources. The specialized part describes events that are specific to certain resources. Specialized part flags for system resources and common part flags are defined in the sysroot-*-kos/include/handle/event_descr.h
header file from KasperskyOS SDK. (For example, the common part flag EVENT_OBJECT_DESTROYED
signifies resource termination, and the specialized part flag EVENT_TASK_COMPLETED
signifies process termination.) Specialized part flags for a user resource are defined by the resource provider with the help of the OBJECT_EVENT_SPEC()
and OBJECT_EVENT_USER()
macros, which are defined in the sysroot-*-kos/include/handle/event_descr.h
header file from the KasperskyOS SDK. The resource provider must export the public header files describing the flags of the specialized part.
The standard scenario for receiving notifications about events associated with resources consists of the following steps:
- Creating a notification receiver (KasperskyOS kernel object that collects notifications) by calling the
KnNoticeCreate()
function.The notification receiver ID is the pointer to the
KosObject
containing the handle of the notification receiver (for details aboutKosObjects
, see Using KosObjects (objects.h)). Destruction of this object will cause the destruction of the notification receiver. If you need to create a copy of the notification receiver ID (for example, for use in another thread), you must increment the counter of links to theKosObject
by calling theKosRefObject()
function to ensure that this object exists while the created copy of the ID exists. If the copy of the notification receiver ID is no longer needed, you must decrement the counter of links to theKosObject
by calling theKosPutObject()
function to make sure that this object is destroyed if there are no other links. - Adding "resource—event mask" entries to the notification receiver to configure it to get notifications about events associated with relevant resources.
To add a "resource—event mask" entry to the notification receiver, you need to call the
KnNoticeSubscribeToObject()
function. (TheOCAP_HANDLE_GET_EVENT
flag should be set in the handle permissions mask of the resource stated in theobject
parameter.) Several "resource—event mask" entries can be added for one resource, and the entry identifiers do not need to be unique. Tracked events for each "resource—event mask" entry should be defined with an event mask that may match one or several events."Resource—event mask" entries added to the notification receiver can be fully or partially removed to prevent the receiver from getting notifications that match these entries. To remove all "resource—event mask" entries from the receiver, you need to call the
KnNoticeDropAndWake()
function. To remove from the receiver "resource—event mask" entries that refer to the same resource, you need to call theKnNoticeUnsubscribeFromObject()
function. To remove from the receiver a "resource—event mask" entry with a specific identifier, you need to call theKnNoticeUnsubscribeFromEvent()
function."Resource—event mask" entries can be added to the notification receiver or removed from it throughout the entire lifetime of this notification receiver.
- Extracting notifications from the receiver by using the
KnNoticeGetEvent()
orKnNoticeGetEventEx()
function.You can set the waiting time for notifications to appear in the receiver when calling the
KnNoticeGetEvent()
orKnNoticeGetEventEx()
function. Threads that are locked while waiting for notifications to appear in the receiver will resume when notifications appear, even if these notifications match "resource—event mask" entries that were added to the receiver during the waiting period.Threads that are locked while waiting for notifications to appear in the receiver will resume their execution and will not be locked upon subsequent calls of the
KnNoticeGetEvent()
orKnNoticeGetEventEx()
function if all "resource—event mask" entries are removed from this receiver by calling theKnNoticeDropAndWake()
function. If you add at least one "resource—event mask" entry to the notification receiver after calling theKnNoticeDropAndWake()
function, threads that get notifications from that receiver will be locked again onKnNoticeGetEvent()
orKnNoticeGetEventEx()
function calls for the defined waiting time as long as there are no notifications. If all "resource—event mask" entries are removed from the notification receiver by using theKnNoticeUnsubscribeFromObject()
and/orKnNoticeUnsubscribeFromEvent()
function, threads waiting for notifications to appear in the receiver will not resume until the timeout elapses, and they will be locked during the waiting period upon subsequent calls of theKnNoticeGetEvent()
orKnNoticeGetEventEx()
function. - Terminate operations with the notification receiver by calling the
KnNoticeRelease()
function.The
KnNoticeRelease()
function removes all "resource—event mask" entries from the notification receiver and makes it impossible to add new ones. Threads that are locked while waiting for notifications to appear in the receiver will resume their execution and will not be locked upon subsequent calls of theKnNoticeGetEvent()
orKnNoticeGetEventEx()
function. In addition, theKnNoticeRelease()
function decrements the counter of links to theKosObject
containing the handle of the notification receiver. If there are no other links to this object, the notification receiver will be destroyed. Otherwise, the notification receiver will exist until all other links are deleted.
To notify other processes and/or threads about events associated with the user resource, you need to call the KnNoticeSetObjectEvent()
function. Calling the function results in notifications appearing in receivers configured to get events defined with the evMask
parameter and associated with the user resource defined with the object
parameter. You cannot set flags of the general part of an event mask in the evMask
parameter, because only the kernel can signal about events that match the general part of an event mask. If the process calling the KnNoticeSetObjectEvent()
function created the user resource handle stated in the object
parameter, you can set flags defined by the OBJECT_EVENT_SPEC()
and OBJECT_EVENT_USER()
macros in the evMask
parameter. If the process calling the KnNoticeSetObjectEvent()
function received the user resource handle stated in the object
parameter from another process, you can set only those flags defined by the OBJECT_EVENT_USER()
macro in the evMask
parameter, while the permissions mask of the resulting handle must have a OCAP_HANDLE_SET_EVENT
flag set.
Information about API functions
notice_api.h functions
Function |
Information about the function |
---|---|
|
Purpose Creates a notification receiver. Parameters
Returned values If successful, the function returns |
|
Purpose Adds a "resource–event mask" entry to the notification receiver so that it can receive notifications about events associated with the defined resource and match the defined event mask. Parameters
Returned values If successful, the function returns |
|
Purpose Extracts notifications from the receiver. Parameters
Returned values If successful, the function returns If the time-out for notifications to appear in the receiver has elapsed, returns If all "resource—event mask" entries are removed from the notification receiver by calling the |
|
Purpose Extracts notifications from the receiver. Parameters
Returned values If successful, the function returns If the time-out for notifications to appear in the receiver has elapsed, returns If all "resource—event mask" entries are removed from the notification receiver by calling the |
|
Purpose Removes from the notification receiver "resource—event mask" entries that match the specified resource to prevent the receiver from getting notifications about events that match these entries. Parameters
Returned values If successful, the function returns Additional information Notifications that correspond to the removed "resource—event mask" entries will be removed from the receiver. |
|
Purpose Removes from the notification receiver "resource—event mask" entries with the specified identifier to prevent the receiver from getting notifications about events that match these entries. Parameters
Returned values If successful, the function returns Additional information Notifications that correspond to the removed "resource—event mask" entries will be removed from the receiver. |
|
Purpose Removes all "resource—event mask" entries from the specified notification receiver and resumes all threads that are waiting for notifications to appear in the specified receiver. Parameters
Returned values If successful, the function returns |
|
Purpose Removes all "resource—event mask" entries from the specified notification receiver and makes it impossible to add new ones, resumes all threads waiting for notifications to appear in the specified receiver, and decrements the counter of links to the Parameters
Returned values If successful, the function returns |
|
Purpose Signals the occurrence of events that are related to the defined user resource and match the defined event mask. Parameters
Returned values If successful, the function returns |