Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add start module handler #70

Open
TheOfficialFloW opened this issue Jun 17, 2017 · 8 comments
Open

Add start module handler #70

TheOfficialFloW opened this issue Jun 17, 2017 · 8 comments

Comments

@TheOfficialFloW
Copy link
Contributor

Provide kernel and user export for registering handlers that capture the moment a module is started.
Here is an example of how this can be done: TheOfficialFloW@f864363
(This however does not capture kernel module loads yet)

@TheOfficialFloW
Copy link
Contributor Author

It might be a good idea to capture both start and stop of a module, so that we can easily hook/release specific patches.

@yifanlu
Copy link
Owner

yifanlu commented Jun 24, 2017

Realistically I won't have the time to implement (& test) this feature.

@TheOfficialFloW
Copy link
Contributor Author

If you describe how you imagine the implementation of this feature, I can do it.

@yifanlu
Copy link
Owner

yifanlu commented Jun 25, 2017

I'm not sure what you want though. A callback before and after module_stop/module_stop?

@TheOfficialFloW
Copy link
Contributor Author

Exactly

@yifanlu
Copy link
Owner

yifanlu commented Jun 26, 2017

Isn't it possible to just hook the module_start export before calling start module?

@TheOfficialFloW
Copy link
Contributor Author

TheOfficialFloW commented Jun 29, 2017

The idea is that we invoke our callback at module_start/stop of every module. If you just hook the module_start export, you'd need to to it after the module is loaded but not yet started, so this won't be any different than manually hook load/start...
The reason we need this is because there are at least 6 different methods to load modules and if you want to hook many weak imports you'd need to hook all these functions which is a waste...

If you still can't imagine what I'm meaning, there exists the same API for PSP CFW: sctrlHENSetStartModuleHandler

@yifanlu
Copy link
Owner

yifanlu commented Jun 29, 2017

I see. Can we generalize it and not worry about module_start/stop? So we currently have hooks and injections. How about we add a third category called "events" and we can have int taiEventsAddHandlerForKernel(int pid, tai_event_t event, tai_event_callback_t handler); which returns a uid and taiEventsRemoveHandlerForKernel(int uid);

Then we have

typedef enum _tai_event {
  TAI_EVENT_MODULE_LOAD,
  TAI_EVENT_MODULE_START,
  TAI_EVENT_MODULE_STOP,
  TAI_EVENT_MODULE_UNLOAD,
  TAI_EVENT_MAX
} tai_event_t;

typedef struct _tai_event_module_start {
  tai_event_t event;
  SceUID modid;
  // other useful params
  SceSize args; // from module_start
  void *argp; // from module_start
} tai_event_module_start_t;

typedef struct _tai_event_module_stop {
  tai_event_t event;
  SceUID modid;
  // other useful params
  SceSize args; // from module_stop
  void *argp; // from module_stop
} tai_event_module_stop_t;

// and so on...

typedef union _tai_event_args {
  tai_event_t event;
  tai_event_module_load_t module_load_event;
  tai_event_module_start_t module_start_event;
  tai_event_module_stop_t module_stop_event;
  tai_event_module_unload_t module_unload_event;
} tai_event_args_t;

typedef void (*tai_event_callback_t)(tai_event_args_t *args);

Implementation wise, I think we can have a hashmap of PID to event handler mappings. Each value will point to a static array of size TAI_EVENT_MAX where each array element is a linked list of handlers.

To trigger an event, we just look up the PID in O(1), and then index in the array in O(1) and then call each O(N) handlers.

You can use the same callback function to handle multiple events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants