Use <string.h> & <3ds/exheader.h>, fix some bugs, etc.

also fix all warnings and use -Werror
This commit is contained in:
TuxSH
2018-05-24 00:55:38 +02:00
parent e6b7dc1dc5
commit d28e961adc
85 changed files with 276 additions and 643 deletions

View File

@@ -261,7 +261,7 @@ Handle Ldr_CodesetFrom3dsx(const char* name, u32* codePages, u32 baseAddr, IFile
// Create the codeset
CodeSetInfo csinfo;
memset(&csinfo, 0, sizeof(csinfo));
strncpy((char*)csinfo.name, name, 8);
memcpy(csinfo.name, name, 8);
csinfo.program_id = tid;
csinfo.text_addr = d.segAddrs[0];
csinfo.text_size = d.segSizes[0] >> 12;

View File

@@ -114,7 +114,7 @@ u32 Draw_DrawFormattedString(u32 posX, u32 posY, u32 color, const char *fmt, ...
void Draw_FillFramebuffer(u32 value)
{
memset32(FB_BOTTOM_VRAM_ADDR, value, FB_BOTTOM_SIZE);
memset(FB_BOTTOM_VRAM_ADDR, value, FB_BOTTOM_SIZE);
}
void Draw_ClearFramebuffer(void)

View File

@@ -52,12 +52,12 @@ MyThread *errDispCreateThread(void)
static inline u32 ERRF_DisplayRegisterValue(u32 posX, u32 posY, const char *name, u32 value)
{
return Draw_DrawFormattedString(posX, posY, COLOR_WHITE, "%-9s %08x", name, value);
return Draw_DrawFormattedString(posX, posY, COLOR_WHITE, "%-9s %08lx", name, value);
}
static inline int ERRF_FormatRegisterValue(char *out, const char *name, u32 value)
{
return sprintf(out, "%-9s %08x", name, value);
return sprintf(out, "%-9s %08lx", name, value);
}
static int ERRF_FormatError(char *out, ERRF_FatalErrInfo *info)
@@ -88,7 +88,7 @@ static int ERRF_FormatError(char *out, ERRF_FatalErrInfo *info)
Handle processHandle;
Result res;
out += sprintf(out, "\nProcess ID: %u\n", info->procId);
out += sprintf(out, "\nProcess ID: %lu\n", info->procId);
res = svcOpenProcess(&processHandle, info->procId);
if(R_SUCCEEDED(res))
@@ -149,9 +149,9 @@ static int ERRF_FormatError(char *out, ERRF_FatalErrInfo *info)
else if(info->type != ERRF_ERRTYPE_CARD_REMOVED)
{
if(info->type != ERRF_ERRTYPE_FAILURE)
out += sprintf(out, "Address: 0x%08x\n", info->pcAddr);
out += sprintf(out, "Address: 0x%08lx\n", info->pcAddr);
out += sprintf(out, "Error code: 0x%08x\n", info->resCode);
out += sprintf(out, "Error code: 0x%08lx\n", info->resCode);
}
const char *desc;

View File

@@ -69,14 +69,16 @@ Result fsregSetupPermissions(void)
u32 pid;
Result res;
FS_ProgramInfo info;
u32 storage[8] = {0};
ExHeader_Arm11StorageInfo storage = {0};
storage[6] = 0x800 | 0x400 | 0x80 | 0x1; // SDMC access and NAND access flags
// SDMC access and NAND access flags
storage.fs_access_info = FSACCESS_NANDRW | FSACCESS_NANDRO_RW |
FSACCESS_SDMC_RW | FSACCESS_CATEGORY_SYSTEM_APPLICATION;
info.programId = 0x0004013000006902LL; // Rosalina TID
info.mediaType = MEDIATYPE_NAND;
if(R_SUCCEEDED(res = svcGetProcessId(&pid, 0xFFFF8001))) // 0xFFFF8001 is an handle to the active process
res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, (u8*)storage);
if(R_SUCCEEDED(res = svcGetProcessId(&pid, CUR_PROCESS_HANDLE))) // 0xFFFF8001 is an handle to the active process
res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storage);
return res;
}
@@ -113,7 +115,7 @@ Result FSREG_LoadProgram(u64 *prog_handle, FS_ProgramInfo *title)
return cmdbuf[1];
}
Result FSREG_GetProgramInfo(exheader_header *exheader, u32 entry_count, u64 prog_handle)
Result FSREG_GetProgramInfo(ExHeader *exheader, u32 entry_count, u64 prog_handle)
{
u32 *cmdbuf = getThreadCommandBuffer();

View File

@@ -163,7 +163,7 @@ static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
s64 dummy;
u32 core;
Result r = svcGetDebugThreadContext(&regs, ctx->debug, threadId, THREADCONTEXT_CONTROL_ALL);
int n = sprintf(out, "T%02xthread:%x;", sig, threadId);
int n = sprintf(out, "T%02xthread:%lx;", sig, threadId);
if(R_FAILED(r))
return n;
@@ -171,12 +171,12 @@ static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
r = svcGetDebugThreadParam(&dummy, &core, ctx->debug, ctx->currentThreadId, DBGTHREAD_PARAMETER_CPU_CREATOR); // Creator = "first ran, and running the thread"
if(R_SUCCEEDED(r))
n += sprintf(out + n, "core:%x;", core);
n += sprintf(out + n, "core:%lx;", core);
for(u32 i = 0; i <= 12; i++)
n += sprintf(out + n, "%x:%08x;", i, __builtin_bswap32(regs.cpu_registers.r[i]));
n += sprintf(out + n, "%lx:%08lx;", i, __builtin_bswap32(regs.cpu_registers.r[i]));
n += sprintf(out + n, "d:%08x;e:%08x;f:%08x;19:%08x;",
n += sprintf(out + n, "d:%08lx;e:%08lx;f:%08lx;19:%08lx;",
__builtin_bswap32(regs.cpu_registers.sp), __builtin_bswap32(regs.cpu_registers.lr), __builtin_bswap32(regs.cpu_registers.pc),
__builtin_bswap32(regs.cpu_registers.cpsr));
@@ -184,10 +184,10 @@ static int GDB_ParseCommonThreadInfo(char *out, GDBContext *ctx, int sig)
{
u64 val;
memcpy(&val, &regs.fpu_registers.d[i], 8);
n += sprintf(out + n, "%x:%016llx;", 26 + i, __builtin_bswap64(val));
n += sprintf(out + n, "%lx:%016llx;", 26 + i, __builtin_bswap64(val));
}
n += sprintf(out + n, "2a:%08x;2b:%08x;", __builtin_bswap32(regs.fpu_registers.fpscr), __builtin_bswap32(regs.fpu_registers.fpexc));
n += sprintf(out + n, "2a:%08lx;2b:%08lx;", __builtin_bswap32(regs.fpu_registers.fpscr), __builtin_bswap32(regs.fpu_registers.fpexc));
return n;
}
@@ -301,7 +301,7 @@ int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info)
{
// no signal, SIGTERM, SIGQUIT (process exited), SIGTERM (process terminated)
static int threadExitRepliesSigs[] = { 0, SIGTERM, SIGQUIT, SIGTERM };
return GDB_SendFormattedPacket(ctx, "w%02x;%x", threadExitRepliesSigs[(u32)info->exit_thread.reason], info->thread_id);
return GDB_SendFormattedPacket(ctx, "w%02x;%lx", threadExitRepliesSigs[(u32)info->exit_thread.reason], info->thread_id);
}
break;
}
@@ -365,7 +365,7 @@ int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info)
GDB_SendDebugString(ctx, "Warning: unknown watchpoint encountered!\n");
GDB_ParseCommonThreadInfo(buffer, ctx, SIGTRAP);
return GDB_SendFormattedPacket(ctx, "%s%swatch:%08x;", buffer, kinds[(u32)kind], exc.stop_point.fault_information);
return GDB_SendFormattedPacket(ctx, "%s%swatch:%08lx;", buffer, kinds[(u32)kind], exc.stop_point.fault_information);
break;
}

