/*
* Copyright ( c ) 2013 Google Inc . All rights reserved
*
* Permission is hereby granted , free of charge , to any person obtaining
* a copy of this software and associated documentation files
* ( the " Software " ) , to deal in the Software without restriction ,
* including without limitation the rights to use , copy , modify , merge ,
* publish , distribute , sublicense , and / or sell copies of the Software ,
* and to permit persons to whom the Software is furnished to do so ,
* subject to the following conditions :
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND ,
* EXPRESS OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT .
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT ,
* TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
*/
#pragma once
#include <lk/compiler.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/uio.h>
#include <uapi/trusty_ipc.h>
#include <uapi/trusty_peer_id.h>
#include <uapi/trusty_uuid.h>
__BEGIN_CDECLS
/*
* handle_t is an opaque 32 bit value that is used to reference an
* object ( like ipc port or channel ) in kernel space
*/
typedef int32_t handle_t;
/*
* Invalid IPC handle
*/
#define INVALID_IPC_HANDLE ((handle_t)-1 )
/*
* Specify this timeout value to wait forever .
*/
#define INFINITE_TIME UINT32_MAX
/*
* The Trusty driver uses a 4096 - byte shared buffer to transfer messages .
* However , the virtio / TIPC bridge overestimates the portion of the buffer
* available to it . Specifically , it does not account for the TIPC headers
* and the FDs being transferred . We reserve some of the buffer here to
* account for this . The reserved size is chosen to allow room for the
* TIPC header ( 16 bytes ) , 8 x FD ( 24 bytes ) , plus some margin .
*/
#define TIPC_HDR_AND_FDS_MAX_SIZE 256
#define VIRTIO_VSOCK_MSG_SIZE_LIMIT (4096 - TIPC_HDR_AND_FDS_MAX_SIZE)
/*
* Combination of these flags sets additional options
* for port_create syscall .
*/
enum {
/* allow Trusted Apps to connect to this port */
IPC_PORT_ALLOW_TA_CONNECT = 0 x1,
/* allow non-secure clients to connect to this port */
IPC_PORT_ALLOW_NS_CONNECT = 0 x2,
};
/*
* Options for connect syscall
*/
enum {
IPC_CONNECT_WAIT_FOR_PORT = 0 x1,
IPC_CONNECT_ASYNC = 0 x2,
};
/*
* IPC message
*/
typedef struct ipc_msg {
uint32_t num_iov;
struct iovec* iov;
uint32_t num_handles;
handle_t* handles;
} ipc_msg_t;
typedef struct ipc_msg_info {
size_t len;
uint32_t id;
uint32_t num_handles;
} ipc_msg_info_t;
/*
* Combination of these values is used for event field
* ot uevent_t structure .
*/
enum {
IPC_HANDLE_POLL_NONE = 0 x0,
IPC_HANDLE_POLL_READY = 0 x1,
IPC_HANDLE_POLL_ERROR = 0 x2,
IPC_HANDLE_POLL_HUP = 0 x4,
IPC_HANDLE_POLL_MSG = 0 x8,
IPC_HANDLE_POLL_SEND_UNBLOCKED = 0 x10,
};
/*
* Values for cmd parameter of handle_set_ctrl call .
* These should be kept in sync with # defines in handle_set . h
*/
enum {
HSET_ADD = 0 x0, /* adds new handle to handle set */
HSET_DEL = 0 x1, /* deletes handle from handle set */
HSET_MOD = 0 x2, /* modifies handle attributes in handle set */
HSET_DEL_GET_COOKIE =
0 x3, /* deletes a handle from handle set and returns its cookie */
HSET_DEL_WITH_COOKIE = 0 x4, /* like `HSET_DEL`, but requires the passed in
cookie to match the stored one */
HSET_MOD_WITH_COOKIE = 0 x5, /* like `HSET_MOD`, but requires the passed in
cookie to match the stored one */
};
/*
* Is used by wait and wait_any calls to return information
* about event .
*/
typedef struct uevent {
handle_t handle; /* handle this event is related too */
uint32_t event; /* combination of IPC_HANDLE_POLL_XXX flags */
void * cookie; /* cookie aasociated with handle */
} uevent_t;
#define UEVENT_INITIAL_VALUE(event) \
{ 0 , 0 , 0 }
handle_t port_create(const char * path,
uint32_t num_recv_bufs,
uint32_t recv_buf_size,
uint32_t flags);
handle_t trusty_connect(const char * path, uint32_t flags);
handle_t trusty_accept(handle_t handle, uuid_t* peer_uuid);
handle_t accept2(handle_t handle, struct trusty_peer_id *peer_id, uint32_t* peer_id_size);
int close(handle_t handle);
int set_cookie(handle_t handle, void * cookie);
handle_t handle_set_create(void );
int handle_set_ctrl(handle_t handle, uint32_t cmd, struct uevent* evt);
int trusty_handle_wait(handle_t handle, uevent_t* event, uint32_t timeout_msecs);
int wait_any(uevent_t* event, uint32_t timeout_msecs);
int get_msg(handle_t handle, ipc_msg_info_t* msg_info);
ssize_t read_msg(handle_t handle,
uint32_t msg_id,
uint32_t offset,
ipc_msg_t* msg);
int put_msg(handle_t handle, uint32_t msg_id);
ssize_t send_msg(handle_t handle, ipc_msg_t* msg);
handle_t dup(handle_t handle);
/*
* The legacy trusty functions below are incompatible with POSIX . Code that
* needs to use or include the POSIX version of these functions should define
* TRUSTY_AVOID_POSIX_CONFLICTS before including any headers to disable these
* compatibility wrappers .
*/
#if !TRUSTY_AVOID_POSIX_CONFLICTS
static inline handle_t accept(handle_t handle, uuid_t* peer_uuid) {
return trusty_accept(handle, peer_uuid);
}
static inline handle_t connect(const char * path, uint32_t flags) {
return trusty_connect(path, flags);
}
static inline int wait(handle_t handle,
uevent_t* event,
uint32_t timeout_msecs) {
return trusty_handle_wait(handle, event, timeout_msecs);
}
#endif
__END_CDECLS
Messung V0.5 in Prozent C=92 H=96 G=93
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-06-27)
¤
*© Formatika GbR, Deutschland