Fix regression in elf2pe program

This commit is contained in:
Justine Tunney 2024-07-04 04:02:20 -07:00
parent bd6d9ff99a
commit 5a9a08d1cf
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2 changed files with 33 additions and 8 deletions

View file

@ -27,6 +27,7 @@
#include "libc/fmt/itoa.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/dll.h"
#include "libc/intrin/kprintf.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
@ -158,6 +159,7 @@ static const char *stubpath;
static long FLAG_SizeOfStackCommit = 64 * 1024;
static long FLAG_SizeOfStackReserve = 8 * 1024 * 1024;
#define TINYMALLOC_MAX_ALIGN MAX_ALIGN
#include "libc/mem/tinymalloc.inc"
static wontreturn void Die(const char *thing, const char *reason) {
@ -186,6 +188,13 @@ static void *Calloc(size_t n) {
return p;
}
static void *Memalign(size_t a, size_t n) {
void *p;
if (!(p = memalign(a, n)))
DieOom();
return p;
}
static void *Realloc(void *p, size_t n) {
if (!(p = realloc(p, n)))
DieOom();
@ -1106,7 +1115,7 @@ int main(int argc, char *argv[]) {
GetOpts(argc, argv);
// translate executable
struct Elf *elf = OpenElf(argv[optind]);
char *buf = memalign(MAX_ALIGN, 134217728);
char *buf = Memalign(MAX_ALIGN, 134217728);
struct ImagePointer ip = GeneratePe(elf, buf, 0x00400000);
if (creat(outpath, 0755) == -1)
DieSys(elf->path);