pyplugins.apis.events module

Events API Plugin

This plugin provides a generic interface for handling hypercall-based events in the penguin system. It maps event numbers (MAGIC values) to named events and their argument types, sets up hypercall handlers, and allows other plugins to register callbacks for these events.

Purpose

  • Maps hypercall event numbers to named events and argument types.

  • Sets up hypercall handlers that parse arguments and publish events.

  • Allows plugins to register for named events and receive parsed arguments.

Usage

This plugin is loaded automatically as part of the penguin plugin system. Other plugins can register for named events (e.g., igloo_open, igloo_string_cmp) and receive callbacks with parsed arguments.

Event Format

Each event is published with the parsed arguments as specified in the EVENTS mapping.

EVENTS = {
    MAGIC_NUMBER: ('event_name', (arg_type1, arg_type2, ...)),
    ...
}

For example:

0xB335A535: ('igloo_send_hypercall', (None, int, int)),

Example

from penguin import plugins

def on_open(cpu, filename, flags):
    print(f"Open: {filename} (flags={flags})")

plugins.subscribe(plugin_instance, "igloo_open", on_open)
class pyplugins.apis.events.Events[source]

Bases: Plugin

Events Plugin

Handles hypercall-based events and publishes them as named events for other plugins to subscribe to.

Features

  • Registers all known event names for notification.

  • Sets up hypercall handlers for each event.

  • Publishes events with parsed arguments to subscribers.

register_notify(name, callback)[source]

Register a callback for an event.

Parameters

namestr

The event name.

callbackcallable

The callback function to register.

Registers the callback for the specified event name. Raises a ValueError if the event name is not found.