adding daemon upload from phi device
This commit is contained in:
@@ -42,7 +42,7 @@ void PhiLog(PhiLogLevel level, const char* fmt, const char* file, const char* fu
|
||||
time_t now = time(0);
|
||||
struct tm tstruct = *localtime(&now);
|
||||
char buffer[128];
|
||||
strftime(buffer, sizeof(buffer), "[%X] ", &tstruct);
|
||||
strftime(buffer, sizeof(buffer), "%X", &tstruct);
|
||||
|
||||
FILE* out = stdout;
|
||||
|
||||
@@ -51,9 +51,9 @@ void PhiLog(PhiLogLevel level, const char* fmt, const char* file, const char* fu
|
||||
|
||||
// Way too much printf calls
|
||||
SetConsoleColor(out, MAGENTA);
|
||||
fprintf(out, "[Phi device ");
|
||||
fprintf(out, "[ApeDriver ");
|
||||
SetConsoleColor(out, GREEN);
|
||||
fprintf(out, "Phi");
|
||||
fprintf(out, "Phi ");
|
||||
SetConsoleColor(out, YELLOW);
|
||||
fprintf(out, "%s", buffer);
|
||||
SetConsoleColor(out, MAGENTA);
|
||||
@@ -76,11 +76,13 @@ void PhiLog(PhiLogLevel level, const char* fmt, const char* file, const char* fu
|
||||
break;
|
||||
}
|
||||
|
||||
SetConsoleColor(out, RESET);
|
||||
|
||||
va_list argptr;
|
||||
va_start(argptr, line);
|
||||
vfprintf(out, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
SetConsoleColor(out, RESET);
|
||||
fprintf(out, fmt, argptr);
|
||||
fputc('\n', out);
|
||||
|
||||
if(level == PHI_LOG_LEVEL_FATAL)
|
||||
|
||||
@@ -14,7 +14,6 @@ int HandleAllocMemory(scif_epd_t endpoint, const PhiMessageHeader* header)
|
||||
.remote_handle = 0,
|
||||
.size = 0,
|
||||
};
|
||||
void* memory;
|
||||
|
||||
if(header->payload_size != sizeof(request))
|
||||
{
|
||||
@@ -26,15 +25,18 @@ int HandleAllocMemory(scif_epd_t endpoint, const PhiMessageHeader* header)
|
||||
if(ReadAll(endpoint, &request, sizeof(request)) < 0)
|
||||
return -1;
|
||||
|
||||
memory = calloc(1, (size_t)request.size);
|
||||
void* memory = malloc((size_t)request.size);
|
||||
|
||||
if(memory == NULL)
|
||||
{
|
||||
reply.result.status = PHI_STATUS_OUT_OF_MEMORY;
|
||||
PhiLogInfoFmt("Failed to allocate %zu bytes", (size_t)request.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
reply.remote_handle = (uint64_t)(uintptr_t)memory;
|
||||
reply.size = request.size;
|
||||
PhiLogInfoFmt("Allocated %zu bytes", (size_t)request.size);
|
||||
PhiLogInfoFmt("Allocated %llu bytes to handle 0x%X", reply.size, reply.remote_handle);
|
||||
}
|
||||
|
||||
return SendReply(endpoint, header, &reply, sizeof(reply));
|
||||
@@ -57,16 +59,19 @@ int HandleFreeMemory(scif_epd_t endpoint, const PhiMessageHeader* header)
|
||||
reply.result.status = PHI_STATUS_BAD_MESSAGE;
|
||||
return SendReply(endpoint, header, &reply, sizeof(reply));
|
||||
}
|
||||
|
||||
if(ReadAll(endpoint, &request, sizeof(request)) < 0)
|
||||
return -1;
|
||||
|
||||
if(request.remote_handle == 0)
|
||||
{
|
||||
reply.result.status = PHI_STATUS_INVALID_HANDLE;
|
||||
PhiLogErrorFmt("Could not free memory: invalid handle 0x%X", request.remote_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
free((void*)(uintptr_t)request.remote_handle);
|
||||
PhiLogInfoFmt("Freed memory handle 0x%X", request.remote_handle);
|
||||
}
|
||||
|
||||
return SendReply(endpoint, header, &reply, sizeof(reply));
|
||||
|
||||
Reference in New Issue
Block a user