Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ endif()
set(BOX64_ROOT ${CMAKE_SOURCE_DIR})

add_definitions(-std=gnu11 -funwind-tables -fvisibility=hidden)
add_definitions(-D_GNU_SOURCE=1)
add_definitions(-D_FILE_OFFSET_BITS=64)

if(USE_CCACHE)
find_program(CCACHE_FOUND ccache)
Expand Down
1 change: 0 additions & 1 deletion external/musl/sincos.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* ====================================================
*/

#define _GNU_SOURCE
#include "libm.h"

void __cdecl sincos(double x, double *sin, double *cos)
Expand Down
1 change: 0 additions & 1 deletion src/box64context.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
1 change: 0 additions & 1 deletion src/custommem.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
1 change: 0 additions & 1 deletion src/custommmap.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <unistd.h>
#include <stdint.h>

Expand Down
1 change: 0 additions & 1 deletion src/dynarec/arm64/dynarec_arm64_functions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion src/dynarec/dynarec_native_functions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion src/dynarec/la64/dynarec_la64_functions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion src/dynarec/ppc64le/dynarec_ppc64le_functions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion src/dynarec/rv64/dynarec_rv64_functions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down
1 change: 0 additions & 1 deletion src/elfs/elfhacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <stdlib.h>
Expand Down
1 change: 0 additions & 1 deletion src/elfs/elfhash.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
1 change: 0 additions & 1 deletion src/elfs/elfhash32.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
5 changes: 2 additions & 3 deletions src/elfs/elfloader.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -433,7 +432,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
setProtection_elf((uintptr_t)p, asize, prot);
head->multiblocks[n].p = p;
if (file_read_size) {
fseeko64(head->file, head->multiblocks[n].offs, SEEK_SET);
fseeko(head->file, head->multiblocks[n].offs, SEEK_SET);
if(fread((void*)head->multiblocks[n].paddr, file_read_size, 1, head->file)!=1) {
printf_log(LOG_NONE, "Cannot read elf block (@%p 0x%zx/0x%zx) for elf \"%s\"\n", (void*)head->multiblocks[n].offs, head->multiblocks[n].asize, (box64_pagesize - 1), head->name);
return 1;
Expand All @@ -458,7 +457,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
char* dest = (char*)(context->tlsdata+context->tlssize+head->tlsbase);
printf_log(LOG_DEBUG, "Loading TLS block #%zu @%p (0x%zx/0x%zx)\n", i, dest, e->p_filesz, e->p_memsz);
if(e->p_filesz) {
fseeko64(head->file, e->p_offset, SEEK_SET);
fseeko(head->file, e->p_offset, SEEK_SET);
if(fread(dest, e->p_filesz, 1, head->file)!=1) {
mutex_unlock(&context->mutex_tls);
printf_log(LOG_NONE, "Fail to read PT_TLS part #%zu (size=%zd)\n", i, e->p_filesz);
Expand Down
19 changes: 9 additions & 10 deletions src/elfs/elfloader32.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -156,22 +155,22 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
void* image = NULL;
if(!head->vaddr) {
sz += head->align;
raw = mmap64(from_ptrv(offs), sz, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
raw = mmap(from_ptrv(offs), sz, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
image = (void*)(((uintptr_t)raw+max_align)&~max_align);
} else {
if(from_ptr(head->vaddr)&(box64_pagesize-1)) {
// load address is not page-aligned, round down and increase size
uintptr_t aligned_addr = ALIGN_DOWN(from_ptr(head->vaddr));
size_t extra = from_ptr(head->vaddr) - aligned_addr;
raw = mmap64((void*)aligned_addr, sz + extra, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
raw = mmap((void*)aligned_addr, sz + extra, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
if(raw != MAP_FAILED && (uintptr_t)raw == aligned_addr) {
image = from_ptrv(head->vaddr);
sz += extra;
} else {
image = raw;
}
} else {
image = raw = mmap64(from_ptrv(head->vaddr), sz, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
image = raw = mmap(from_ptrv(head->vaddr), sz, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
}
}
if(image!=MAP_FAILED && !head->vaddr && image!=from_ptrv(offs)) {
Expand Down Expand Up @@ -231,7 +230,7 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
try_mmap = 0;
if(try_mmap) {
printf_dump(log_level, "Mmaping 0x%lx(0x%lx) bytes @%p for Elf \"%s\"\n", head->multiblocks[n].size, head->multiblocks[n].asize, (void*)head->multiblocks[n].paddr, head->name);
void* p = mmap64(
void* p = mmap(
(void*)head->multiblocks[n].paddr,
head->multiblocks[n].size,
prot,
Expand Down Expand Up @@ -269,7 +268,7 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
file_map_addr += box64_pagesize;
if(file_map_addr < head->multiblocks[n].paddr + e->p_filesz) {
size_t file_map_delta = file_map_addr - paddr;
void* file_map = mmap64((void*)file_map_addr, file_size - file_map_delta, prot | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, head->fileno, file_offset + file_map_delta);
void* file_map = mmap((void*)file_map_addr, file_size - file_map_delta, prot | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, head->fileno, file_offset + file_map_delta);
mapped_file = file_map == (void*)file_map_addr;
if(mapped_file) {
p = (void*)paddr;
Expand All @@ -283,7 +282,7 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
}
if (!mapped_file && !file_delta) {
printf_dump(log_level, "Allocating 0x%zx (0x%zx) bytes @%p, will read 0x%zx @%p for Elf \"%s\"\n", asize, e->p_memsz, (void*)paddr, e->p_filesz, (void*)head->multiblocks[n].paddr, head->name);
p = mmap64((void*)paddr, asize, prot | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
p = mmap((void*)paddr, asize, prot | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
} else if (!mapped_file) {
// difference in pagesize, so need to mmap only what needed to be...
//check startint point
Expand All @@ -299,7 +298,7 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
}
if(new_size>0) {
printf_dump(log_level, "Allocating 0x%zx (0x%zx/0x%zx) bytes @%p, will read 0x%zx @%p for Elf \"%s\"\n", ALIGN(new_size), paddr, e->p_memsz, (void*)new_addr, e->p_filesz, (void*)head->multiblocks[n].paddr, head->name);
p = mmap64(
p = mmap(
(void*)new_addr,
ALIGN(new_size),
prot|PROT_WRITE,
Expand All @@ -326,7 +325,7 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
setProtection_elf((uintptr_t)p, asize, prot);
head->multiblocks[n].p = p;
if (file_read_size) {
fseeko64(head->file, head->multiblocks[n].offs, SEEK_SET);
fseeko(head->file, head->multiblocks[n].offs, SEEK_SET);
if(fread((void*)head->multiblocks[n].paddr, file_read_size, 1, head->file)!=1) {
printf_log(LOG_NONE, "Cannot read elf block (@%p 0x%zx/0x%zx) for elf \"%s\"\n", (void*)head->multiblocks[n].offs, head->multiblocks[n].asize, (box64_pagesize - 1), head->name);
return 1;
Expand All @@ -351,7 +350,7 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
char* dest = (char*)(context->tlsdata+context->tlssize+head->tlsbase);
printf_log(LOG_DEBUG, "Loading TLS block #%zu @%p (0x%zx/0x%zx)\n", i, dest, e->p_filesz, e->p_memsz);
if(e->p_filesz) {
fseeko64(head->file, e->p_offset, SEEK_SET);
fseeko(head->file, e->p_offset, SEEK_SET);
if(fread(dest, e->p_filesz, 1, head->file)!=1) {
mutex_unlock(&context->mutex_tls);
printf_log(LOG_NONE, "Fail to read PT_TLS part #%zu (size=%zd)\n", i, e->p_filesz);
Expand Down
13 changes: 6 additions & 7 deletions src/elfs/elfparser.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -28,7 +27,7 @@ static int LoadSH(FILE *f, Elf64_Shdr *s, void** SH, const char* name, uint32_t
printf_log(LOG_INFO, "Section Header \"%s\" (off=%ld, size=%ld) has size (not multiple of %ld)\n", name, s->sh_offset, s->sh_size, sizeof(Elf64_Sym));
}
*SH = box_calloc(1, s->sh_size);
fseeko64(f, s->sh_offset ,SEEK_SET);
fseeko(f, s->sh_offset ,SEEK_SET);
if(fread(*SH, s->sh_size, 1, f)!=1) {
printf_log(LOG_INFO, "Cannot read Section Header \"%s\" (off=%ld, size=%ld)\n", name, s->sh_offset, s->sh_size);
return -1;
Expand Down Expand Up @@ -71,7 +70,7 @@ static void LoadProgramSection(FILE *f, elfheader_t* h, int size, uint32_t type,
for (size_t i=0; i<h->numPHEntries && !*what; ++i) {
if(h->PHEntries._64[i].p_type == type) {
*what = box_calloc(1, h->PHEntries._64[i].p_memsz);
fseeko64(f, h->PHEntries._64[i].p_offset ,SEEK_SET);
fseeko(f, h->PHEntries._64[i].p_offset ,SEEK_SET);
if(fread(h->Dynamic._64, h->PHEntries._64[i].p_filesz, 1, f)!=1) {
printf_log(LOG_INFO, "Cannot read Program Header %zd \"%s\" (off=%ld, size=%ld)\n", i, "PT_DYNAMIC", h->PHEntries._64[i].p_offset, h->PHEntries._64[i].p_filesz);
box_free(*what);
Expand Down Expand Up @@ -104,7 +103,7 @@ static void* LoadSubLoadSection(FILE *f, elfheader_t* h, uintptr_t offset, size_
size = end - start;
}
ret = box_calloc(1, size);
fseeko64(f, h->PHEntries._64[i].p_offset + offset - h->PHEntries._64[i].p_vaddr, SEEK_SET);
fseeko(f, h->PHEntries._64[i].p_offset + offset - h->PHEntries._64[i].p_vaddr, SEEK_SET);
size_t to_read = size;
if (size + offset - h->PHEntries._64[i].p_vaddr > h->PHEntries._64[i].p_filesz)
to_read -= (size + offset - h->PHEntries._64[i].p_vaddr) - h->PHEntries._64[i].p_filesz;
Expand Down Expand Up @@ -197,7 +196,7 @@ elfheader_t* ParseElfHeader64(FILE* f, const char* name, int exec)
if(header.e_shentsize && !h->numSHEntries && header.e_shoff) {
printf_dump(LOG_DEBUG, "Read number of Sections in 1st Section\n");
// read 1st section header and grab actual number from here
fseeko64(f, header.e_shoff, SEEK_SET);
fseeko(f, header.e_shoff, SEEK_SET);
Elf64_Shdr section;
if(fread(&section, sizeof(Elf64_Shdr), 1, f)!=1) {
box_free(h);
Expand All @@ -210,7 +209,7 @@ elfheader_t* ParseElfHeader64(FILE* f, const char* name, int exec)
// now read all section headers
printf_dump(LOG_DEBUG, "Read %zu Section header\n", h->numSHEntries);
h->SHEntries._64 = (Elf64_Shdr*)box_calloc(h->numSHEntries, sizeof(Elf64_Shdr));
fseeko64(f, header.e_shoff ,SEEK_SET);
fseeko(f, header.e_shoff ,SEEK_SET);
if(fread(h->SHEntries._64, sizeof(Elf64_Shdr), h->numSHEntries, f)!=h->numSHEntries) {
FreeElfHeader(&h);
printf_log(LOG_INFO, "Cannot read all Section Header\n");
Expand All @@ -226,7 +225,7 @@ elfheader_t* ParseElfHeader64(FILE* f, const char* name, int exec)

printf_dump(LOG_DEBUG, "Read %zu Program header\n", h->numPHEntries);
h->PHEntries._64 = (Elf64_Phdr*)box_calloc(h->numPHEntries, sizeof(Elf64_Phdr));
fseeko64(f, header.e_phoff ,SEEK_SET);
fseeko(f, header.e_phoff ,SEEK_SET);
if(fread(h->PHEntries._64, sizeof(Elf64_Phdr), h->numPHEntries, f)!=h->numPHEntries) {
FreeElfHeader(&h);
printf_log(LOG_INFO, "Cannot read all Program Header\n");
Expand Down
9 changes: 4 additions & 5 deletions src/elfs/elfparser32.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -26,7 +25,7 @@ static int LoadSH(FILE *f, Elf32_Shdr *s, void** SH, const char* name, uint32_t
printf_log(LOG_INFO, "Section Header \"%s\" (off=%d, size=%d) has size (not multiple of %ld)\n", name, s->sh_offset, s->sh_size, sizeof(Elf32_Sym));
}
*SH = actual_calloc(1, s->sh_size);
fseeko64(f, s->sh_offset ,SEEK_SET);
fseeko(f, s->sh_offset ,SEEK_SET);
if(fread(*SH, s->sh_size, 1, f)!=1) {
printf_log(LOG_INFO, "Cannot read Section Header \"%s\" (off=%d, size=%d)\n", name, s->sh_offset, s->sh_size);
return -1;
Expand Down Expand Up @@ -128,7 +127,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
if(h->numSHEntries == 0) {
printf_log(LOG_DEBUG, "Read number of Sections in 1st Section\n");
// read 1st section header and grab actual number from here
fseeko64(f, header.e_shoff, SEEK_SET);
fseeko(f, header.e_shoff, SEEK_SET);
Elf32_Shdr section;
if(fread(&section, sizeof(Elf32_Shdr), 1, f)!=1) {
actual_free(h);
Expand All @@ -140,7 +139,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)
// now read all section headers
printf_log(LOG_DEBUG, "Read %d Section header\n", h->numSHEntries);
h->SHEntries._32 = (Elf32_Shdr*)actual_calloc(h->numSHEntries, sizeof(Elf32_Shdr));
fseeko64(f, header.e_shoff ,SEEK_SET);
fseeko(f, header.e_shoff ,SEEK_SET);
if(fread(h->SHEntries._32, sizeof(Elf32_Shdr), h->numSHEntries, f)!=h->numSHEntries) {
FreeElfHeader(&h);
printf_log(LOG_INFO, "Cannot read all Section Header\n");
Expand All @@ -156,7 +155,7 @@ elfheader_t* ParseElfHeader32(FILE* f, const char* name, int exec)

printf_log(LOG_DEBUG, "Read %d Program header\n", h->numPHEntries);
h->PHEntries._32 = (Elf32_Phdr*)actual_calloc(h->numPHEntries, sizeof(Elf32_Phdr));
fseeko64(f, header.e_phoff ,SEEK_SET);
fseeko(f, header.e_phoff ,SEEK_SET);
if(fread(h->PHEntries._32, sizeof(Elf32_Phdr), h->numPHEntries, f)!=h->numPHEntries) {
FreeElfHeader(&h);
printf_log(LOG_INFO, "Cannot read all Program Header\n");
Expand Down
1 change: 0 additions & 1 deletion src/emu/x64int3.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
Expand Down
1 change: 0 additions & 1 deletion src/emu/x64run.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: MIT
#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
Loading
Loading