vita: switch to princesslog, try to fix video

vita
AAGaming 8 months ago
parent 3bd3293226
commit e72aee016d
Signed by: aa
GPG Key ID: 3050166AC290BDF5

5
.gitmodules vendored

@ -18,4 +18,7 @@
url = https://git.sr.ht/~thestr4ng3r/borealis
[submodule "scripts/vita/parse_core"]
path = scripts/vita/parse_core
url = https://github.com/xyzz/vita-parse-core
url = https://github.com/xyzz/vita-parse-core
[submodule "vita/third_party/tomlc99"]
path = vita/third_party/tomlc99
url = https://github.com/cktan/tomlc99.git

@ -20,15 +20,15 @@ typedef SOCKET chiaki_socket_t;
#define CHIAKI_SOCKET_ERROR_FMT "%d"
#define CHIAKI_SOCKET_ERROR_VALUE (WSAGetLastError())
#define CHIAKI_SOCKET_EINPROGRESS (WSAGetLastError() == WSAEWOULDBLOCK)
#elif defined(__PSVITA__)
#include <psp2/net/net.h>
typedef int chiaki_socket_t;
#define CHIAKI_SOCKET_IS_INVALID(s) ((s) < 0)
#define CHIAKI_INVALID_SOCKET (-1)
#define CHIAKI_SOCKET_CLOSE(s) sceNetSocketClose (s)
#define CHIAKI_SOCKET_ERROR_FMT "0x%x"
#define CHIAKI_SOCKET_ERROR_VALUE (errno)
#define CHIAKI_SOCKET_EINPROGRESS (errno == SCE_NET_EINPROGRESS)
// #elif defined(__PSVITA__)
// #include <psp2/net/net.h>
// typedef int chiaki_socket_t;
// #define CHIAKI_SOCKET_IS_INVALID(s) ((s) < 0)
// #define CHIAKI_INVALID_SOCKET (-1)
// #define CHIAKI_SOCKET_CLOSE(s) sceNetSocketClose (s)
// #define CHIAKI_SOCKET_ERROR_FMT "0x%x"
// #define CHIAKI_SOCKET_ERROR_VALUE (errno)
// #define CHIAKI_SOCKET_EINPROGRESS (errno == SCE_NET_EINPROGRESS)
#else
#include <unistd.h>
#include <errno.h>

@ -35,9 +35,9 @@ typedef struct chiaki_stop_pipe_t
#else
int fds[2];
#endif
#ifdef __PSVITA__
int epoll_fd;
#endif
// #ifdef __PSVITA__
// int epoll_fd;
// #endif
} ChiakiStopPipe;
struct sockaddr;

