Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use of 64-bit pointers #48

Closed
JayFoxRox opened this issue Mar 14, 2019 · 0 comments
Closed

Avoid use of 64-bit pointers #48

JayFoxRox opened this issue Mar 14, 2019 · 0 comments
Labels

Comments

@JayFoxRox
Copy link

JayFoxRox commented Mar 14, 2019

Until the entire game code is rewritten, the code will require 32-bit pointers as they might be casted to register values or 32-bit variables.

However, internally, the code will continue to use some native pointers, so the sizeof() structures would change on 64 bit (which is why 64 bit compilation is not supported, even with the Cpp module).

Example (lfbPtr is native pointer):

NFSIISE/src/Glide2x.h

Lines 294 to 300 in fd87de0

typedef struct {
int size;
void *lfbPtr;
uint32_t strideInBytes;
GrLfbWriteMode_t writeMode;
GrOriginLocation_t origin;
} GrLfbInfo_t;

A possible solution is:

// For Cpp
typedef uint32_t _GuestPointer;
#define GuestPointer(x) _GuestPointer
#define ConstGuestPointer(x) ConstGuestPointer(x)

// For 32-bit / ASM
#define GuestPointer(x) x*
#define ConstGuestPointer(x) const x*

(or a more C++-esque solution)

For allocations, one could use the following (for Linux - Windows code would be similar):

GuestPointer(void) malloc32(size_t size) {
	return mmap(NULL, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_32BIT|MAP_ANONYMOUS|MAP_SHARED, -1, 0);
}

void free32(GuestPointer(void) base) {
	munmap(base, 0); //FIXME: Specify proper size
}

GuestPointer(char) strdup32(ConstGuestPointer(char) s) {
	GuestPointer(char) p = malloc32(strlen(s) + 1);
	strcpy(p, s);
	return p;
}

Alternatively, there could be virtual memory to handle allocations in another address-space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants