github.com/racerxdl/gonx@v0.0.0-20210103083128-c5afc43bcbd2/svc/tls.go (about)

     1  package svc
     2  
     3  // Default Handles
     4  const (
     5  	CurrentProcessHandle = 0xFFFF8001 /// Pseudo handle for the current process.
     6  	CurrentThreadHandle  = 0xFFFF8000 /// Pseudo handle for the current thread.
     7  )
     8  
     9  // TLS is the Nintendo Switch Thread Local Storage
    10  // this struct represents what the TLS space are in Horizon OS
    11  // More details: https://switchbrew.org/wiki/Thread_Local_Region
    12  type TLS struct {
    13  	// IPC command buffer.
    14  	IPCBuffer [0x40]uint32
    15  	// If userland sets this to non-zero, kernel will pin the thread and disallow calls to almost all SVCs.
    16  	DisableCounter uint16
    17  	// If a context switch would have occurred when user disable count was non-zero, kernel will set this to
    18  	// 1. This signifies that the user must call SynchronizePreemptionState to unpin itself and regain access other SVCs
    19  	InterruptFlag uint16
    20  	reserved0     uint32
    21  	reserved1     [0x78]uint8
    22  	tls           [0x50]uint8
    23  	LocalePointer uintptr
    24  	ErrnoVal      uintptr
    25  	ThreadData    uintptr
    26  	EhGlobals     uintptr
    27  	ThreadPointer uintptr
    28  	ThreadType    uintptr
    29  }
    30  
    31  // ClearIPCBuffer fills the IPC Buffer with zeroes
    32  func (tls *TLS) ClearIPCBuffer() {
    33  	for i := range tls.IPCBuffer {
    34  		tls.IPCBuffer[i] = 0
    35  	}
    36  }