@ -365,7 +365,11 @@ static void *ctrl_thread_func(void *user)
break;
}
int received = recv(ctrl->sock, ctrl->recv_buf + ctrl->recv_buf_size, sizeof(ctrl->recv_buf) - ctrl->recv_buf_size, 0);
// #ifdef __PSVITA__
// int received = sceNetRecv(ctrl->sock, ctrl->recv_buf + ctrl->recv_buf_size, sizeof(ctrl->recv_buf) - ctrl->recv_buf_size, 0);
// #else
int received = recv(ctrl->sock, ctrl->recv_buf + ctrl->recv_buf_size, sizeof(ctrl->recv_buf) - ctrl->recv_buf_size, 0);
// #endif
if(received <= 0)
{
if(received < 0)
@ -418,7 +422,11 @@ static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, uint16_t type, const
*((uint16_t *)(header + 4)) = htons(type);
*((uint16_t *)(header + 6)) = 0;
int sent = send(ctrl->sock, header, sizeof(header), 0);
// #ifdef __PSVITA__
// int sent = sceNetSend(ctrl->sock, header, sizeof(header), 0);
// #else
int sent = send(ctrl->sock, header, sizeof(header), 0);
// #endif
if(sent < 0)
{
CHIAKI_LOGE(ctrl->session->log, "Failed to send Ctrl Message Header");
@ -427,7 +435,11 @@ static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, uint16_t type, const
if(enc)
{
sent = send(ctrl->sock, enc, payload_size, 0);
// #ifdef __PSVITA__
// sent = sceNetSend(ctrl->sock, enc, payload_size, 0);
// #else
sent = send(ctrl->sock, enc, payload_size, 0);
// #endif
free(enc);
if(sent < 0)
{
@ -730,11 +742,11 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
return CHIAKI_ERR_INVALID_DATA;
}
#ifdef __PSVITA__
chiaki_socket_t sock = sceNetSocket("", sa->sa_family, SCE_NET_SOCK_STREAM, SCE_NET_IPPROTO_IP);
#else
// #ifdef __PSVITA__
// chiaki_socket_t sock = sceNetSocket("", sa->sa_family, SCE_NET_SOCK_STREAM, SCE_NET_IPPROTO_IP);
// #else
chiaki_socket_t sock = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
#endif
// #endif
if(CHIAKI_SOCKET_IS_INVALID(sock))
{
CHIAKI_LOGE(session->log, "Session ctrl socket creation failed.");
@ -892,11 +904,11 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
CHIAKI_LOGI(session->log, "Sending ctrl request");
chiaki_log_hexdump(session->log, CHIAKI_LOG_VERBOSE, (const uint8_t *)buf, (size_t)request_len);
#ifdef __PSVITA__
int sent = sceNetSend(sock, buf, request_len, 0);
#else
// #ifdef __PSVITA__
// int sent = sceNetSend(sock, buf, request_len, 0);
// #else
int sent = send(sock, buf, (size_t)request_len, 0);
#endif
// #endif
if(sent < 0)
{
CHIAKI_LOGE(session->log, "Failed to send ctrl request");

@ -149,11 +149,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
discovery->log = log;
#ifdef __PSVITA__
discovery->socket = sceNetSocket("", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
#else
// #ifdef __PSVITA__
// discovery->socket = sceNetSocket("", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
// #else
discovery->socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
// #endif
if(CHIAKI_SOCKET_IS_INVALID(discovery->socket))
{
CHIAKI_LOGE(discovery->log, "Discovery failed to create socket");
@ -169,11 +169,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
discovery->local_addr.sa_family = family;
if(family == AF_INET6)
{
#ifndef __SWITCH__
#if !(defined(__SWITCH__) || defined(__PSVITA__))
struct in6_addr anyaddr = IN6ADDR_ANY_INIT;
#endif
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)&discovery->local_addr;
#ifndef __SWITCH__
#if !(defined(__SWITCH__) || defined(__PSVITA__))
addr->sin6_addr = anyaddr;
#endif
addr->sin6_port = htons(port);
@ -185,11 +185,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
addr->sin_port = htons(port);
}
#ifdef __PSVITA__
r = sceNetBind(discovery->socket, (SceNetSockaddr*) &discovery->local_addr, sizeof(discovery->local_addr));
#else
// #ifdef __PSVITA__
// r = sceNetBind(discovery->socket, (SceNetSockaddr*) &discovery->local_addr, sizeof(discovery->local_addr));
// #else
r = bind(discovery->socket, &discovery->local_addr, sizeof(discovery->local_addr));
#endif
// #endif
if(r >= 0 || !port)
break;
if(port == CHIAKI_DISCOVERY_PORT_LOCAL_MAX)
@ -214,11 +214,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery,
}
const int broadcast = 1;
#ifdef __PSVITA__
r = sceNetSetsockopt(discovery->socket, SCE_NET_SOL_SOCKET, SCE_NET_SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast));
#else
// #ifdef __PSVITA__
// r = sceNetSetsockopt(discovery->socket, SCE_NET_SOL_SOCKET, SCE_NET_SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast));
// #else
r = setsockopt(discovery->socket, SOL_SOCKET, SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast));
#endif
// #endif
if(r < 0)
CHIAKI_LOGE(discovery->log, "Discovery failed to setsockopt SO_BROADCAST");
@ -276,7 +276,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThrea
ChiakiErrorCode err = chiaki_stop_pipe_init(&thread->stop_pipe);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(discovery->log, "Discovery (thread) failed to create pipe");
CHIAKI_LOGE(discovery->log, "Discovery (thread) failed to create pipe %d", err);
return err;
}
@ -322,11 +322,11 @@ static void *discovery_thread_func(void *user)
char buf[512];
struct sockaddr client_addr;
socklen_t client_addr_size = sizeof(client_addr);
#ifdef __PSVITA__
int n = sceNetRecvfrom(discovery->socket, buf, sizeof(buf) - 1, 0, (SceNetSockaddr*) &client_addr, &client_addr_size);
#else
// #ifdef __PSVITA__
// int n = sceNetRecvfrom(discovery->socket, buf, sizeof(buf) - 1, 0, (SceNetSockaddr*) &client_addr, &client_addr_size);
// #else
int n = recvfrom(discovery->socket, buf, sizeof(buf) - 1, 0, &client_addr, &client_addr_size);
#endif
// #endif
if(n < 0)
{
CHIAKI_LOGE(discovery->log, "Discovery thread failed to read from socket");

@ -121,6 +121,7 @@ static void *discovery_service_thread_func(void *user)
{
err = chiaki_bool_pred_cond_timedwait(&service->stop_cond, service->options.ping_ms);
if(err != CHIAKI_ERR_TIMEOUT) {
CHIAKI_LOGE(service->log, "Discovery Service thread err %d", err);
break;
}
discovery_service_ping(service);
@ -162,8 +163,13 @@ static void discovery_service_ping(ChiakiDiscoveryService *service)
packet.protocol_version = CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS5;
if(service->options.send_addr->sa_family == AF_INET)
((struct sockaddr_in *)service->options.send_addr)->sin_port = htons(CHIAKI_DISCOVERY_PORT_PS5);
else // if(service->options.send_addr->sa_family == AF_INET6)
else if(service->options.send_addr->sa_family == AF_INET6)
((struct sockaddr_in6 *)service->options.send_addr)->sin6_port = htons(CHIAKI_DISCOVERY_PORT_PS5);
else
{
CHIAKI_LOGE(service->log, "Discovery Service send_addr has unknown sa_family");
return;
}
err = chiaki_discovery_send(&service->discovery, &packet, service->options.send_addr, service->options.send_addr_size);
if(err != CHIAKI_ERR_SUCCESS)
CHIAKI_LOGE(service->log, "Discovery Service failed to send ping for PS5, error was %s (%d)", chiaki_error_string(err), err);

@ -23,8 +23,8 @@ CHIAKI_EXPORT void chiaki_stream_stats_frame(ChiakiStreamStats *stats, uint64_t
{
stats->frames++;
stats->bytes += size;
//float br = (float)chiaki_stream_stats_bitrate(stats, 60) / 1000000.0f;
//CHIAKI_LOGD(NULL, "bitrate: %f", br);
float br = (float)chiaki_stream_stats_bitrate(stats, 60) / 1000000.0f;
CHIAKI_LOGD(NULL, "bitrate: %f", br);
}
CHIAKI_EXPORT uint64_t chiaki_stream_stats_bitrate(ChiakiStreamStats *stats, uint64_t framerate)
@ -170,9 +170,10 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_frame_processor_put_unit(ChiakiFrameProcess
{
CHIAKI_LOGW(frame_processor->log, "Received duplicate unit");
return CHIAKI_ERR_INVALID_DATA;
} else {
unit->data_size = packet->data_size;
}
unit->data_size = packet->data_size;
if(!frame_processor->flushed)
{
memcpy(frame_processor->frame_buf + packet->unit_index * frame_processor->buf_stride_per_unit,

@ -146,7 +146,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_recv_http_header(int sock, char *buf, size_
return err;
}
int received = (int)recv(sock, buf, (int)buf_size, 0);
// #ifdef __PSVITA__
// int received = (int)sceNetRecv(sock, buf, (int)buf_size, 0);
// #else
int received = (int)recv(sock, buf, (int)buf_size, 0);
// #endif
if(received <= 0)
return received == 0 ? CHIAKI_ERR_DISCONNECTED : CHIAKI_ERR_NETWORK;

@ -286,11 +286,11 @@ static void *regist_thread_func(void *user)
CHIAKI_LOGI(regist->log, "Regist connected to %s, sending request", regist->info.host);
#ifdef __PSVITA__
int s = sceNetSend(sock, request_header, request_header_size, 0);
#else
// #ifdef __PSVITA__
// int s = sceNetSend(sock, request_header, request_header_size, 0);
// #else
int s = send(sock, request_header, request_header_size, 0);
#endif
// #endif
if(s < 0)
{
#ifdef _WIN32
@ -303,11 +303,11 @@ static void *regist_thread_func(void *user)
goto fail_socket;
}
#ifdef __PSVITA__
s = sceNetSend(sock, payload, payload_size, 0);
#else
// #ifdef __PSVITA__
// s = sceNetSend(sock, payload, payload_size, 0);
// #else
s = send(sock, payload, payload_size, 0);
#endif
// #endif
if(s < 0)
{
#ifdef _WIN32
@ -382,11 +382,11 @@ static ChiakiErrorCode regist_search(ChiakiRegist *regist, struct addrinfo *addr
if(regist->info.broadcast)
r = sendto_broadcast(regist->log, sock, src, strlen(src) + 1, 0, &send_addr, send_addr_len);
else
#ifdef __PSVITA__
r = sceNetSend(sock, src, strlen(src) + 1, 0);
#else
// #ifdef __PSVITA__
// r = sceNetSend(sock, src, strlen(src) + 1, 0);
// #else
r = send(sock, src, strlen(src) + 1, 0);
#endif
// #endif
if(r < 0)
{
CHIAKI_LOGE(regist->log, "Regist failed to send search: %s", strerror(errno));
@ -410,11 +410,11 @@ static ChiakiErrorCode regist_search(ChiakiRegist *regist, struct addrinfo *addr
}
uint8_t buf[0x100];
#ifdef __PSVITA__
int n = sceNetRecvfrom(sock, buf, sizeof(buf) - 1, 0, (SceNetSockaddr*) recv_addr, recv_addr_size);
#else
// #ifdef __PSVITA__
// int n = sceNetRecvfrom(sock, buf, sizeof(buf) - 1, 0, (SceNetSockaddr*) recv_addr, recv_addr_size);
// #else
int n = recvfrom(sock, buf, sizeof(buf) - 1, 0, recv_addr, recv_addr_size);
#endif
// #endif
if(n <= 0)
{
if(n < 0)
@ -460,11 +460,11 @@ static chiaki_socket_t regist_search_connect(ChiakiRegist *regist, struct addrin
set_port(send_addr, htons(REGIST_PORT));
#ifdef __PSVITA__
sock = sceNetSocket("", ai->ai_family, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
#else
// #ifdef __PSVITA__
// sock = sceNetSocket("", ai->ai_family, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
// #else
sock = socket(ai->ai_family, SOCK_DGRAM, IPPROTO_UDP);
#endif
// #endif
if(CHIAKI_SOCKET_IS_INVALID(sock))
{
CHIAKI_LOGE(regist->log, "Regist failed to create socket for search");
@ -474,11 +474,11 @@ static chiaki_socket_t regist_search_connect(ChiakiRegist *regist, struct addrin
if(regist->info.broadcast)
{
const int broadcast = 1;
#ifdef __PSVITA__
int r = sceNetSetsockopt(sock, SCE_NET_SOL_SOCKET, SCE_NET_SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast));
#else
// #ifdef __PSVITA__
// int r = sceNetSetsockopt(sock, SCE_NET_SOL_SOCKET, SCE_NET_SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast));
// #else
int r = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const void *)&broadcast, sizeof(broadcast));
#endif
// #endif
if(r < 0)
{
#ifdef _WIN32
@ -503,11 +503,11 @@ static chiaki_socket_t regist_search_connect(ChiakiRegist *regist, struct addrin
}
else
{
#ifdef __PSVITA__
int r = sceNetConnect(sock, (SceNetSockaddr*) send_addr, *send_addr_len);
#else
// #ifdef __PSVITA__
// int r = sceNetConnect(sock, (SceNetSockaddr*) send_addr, *send_addr_len);
// #else
int r = connect(sock, send_addr, *send_addr_len);
#endif
// #endif
if(r < 0)
{
#ifdef _WIN32
@ -533,21 +533,21 @@ connect_fail:
static chiaki_socket_t regist_request_connect(ChiakiRegist *regist, const struct sockaddr *addr, size_t addr_len)
{
#ifdef __PSVITA__
chiaki_socket_t sock = sceNetSocket("", SCE_NET_AF_INET, SCE_NET_SOCK_STREAM, SCE_NET_IPPROTO_TCP);
#else
// #ifdef __PSVITA__
// chiaki_socket_t sock = sceNetSocket("", SCE_NET_AF_INET, SCE_NET_SOCK_STREAM, SCE_NET_IPPROTO_TCP);
// #else
chiaki_socket_t sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
#endif
// #endif
if(CHIAKI_SOCKET_IS_INVALID(sock))
{
return CHIAKI_INVALID_SOCKET;
}
#ifdef __PSVITA__
int r = sceNetConnect(sock, (SceNetSockaddr*) addr, addr_len);
#else
// #ifdef __PSVITA__
// int r = sceNetConnect(sock, (SceNetSockaddr*) addr, addr_len);
// #else
int r = connect(sock, addr, addr_len);
#endif
// #endif
if(r < 0)
{
#ifdef _WIN32
@ -641,11 +641,11 @@ static ChiakiErrorCode regist_recv_response(ChiakiRegist *regist, ChiakiRegister
return err;
}
#ifdef __PSVITA__
int received = sceNetRecv(sock, buf + buf_filled_size, (content_size + header_size) - buf_filled_size, 0);
#else
// #ifdef __PSVITA__
// int received = sceNetRecv(sock, buf + buf_filled_size, (content_size + header_size) - buf_filled_size, 0);
// #else
int received = recv(sock, buf + buf_filled_size, (content_size + header_size) - buf_filled_size, 0);
#endif
// #endif
if(received <= 0)
{
CHIAKI_LOGE(regist->log, "Regist failed to receive response content");

@ -218,6 +218,9 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki
chiaki_controller_state_set_idle(&session->controller_state);
session->connect_info.ps5 = connect_info->ps5;
#ifdef __PSVITA__
strcpy(session->connect_info.hostname, connect_info->host); //HACK
#endif
memcpy(session->connect_info.regist_key, connect_info->regist_key, sizeof(session->connect_info.regist_key));
memcpy(session->connect_info.morning, connect_info->morning, sizeof(session->connect_info.morning));
@ -597,28 +600,29 @@ static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, Ch
set_port(sa, htons(SESSION_PORT));
#ifdef __PSVITA__
int errno;
int rid = sceNetResolverCreate("resolver", NULL, 0);
if (rid < 0) {
errno = rid & 0xFF;
goto vitadns_err;
}
sockaddr_in* sa_in = (sockaddr_in*) sa;
SceNetInAddr addr = { (sa_in->sin_addr).s_addr };
int r = sceNetResolverStartAton(
rid,
&addr,
session->connect_info.hostname,
sizeof(session->connect_info.hostname),
1500,
3,
0);
if (r < 0) {
vitadns_err:
CHIAKI_LOGE(session->log, "Failed to resolve hostname, %d", errno);
memcpy(session->connect_info.hostname, "unknown", 8);
}
sceNetResolverDestroy(rid);
// FIXME: this is broken, error 0
// int errno;
// int rid = sceNetResolverCreate("resolver", NULL, 0);
// if (rid < 0) {
// errno = rid & 0xFF;
// goto vitadns_err;
// }
// sockaddr_in* sa_in = (sockaddr_in*) sa;
// SceNetInAddr addr = { (sa_in->sin_addr).s_addr };
// int r = sceNetResolverStartAton(
// rid,
// &addr,
// session->connect_info.hostname,
// sizeof(session->connect_info.hostname),
// 1500,
// 3,
// 0);
// if (r < 0) {
// vitadns_err:
// CHIAKI_LOGE(session->log, "Failed to resolve hostname, %d", errno);
// memcpy(session->connect_info.hostname, "unknown", 8);
// }
// sceNetResolverDestroy(rid);
#else
// TODO: this can block, make cancelable somehow
int r = getnameinfo(sa, (socklen_t)ai->ai_addrlen, session->connect_info.hostname, sizeof(session->connect_info.hostname), NULL, 0, NI_NUMERICHOST);
@ -631,11 +635,11 @@ static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, Ch
CHIAKI_LOGI(session->log, "Trying to request session from %s:%d", session->connect_info.hostname, SESSION_PORT);
#ifdef __PSVITA__
session_sock = sceNetSocket("", ai->ai_family, SCE_NET_SOCK_STREAM, 0);
#else
// #ifdef __PSVITA__
// session_sock = sceNetSocket("", ai->ai_family, SCE_NET_SOCK_STREAM, 0);
// #else
session_sock = socket(ai->ai_family, SOCK_STREAM, 0);
#endif
// #endif
if(CHIAKI_SOCKET_IS_INVALID(session_sock))
{
#ifdef _WIN32
@ -667,7 +671,8 @@ static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, Ch
}
else if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(session->log, "Session request connect failed: %s", chiaki_error_string(err));
// CHIAKI_LOGE(session->log, "Session request connect failed: %s", chiaki_error_string(err));
CHIAKI_LOGE(session->log, "Session request connect failed: %d", err);
if(err == CHIAKI_ERR_CONNECTION_REFUSED)
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_CONNECTION_REFUSED;
else
@ -750,11 +755,11 @@ static ChiakiErrorCode session_thread_request_session(ChiakiSession *session, Ch
CHIAKI_LOGI(session->log, "Sending session request");
chiaki_log_hexdump(session->log, CHIAKI_LOG_VERBOSE, (uint8_t *)buf, request_len);
#ifdef __PSVITA__
int sent = sceNetSend(session_sock, buf, request_len, 0);
#else
// #ifdef __PSVITA__
// int sent = sceNetSend(session_sock, buf, request_len, 0);
// #else
int sent = send(session_sock, buf, (size_t)request_len, 0);
#endif
// #endif
if(sent < 0)
{
CHIAKI_LOGE(session->log, "Failed to send session request");

@ -3,6 +3,11 @@
#include <chiaki/sock.h>
#include <fcntl.h>
#ifdef __PSVITA__
#include <psp2/net/net.h>
#include <sys/socket.h>
#endif
CHIAKI_EXPORT ChiakiErrorCode chiaki_socket_set_nonblock(chiaki_socket_t sock, bool nonblock)
{
#ifdef _WIN32
@ -11,7 +16,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_socket_set_nonblock(chiaki_socket_t sock, b
return CHIAKI_ERR_UNKNOWN;
#elif defined(__PSVITA__)
int nbio = nonblock ? 1 : 0;
if (sceNetSetsockopt(sock, SCE_NET_SOL_SOCKET, SCE_NET_SO_NBIO, &nbio, sizeof(int)) < 0)
if (setsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &nbio, sizeof(int)) < 0)
return CHIAKI_ERR_UNKNOWN;
#else
int flags = fcntl(sock, F_GETFL, 0);

@ -2,13 +2,14 @@
#include <chiaki/stoppipe.h>
#include <chiaki/sock.h>
#include <chiaki/log.h>
#include <fcntl.h>
#ifdef _WIN32
#include <ws2tcpip.h>
#elif defined(__PSVITA__)
#include <psp2/net/net.h>
// #include <psp2/net/net.h>
#else
#include <unistd.h>
#include <sys/socket.h>
@ -21,8 +22,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_init(ChiakiStopPipe *stop_pipe)
stop_pipe->event = WSACreateEvent();
if(stop_pipe->event == WSA_INVALID_EVENT)
return CHIAKI_ERR_UNKNOWN;
#elif defined(__SWITCH__)
// currently pipe or socketpare are not available on switch
#elif defined(__SWITCH__) || defined(__PSVITA__)
// currently pipe or socketpare are not available on switch or vita
// use a custom udp socket as pipe
// struct sockaddr_in addr;
@ -40,36 +41,41 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_init(ChiakiStopPipe *stop_pipe)
bind(stop_pipe->fd, (struct sockaddr *) &stop_pipe->addr, addr_size);
// listen
getsockname(stop_pipe->fd, (struct sockaddr *) &stop_pipe->addr, &addr_size);
#ifdef __PSVITA__
int nbio = 1;
int r = setsockopt(stop_pipe->fd, SOL_SOCKET, SO_NONBLOCK, &nbio, sizeof(int));
#else
int r = fcntl(stop_pipe->fd, F_SETFL, O_NONBLOCK);
#endif
if(r == -1)
{
close(stop_pipe->fd);
return CHIAKI_ERR_UNKNOWN;
}
#elif defined(__PSVITA__)
int addr_size = sizeof(stop_pipe->addr);
stop_pipe->fd = sceNetSocket("", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
if (stop_pipe->fd < 0)
return CHIAKI_ERR_UNKNOWN;
stop_pipe->addr.sin_family = AF_INET;
stop_pipe->addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
stop_pipe->addr.sin_port = htons(0);
int r = sceNetBind(stop_pipe->fd, (SceNetSockaddr *) &stop_pipe->addr, (unsigned int) addr_size);
if (r < 0) {
return CHIAKI_ERR_UNKNOWN;
}
sceNetGetsockname(stop_pipe->fd, (SceNetSockaddr *) &stop_pipe->addr, (unsigned int*) &addr_size);
int val = 1;
r = sceNetSetsockopt(stop_pipe->fd, SCE_NET_SOL_SOCKET, SCE_NET_SO_NBIO, &val, sizeof(val));
if(r < 0) {
sceNetSocketClose(stop_pipe->fd);
return CHIAKI_ERR_UNKNOWN;
}
stop_pipe->epoll_fd = sceNetEpollCreate("chiaki-epoll", 0);
if (stop_pipe->epoll_fd < 0) {
return CHIAKI_ERR_UNKNOWN;
}
// #elif defined(__PSVITA__)
// int addr_size = sizeof(stop_pipe->addr);
// stop_pipe->fd = sceNetSocket("", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
// if (stop_pipe->fd < 0)
// return CHIAKI_ERR_UNKNOWN;
// stop_pipe->addr.sin_family = AF_INET;
// stop_pipe->addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
// stop_pipe->addr.sin_port = htons(0);
// int r = sceNetBind(stop_pipe->fd, (SceNetSockaddr *) &stop_pipe->addr, (unsigned int) addr_size);
// if (r < 0) {
// return CHIAKI_ERR_UNKNOWN;
// }
// sceNetGetsockname(stop_pipe->fd, (SceNetSockaddr *) &stop_pipe->addr, (unsigned int*) &addr_size);
// int val = 1;
// r = sceNetSetsockopt(stop_pipe->fd, SCE_NET_SOL_SOCKET, SCE_NET_SO_NBIO, &val, sizeof(val));
// if(r < 0) {
// sceNetSocketClose(stop_pipe->fd);
// return CHIAKI_ERR_UNKNOWN;
// }
// stop_pipe->epoll_fd = sceNetEpollCreate("chiaki-epoll", 0);
// if (stop_pipe->epoll_fd < 0) {
// return CHIAKI_ERR_UNKNOWN;
// }
#else
int r = pipe(stop_pipe->fds);
if(r < 0)
@ -92,8 +98,8 @@ CHIAKI_EXPORT void chiaki_stop_pipe_fini(ChiakiStopPipe *stop_pipe)
#elif defined(__SWITCH__)
close(stop_pipe->fd);
#elif defined(__PSVITA__)
sceNetSocketClose(stop_pipe->fd);
sceNetEpollDestroy(stop_pipe->epoll_fd);
close(stop_pipe->fd);
// sceNetEpollDestroy(stop_pipe->epoll_fd);
#else
close(stop_pipe->fds[0]);
close(stop_pipe->fds[1]);
@ -104,14 +110,14 @@ CHIAKI_EXPORT void chiaki_stop_pipe_stop(ChiakiStopPipe *stop_pipe)
{
#ifdef _WIN32
WSASetEvent(stop_pipe->event);
#elif defined(__SWITCH__)
#elif defined(__SWITCH__) || defined(__PSVITA__)
// send to local socket (FIXME MSG_CONFIRM)
sendto(stop_pipe->fd, "\x00", 1, 0,
(struct sockaddr*)&stop_pipe->addr, sizeof(struct sockaddr_in));
#elif defined(__PSVITA__)
int r = sceNetSendto(stop_pipe->fd, "\x00", 1, 0, (SceNetSockaddr*)&stop_pipe->addr, sizeof(stop_pipe->addr));
if (r < 0) {
}
// #elif defined(__PSVITA__)
// int r = sceNetSendto(stop_pipe->fd, "\x00", 1, 0, (SceNetSockaddr*)&stop_pipe->addr, sizeof(stop_pipe->addr));
// if (r < 0) {
// }
#else
write(stop_pipe->fds[1], "\x00", 1);
#endif
@ -149,48 +155,48 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_select_single(ChiakiStopPipe *sto
default:
return CHIAKI_ERR_UNKNOWN;
}
#elif defined(__PSVITA__)
SceNetEpollEvent ev = {0};
ev.events = SCE_NET_EPOLLIN | SCE_NET_EPOLLHUP;
ev.data.fd = stop_pipe->fd;
int r = sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_ADD, stop_pipe->fd, &ev);
if (r < 0) {
return CHIAKI_ERR_UNKNOWN;
}
if (!CHIAKI_SOCKET_IS_INVALID(fd)) {
ev.events = (write ? SCE_NET_EPOLLOUT : SCE_NET_EPOLLIN) | SCE_NET_EPOLLHUP;
ev.data.fd = fd;
r = sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_ADD, fd, &ev);
if (r < 0) {
return CHIAKI_ERR_UNKNOWN;
}
}
if (r == 0) {
r = sceNetEpollWait(stop_pipe->epoll_fd, &ev, 1, timeout_ms * 1000);
}
sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_DEL, stop_pipe->fd, NULL);
if (!CHIAKI_SOCKET_IS_INVALID(fd)) {
sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_DEL, fd, NULL);
}
if(r < 0) {
return CHIAKI_ERR_UNKNOWN;
}
if (ev.data.fd == stop_pipe->fd) {
return CHIAKI_ERR_CANCELED;
} else if (ev.data.fd == fd) {
return CHIAKI_ERR_SUCCESS;
}
return CHIAKI_ERR_TIMEOUT;
// #elif defined(__PSVITA__)
// SceNetEpollEvent ev = {0};
// ev.events = SCE_NET_EPOLLIN | SCE_NET_EPOLLHUP;
// ev.data.fd = stop_pipe->fd;
// int r = sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_ADD, stop_pipe->fd, &ev);
// if (r < 0) {
// return CHIAKI_ERR_UNKNOWN;
// }
// if (!CHIAKI_SOCKET_IS_INVALID(fd)) {
// ev.events = (write ? SCE_NET_EPOLLOUT : SCE_NET_EPOLLIN) | SCE_NET_EPOLLHUP;
// ev.data.fd = fd;
// r = sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_ADD, fd, &ev);
// if (r < 0) {
// return CHIAKI_ERR_UNKNOWN;
// }
// }
// if (r == 0) {
// r = sceNetEpollWait(stop_pipe->epoll_fd, &ev, 1, timeout_ms * 1000);
// }
// sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_DEL, stop_pipe->fd, NULL);
// if (!CHIAKI_SOCKET_IS_INVALID(fd)) {
// sceNetEpollControl(stop_pipe->epoll_fd, SCE_NET_EPOLL_CTL_DEL, fd, NULL);
// }
// if(r < 0) {
// return CHIAKI_ERR_UNKNOWN;
// }
// if (ev.data.fd == stop_pipe->fd) {
// return CHIAKI_ERR_CANCELED;
// } else if (ev.data.fd == fd) {
// return CHIAKI_ERR_SUCCESS;
// }
// return CHIAKI_ERR_TIMEOUT;
#else
fd_set rfds;
FD_ZERO(&rfds);
#if defined(__SWITCH__)
#if defined(__SWITCH__) || defined(__PSVITA__)
// push udp local socket as fd
int stop_fd = stop_pipe->fd;
#else
@ -218,6 +224,15 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_select_single(ChiakiStopPipe *sto
timeout_s.tv_usec = (timeout_ms % 1000) * 1000;
timeout = &timeout_s;
}
#ifdef __PSVITA__
// workaround crash in newlib
else {
timeout_s.tv_sec = 999999999;
timeout_s.tv_usec = 0;
timeout = &timeout_s;
}
#endif
int r = select(nfds, &rfds, write ? &wfds : NULL, NULL, timeout);
if(r < 0)
@ -235,12 +250,12 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_select_single(ChiakiStopPipe *sto
CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_connect(ChiakiStopPipe *stop_pipe, chiaki_socket_t fd, struct sockaddr *addr, size_t addrlen)
{
#ifdef __PSVITA__
int r = sceNetConnect(fd, (SceNetSockaddr*) addr, addrlen);
int errno = r;
#else
// #ifdef __PSVITA__
// int r = sceNetConnect(fd, (SceNetSockaddr*) addr, addrlen);
// int errno = r;
// #else
int r = connect(fd, addr, (socklen_t)addrlen);
#endif
// #endif
if(r >= 0)
return CHIAKI_ERR_SUCCESS;
@ -258,11 +273,12 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_connect(ChiakiStopPipe *stop_pipe
return CHIAKI_ERR_CONNECTION_REFUSED;
else
return CHIAKI_ERR_NETWORK;
#elif defined(__PSVITA__)
if (r == SCE_NET_ERROR_ECONNREFUSED)
return CHIAKI_ERR_CONNECTION_REFUSED;
else
return CHIAKI_ERR_NETWORK;
// #elif defined(__PSVITA__)
// if (r == SCE_NET_ERROR_ECONNREFUSED)
// return CHIAKI_ERR_CONNECTION_REFUSED;
// else {
// return CHIAKI_ERR_NETWORK;
// }
#else
if(errno == ECONNREFUSED)
return CHIAKI_ERR_CONNECTION_REFUSED;
@ -276,27 +292,28 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_connect(ChiakiStopPipe *stop_pipe
if(getpeername(fd, &peer, &peerlen) == 0)
return CHIAKI_ERR_SUCCESS;
#ifdef __PSVITA__
if (r == SCE_NET_ERROR_ENOTCONN)
#else
if(errno != ENOTCONN)
#endif
// #ifdef __PSVITA__
// if (errno == SCE_NET_ERROR_ENOTCONN) {
// #else
if(errno != ENOTCONN) {
// #endif
return CHIAKI_ERR_UNKNOWN;
}
#ifdef _WIN32
DWORD sockerr;
#else
int sockerr;
#endif
#ifdef __PSVITA__
socklen_t sockerr_sz = sizeof(sockerr);
if(sceNetGetsockopt(fd, SCE_NET_SOL_SOCKET, SCE_NET_SO_ERROR, &sockerr, &sockerr_sz) < 0)
return CHIAKI_ERR_UNKNOWN;
#else
// #ifdef __PSVITA__
// socklen_t sockerr_sz = sizeof(sockerr);
// if(sceNetGetsockopt(fd, SCE_NET_SOL_SOCKET, SCE_NET_SO_ERROR, &sockerr, &sockerr_sz) < 0)
// return CHIAKI_ERR_UNKNOWN;
// #else
socklen_t sockerr_sz = sizeof(sockerr);
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, &sockerr_sz) < 0)
return CHIAKI_ERR_UNKNOWN;
#endif
// #endif
#ifdef _WIN32
switch(sockerr)
@ -312,19 +329,21 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_connect(ChiakiStopPipe *stop_pipe
default:
return CHIAKI_ERR_UNKNOWN;
}
#elif defined(__PSVITA__)
switch (sockerr) {
case SCE_NET_ERROR_ETIMEDOUT:
return CHIAKI_ERR_TIMEOUT;
case SCE_NET_ERROR_ECONNREFUSED:
return CHIAKI_ERR_CONNECTION_REFUSED;
case SCE_NET_ERROR_EHOSTDOWN:
return CHIAKI_ERR_HOST_DOWN;
case SCE_NET_ERROR_EHOSTUNREACH:
return CHIAKI_ERR_HOST_UNREACH;
default:
return CHIAKI_ERR_UNKNOWN;
}
// #elif defined(__PSVITA__)
// switch (sockerr) {
// case 0:
// return CHIAKI_ERR_SUCCESS; // I have no idea.
// case SCE_NET_ERROR_ETIMEDOUT:
// return CHIAKI_ERR_TIMEOUT;
// case SCE_NET_ERROR_ECONNREFUSED:
// return CHIAKI_ERR_CONNECTION_REFUSED;
// case SCE_NET_ERROR_EHOSTDOWN:
// return CHIAKI_ERR_HOST_DOWN;
// case SCE_NET_ERROR_EHOSTUNREACH:
// return CHIAKI_ERR_HOST_UNREACH;
// default:
// return CHIAKI_ERR_UNKNOWN;
// }
#else
switch(sockerr)
{
@ -347,17 +366,17 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stop_pipe_reset(ChiakiStopPipe *stop_pipe)
#ifdef _WIN32
BOOL r = WSAResetEvent(stop_pipe->event);
return r ? CHIAKI_ERR_SUCCESS : CHIAKI_ERR_UNKNOWN;
#elif defined(__SWITCH__)
#elif defined(__SWITCH__) || defined(__PSVITA__)
//FIXME
uint8_t v;
int r;
while((r = read(stop_pipe->fd, &v, sizeof(v))) > 0);
return r < 0 ? CHIAKI_ERR_UNKNOWN : CHIAKI_ERR_SUCCESS;
#elif defined(__PSVITA__)
int r;
uint8_t v;
while((r = sceNetRecv(stop_pipe->fd, &v, sizeof(v), 0)) > 0);
return r < 0 ? CHIAKI_ERR_UNKNOWN : CHIAKI_ERR_SUCCESS;
// #elif defined(__PSVITA__)
// int r;
// uint8_t v;
// while((r = /*sceNetRecv*/read(stop_pipe->fd, &v, sizeof(v)/*, 0*/)) > 0);
// return r < 0 ? CHIAKI_ERR_UNKNOWN : CHIAKI_ERR_SUCCESS;
#else
uint8_t v;
int r;

@ -175,11 +175,12 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
stream_connection->state = STATE_TAKION_CONNECT;
stream_connection->state_finished = false;
stream_connection->state_failed = false;
takion_info.log = session->log;
err = chiaki_takion_connect(&stream_connection->takion, &takion_info);
free(takion_info.sa);
if(err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(session->log, "StreamConnection connect failed");
CHIAKI_LOGE(session->log, "StreamConnection connect failed %d", err);
chiaki_mutex_unlock(&stream_connection->state_mutex);
goto err_video_receiver;
}
@ -662,6 +663,8 @@ static void stream_connection_takion_data_expect_streaminfo(ChiakiStreamConnecti
return;
}
CHIAKI_LOGI(stream_connection->log, "StreamConnection recieved payload of type %d", msg.type);
if(msg.type != tkproto_TakionMessage_PayloadType_STREAMINFO || !msg.has_stream_info_payload)
{
if(msg.type == tkproto_TakionMessage_PayloadType_DISCONNECT)

@ -181,7 +181,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
takion->log = info->log;
takion->version = info->protocol_version;
CHIAKI_LOGI(takion->log, "Init Takion");
switch(takion->version)
{
case 7:
@ -202,6 +202,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
ret = chiaki_mutex_init(&takion->gkcrypt_local_mutex, true);
if(ret != CHIAKI_ERR_SUCCESS)
return ret;
CHIAKI_LOGI(takion->log, "Mutex1 created");
takion->key_pos_local = 0;
takion->gkcrypt_remote = NULL;
takion->cb = info->cb;
@ -213,6 +214,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
ret = chiaki_mutex_init(&takion->seq_num_local_mutex, false);
if(ret != CHIAKI_ERR_SUCCESS)
goto error_gkcrypt_local_mutex;
CHIAKI_LOGI(takion->log, "Mutex2 created");
takion->tag_remote = 0;
takion->enable_crypt = info->enable_crypt;
@ -229,7 +231,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
goto error_seq_num_local_mutex;
}
takion->sock = socket(info->sa->sa_family, SOCK_DGRAM, IPPROTO_UDP);
// #ifdef __PSVITA__
// takion->sock = sceNetSocket("", info->sa->sa_family, SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP);
// #else
takion->sock = socket(info->sa->sa_family, SOCK_DGRAM, IPPROTO_UDP);
// #endif
if(CHIAKI_SOCKET_IS_INVALID(takion->sock))
{
CHIAKI_LOGE(takion->log, "Takion failed to create socket");
@ -238,7 +244,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
}
const int rcvbuf_val = takion->a_rwnd;
int r = setsockopt(takion->sock, SOL_SOCKET, SO_RCVBUF, (const void *)&rcvbuf_val, sizeof(rcvbuf_val));
// #ifdef __PSVITA__
// int r = sceNetSetsockopt(takion->sock, SCE_NET_SOL_SOCKET, SCE_NET_SO_RCVBUF, (const void *)&rcvbuf_val, sizeof(rcvbuf_val));
// #else
int r = setsockopt(takion->sock, SOL_SOCKET, SO_RCVBUF, (const void *)&rcvbuf_val, sizeof(rcvbuf_val));
// #endif
if(r < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to setsockopt SO_RCVBUF: %s", strerror(errno));
@ -254,6 +264,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
#elif defined(__FreeBSD__) || defined(__SWITCH__)
const int dontfrag_val = 1;
r = setsockopt(takion->sock, IPPROTO_IP, IP_DONTFRAG, (const void *)&dontfrag_val, sizeof(dontfrag_val));
#elif defined(__PSVITA__)
CHIAKI_LOGW(takion->log, "Don't fragment is not supported on this platform, MTU values may be incorrect.");
#define NO_DONTFRAG
// const int dontfrag_val = 1;
// r = sceNetSetsockopt(takion->sock, SCE_NET_IPPROTO_IP, SCE_NET_IP_DF, (const void *)&dontfrag_val, sizeof(dontfrag_val));
#elif defined(IP_PMTUDISC_DO)
const int mtu_discover_val = IP_PMTUDISC_DO;
r = setsockopt(takion->sock, IPPROTO_IP, IP_MTU_DISCOVER, (const void *)&mtu_discover_val, sizeof(mtu_discover_val));
@ -274,7 +289,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
#endif
}
r = connect(takion->sock, info->sa, info->sa_len);
// #ifdef __PSVITA__
// r = sceNetConnect(takion->sock, (SceNetSockaddr*)info->sa, info->sa_len);
// #else
r = connect(takion->sock, info->sa, info->sa_len);
// #endif
if(r < 0)
{
CHIAKI_LOGE(takion->log, "Takion failed to connect: %s", strerror(errno));
@ -340,7 +359,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_crypt_advance_key_pos(ChiakiTakion *
CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_raw(ChiakiTakion *takion, const uint8_t *buf, size_t buf_size)
{
int r = send(takion->sock, buf, buf_size, 0);
// #ifdef __PSVITA__
// int r = sceNetSend(takion->sock, buf, buf_size, 0);
// #else
int r = send(takion->sock, buf, buf_size, 0);
// #endif
if(r < 0)
return CHIAKI_ERR_NETWORK;
return CHIAKI_ERR_SUCCESS;
@ -414,8 +437,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send(ChiakiTakion *takion, uint8_t *
if(err != CHIAKI_ERR_SUCCESS)
return err;
//CHIAKI_LOGD(takion->log, "Takion sending:");
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
// CHIAKI_LOGD(takion->log, "Takion sending:");
// chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
return chiaki_takion_send_raw(takion, buf, buf_size);
}
@ -787,7 +810,11 @@ static ChiakiErrorCode takion_recv(ChiakiTakion *takion, uint8_t *buf, size_t *b
return err;
}
int received_sz = recv(takion->sock, buf, *buf_size, 0);
// #ifdef __PSVITA__
// int received_sz = sceNetRecv(takion->sock, buf, *buf_size, 0);
// #else
int received_sz = recv(takion->sock, buf, *buf_size, 0);
// #endif
if(received_sz <= 0)
{
if(received_sz < 0)
@ -908,8 +935,8 @@ static void takion_handle_packet_message(ChiakiTakion *takion, uint8_t *buf, siz
return;
}
//CHIAKI_LOGD(takion->log, "Takion received message with tag %#x, key pos %#x, type (%#x, %#x), payload size %#x, payload:", msg.tag, msg.key_pos, msg.type_a, msg.type_b, msg.payload_size);
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
// CHIAKI_LOGD(takion->log, "Takion received message with tag %#x, key pos %#x, type %#x, payload size %#x, payload:", msg.tag, msg.key_pos, msg.chunk_type, msg.payload_size);
// chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
switch(msg.chunk_type)
{

@ -149,7 +149,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_init(ChiakiMutex *mutex, bool rec)
#elif defined(__PSVITA__)
snprintf(name_buffer, sizeof(name_buffer), "0x%08X", (unsigned int) mutex);
mutex->mutex_id = sceKernelCreateMutex(
name_buffer, 0, rec ? SCE_KERNEL_MUTEX_ATTR_RECURSIVE : 0, 0);
name_buffer, rec ? SCE_KERNEL_MUTEX_ATTR_RECURSIVE : 0, 0, 0);
if (mutex->mutex_id < 0) {
return CHIAKI_ERR_UNKNOWN;
}

@ -93,8 +93,8 @@ static inline int sendto_broadcast(ChiakiLog *log, chiaki_socket_t s, const void
freeifaddrs(ifap);
return r;
}
#elif defined(__PSVITA__)
return sceNetSendto(s, msg, len, flags, (SceNetSockaddr*)to, tolen);
// #elif defined(__PSVITA__)
// return sceNetSendto(s, msg, len, flags, (SceNetSockaddr*)to, tolen);
#endif
return sendto(s, msg, len, flags, to, tolen);
}

@ -11,6 +11,7 @@ build_chiaki (){
cmake -B "./build" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake \
-DCMAKE_C_FLAGS="-g -O0" \
-DCHIAKI_ENABLE_VITA=ON \
-DCHIAKI_ENABLE_TESTS=OFF \
-DCHIAKI_ENABLE_CLI=OFF \

@ -9,6 +9,7 @@ import zipfile
from pathlib import Path
from ftplib import FTP, error_perm, error_reply
from typing import Optional
from collections import defaultdict
path_root = Path(__file__).parents[0]
sys.path.insert(0, ".")
@ -16,8 +17,9 @@ sys.path.insert(0, str(path_root) + "/parse_core")
from parse_core.core import CoreParser
from parse_core.elf import ElfParser
from parse_core.util import u32
from parse_core import main as pcore
from parse_core.util import u16, u32, c_str, hexdump
from parse_core.indent import iprint, indent
# from parse_core.main import print_thread_info, print_module_info
COLOR_RED = '\x1b[31;1m'
COLOR_BLUE = '\x1b[34;1m'
@ -54,6 +56,56 @@ def fetch_latest_coredump(hostname: str) -> Optional[Path]:
raise e
return Path(corepath)
str_stop_reason = defaultdict(str, {
0: "No reason",
0x30002: "Undefined instruction exception",
0x30003: "Prefetch abort exception",
0x30004: "Data abort exception",
0x60080: "Division by zero",
})
str_status = defaultdict(str, {
1: "Running",
8: "Waiting",
16: "Not started",
})
str_attr = defaultdict(str, {
5: "RX",
6: "RW",
})
reg_names = {
13: "SP",
14: "LR",
15: "PC",
}
isPC = True
def print_module_info(module):
iprint(module.name)
with indent():
for x, segment in enumerate(module.segments):
iprint("Segment {}".format(x + 1))
with indent():
iprint("Start: 0x{:x}".format(segment.start))
iprint("Size: 0x{:x} bytes".format(segment.size))
iprint("Attributes: 0x{:x} ({})".format(segment.attr, str_attr[segment.attr & 0xF]))
iprint("Alignment: 0x{:x}".format(segment.align))
def print_thread_info(thread, core=None, elf=None):
iprint(thread.name)
with indent():
iprint("ID: 0x{:x}".format(thread.uid))
iprint("Stop reason: 0x{:x} ({})".format(thread.stop_reason, str_stop_reason[thread.stop_reason]))
iprint("Status: 0x{:x} ({})".format(thread.status, str_status[thread.status]))
pc = core.get_address_notation("PC", thread.pc)
iprint(pc.to_string(elf))
if not pc.is_located():
iprint(core.get_address_notation("LR", thread.regs.gpr[14]).to_string(elf))
def print_coredump(corepath: Path) -> None:
elfpath = Path(__file__).parent / '../../build/vita/chiaki.elf'
@ -64,26 +116,47 @@ def print_coredump(corepath: Path) -> None:
sys.exit(1)
elf = ElfParser(str(elfpath))
core = CoreParser(str(corepath))
crashed = [t for t in core.threads if t.stop_reason != 0]
iprint("=== THREADS ===")
crashed = []
with indent():
for thread in core.threads:
if thread.stop_reason != 0:
crashed.append(thread)
print_thread_info(thread, core, elf)
iprint()
for thread in crashed:
print(f"{COLOR_RED}๐Ÿ’ฃ๐Ÿ’ฃ Thread 0x{thread.uid:x} crashed due to 0x{thread.stop_reason:x} ({pcore.str_stop_reason[thread.stop_reason]}) ๐Ÿ’ฃ๐Ÿ’ฃ")
pc = core.get_address_notation("PC ", thread.pc)
print(pc.to_string(elf) + COLOR_END, end="\n\n")
if not pc.is_located():
print(core.get_address_notation("LR", thread.regs.gpr[14]).to_string(elf))
sp = thread.regs.gpr[13]
for x in range(-16, 24):
addr = 4 * x + sp
data = core.read_vaddr(addr, 4)
if not data:
continue
data = u32(data, 0)
prefix = f'{COLOR_RED}๐Ÿšฉ' if addr == sp else ' '
suffix = f'๐Ÿšฉ{COLOR_END}' if addr == sp else ''
txt = core.get_address_notation(f"{prefix}0x{addr:x}", data).to_string(elf)
if '0xdeadbeef' in txt:
continue
print(txt + suffix)
iprint('=== THREAD "{}" <0x{:x}> CRASHED ({}) ==='.format(thread.name, thread.uid, str_stop_reason[thread.stop_reason]))
pc = core.get_address_notation('PC', thread.pc)
pc.print_disas_if_available(elf)
lr = core.get_address_notation('LR', thread.regs.gpr[14])
lr.print_disas_if_available(elf)
iprint("REGISTERS:")
with indent():
for x in range(14):