View File

@@ -127,7 +127,7 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(SyncRequestInfo)
if(R_FAILED(r))
name[0] = 0;
n = sprintf(outbuf, "%s 0x%x, 0x%08x\n", name, cmdId, ctx->threadInfos[id].tls + 0x80);
n = sprintf(outbuf, "%s 0x%lx, 0x%08lx\n", name, cmdId, ctx->threadInfos[id].tls + 0x80);
end:
svcCloseHandle(handle);
@@ -181,9 +181,9 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(TranslateHandle)
svcControlService(SERVICEOP_GET_NAME, serviceBuf, handle);
refcount = (u32)(refcountRaw - 1);
if(serviceBuf[0] != 0)
n = sprintf(outbuf, "(%s *)0x%08x /* %s handle, %u %s */\n", classBuf, kernelAddr, serviceBuf, refcount, refcount == 1 ? "reference" : "references");
n = sprintf(outbuf, "(%s *)0x%08lx /* %s handle, %lu %s */\n", classBuf, kernelAddr, serviceBuf, refcount, refcount == 1 ? "reference" : "references");
else
n = sprintf(outbuf, "(%s *)0x%08x /* %u %s */\n", classBuf, kernelAddr, refcount, refcount == 1 ? "reference" : "references");
n = sprintf(outbuf, "(%s *)0x%08lx /* %lu %s */\n", classBuf, kernelAddr, refcount, refcount == 1 ? "reference" : "references");
end:
svcCloseHandle(handle);
@@ -210,16 +210,16 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMmuConfig)
s64 TTBCR, TTBR0;
svcGetSystemInfo(&TTBCR, 0x10002, 0);
svcGetProcessInfo(&TTBR0, process, 0x10008);
n = sprintf(outbuf, "TTBCR = %u\nTTBR0 = 0x%08x\nTTBR1 =", (u32)TTBCR, (u32)TTBR0);
n = sprintf(outbuf, "TTBCR = %lu\nTTBR0 = 0x%08lx\nTTBR1 =", (u32)TTBCR, (u32)TTBR0);
for(u32 i = 0; i < (isN3DS ? 4 : 2); i++)
{
s64 TTBR1;
svcGetSystemInfo(&TTBR1, 0x10002, 1 + i);
if(i == (isN3DS ? 3 : 1))
n += sprintf(outbuf + n, " 0x%08x\n", (u32)TTBR1);
n += sprintf(outbuf + n, " 0x%08lx\n", (u32)TTBR1);
else
n += sprintf(outbuf + n, " 0x%08x /", (u32)TTBR1);
n += sprintf(outbuf + n, " 0x%08lx /", (u32)TTBR1);
}
svcCloseHandle(process);
}
@@ -294,7 +294,7 @@ GDB_DECLARE_REMOTE_COMMAND_HANDLER(GetMemRegions)
const char *perm = FormatMemPerm(memi.perm);
const char *state = FormatMemState(memi.state);
posInBuffer += sprintf(outbuf + posInBuffer, "%08X - %08X %s %s\n",
posInBuffer += sprintf(outbuf + posInBuffer, "%08lx - %08lx %s %s\n",
memi.base_addr, address, perm, state);
}
}

