libnx  v4.7.0
Data Structures | Macros | Functions
sm.h File Reference

Service manager (sm) IPC wrapper. More...

#include "../types.h"
#include "../kernel/svc.h"
#include "../sf/service.h"
#include "../sf/tipc.h"

Go to the source code of this file.

Data Structures

struct  SmServiceName
 Structure representing a service name (null terminated, remaining characters set to zero). More...
 

Macros

#define __COPY_CHAR(_n)    if (len > _n) name_encoded.name[_n] = name[_n]
 

Functions

static u64 smServiceNameToU64 (SmServiceName name)
 Converts a service name into a 64-bit integer.
 
static SmServiceName smServiceNameFromU64 (u64 name)
 Converts a 64-bit integer into a service name.
 
static bool smServiceNamesAreEqual (SmServiceName a, SmServiceName b)
 Checks whether two service names are equal. More...
 
static SmServiceName smEncodeName (const char *name)
 Encodes a service name string as a SmServiceName structure. More...
 
Result smInitialize (void)
 Initializes SM. More...
 
void smExit (void)
 Uninitializes SM. More...
 
Result smGetServiceWrapper (Service *service_out, SmServiceName name)
 Requests a service from SM, allowing overrides. More...
 
Result smGetServiceOriginal (Handle *handle_out, SmServiceName name)
 Requests a service from SM, as an IPC session handle directly. More...
 
static Result smGetService (Service *service_out, const char *name)
 Requests a service from SM. More...
 
Handle smGetServiceOverride (SmServiceName name)
 Retrieves an overriden service in the homebrew environment. More...
 
Result smRegisterService (Handle *handle_out, SmServiceName name, bool is_light, s32 max_sessions)
 Creates and registers a new service within SM. More...
 
Result smRegisterServiceCmif (Handle *handle_out, SmServiceName name, bool is_light, s32 max_sessions)
 Same as smRegisterService, but always using cmif serialization.
 
Result smRegisterServiceTipc (Handle *handle_out, SmServiceName name, bool is_light, s32 max_sessions)
 Same as smRegisterService, but always using tipc serialization.
 
Result smUnregisterService (SmServiceName name)
 Unregisters a previously registered service in SM. More...
 
Result smUnregisterServiceCmif (SmServiceName name)
 Same as smUnregisterService, but always using cmif serialization.
 
Result smUnregisterServiceTipc (SmServiceName name)
 Same as smUnregisterService, but always using tipc serialization.
 
Result smDetachClient (void)
 Detaches the current SM session. More...
 
Result smDetachClientCmif (void)
 Same as smDetachClient, but always using cmif serialization.
 
Result smDetachClientTipc (void)
 Same as smDetachClient, but always using tipc serialization.
 
ServicesmGetServiceSession (void)
 Gets the Service session used to communicate with SM. More...
 
TipcServicesmGetServiceSessionTipc (void)
 Gets the TipcService session used to communicate with SM. More...
 
void smAddOverrideHandle (SmServiceName name, Handle handle)
 Overrides a service with a custom IPC service handle. More...
 

Detailed Description

Service manager (sm) IPC wrapper.

Author
plutoo
yellows8

Function Documentation

◆ smAddOverrideHandle()

void smAddOverrideHandle ( SmServiceName  name,
Handle  handle 
)

Overrides a service with a custom IPC service handle.

Parameters
[in]nameName of the service.
[in]handleIPC session handle.

◆ smDetachClient()

Result smDetachClient ( void  )

Detaches the current SM session.

Note
After this function is called, the rest of the SM API cannot be used.
Only available on [11.0.0-11.0.1], or Atmosphère.

◆ smEncodeName()

static SmServiceName smEncodeName ( const char *  name)
inlinestatic

Encodes a service name string as a SmServiceName structure.

Parameters
[in]nameName of the service.
Returns
Encoded name.

◆ smExit()

void smExit ( void  )

Uninitializes SM.

Returns
Result code.
Note
This function is already handled in the default application exit code (after main() returns).

◆ smGetService()

static Result smGetService ( Service service_out,
const char *  name 
)
inlinestatic

Requests a service from SM.

Parameters
[out]service_outService structure which will be filled in.
[in]nameName of the service to request (as a string).
Returns
Result code.

◆ smGetServiceOriginal()

Result smGetServiceOriginal ( Handle handle_out,
SmServiceName  name 
)

Requests a service from SM, as an IPC session handle directly.

Parameters
[out]handle_outVariable containing IPC session handle.
[in]nameName of the service to request.
Returns
Result code.

◆ smGetServiceOverride()

Handle smGetServiceOverride ( SmServiceName  name)

Retrieves an overriden service in the homebrew environment.

Parameters
[in]nameName of the service to request.
Returns
IPC session handle.

◆ smGetServiceSession()

Service* smGetServiceSession ( void  )

Gets the Service session used to communicate with SM.

Returns
Pointer to service session used to communicate with SM.

◆ smGetServiceSessionTipc()

TipcService* smGetServiceSessionTipc ( void  )

Gets the TipcService session used to communicate with SM.

Returns
Pointer to tipc service session used to communicate with SM.
Note
Only available on [12.0.0+], or Atmosphère.

◆ smGetServiceWrapper()

Result smGetServiceWrapper ( Service service_out,
SmServiceName  name 
)

Requests a service from SM, allowing overrides.

Parameters
[out]service_outService structure which will be filled in.
[in]nameName of the service to request.
Returns
Result code.

◆ smInitialize()

Result smInitialize ( void  )

Initializes SM.

Returns
Result code.
Note
This function is already called in the default application startup code (before main() is called).

◆ smRegisterService()

Result smRegisterService ( Handle handle_out,
SmServiceName  name,
bool  is_light,
s32  max_sessions 
)

Creates and registers a new service within SM.

Parameters
[out]handle_outVariable containing IPC port handle.
[in]nameName of the service.
[in]is_light"Is light"
[in]max_sessionsMaximum number of concurrent sessions that the service will accept.
Returns
Result code.

◆ smServiceNamesAreEqual()

static bool smServiceNamesAreEqual ( SmServiceName  a,
SmServiceName  b 
)
inlinestatic

Checks whether two service names are equal.

Parameters
[in]aFirst name.
[in]bSecond name.
Returns
Comparison result.

◆ smUnregisterService()

Result smUnregisterService ( SmServiceName  name)

Unregisters a previously registered service in SM.

Parameters
[in]nameName of the service.
Returns
Result code.