]> Chaos Git - corbenik/corbenik.git/commitdiff
Remove malloc (not working, obviously)
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 20 Dec 2016 04:10:17 +0000 (23:10 -0500)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 20 Dec 2016 04:10:17 +0000 (23:10 -0500)
include/common.h
include/std/allocator.h [deleted file]
include/std/memory.h
source/Makefile.am
source/config-backend-file.c
source/std/allocator.c [deleted file]
source/std/memory.c

index cae7211f5c80d542201b30a23908d4b32bd300be..9fa1ce2a7c429e3fe2eb7cf0c59f8a8662673914 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __COMMON_H
 #define __COMMON_H
 
+#include <stdlib.h>
+
 #include <corbconf.h>
 
 #include <std/unused.h>
@@ -15,7 +17,6 @@
 #include <std/draw.h>
 
 #include <firm/headers.h>
-#include <std/allocator.h>
 #include <firm/decryptor.h>
 #include <firm/firm.h>
 #include <firm/keys.h>
diff --git a/include/std/allocator.h b/include/std/allocator.h
deleted file mode 100644 (file)
index c0fad2b..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#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
index 464b847cae7e7f81bb0f4569b8e9e38a8b252c8a..ca4df94462a847b50e958cfb7e5e5a9d291fdf5d 100644 (file)
@@ -6,8 +6,6 @@
 #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.
index 8a3142a24d82dd85370e3688b9a4c77a589b5ff4..0dae7bafca71ff89f636b1d4110644ec7e725a63 100644 (file)
@@ -19,4 +19,4 @@ corbenikdir = $(top_srcdir)/source
 
 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
index abef848f337e65959136c125d4c0b04227904868..1d72774398a859c3c4ccbbe1f2174388ceae4255 100644 (file)
@@ -8,6 +8,8 @@ char *config_file_path = NULL;
 int changed_consoles = 0;
 uint32_t cid[4];
 
+#define PATCH_MAX 0x100000
+
 void
 regenerate_config(void)
 {
@@ -21,7 +23,7 @@ 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);
 }
 
@@ -111,8 +113,8 @@ load_config(void)
             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);
     }
@@ -121,7 +123,7 @@ load_config(void)
     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);
 
@@ -157,7 +159,7 @@ save_config(void)
     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);
 }
diff --git a/source/std/allocator.c b/source/std/allocator.c
deleted file mode 100644 (file)
index 9c26e56..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-#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;
-}
index 977e7f9b243d33336a6c87d1db79306437c37bae..60b7a0a720bb78070ded1693ccb162c9e1a5954b 100644 (file)
@@ -23,20 +23,6 @@ strdupcat(const char* str, const char *cat)
     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)