View File

@@ -163,7 +163,7 @@ GDB_DECLARE_QUERY_HANDLER(CurrentThreadId)
if(ctx->currentThreadId == 0)
ctx->currentThreadId = GDB_GetCurrentThread(ctx);
return ctx->currentThreadId != 0 ? GDB_SendFormattedPacket(ctx, "QC%x", ctx->currentThreadId) : GDB_ReplyErrno(ctx, EPERM);
return ctx->currentThreadId != 0 ? GDB_SendFormattedPacket(ctx, "QC%lx", ctx->currentThreadId) : GDB_ReplyErrno(ctx, EPERM);
}
static void GDB_GenerateThreadListData(GDBContext *ctx)
@@ -187,7 +187,7 @@ static void GDB_GenerateThreadListData(GDBContext *ctx)
char *bufptr = ctx->threadListData;
for(u32 i = 0; i < nbAliveThreads; i++)
bufptr += sprintf(bufptr, i == (nbAliveThreads - 1) ? "%x" : "%x,", aliveThreadIds[i]);
bufptr += sprintf(bufptr, i == (nbAliveThreads - 1) ? "%lx" : "%lx,", aliveThreadIds[i]);
}
static int GDB_SendThreadData(GDBContext *ctx)
@@ -277,27 +277,27 @@ GDB_DECLARE_QUERY_HANDLER(ThreadExtraInfo)
if(val == 65)
sThreadDynamicPriority[0] = 0;
else
sprintf(sThreadDynamicPriority, "dynamic prio.: %d, ", (s32)val);
sprintf(sThreadDynamicPriority, "dynamic prio.: %ld, ", (s32)val);
r = svcGetDebugThreadParam(&dummy, &val, ctx->debug, id, DBGTHREAD_PARAMETER_PRIORITY);
if(R_FAILED(r))
sThreadStaticPriority[0] = 0;
else
sprintf(sThreadStaticPriority, "static prio.: %d, ", (s32)val);
sprintf(sThreadStaticPriority, "static prio.: %ld, ", (s32)val);
r = svcGetDebugThreadParam(&dummy, &val, ctx->debug, id, DBGTHREAD_PARAMETER_CPU_IDEAL);
if(R_FAILED(r))
sCoreIdeal[0] = 0;
else
sprintf(sCoreIdeal, "ideal core: %u, ", val);
sprintf(sCoreIdeal, "ideal core: %lu, ", val);
r = svcGetDebugThreadParam(&dummy, &val, ctx->debug, id, DBGTHREAD_PARAMETER_CPU_CREATOR); // Creator = "first ran, and running the thread"
if(R_FAILED(r))
sCoreCreator[0] = 0;
else
sprintf(sCoreCreator, "running on core %u", val);
sprintf(sCoreCreator, "running on core %lu", val);
n = sprintf(buf, "TLS: 0x%08x%s%s%s%s%s", tls, sStatus, sThreadDynamicPriority, sThreadStaticPriority,
n = sprintf(buf, "TLS: 0x%08lx%s%s%s%s%s", tls, sStatus, sThreadDynamicPriority, sThreadStaticPriority,
sCoreIdeal, sCoreCreator);
return GDB_SendHexPacket(ctx, buf, (u32)n);
@@ -324,5 +324,5 @@ GDB_DECLARE_QUERY_HANDLER(GetTLSAddr)
if(tls == 0)
return GDB_ReplyErrno(ctx, EINVAL);
return GDB_SendFormattedPacket(ctx, "%08x", tls + offset);
return GDB_SendFormattedPacket(ctx, "%08lx", tls + offset);
}

