#ifndef __COMMON_H
#define __COMMON_H
+#include <stdlib.h>
+
#include <corbconf.h>
#include <std/unused.h>
#include <std/draw.h>
#include <firm/headers.h>
-#include <std/allocator.h>
#include <firm/decryptor.h>
#include <firm/firm.h>
#include <firm/keys.h>
+++ /dev/null
-#ifndef __FCRAM_H
-#define __FCRAM_H
-
-#include <stdint.h>
-#include <stddef.h>
-
-#define FCRAM_SPACING 0x100000 ///< Space between most of the locations (remove me)
-
-/* Grow program break.
- *
- * \param bytes Number of bytes to grow by.
- */
-void *sbrk(size_t bytes);
-
-#ifdef MALLOC_DEBUG
-
-/* Prints stats for allocation to stderr.
- */
-void print_alloc_stats(void);
-
-/* Allocate memory for use (debugging only, don't call)
- *
- * \param size Size in bytes to allocate.
- * \param info Info to store about malloc
- */
-void* malloc_chkd(size_t size, const char* info);
-
-/* Free in-use memory allocated by malloc (debugging only, don't call)
- *
- * \param ptr Pointer to free.
- * \param info Info to store about free
- */
-void free_chkd(void* ptr, const char* info);
-
-#define STRINGIFY(x) #x
-#define TOSTRING(x) STRINGIFY(x)
-#define malloc(x) malloc_chkd( x , __FILE__ ":" TOSTRING(__LINE__) )
-#define free(x) free_chkd( x , __FILE__ ":" TOSTRING(__LINE__) )
-
-#else
-
-/* Allocate memory for use.
- *
- * \param size Size in bytes to allocate.
- */
-void *malloc (size_t size);
-
-/* Free in-use memory allocated by malloc.
- *
- * \param ptr Pointer to free.
- */
-void free (void* ptr);
-
-/* Reallocates memory to size. Guaranteed to preserve the original data.
- *
- * \param ptr Pointer to reallocate
- * \param size Size to reallocate as
- */
-void *realloc(void* ptr, size_t size);
-
-#endif
-
-#endif
#include <string.h>
#include <ctype.h>
-int atoi(const char *str);
-
uint8_t *memfind(uint8_t *startPos, uint32_t size, const void *pattern, uint32_t patternSize);
/* Basically strdup, because newlib's memory handling is crap.
inc_dir = $(top_srcdir)/include
-corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c std/fs.c std/draw.c std/memory.c std/abort.c std/allocator.c menu.c firm/util.c firm/keys.c firm/firmlaunch.c firm/version.c firm/firm.c firm/decryptor.c interpreter.c input.c patcher.c chainloader.c config-backend-file.c menu-backend.c start.s interrupt.c arm11.c test-framework.c
+corbenik_SOURCES = patch/reboot.c patch/svc.c patch/module.c patch/emunand.c main.c std/fs.c std/draw.c std/memory.c std/abort.c menu.c firm/util.c firm/keys.c firm/firmlaunch.c firm/version.c firm/firm.c firm/decryptor.c interpreter.c input.c patcher.c chainloader.c config-backend-file.c menu-backend.c start.s interrupt.c arm11.c test-framework.c
int changed_consoles = 0;
uint32_t cid[4];
+#define PATCH_MAX 0x100000
+
void
regenerate_config(void)
{
if (!(conf_handle = fopen(config_file_path, "w")))
poweroff();
- fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
+ fwrite(config, 1, sizeof(struct config_file) + PATCH_MAX, conf_handle);
fclose(conf_handle);
}
cid_cp >>= 4;
}
- config = (struct config_file*)malloc(sizeof(struct config_file) + FCRAM_SPACING / 2);
- memset(config, 0, sizeof(struct config_file) + FCRAM_SPACING / 2);
+ config = (struct config_file*)malloc(sizeof(struct config_file) + PATCH_MAX);
+ memset(config, 0, sizeof(struct config_file) + PATCH_MAX);
enable_list = (uint8_t*)config + sizeof(struct config_file);
fclose(f);
}
if (!(conf_handle = fopen(config_file_path, "r"))) {
regenerate_config();
} else {
- fread(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
+ fread(config, 1, sizeof(struct config_file) + PATCH_MAX, conf_handle);
fclose(conf_handle);
if (!(conf_handle = fopen(config_file_path, "w")))
while(1);
- fwrite(config, 1, sizeof(struct config_file) + FCRAM_SPACING / 2, conf_handle);
+ fwrite(config, 1, sizeof(struct config_file) + PATCH_MAX, conf_handle);
fclose(conf_handle);
}
+++ /dev/null
-#include <common.h>
-
-// 16 <- AES block size.
-#define SALLOC_ALIGN 16
-
-struct alloc_info* first_mem = NULL;
-static uint32_t *heap_end = NULL;
-extern uint32_t __end__; /* Defined by the linker */
-
-void* sbrk(size_t incr) {
- uint32_t *prev_heap_end;
-
- if (heap_end == NULL) {
- heap_end = &__end__;
- }
-
- // FIXME - Make sure heap isn't leaking into stack here. That would be bad.
-
- prev_heap_end = heap_end;
-
- heap_end += incr;
- return (void*) prev_heap_end;
-}
-
-// This is an incredibly crappy and inefficient implementation of malloc/free nicked from stackoverflow.
-
-typedef struct free_block {
- size_t size;
- size_t real_size;
-#ifdef MALLOC_DEBUG
- const char* info;
-#endif
- struct free_block* next;
-
- uint32_t canary;
- uint32_t pad[3]; // Otherwise, not a 16-multiple
-} free_block;
-
-static free_block free_block_list_head = {
- 0,
- 0,
-#ifdef MALLOC_DEBUG
- NULL,
-#endif
- 0,
- 0,
- {0}
-};
-
-static const size_t align_to = 64;
-
-#ifdef MALLOC_DEBUG
-static size_t alloc_count = 0;
-static size_t free_count = 0;
-static size_t allocated_memory = 0;
-#endif
-
-#ifdef MALLOC_DEBUG
-void* malloc_chkd(size_t size, const char* info) {
-#else
-void* malloc(size_t size) {
-#endif
- size_t bsize = (size + sizeof(free_block) + (align_to - 1)) & ~ (align_to - 1);
-
- free_block* block = free_block_list_head.next;
- free_block** head = &(free_block_list_head.next);
-
- while (block != 0) {
- if (block->size >= bsize) {
- *head = block->next;
-
- block->real_size = size;
-#ifdef MALLOC_DEBUG
- block->info = info;
-
- ++alloc_count;
- allocated_memory += block->size;
-#endif
-
- return ((char*)block) + sizeof(free_block);
- }
- head = &(block->next);
- block = block->next;
- }
-
- block = (free_block*)sbrk(bsize);
- block->size = bsize;
- block->real_size = size;
- block->canary = 0x1337d00d; // Arbitrary. No special meaning.
-
-#ifdef MALLOC_DEBUG
- block->info = info;
-
- ++alloc_count;
- allocated_memory += bsize;
-#endif
-
- return ((char*)block) + sizeof(free_block);
-}
-
-void* malloc_zero(size_t size) {
- void* ret = malloc(size);
-
- if (ret)
- memset(ret, 0, size);
-
- return ret;
-}
-
-#ifdef MALLOC_DEBUG
-void free_chkd(void* ptr, const char* info) {
-#else
-void free(void* ptr) {
-#endif
- if (ptr == NULL) return;
-
- free_block* block = (free_block*)(((char*)ptr) - sizeof(free_block ));
-
-#ifdef MALLOC_DEBUG
- if (block->canary != 0x1337d00d) {
- panic("%s: Attempt free non-pointer.\n", info);
- }
-
- ++free_count;
- if (allocated_memory < block->size) {
- fprintf(stderr, "%s: Invalid free detected.\n"
- " Allocated at: %s\n",
- info, block->info);
- }
- allocated_memory -= block->size;
-#endif
-
- block->next = free_block_list_head.next;
- free_block_list_head.next = block;
-}
-
-#ifdef MALLOC_DEBUG
-void print_alloc_stats(void) {
- fprintf(stderr, "[A] %u [F] %u [M] %u [B] %lu\n", alloc_count, free_count, allocated_memory, (uint32_t)heap_end - (uint32_t)&__end__);
-}
-#endif
-
-void *realloc(void* ptr, size_t size) {
- if (ptr == NULL)
- return malloc(size);
-
- free_block* current = (free_block*)(((char*)ptr) - sizeof(free_block));
-
- if (size < current->size || size < current->real_size)
- return ptr;
-
- void* new_ptr = malloc(size);
-
- memcpy(new_ptr, ptr, current->real_size);
-
- free(ptr);
-
- return new_ptr;
-}
return out;
}
-int
-atoi(const char *str)
-{
- int res = 0;
-
- while (str[0] && str[0] >= '0' && str[0] <= '9') {
- res *= 10;
- res += str[0] - '0';
- str++;
- }
-
- return res;
-}
-
#define ALPHABET_LEN 256
#define NOT_FOUND patlen
#define max(a, b) ((a < b) ? b : a)