Skip to content

Commit

Permalink
Rename plugin to "Thread List", use proper thread sizes, cleanup
Browse files Browse the repository at this point in the history
First, show as many threads as there are running on the system using OSCheckActiveThreads

Then, cleanup the NULL checks. They're good to have and some are overkill, but just in case, have them.

Third, rename to "Thread List". I feel like for the purpose of to a user it may be best to rename
this to "Process List" because that's what these are (I think), and it lines up with Rosalina's Process
List but the OS calls them "Threads", so, they are threads.
  • Loading branch information
ItzSwirlz committed May 7, 2024
1 parent 964f696 commit 14c962c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WUT_ROOT := $(DEVKITPRO)/wut
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#-------------------------------------------------------------------------------
TARGET := ThreadsViewer
TARGET := ThreadList
BUILD := build
SOURCES := src src/utils
DATA := data
Expand All @@ -30,12 +30,12 @@ INCLUDES := src
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(MACHDEP)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__

CXXFLAGS := $(CFLAGS)

ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUPSSPECS)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUPSSPECS)

ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
Expand All @@ -47,7 +47,7 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
endif

LIBS := -lwups -lwut
LIBS := -lwups -lwut

#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Threads Viewer
# Thread List

This is a plugin for [Aroma](https://github.com/wiiu-env/Aroma) that shows a list of active threads in the plugin menu.

**Note: This code is new and likely to break and have problems. It is a bit messy with excessive NULL checks. It will be cleaned up soon.**

## Installation

1. Copy the file `ThreadsViewer.wps` into `sd:/wiiu/environments/aroma/plugins`.
1. Copy the file `ThreadList.wps` into `sd:/wiiu/environments/aroma/plugins`.
2. Requires the [WiiUPluginLoaderBackend](https://github.com/wiiu-env/WiiUPluginLoaderBackend) in `sd:/wiiu/environments/aroma/modules`.

Start Aroma and the backend should load the plugin.
Expand Down
48 changes: 27 additions & 21 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,59 @@
Mandatory plugin information.
If not set correctly, the loader will refuse to use the plugin.
**/
WUPS_PLUGIN_NAME("Threads Viewer");
WUPS_PLUGIN_NAME("Thread List");
WUPS_PLUGIN_DESCRIPTION("Displays a list of active threads");
WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("ItzSwirlz, Maschell");
WUPS_PLUGIN_LICENSE("BSD");

WUPS_USE_WUT_DEVOPTAB(); // Use the wut devoptabs
WUPS_USE_STORAGE("threads_viewer"); // Unique id for the storage api
WUPS_USE_WUT_DEVOPTAB(); // Use the wut devoptabs
WUPS_USE_STORAGE("thread_list"); // Unique id for the storage api

WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle root) {
{
int sizeThreads = OSCheckActiveThreads();
if (sizeThreads == 0) {
DEBUG_FUNCTION_LINE_ERR("OSCheckActiveThreads() claims no threads are running. This should never happen.");
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}

OSThread *threads[sizeThreads];
OSThread *curThread = OSGetCurrentThread();
int state = OSDisableInterrupts();
int i = 0;

__OSLockScheduler(curThread);
OSThread *t = *((OSThread **) 0x100567F8); // active threadlist address
if(t == NULL) {
if (t == NULL) {
DEBUG_FUNCTION_LINE_ERR("The first thread obtained was NULL. This should never happen.");
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}

OSThread *threads[30]; // lets hope we dont have more than 100
int i = 0;

// threads are handled by a linked list.
// Since the scheduler is locked and interrupts are disabled, to save time,
// have a local array pointing to these threads instead of making new ones
// and holding up the system
while (t->activeLink.next != NULL && t != NULL && i < 30) {
while (t && i < sizeThreads) {
threads[i] = t;
if(t->activeLink.next == NULL) break;
t = t->activeLink.next;
i++;
}
__OSUnlockScheduler(curThread);
OSRestoreInterrupts(state);

if(threads[0] == NULL) {
if (!threads[0]) {
DEBUG_FUNCTION_LINE_ERR("The first thread obtained was NULL. This should never happen.");
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}
for (int i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) {

for (int i = 0; i < sizeThreads; i++) {
if (threads[i]) {
if(threads[i]->name != NULL) {
if (WUPSConfigItemStub_AddToCategory(root, threads[i]->name) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to add thread %d to the list", threads[i]->name);
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
};
if (threads[i]->name) {
if (WUPSConfigItemStub_AddToCategory(root, threads[i]->name) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to add thread %d to the list", threads[i]->name);
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
};
}
}
}
Expand All @@ -74,9 +80,9 @@ void ConfigMenuClosedCallback() {
INITIALIZE_PLUGIN() {
// Logging only works when compiled with `make DEBUG=1`. See the README for more information.
initLogging();
DEBUG_FUNCTION_LINE("INITIALIZE_PLUGIN of threads_viewer!");
DEBUG_FUNCTION_LINE("INITIALIZE_PLUGIN of thread_list!");

WUPSConfigAPIOptionsV1 configOptions = {.name = "Threads Viewer"};
WUPSConfigAPIOptionsV1 configOptions = {.name = "Thread List"};
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
}
Expand All @@ -90,7 +96,7 @@ INITIALIZE_PLUGIN() {
Gets called when the plugin will be unloaded.
**/
DEINITIALIZE_PLUGIN() {
DEBUG_FUNCTION_LINE("DEINITIALIZE_PLUGIN of threads_viewer!");
DEBUG_FUNCTION_LINE("DEINITIALIZE_PLUGIN of thread_list!");
}

/**
Expand All @@ -99,7 +105,7 @@ DEINITIALIZE_PLUGIN() {
ON_APPLICATION_START() {
initLogging();

DEBUG_FUNCTION_LINE("ON_APPLICATION_START of threads_viewer!");
DEBUG_FUNCTION_LINE("ON_APPLICATION_START of thread_list!");
}

/**
Expand All @@ -113,5 +119,5 @@ ON_APPLICATION_ENDS() {
Gets called when an application request to exit.
**/
ON_APPLICATION_REQUESTS_EXIT() {
DEBUG_FUNCTION_LINE_INFO("ON_APPLICATION_REQUESTS_EXIT of threads_viewer!");
DEBUG_FUNCTION_LINE_INFO("ON_APPLICATION_REQUESTS_EXIT of thread_list!");
}

0 comments on commit 14c962c

Please sign in to comment.