View File

@@ -87,9 +87,9 @@ GDB_DECLARE_XFER_OSDATA_HANDLER(CfwVersion)
isRelease = (bool)out;
if(GET_VERSION_REVISION(version) == 0)
sprintf(versionString, "v%u.%u", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
sprintf(versionString, "v%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
else
sprintf(versionString, "v%u.%u.%u", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
sprintf(versionString, "v%lu.%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
sz = (u32)sprintf(buf, (const char *)osdata_cfw_version_template_xml, versionString, commitHash, isRelease ? "Yes" : "No");
@@ -150,7 +150,7 @@ GDB_DECLARE_XFER_OSDATA_HANDLER(Processes)
static const char item[] =
" <item>\n"
" <column name=\"pid\">%u</column>\n"
" <column name=\"pid\">%lu</column>\n"
" <column name=\"command\">%s</column>\n"
" </item>\n";

View File

@@ -3,7 +3,7 @@
<osdata type="cfwversion">
<item>
<column name="Version">%s</column>
<column name="Commit hash">%08x</column>
<column name="Commit hash">%08lx</column>
<column name="Release">%s</column>
</item>
</osdata>

View File

@@ -32,7 +32,6 @@
#include "menu.h"
#include "csvc.h"
#include "memory.h"
#include "exheader.h"
#define MAP_BASE 0x10000000
@@ -254,45 +253,66 @@ static void HBLDR_HandleCommands(void)
}
case 4:
{
if (cmdbuf[0] != IPC_MakeHeader(4, 0, 2) || cmdbuf[1] != IPC_Desc_Buffer(sizeof(exheader_header), IPC_BUFFER_RW))
if (cmdbuf[0] != IPC_MakeHeader(4, 0, 2) || cmdbuf[1] != IPC_Desc_Buffer(sizeof(ExHeader), IPC_BUFFER_RW))
{
error(cmdbuf, 0xD9001830);
break;
}
// Perform ExHeader patches
exheader_header* exh = (exheader_header*)cmdbuf[2];
u32 stacksize = 4096; // 3dsx/libctru don't require anymore than this
memcpy(exh->codesetinfo.name, "3dsx_app", 8);
memcpy(exh->codesetinfo.stacksize, &stacksize, 4);
memset(&exh->deplist, 0, sizeof(exh->deplist));
memcpy(exh->deplist.programid, dependencyList, sizeof(dependencyList));
ExHeader* exh = (ExHeader*)cmdbuf[2];
memcpy(exh->info.sci.codeset_info.name, "3dsx_app", 8);
exh->info.sci.codeset_info.stack_size = 0x1000; // 3dsx/libctru don't require anymore than this
memset(&exh->info.sci.dependencies, 0, sizeof(exh->info.sci.dependencies));
memcpy(exh->info.sci.dependencies, dependencyList, sizeof(dependencyList));
exheader_arm11systemlocalcaps* localcaps0 = &exh->arm11systemlocalcaps;
exheader_arm11systemlocalcaps* localcaps1 = &exh->accessdesc.arm11systemlocalcaps;
localcaps0->flags[0] = 0x00;
localcaps1->flags[0] = 0x00;
localcaps0->flags[1] = 0x01;
localcaps1->flags[1] = 0x01;
localcaps0->flags[2] = 0x04;
localcaps1->flags[2] = 0x05;
localcaps0->priority = 0x30;
localcaps1->priority = 0;
memset(localcaps0->resourcelimitdescriptor, 0, 0x10);
memset(localcaps1->resourcelimitdescriptor, 0, 0x10);
localcaps0->resourcelimitdescriptor[0] = 0x9E;
localcaps0->resourcelimitdescriptor[1] = 0x9E;
memset(localcaps0->storageinfo.accessinfo, 0xFF, 7);
memset(localcaps1->storageinfo.accessinfo, 0xFF, 7);
memcpy(localcaps0->serviceaccesscontrol, serviceList, sizeof(serviceList));
memcpy(localcaps1->serviceaccesscontrol, serviceList, sizeof(serviceList));
memset(localcaps0->serviceaccesscontrol+0x20, 0, 2);
memset(localcaps1->serviceaccesscontrol+0x20, 0, 2);
localcaps0->resourcelimitcategory = 0;
localcaps1->resourcelimitcategory = 0;
ExHeader_Arm11SystemLocalCapabilities* localcaps0 = &exh->info.aci.local_caps;
ExHeader_Arm11SystemLocalCapabilities* localcaps1 = &exh->access_descriptor.acli.local_caps;
exheader_arm11kernelcapabilities* kcaps0 = &exh->arm11kernelcaps;
exheader_arm11kernelcapabilities* kcaps1 = &exh->accessdesc.arm11kernelcaps;
localcaps0->core_info.core_version = 2;
localcaps0->core_info.use_cpu_clockrate_804MHz = false;
localcaps0->core_info.enable_l2c = false;
localcaps0->core_info.n3ds_system_mode = SYSMODE_N3DS_PROD;
localcaps0->core_info.ideal_processor = 0;
localcaps0->core_info.affinity_mask = BIT(0);
localcaps0->core_info.o3ds_system_mode = SYSMODE_O3DS_PROD;
localcaps0->core_info.priority = 0x30;
localcaps1->core_info.core_version = 2;
localcaps1->core_info.use_cpu_clockrate_804MHz = false;
localcaps1->core_info.enable_l2c = false;
localcaps1->core_info.n3ds_system_mode = SYSMODE_N3DS_PROD;
localcaps1->core_info.ideal_processor = BIT(0); // Intended, this is an oddity of the ExHeader
localcaps1->core_info.affinity_mask = BIT(0);
localcaps1->core_info.o3ds_system_mode = SYSMODE_O3DS_PROD;
localcaps1->core_info.priority = 0; // Intended
memset(localcaps0->reslimits, 0, sizeof(localcaps0->reslimits));
memset(localcaps1->reslimits, 0, sizeof(localcaps0->reslimits));
localcaps0->reslimits[0] = 0x9E; // Stuff needed to run stuff on core1
localcaps1->reslimits[1] = 0x9E;
localcaps0->storage_info.fs_access_info = 0xFFFFFFFF; // Give access to everything
localcaps0->storage_info.no_romfs = true;
localcaps0->storage_info.use_extended_savedata_access = true; // Whatever
localcaps1->storage_info.fs_access_info = 0xFFFFFFFF; // Give access to everything
localcaps0->storage_info.no_romfs = true;
localcaps0->storage_info.use_extended_savedata_access = true; // Whatever
/* We have a patched SM, so whatever... */
memset(localcaps0->service_access, 0, sizeof(localcaps0->service_access));
memcpy(localcaps0->service_access, serviceList, sizeof(serviceList));
memset(localcaps1->service_access, 0, sizeof(localcaps0->service_access));
memcpy(localcaps1->service_access, serviceList, sizeof(serviceList));
localcaps0->reslimit_category = RESLIMIT_CATEGORY_APPLICATION;
localcaps1->reslimit_category = RESLIMIT_CATEGORY_APPLICATION;
ExHeader_Arm11KernelCapabilities* kcaps0 = &exh->info.aci.kernel_caps;
ExHeader_Arm11KernelCapabilities* kcaps1 = &exh->access_descriptor.acli.kernel_caps;
memset(kcaps0->descriptors, 0xFF, sizeof(kcaps0->descriptors));
memset(kcaps1->descriptors, 0xFF, sizeof(kcaps1->descriptors));
memcpy(kcaps0->descriptors, kernelCaps, sizeof(kernelCaps));
@@ -301,22 +321,22 @@ static void HBLDR_HandleCommands(void)
u64 lastdep = sizeof(dependencyList)/8;
if (osGetFirmVersion() >= SYSTEM_VERSION(2,50,0)) // 9.6+ FIRM
{
exh->deplist.programid[lastdep++] = 0x0004013000004002ULL; // nfc
strncpy((char*)&localcaps0->serviceaccesscontrol[0x20], "nfc:u", 8);
strncpy((char*)&localcaps1->serviceaccesscontrol[0x20], "nfc:u", 8);
exh->info.sci.dependencies[lastdep++] = 0x0004013000004002ULL; // nfc
strncpy((char*)&localcaps0->service_access[0x20], "nfc:u", 8);
strncpy((char*)&localcaps1->service_access[0x20], "nfc:u", 8);
s64 dummy = 0;
bool isN3DS = svcGetSystemInfo(&dummy, 0x10001, 0) == 0;
if (isN3DS)
{
exh->deplist.programid[lastdep++] = 0x0004013020004102ULL; // mvd
strncpy((char*)&localcaps0->serviceaccesscontrol[0x21], "mvd:STD", 8);
strncpy((char*)&localcaps1->serviceaccesscontrol[0x21], "mvd:STD", 8);
exh->info.sci.dependencies[lastdep++] = 0x0004013020004102ULL; // mvd
strncpy((char*)&localcaps0->service_access[0x21], "mvd:STD", 8);
strncpy((char*)&localcaps1->service_access[0x21], "mvd:STD", 8);
}
}
cmdbuf[0] = IPC_MakeHeader(4, 1, 2);
cmdbuf[1] = 0;
cmdbuf[2] = IPC_Desc_Buffer(sizeof(exheader_header), IPC_BUFFER_RW);
cmdbuf[2] = IPC_Desc_Buffer(sizeof(ExHeader), IPC_BUFFER_RW);
cmdbuf[3] = (u32)exh;
break;
}

View File

@@ -26,50 +26,6 @@
#include "memory.h"
void *memcpy(void *dest, const void *src, u32 size)
{
u8 *destc = (u8 *)dest;
const u8 *srcc = (const u8 *)src;
for(u32 i = 0; i < size; i++)
destc[i] = srcc[i];
return dest;
}
int memcmp(const void *buf1, const void *buf2, u32 size)
{
const u8 *buf1c = (const u8 *)buf1;
const u8 *buf2c = (const u8 *)buf2;
for(u32 i = 0; i < size; i++)
{
int cmp = buf1c[i] - buf2c[i];
if(cmp)
return cmp;
}
return 0;
}
void *memset(void *dest, u32 value, u32 size)
{
u8 *destc = (u8 *)dest;
for(u32 i = 0; i < size; i++) destc[i] = (u8)value;
return dest;
}
void *memset32(void *dest, u32 value, u32 size)
{
u32 *dest32 = (u32 *)dest;
for(u32 i = 0; i < size/4; i++) dest32[i] = value;
return dest;
}
//Boyer-Moore Horspool algorithm, adapted from http://www-igm.univ-mlv.fr/~lecroq/string/node18.html#SECTION00180
u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
{
@@ -95,82 +51,6 @@ u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
return NULL;
}
char *strcpy(char *dest, const char *src)
{
u32 i;
for(i = 0; src[i] != 0; i++)
dest[i] = src[i];
dest[i] = 0;
return dest;
}
char *strncpy(char *dest, const char *src, u32 size)
{
u32 i;
for(i = 0; i < size && src[i] != 0; i++)
dest[i] = src[i];
for(; i < size; i++)
dest[i] = 0;
return dest;
}
s32 strnlen(const char *string, s32 maxlen)
{
s32 size;
for(size = 0; size < maxlen && *string; string++, size++);
return size;
}
s32 strlen(const char *string)
{
char *stringEnd = (char *)string;
while(*stringEnd) stringEnd++;
return stringEnd - string;
}
s32 strcmp(const char *str1, const char *str2)
{
while(*str1 && (*str1 == *str2))
{
str1++;
str2++;
}
return *str1 - *str2;
}
s32 strncmp(const char *str1, const char *str2, u32 size)
{
while(size && *str1 && (*str1 == *str2))
{
str1++;
str2++;
size--;
}
if (!size)
return 0;
else
return *(u8*)str1 - *(u8*)str2;
}
const char *strchr(const char *string, int c)
{
char *stringEnd = (char *)string;
while(*stringEnd != 0)
{
if(*stringEnd == c) return stringEnd;
stringEnd++;
}
return NULL;
}
void hexItoa(u64 number, char *out, u32 digits, bool uppercase)
{
const char hexDigits[] = "0123456789ABCDEF";

View File

@@ -228,9 +228,9 @@ static void menuDraw(Menu *menu, u32 selected)
isRelease = (bool)out;
if(GET_VERSION_REVISION(version) == 0)
sprintf(versionString, "v%u.%u", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
sprintf(versionString, "v%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
else
sprintf(versionString, "v%u.%u.%u", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
sprintf(versionString, "v%lu.%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
Draw_DrawString(10, 10, COLOR_TITLE, menu->title);
@@ -261,7 +261,7 @@ static void menuDraw(Menu *menu, u32 selected)
if(isRelease)
Draw_DrawFormattedString(10, SCREEN_BOT_HEIGHT - 20, COLOR_TITLE, "Luma3DS %s", versionString);
else
Draw_DrawFormattedString(10, SCREEN_BOT_HEIGHT - 20, COLOR_TITLE, "Luma3DS %s-%08x", versionString, commitHash);
Draw_DrawFormattedString(10, SCREEN_BOT_HEIGHT - 20, COLOR_TITLE, "Luma3DS %s-%08lx", versionString, commitHash);
Draw_FlushFramebuffer();
}

View File

@@ -224,7 +224,7 @@ void RosalinaMenu_TakeScreenshot(void)
days++;
month++;
sprintf(filename, "/luma/screenshots/%04u-%02u-%02u_%02u-%02u-%02u.%03u_top.bmp", year, month, days, hours, minutes, seconds, milliseconds);
sprintf(filename, "/luma/screenshots/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_top.bmp", year, month, days, hours, minutes, seconds, milliseconds);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
Draw_CreateBitmapHeader(framebufferCache, 400, 240);
@@ -239,7 +239,7 @@ void RosalinaMenu_TakeScreenshot(void)
TRY(IFile_Write(&file, &total, framebufferCache, 3 * 400 * 120, 0));
TRY(IFile_Close(&file));
sprintf(filename, "/luma/screenshots/%04u-%02u-%02u_%02u-%02u-%02u.%03u_bot.bmp", year, month, days, hours, minutes, seconds, milliseconds);
sprintf(filename, "/luma/screenshots/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_bot.bmp", year, month, days, hours, minutes, seconds, milliseconds);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
Draw_CreateBitmapHeader(framebufferCache, 320, 240);
@@ -256,7 +256,7 @@ void RosalinaMenu_TakeScreenshot(void)
if((GPU_FB_TOP_FMT & 0x20) && (Draw_GetCurrentFramebufferAddress(true, true) != Draw_GetCurrentFramebufferAddress(true, false)))
{
sprintf(filename, "/luma/screenshots/%04u-%02u-%02u_%02u-%02u-%02u.%03u_top_right.bmp", year, month, days, hours, minutes, seconds, milliseconds);
sprintf(filename, "/luma/screenshots/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_top_right.bmp", year, month, days, hours, minutes, seconds, milliseconds);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
Draw_CreateBitmapHeader(framebufferCache, 400, 240);
@@ -285,7 +285,7 @@ end:
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Screenshot");
if(R_FAILED(res))
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08x).", (u32)res);
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08lx).", (u32)res);
else
Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded.");

View File

@@ -1080,7 +1080,8 @@ static void Cheat_LoadCheatsIntoMemory(u64 titleId)
cheat = Cheat_AllocCheat();
}
}
strncpy(cheat->name, line, 39);
strncpy(cheat->name, line, 38);
cheat->name[38] = '\0';
}
}
} while (R_SUCCEEDED(res));
@@ -1225,7 +1226,7 @@ void RosalinaMenu_Cheats(void)
}
else
{
Draw_DrawFormattedString(10, 10, COLOR_TITLE, "ERROR: %08x", r);
Draw_DrawFormattedString(10, 10, COLOR_TITLE, "ERROR: %08lx", r);
Draw_DrawFormattedString(10, 30, COLOR_RED, failureReason);
}
Draw_FlushFramebuffer();

