mirror of
https://github.com/ptitSeb/box64.git
synced 2026-11-08 10:10:25 -10:00
[BOX32][WRAPPER] Various box32 fixes
This commit is contained in:
1 parent
0254fbdd83
commit
bebae710ec
11 files changed
+119
-28
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#ifndef __MY_ALIGN32__H_
|
||||
#define __MY_ALIGN32__H_
|
||||
#include <stdint.h>
|
||||
#include <net/if.h>
|
||||
#include "box32.h"
|
||||
|
||||
#define X64_VA_MAX_REG (6*8)
|
||||
@@ -678,4 +679,40 @@ struct my_obstack_32_t
|
||||
void convert_obstack_to_32(void* d, void* s);
|
||||
void convert_obstack_to_64(void* d, void* s);
|
||||
|
||||
typedef struct i386_ifmap_s {
|
||||
ulong_t mem_start;
|
||||
ulong_t mem_end;
|
||||
unsigned short base_addr;
|
||||
unsigned char irq;
|
||||
unsigned char dma;
|
||||
unsigned char port;
|
||||
} i386_ifmap_t;
|
||||
|
||||
typedef struct i386_ifreq_s {
|
||||
char i386_ifr_name[16]; /* Interface name */
|
||||
union {
|
||||
struct sockaddr i386_ifr_addr;
|
||||
struct sockaddr i386_ifr_dstaddr;
|
||||
struct sockaddr i386_ifr_broadaddr;
|
||||
struct sockaddr i386_ifr_netmask;
|
||||
struct sockaddr i386_ifr_hwaddr;
|
||||
short i386_ifr_flags;
|
||||
int i386_ifr_ifindex;
|
||||
int i386_ifr_metric;
|
||||
int i386_ifr_mtu;
|
||||
i386_ifmap_t i386_ifr_map;
|
||||
char i386_ifr_slave[16];
|
||||
char i386_ifr_newname[16];
|
||||
ptr_t i386_ifr_data; // char*
|
||||
};
|
||||
} i386_ifreq_t;
|
||||
|
||||
typedef struct i386_ifconf_s {
|
||||
int ifc_len;
|
||||
union {
|
||||
ptr_t i386_ifc_buf; // char*
|
||||
ptr_t i386_ifc_req; // i386_ifreq_t*
|
||||
};
|
||||
} i386_ifconf_t;
|
||||
|
||||
#endif//__MY_ALIGN32__H_
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <net/if.h>
|
||||
#include <resolv.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "box64stack.h"
|
||||
#include "x64emu.h"
|
||||
@@ -740,3 +741,35 @@ void libc32_net_init()
|
||||
my32_in6addr_any = in6addr_any;
|
||||
my32_in6addr_loopback = in6addr_loopback;
|
||||
}
|
||||
|
||||
int ioctl_cgifconf(x64emu_t* emu, int fd, void* arg)
|
||||
{
|
||||
i386_ifconf_t *i386_conf = (i386_ifconf_t*)arg;
|
||||
if(!i386_conf->i386_ifc_buf)
|
||||
{
|
||||
return ioctl(fd, SIOCGIFCONF, i386_conf);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct ifconf conf;
|
||||
conf.ifc_len = i386_conf->ifc_len;
|
||||
conf.ifc_buf = from_ptrv(i386_conf->i386_ifc_buf);
|
||||
int ret = ioctl(fd, SIOCGIFCONF, &conf);
|
||||
if(ret<0) return ret;
|
||||
i386_ifreq_t *i386_reqs = (i386_ifreq_t*)conf.ifc_buf;
|
||||
struct ifreq *reqs = conf.ifc_req;
|
||||
for(int i=0; i*sizeof(struct ifreq)<conf.ifc_len; ++i)
|
||||
{
|
||||
memmove(i386_reqs + i, reqs + i, offsetof(struct ifreq, ifr_map));
|
||||
i386_reqs[i].i386_ifr_map.mem_start = to_ulong_silent(reqs[i].ifr_map.mem_start);
|
||||
i386_reqs[i].i386_ifr_map.mem_end = to_ulong_silent(reqs[i].ifr_map.mem_end);
|
||||
i386_reqs[i].i386_ifr_map.base_addr = reqs[i].ifr_map.base_addr;
|
||||
i386_reqs[i].i386_ifr_map.irq = reqs[i].ifr_map.irq;
|
||||
i386_reqs[i].i386_ifr_map.dma = reqs[i].ifr_map.dma;
|
||||
i386_reqs[i].i386_ifr_map.port = reqs[i].ifr_map.port;
|
||||
memmove(&i386_reqs[i].i386_ifr_slave, &reqs[i].ifr_slave, sizeof(struct ifreq) - offsetof(struct ifreq, ifr_slave));
|
||||
}
|
||||
i386_conf->ifc_len = conf.ifc_len * sizeof(i386_ifreq_t) / sizeof(struct ifreq);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,9 @@ void convertXEvent(my_XEvent_32_t* dst, my_XEvent_t* src)
|
||||
if(!src->type) {
|
||||
// This is an XErrorEvent, and it's different!
|
||||
dst->xerror.type = src->xerror.type;
|
||||
// use the silent version here because sometimes src->xerror points to some garbage (we don't know why!)
|
||||
dst->xerror.display = to_ptrv_silent(FindDisplay(src->xerror.display));
|
||||
dst->xerror.resourceid = to_ulong_silent(src->xerror.resourceid);
|
||||
dst->xerror.serial = to_ulong_silent(src->xerror.serial);
|
||||
dst->xerror.display = to_ptrv(FindDisplay(src->xerror.display));
|
||||
dst->xerror.resourceid = to_ulong(src->xerror.resourceid);
|
||||
dst->xerror.serial = to_ulong(src->xerror.serial);
|
||||
dst->xerror.error_code = src->xerror.error_code;
|
||||
dst->xerror.request_code = src->xerror.request_code;
|
||||
dst->xerror.minor_code = src->xerror.minor_code;
|
||||
|
||||
+19
-19
@@ -312,23 +312,27 @@ EXPORT int my32_pthread_rwlock_init(void* rdlock, void* attr)
|
||||
// the structure is bigger, but the "active" part should be the same size, so just save/restoore the padding at init
|
||||
uint8_t buff[sizeof(pthread_rwlock_t)];
|
||||
if(rdlock && sizeof(pthread_rwlock_t)>X86_RWLOCK_SIZE) {
|
||||
memcpy(buff, rdlock+32, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
memcpy(buff, rdlock+X86_RWLOCK_SIZE, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
}
|
||||
int ret = pthread_rwlock_init(rdlock, attr);
|
||||
memcpy(rdlock+32, buff, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
if(rdlock && sizeof(pthread_rwlock_t)>X86_RWLOCK_SIZE) {
|
||||
memcpy(rdlock+X86_RWLOCK_SIZE, buff, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT int my32___pthread_rwlock_init(void*, void*) __attribute__((alias("my32_pthread_rwlock_init")));
|
||||
|
||||
EXPORT int my32_pthread_rwlock_destroy(void* rdlock)
|
||||
{
|
||||
// the structure is bigger, but the "active" part should be the same size, so just save/restoore the padding at init
|
||||
// the structure is bigger, but the "active" part should be the same size, so just save/restore the padding at init
|
||||
uint8_t buff[sizeof(pthread_rwlock_t)];
|
||||
if(rdlock && sizeof(pthread_rwlock_t)>X86_RWLOCK_SIZE) {
|
||||
memcpy(buff, rdlock+32, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
memcpy(buff, rdlock+X86_RWLOCK_SIZE, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
}
|
||||
int ret = pthread_rwlock_destroy(rdlock);
|
||||
memcpy(rdlock+32, buff, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
if(rdlock && sizeof(pthread_rwlock_t)>X86_RWLOCK_SIZE) {
|
||||
memcpy(rdlock+X86_RWLOCK_SIZE, buff, sizeof(pthread_rwlock_t)-X86_RWLOCK_SIZE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -493,19 +497,15 @@ static pthread_cond_t* get_cond(void* cond)
|
||||
pthread_cond_t* ret;
|
||||
int r;
|
||||
mutex_lock(&my_context->mutex_thread);
|
||||
khint_t k = kh_get(mapcond, mapcond, *(uintptr_t*)cond);
|
||||
khint_t k = kh_get(mapcond, mapcond, (uintptr_t)cond);
|
||||
if(k==kh_end(mapcond)) {
|
||||
khint_t k = kh_get(mapcond, mapcond, (uintptr_t)cond);
|
||||
if(k==kh_end(mapcond)) {
|
||||
printf_log(LOG_DEBUG, "BOX32: Note: phtread_cond not found, create a new empty one\n");
|
||||
ret = (pthread_cond_t*)box_calloc(1, sizeof(pthread_cond_t));
|
||||
k = kh_put(mapcond, mapcond, (uintptr_t)cond, &r);
|
||||
kh_value(mapcond, k) = ret;
|
||||
//*(ptr_t*)cond = to_ptrv(cond);
|
||||
//pthread_cond_init(ret, NULL);
|
||||
memcpy(ret, cond, sizeof(pthread_cond_t));
|
||||
} else
|
||||
ret = kh_value(mapcond, k);
|
||||
printf_log(LOG_DEBUG, "BOX32: Note: phtread_cond not found, create a new empty one\n");
|
||||
ret = (pthread_cond_t*)box_calloc(1, sizeof(pthread_cond_t));
|
||||
k = kh_put(mapcond, mapcond, (uintptr_t)cond, &r);
|
||||
kh_value(mapcond, k) = ret;
|
||||
//*(ptr_t*)cond = to_ptrv(cond);
|
||||
//pthread_cond_init(ret, NULL);
|
||||
memcpy(ret, cond, sizeof(pthread_cond_t));
|
||||
} else
|
||||
ret = kh_value(mapcond, k);
|
||||
mutex_unlock(&my_context->mutex_thread);
|
||||
@@ -518,8 +518,8 @@ static void del_cond(void* cond)
|
||||
if(!mapcond)
|
||||
return;
|
||||
mutex_lock(&my_context->mutex_thread);
|
||||
khint_t k = kh_get(mapcond, mapcond, *(uintptr_t*)cond);
|
||||
if(k!=kh_end(mapcond)) {
|
||||
khint_t k = kh_get(mapcond, mapcond, (uintptr_t)cond);
|
||||
if(k==kh_end(mapcond)) {
|
||||
box_free(kh_value(mapcond, k));
|
||||
kh_del(mapcond, mapcond, k);
|
||||
}
|
||||
|
||||
@@ -991,6 +991,7 @@
|
||||
#() cFpiii -> cFpiii
|
||||
#() iEEiip -> iEEiip
|
||||
#() iEEiiN -> iEEiiN
|
||||
#() iEEiLp -> iEEiLp
|
||||
#() iEEipp -> iEEipp
|
||||
#() iFEipp -> iFEipp
|
||||
#() iEEipV -> iEEipV
|
||||
@@ -2529,6 +2530,7 @@ wrappedlibc:
|
||||
- __fcntl_time64
|
||||
- iEiLp:
|
||||
- __ioctl_time64
|
||||
- ioctl
|
||||
- iEipp:
|
||||
- iEipV:
|
||||
- iEpii:
|
||||
|
||||
@@ -241,6 +241,7 @@ typedef int32_t (*iFpuippupp_t)(void*, uint32_t, int32_t, void*, void*, uint32_t
|
||||
GO(_ITM_addUserCommitAction, vEpup_t) \
|
||||
GO(__fcntl_time64, iEiiN_t) \
|
||||
GO(__ioctl_time64, iEiLp_t) \
|
||||
GO(ioctl, iEiLp_t) \
|
||||
GO(regcomp, iEppi_t) \
|
||||
GO(__isoc23_vsscanf, iEppp_t) \
|
||||
GO(vswscanf, iEppp_t) \
|
||||
|
||||
@@ -1085,6 +1085,7 @@ typedef void (*vFXppL_t)(void*, void*, void*, uintptr_t);
|
||||
typedef int8_t (*cFpiii_t)(void*, int32_t, int32_t, int32_t);
|
||||
typedef int32_t (*iEEiip_t)(x64emu_t*, int32_t, int32_t, void*);
|
||||
typedef int32_t (*iEEiiN_t)(x64emu_t*, int32_t, int32_t, ...);
|
||||
typedef int32_t (*iEEiLp_t)(x64emu_t*, int32_t, uintptr_t, void*);
|
||||
typedef int32_t (*iEEipp_t)(x64emu_t*, int32_t, void*, void*);
|
||||
typedef int32_t (*iFEipp_t)(x64emu_t*, int32_t, void*, void*);
|
||||
typedef int32_t (*iEEipV_t)(x64emu_t*, int32_t, void*, void*);
|
||||
@@ -3269,6 +3270,7 @@ void vFXppL_32(x64emu_t *emu, uintptr_t fcn) { vFXppL_t fn = (vFXppL_t)fcn; fn(g
|
||||
void cFpiii_32(x64emu_t *emu, uintptr_t fcn) { cFpiii_t fn = (cFpiii_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); }
|
||||
void iEEiip_32(x64emu_t *emu, uintptr_t fcn) { iEEiip_t fn = (iEEiip_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); emu->libc_err = errno; }
|
||||
void iEEiiN_32(x64emu_t *emu, uintptr_t fcn) { iEEiiN_t fn = (iEEiiN_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); emu->libc_err = errno; }
|
||||
void iEEiLp_32(x64emu_t *emu, uintptr_t fcn) { iEEiLp_t fn = (iEEiLp_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12)); emu->libc_err = errno; }
|
||||
void iEEipp_32(x64emu_t *emu, uintptr_t fcn) { iEEipp_t fn = (iEEipp_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); emu->libc_err = errno; }
|
||||
void iFEipp_32(x64emu_t *emu, uintptr_t fcn) { iFEipp_t fn = (iFEipp_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); }
|
||||
void iEEipV_32(x64emu_t *emu, uintptr_t fcn) { iEEipV_t fn = (iEEipV_t)fcn; errno = emu->libc_err; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); emu->libc_err = errno; }
|
||||
|
||||
@@ -1032,6 +1032,7 @@ void vFXppL_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void cFpiii_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void iEEiip_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void iEEiiN_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void iEEiLp_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void iEEipp_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void iFEipp_32(x64emu_t *emu, uintptr_t fnc);
|
||||
void iEEipV_32(x64emu_t *emu, uintptr_t fnc);
|
||||
|
||||
@@ -3655,6 +3655,18 @@ EXPORT int my32_close(x64emu_t* emu, int fd)
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
extern int ioctl_cgifconf(x64emu_t* emu, int fd, void* arg);
|
||||
EXPORT int my32_ioctl(x64emu_t* emu, int fd, unsigned long op, void* arg)
|
||||
{
|
||||
switch(op)
|
||||
{
|
||||
case SIOCGIFCONF:
|
||||
return ioctl_cgifconf(emu, fd, arg);
|
||||
default:
|
||||
return ioctl(fd, op, arg);
|
||||
}
|
||||
}
|
||||
|
||||
#undef HAS_MY
|
||||
|
||||
#define PRE_INIT\
|
||||
|
||||
@@ -740,7 +740,7 @@ GO(inotify_rm_watch, iEii)
|
||||
//DATA(_IO_2_1_stdout_, 152)
|
||||
//GO(_IO_adjust_column, uEupi)
|
||||
// _IO_adjust_wcolumn
|
||||
GO(ioctl, iEiLp) //the vararg is just to have optional arg of various type, but only 1 arg
|
||||
GOM(ioctl, iEEiLp) //the vararg is just to have optional arg of various type, but only 1 arg
|
||||
GO2(__ioctl_time64, iEiLp, ioctl)
|
||||
//GO(_IO_default_doallocate, iES)
|
||||
//GO(_IO_default_finish, vESi)
|
||||
|
||||
@@ -1420,7 +1420,8 @@ EXPORT int32_t my32_XIfEvent(x64emu_t* emu, void* d,void* ev, EventHandler h, vo
|
||||
{
|
||||
my_XEvent_t event = {0};
|
||||
int32_t ret = my->XIfEvent(d, &event, findxifeventFct(h), arg);
|
||||
convertXEvent(ev, &event);
|
||||
if(ret)
|
||||
convertXEvent(ev, &event);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1428,14 +1429,16 @@ EXPORT int32_t my32_XCheckIfEvent(x64emu_t* emu, void* d,void* ev, EventHandler
|
||||
{
|
||||
my_XEvent_t event = {0};
|
||||
int32_t ret = my->XCheckIfEvent(d, &event, findxifeventFct(h), arg);
|
||||
convertXEvent(ev, &event);
|
||||
if(ret)
|
||||
convertXEvent(ev, &event);
|
||||
return ret;
|
||||
}
|
||||
EXPORT int32_t my32_XPeekIfEvent(x64emu_t* emu, void* d,void* ev, EventHandler h, void* arg)
|
||||
{
|
||||
my_XEvent_t event = {0};
|
||||
int32_t ret = my->XPeekIfEvent(d, &event, findxifeventFct(h), arg);
|
||||
convertXEvent(ev, &event);
|
||||
if(ret)
|
||||
convertXEvent(ev, &event);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1457,7 +1460,8 @@ EXPORT int my32_XCheckMaskEvent(x64emu_t* emu, void* dpy, long mask, my_XEvent_3
|
||||
{
|
||||
my_XEvent_t event = {0};
|
||||
int32_t ret = my->XCheckMaskEvent(dpy, mask, &event);
|
||||
convertXEvent(evt, &event);
|
||||
if(ret)
|
||||
convertXEvent(evt, &event);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user