* threads.c
* - Common Thread Control
*/
-#include <common.h>
+#include <acess.h>
#include <threads.h>
#include <errno.h>
void Threads_AddActive(tThread *Thread);
int Threads_GetPID();
int Threads_GetTID();
- int Threads_GetUID();
- int Threads_GetGID();
+tUID Threads_GetUID();
+ int Threads_SetUID(Uint *Errno, tUID ID);
+tGID Threads_GetGID();
+ int Threads_SetGID(Uint *Errno, tUID ID);
void Threads_Dump();
// === GLOBALS ===
}
/**
- * \fn tThread *Threads_int_GetPrev(tThread *List, tThread *Thread)
+ * \fn tThread *Threads_int_GetPrev(tThread **List, tThread *Thread)
* \brief Gets the previous entry in a thead linked list
*/
tThread *Threads_int_GetPrev(tThread **List, tThread *Thread)
/**
* \fn void Threads_Kill(tThread *Thread, int Status)
* \brief Kill a thread
- * \param TID Thread ID (0 for current)
+ * \param Thread Thread to kill
+ * \param Status Status code to return to the parent
*/
void Threads_Kill(tThread *Thread, int Status)
{
tThread *cur = Proc_GetCurThread();
tThread *thread;
- //Log("Proc_Sleep: %i going to sleep", cur->TID);
+ Log("Proc_Sleep: %i going to sleep", cur->TID);
// Acquire Spinlock
LOCK( &giThreadListLock );
// Get thread before current thread
thread = Threads_int_GetPrev( &gActiveThreads, cur );
if(!thread) {
- Warning("Proc_Sleep - Current thread is not on the active queue");
+ Warning("Threads_Sleep - Current thread is not on the active queue");
+ Threads_Dump();
return;
}
// Release Spinlock
RELEASE( &giThreadListLock );
- HALT();
+ while(cur->Status != THREAD_STAT_ACTIVE) HALT();
}
-/**c0108919:
+/**
* \fn void Threads_Wake( tThread *Thread )
* \brief Wakes a sleeping/waiting thread up
*/
#endif
// --- Process Structure Access Functions ---
-int Threads_GetPID()
+tPID Threads_GetPID()
{
return Proc_GetCurThread()->TGID;
}
-int Threads_GetTID()
+tTID Threads_GetTID()
{
return Proc_GetCurThread()->TID;
}
-int Threads_GetUID()
+tUID Threads_GetUID()
{
return Proc_GetCurThread()->UID;
}
-int Threads_GetGID()
+tGID Threads_GetGID()
{
return Proc_GetCurThread()->GID;
}
+int Threads_SetUID(Uint *Errno, tUID ID)
+{
+ tThread *t = Proc_GetCurThread();
+ if( t->UID != 0 ) {
+ *Errno = -EACCES;
+ return -1;
+ }
+ Log("Threads_SetUID - Setting User ID to %i", ID);
+ t->UID = ID;
+ return 0;
+}
+
+int Threads_SetGID(Uint *Errno, tGID ID)
+{
+ tThread *t = Proc_GetCurThread();
+ if( t->UID != 0 ) {
+ *Errno = -EACCES;
+ return -1;
+ }
+ Log("Threads_SetGID - Setting Group ID to %i", ID);
+ t->GID = ID;
+ return 0;
+}
+
/**
* \fn void Threads_Dump()
* \brief Dums a list of currently running threads
void Threads_Dump()
{
tThread *thread;
+ tThread *cur = Proc_GetCurThread();
Log("Active Threads:");
for(thread=gActiveThreads;thread;thread=thread->Next)
{
- Log(" %i (%i) - %s", thread->TID, thread->TGID, thread->ThreadName);
+ Log("%c%i (%i) - %s",
+ (thread==cur?'*':' '),
+ thread->TID, thread->TGID, thread->ThreadName);
Log(" %i Tickets, Quantum %i", thread->NumTickets, thread->Quantum);
Log(" KStack 0x%x", thread->KernelStack);
}
Log("Sleeping Threads:");
for(thread=gSleepingThreads;thread;thread=thread->Next)
{
- Log(" %i (%i) - %s", thread->TID, thread->TGID, thread->ThreadName);
+ Log("%c%i (%i) - %s",
+ (thread==cur?'*':' '),
+ thread->TID, thread->TGID, thread->ThreadName);
Log(" %i Tickets, Quantum %i", thread->NumTickets, thread->Quantum);
Log(" KStack 0x%x", thread->KernelStack);
}
Warning("Thread #%i committed a segfault at address %p", Proc_GetCurThread()->TID, Addr);
Threads_Exit( 0, -1 );
}
+
+// === EXPORTS ===
+EXPORT(Threads_GetUID);