View File

@@ -103,7 +103,7 @@ void DebuggerMenu_EnableDebugger(void)
}
if(res != 0)
sprintf(buf, "Starting debugger... failed (0x%08x).", (u32)res);
sprintf(buf, "Starting debugger... failed (0x%08lx).", (u32)res);
done = true;
}
@@ -135,7 +135,7 @@ void DebuggerMenu_DisableDebugger(void)
}
if(res != 0)
sprintf(buf, "Failed to disable debugger (0x%08x).", (u32)res);
sprintf(buf, "Failed to disable debugger (0x%08lx).", (u32)res);
do
{

View File

@@ -78,7 +78,7 @@ void MiscellaneousMenu_SwitchBoot3dsxTargetTitle(void)
miscellaneousMenu.items[0].title = "Switch the hb. title to hblauncher_loader";
}
else if(R_FAILED(res))
sprintf(failureReason, "%08x", (u32)res);
sprintf(failureReason, "%08lx", (u32)res);
else
{
res = -1;
@@ -175,7 +175,7 @@ void MiscellaneousMenu_SaveSettings(void)
IFile file;
u64 total;
struct PACKED
struct PACKED ALIGN(4)
{
char magic[4];
u16 formatVersionMajor, formatVersionMinor;
@@ -227,7 +227,7 @@ void MiscellaneousMenu_SaveSettings(void)
if(R_SUCCEEDED(res))
Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded.");
else
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08x).", res);
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08lx).", res);
Draw_FlushFramebuffer();
Draw_Unlock();
}
@@ -252,7 +252,7 @@ void MiscellaneousMenu_InputRedirection(void)
svcCloseHandle(inputRedirectionThreadStartedEvent);
if(res != 0)
sprintf(buf, "Failed to stop InputRedirection (0x%08x).", (u32)res);
sprintf(buf, "Failed to stop InputRedirection (0x%08lx).", (u32)res);
else
miscellaneousMenu.items[2].title = "Start InputRedirection";
}
@@ -308,7 +308,7 @@ void MiscellaneousMenu_InputRedirection(void)
}
if(res != 0)
sprintf(buf, "Starting InputRedirection... failed (0x%08x).", (u32)res);
sprintf(buf, "Starting InputRedirection... failed (0x%08lx).", (u32)res);
else
miscellaneousMenu.items[2].title = "Stop InputRedirection";

