about summary refs log tree commit diff stats
path: root/src/libtools
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-08-28 18:35:24 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-08-28 18:35:24 +0200
commit126c59b4a41b3f17b4fdea6e1fd94bd15d1638d7 (patch)
treef4ddcd2506cc59d159dc9e937e4bbab53e0b4b23 /src/libtools
parentb7be225846153a1ed44b149b6600fb86c3fa0b42 (diff)
downloadbox64-126c59b4a41b3f17b4fdea6e1fd94bd15d1638d7.tar.gz
box64-126c59b4a41b3f17b4fdea6e1fd94bd15d1638d7.zip
[BOX32] More wrapped 32bits functions, and some fixes too
Diffstat (limited to 'src/libtools')
-rwxr-xr-xsrc/libtools/myalign32.c99
-rwxr-xr-xsrc/libtools/threads32.c14
2 files changed, 113 insertions, 0 deletions
diff --git a/src/libtools/myalign32.c b/src/libtools/myalign32.c
index ee0b2790..6bcb015f 100755
--- a/src/libtools/myalign32.c
+++ b/src/libtools/myalign32.c
@@ -138,6 +138,105 @@ void myStackAlign32(const char* fmt, uint32_t* st, uint64_t* mystack)
     }
 }
 
+void myStackAlignScanf32(const char* fmt, uint32_t* st, uint64_t* mystack)
+{
+    
+    if(!fmt)
+        return;
+    // loop...
+    const char* p = fmt;
+    int state = 0;
+    int ign = 0;
+    while(*p)
+    {
+        switch(state) {
+            case 0:
+                ign = 0;
+                switch(*p) {
+                    case '%': state = 1; ++p; break;
+                    default:
+                        ++p;
+                }
+                break;
+            case 1: // normal
+            case 2: // l
+            case 3: // ll
+            case 4: // L
+            case 5: // z
+                switch(*p) {
+                    case '%': state = 0;  ++p; break; //%% = back to 0
+                    case 'l': ++state; if (state>3) state=3; ++p; break;
+                    case 'L': state = 4; ++p; break;
+                    case 'z': state = 5; ++p; break;
+                    case 'a':
+                    case 'A':
+                    case 'e':
+                    case 'E':
+                    case 'g':
+                    case 'G':
+                    case 'F':
+                    case 'f': state += 10; break;    //  float
+                    case 'd':
+                    case 'i':
+                    case 'o':
+                    case 'u':
+                    case 'x':
+                    case 'X': state += 20; break;   // int
+                    case 'h': ++p; break;  // ignored...
+                    case '\'':
+                    case '0':
+                    case '1':
+                    case '2':
+                    case '3':
+                    case '4':
+                    case '5':
+                    case '6':
+                    case '7':
+                    case '8':
+                    case '9':
+                    case '.': 
+                    case '#':
+                    case '+': 
+                    case '-': ++p; break; // formating, ignored
+                    case 'm': state = 0; ++p; break; // no argument
+                    case 'n':
+                    case 'p':
+                    case 'S':
+                    case 's': state = 30; break; // pointers
+                    case '$': ++p; break; // should issue a warning, it's not handled...
+                    case '*': ign=1; ++p; break; // ignore arg
+                    case ' ': state=0; ++p; break;
+                    default:
+                        state=20; // other stuff, put an int...
+                }
+                break;
+            case 11:    //double
+            case 12:    //%lg, still double
+            case 13:    //%llg, still double
+            case 14:    //%Lg long double
+            case 15:    //%zg
+            case 20:    // fallback
+            case 21:
+            case 22:
+            case 23:    // 64bits int
+            case 24:    // normal int / pointer
+            case 25:    // size_t int
+            case 30:
+                if(!ign) {
+                    *mystack = *st;
+                    ++st;
+                    ++mystack;
+                }
+                state = 0;
+                ++p;
+                break;
+            default:
+                // whaaaat?
+                state = 0;
+        }
+    }
+}
+
 void myStackAlignGVariantNew32(const char* fmt, uint32_t* st, uint64_t* mystack)
 {
     if (!fmt)
diff --git a/src/libtools/threads32.c b/src/libtools/threads32.c
index 1fc3a2df..bab4cf4f 100755
--- a/src/libtools/threads32.c
+++ b/src/libtools/threads32.c
@@ -293,6 +293,20 @@ EXPORT void my32___pthread_unregister_cancel(x64emu_t* emu, x64_unwind_buff_t* b
 	}
 }
 
+#define X86_RWLOCK_SIZE	32
+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);
+	}
+	int ret = pthread_rwlock_init(rdlock, attr);
+	memcpy(rdlock+32, 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 void my32___pthread_unwind_next(x64emu_t* emu, void* p)
 {
 	emu->quit = 1;