View File

@@ -50,7 +50,7 @@ void N3DSMenu_UpdateStatus(void)
svcGetSystemInfo(&L2CacheEnabled, 0x10001, 2);
N3DSMenu.items[0].title = L2CacheEnabled ? "Disable L2 cache" : "Enable L2 cache";
sprintf(clkRateBuf, "Set clock rate to %uMHz", clkRate != 268 ? 268 : (u32)higherClkRate);
sprintf(clkRateBuf, "Set clock rate to %luMHz", clkRate != 268 ? 268 : (u32)higherClkRate);
}
void N3DSMenu_ChangeClockRate(void)

View File

@@ -73,11 +73,11 @@ static inline int ProcessListMenu_FormatInfoLine(char *out, const ProcessInfo *i
else
{
checkbox = "(W) ";
sprintf(commentBuf, "Port: %d", GDB_PORT_BASE + id);
sprintf(commentBuf, "Port: %ld", GDB_PORT_BASE + id);
}
}
return sprintf(out, "%s%-4u %-8.8s %s", checkbox, info->pid, info->name, commentBuf); // Theoritically PIDs are 32-bit ints, but we'll only justify 4 digits
return sprintf(out, "%s%-4lu %-8.8s %s", checkbox, info->pid, info->name, commentBuf); // Theoritically PIDs are 32-bit ints, but we'll only justify 4 digits
}
static void ProcessListMenu_DumpMemory(const char *name, void *start, u32 size)