Skip to content

Commit

Permalink
Merge pull request #123 from emkey1/dev
Browse files Browse the repository at this point in the history
Merge 1.2.4 Build 429 changes
  • Loading branch information
emkey1 committed Oct 30, 2022
2 parents 99bc216 + 02b6bd0 commit e9490b4
Show file tree
Hide file tree
Showing 33 changed files with 474 additions and 240 deletions.
4 changes: 4 additions & 0 deletions app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ @interface AppDelegate ()
static void ios_handle_exit(struct task *task, int code) {
// we are interested in init and in children of init
// this is called with pids_lock as an implementation side effect, please do not cite as an example of good API design
if(task->pid > MAX_PID) {// Corruption
printk("ERROR: Insane PID in ios_handle_exit(%d)\n", task->pid);
return;
}
if (task->parent != NULL && task->parent->parent != NULL)
return;
// pid should be saved now since task would be freed
Expand Down
13 changes: 13 additions & 0 deletions app/UserPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#import "UserPreferences.h"
#import "fs/proc/ish.h"
#include "sync.h"
#include "task.h"

// Stuff to allow for cleaning up when doEnableExtraLocking is disabled. -mke
extern bool doEnableExtraLocking;
extern lock_t pids_lock;
extern struct list alive_pids_list;

// IMPORTANT: If you add a constant here and expose it via UserPreferences,
// consider if it also needs to be exposed as a friendly preference and included
Expand Down Expand Up @@ -438,6 +445,12 @@ - (void)setShouldEnableExtraLocking:(BOOL)dim {
}

- (BOOL)validateShouldEnableExtraLocking:(id *)value error:(NSError **)error {
// Should set task->critical_region.count to 0 for all active processes when this is set to false. Otherwise stuff blows up. -mke
if(doEnableExtraLocking == true) { // This needs to be the opposite of what you would expect because of reasons. -mke
complex_lockt(&pids_lock, 0, __FILE__, __LINE__);
dword_t res = zero_critical_regions_count();
unlock(&pids_lock);
}
return [*value isKindOfClass:NSNumber.class];
}

Expand Down
11 changes: 11 additions & 0 deletions app/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
extern void run_at_boot(void);
#import <Foundation/Foundation.h>
#import <Foundation/NSProcessInfo.h>

void disable_app_nap(void)
{
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:reason:)])
{
[[NSProcessInfo processInfo] beginActivityWithOptions:0x00FFFFFF reason:@"Not sleepy and don't want to nap"];
}
}

int main(int argc, char * argv[]) {
@autoreleasepool {
disable_app_nap(); // No napping I say. -mke
run_at_boot();
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
Expand Down
2 changes: 1 addition & 1 deletion deps/aports/community/x86/index.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APKINDEX-v3.14-2022-10-01.tar.gz
APKINDEX-v3.14-2022-10-28.tar.gz
2 changes: 1 addition & 1 deletion deps/aports/main/x86/index.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APKINDEX-v3.14-2022-10-09.tar.gz
APKINDEX-v3.14-2022-10-28.tar.gz
12 changes: 11 additions & 1 deletion emu/cpuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CPUID_H

#include "misc.h"
extern bool isGlibC;

static inline void do_cpuid(dword_t *eax, dword_t *ebx, dword_t *ecx, dword_t *edx) {
dword_t leaf = *eax;
Expand All @@ -17,11 +18,20 @@ static inline void do_cpuid(dword_t *eax, dword_t *ebx, dword_t *ecx, dword_t *e
*eax = 0x0; // say nothing about cpu model number
*ebx = 0x0; // processor number 0, flushes 0 bytes on clflush
*ecx = 0; // we support none of the features in ecx
*edx = (1 << 0) // fpu
if(isGlibC) {
*edx = (1 << 0) // fpu
| (1 << 15) // cmov
| (1 << 23) // mmx
| (1 << 25) // sse // musl handles sse being enabled badly. -mke
| (1 << 26) // sse2
;
} else {
*edx = (1 << 0) // fpu
| (1 << 15) // cmov
| (1 << 23) // mmx
| (1 << 26) // sse2
;
}
break;
}
}
Expand Down
32 changes: 19 additions & 13 deletions emu/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,18 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; VMOV(xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x11: TRACEI("movupd xmm, xmm:modrm");
READMODRM; VMOV(xmm_modrm_reg, xmm_modrm_val,128); break;
case 0x12: TRACEI("movlpd xmm, xmm:modrm");
READMODRM; V_OP(movl_pd, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x13: TRACEI("movlpd xmm:modrm, reg");
READMODRM; V_OP(movl_mem_pd, xmm_modrm_val, modrm_reg,128); break;
case 0x12: TRACEI("movlpd xmm, modrm");
READMODRM; V_OP(movl_p, modrm_val, xmm_modrm_reg,64); break;
case 0x13: TRACEI("movlpd modrm, xmm");
READMODRM; V_OP(movl_pm, xmm_modrm_reg, modrm_val,64); break;
case 0x14: TRACEI("unpcklpd xmm, xmm:modrm");
READMODRM; V_OP(unpackl_pd, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x15: TRACEI("unpckhpd xmm, xmm:modrm");
READMODRM; V_OP(unpackh_pd, xmm_modrm_val, xmm_modrm_reg,128); break;

case 0x16: TRACEI("movhpd xmm, modrm");
READMODRM; V_OP(movh_p, modrm_val, xmm_modrm_reg,64); break;
case 0x17: TRACEI("movhpd modrm, xmm");
READMODRM; V_OP(movh_pm, xmm_modrm_reg, modrm_val,64); break;
case 0x2e: TRACEI("ucomisd xmm, xmm:modrm");
READMODRM; V_OP(single_ucomi, xmm_modrm_val, xmm_modrm_reg,64); break;
case 0x2f: TRACEI("comisd xmm, xmm:modrm");
Expand Down Expand Up @@ -427,8 +430,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; V_OP(mulu, xmm_modrm_val, xmm_modrm_reg, 128); break;
case 0xe6: TRACEI("cvttpd2dq xmm:modrm, xmm");
READMODRM; V_OP(cvttpd2dq, xmm_modrm_val, xmm_modrm_reg,64); break;
case 0xe7: TRACEI("movntdq xmm:modrm, xmm");
READMODRM_MEM; VMOV(xmm_modrm_reg, xmm_modrm_val,128); break;
case 0xe7: TRACEI("movntdq xmm, xmm:modrm");
READMODRM; VMOV(xmm_modrm_reg, xmm_modrm_val,128); break;
case 0xe8: TRACEI("psubsb xmm:modrm, xmm");
READMODRM; V_OP(subss_b, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0xe9: TRACEI("psubsw xmm:modrm, xmm");
Expand Down Expand Up @@ -472,14 +475,18 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {
READMODRM; VMOV(xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x11: TRACEI("movups xmm, xmm:modrm");
READMODRM; VMOV(xmm_modrm_reg, xmm_modrm_val,128); break;

case 0x12: TRACEI("movlps xmm, modrm");
READMODRM; V_OP(movl_p, modrm_val, xmm_modrm_reg,64); break;
case 0x13: TRACEI("movlps modrm, xmm");
READMODRM; V_OP(movl_pm, xmm_modrm_reg, modrm_val,64); break;
case 0x14: TRACEI("unpcklps xmm, xmm:modrm");
READMODRM; V_OP(unpackl_ps, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x15: TRACEI("unpckhps xmm, xmm:modrm");
READMODRM; V_OP(unpackh_ps, xmm_modrm_val, xmm_modrm_reg,128); break;
case 0x16: TRACEI("movlhps xmm, xmm:modrm");
READMODRM; V_OP(movlh_ps, xmm_modrm_val, xmm_modrm_reg,128); break;

case 0x16: TRACEI("movhps xmm, modrm");
READMODRM; V_OP(movh_p, modrm_val, xmm_modrm_reg,64); break;
case 0x17: TRACEI("movhps modrm, xmm");
READMODRM; V_OP(movh_pm, xmm_modrm_reg, modrm_val,64); break;
case 0x2e: TRACEI("ucomiss xmm, xmm:modrm");
READMODRM; V_OP(single_ucomi, xmm_modrm_val, xmm_modrm_reg,32); break;
case 0x2f: TRACEI("comiss xmm, xmm:modrm");
Expand Down Expand Up @@ -537,9 +544,8 @@ __no_instrument DECODER_RET glue(DECODER_NAME, OP_SIZE)(DECODER_ARGS) {

case 0xe5: TRACEI("pmulhw mm:modrm, mm");
READMODRM; V_OP(mulu, mm_modrm_val, mm_modrm_reg,64); break;
case 0xe7: TRACEI("movntq mm:modrm, mm");
case 0xe7: TRACEI("movntq mm, mm:modrm");
READMODRM_MEM; VMOV(mm_modrm_reg, mm_modrm_val,64); break;

case 0xef: TRACEI("pxor mm:modrm, mm");
READMODRM; V_OP(xor, mm_modrm_val, mm_modrm_reg,64); break;

Expand Down
7 changes: 0 additions & 7 deletions emu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ void mem_init(struct mem *mem) {
}

void mem_destroy(struct mem *mem) {
//int elock_fail = 0;
// if(doEnableExtraLocking)
// elock_fail = extra_lockf(0);

write_lock(&mem->lock);
while((critical_region_count(current) > 1) && (current->pid > 1) ){ // Wait for now, task is in one or more critical sections, and/or has locks
nanosleep(&lock_pause, NULL);
Expand Down Expand Up @@ -85,9 +81,6 @@ void mem_destroy(struct mem *mem) {

//modify_critical_region_counter(current, -1, __FILE__, __LINE__);

//if((doEnableExtraLocking) && (!elock_fail))
// extra_unlockf(0);

}

#define PGDIR_TOP(page) ((page) >> 10)
Expand Down
62 changes: 11 additions & 51 deletions emu/vec.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#ifdef __ARM_NEON__
#include <arm_neon.h>
#endif
#include <math.h>
#include <string.h>

Expand Down Expand Up @@ -193,15 +190,8 @@ void vec_imm_shiftrs_d128(NO_CPU, const uint8_t amount, union xmm_reg *dst) {
}

void vec_add_b128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
#ifdef __ARM_NEON__
uint8x16_t neon_dst = vld1q_u8(dst->u8);
uint8x16_t neon_src = vld1q_u8(src->u8);
uint8x16_t neon_res = vaddq_u8(neon_dst, neon_src);
vst1q_u8(dst->u8, neon_res);
#else
for (unsigned i = 0; i < array_size(src->u8); i++)
dst->u8[i] += src->u8[i];
#endif
}
void vec_add_w128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u16); i++)
Expand Down Expand Up @@ -332,16 +322,9 @@ void vec_xor64(NO_CPU, union mm_reg *src, union mm_reg *dst) {
}

void vec_min_ub128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
#ifdef __ARM_NEON__
uint8x16_t neon_dst = vld1q_u8(dst->u8);
uint8x16_t neon_src = vld1q_u8(src->u8);
uint8x16_t neon_res = vminq_u8(neon_dst, neon_src);
vst1q_u8(dst->u8, neon_res);
#else
for (unsigned i = 0; i < array_size(src->u8); i++)
if (src->u8[i] < dst->u8[i])
dst->u8[i] = src->u8[i];
#endif
}
void vec_max_ub128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u8); i++)
Expand All @@ -359,7 +342,7 @@ void vec_maxs_w128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
}

static bool cmpd(double a, double b, int type) {
bool res = false;
bool res;
switch (type % 4) {
case 0: res = a == b; break;
case 1: res = a < b; break;
Expand All @@ -370,7 +353,7 @@ static bool cmpd(double a, double b, int type) {
return res;
}
static bool cmps(float a, float b, int type) {
bool res = false;
bool res;
switch (type % 4) {
case 0: res = a == b; break;
case 1: res = a < b; break;
Expand Down Expand Up @@ -555,9 +538,6 @@ void vec_unpackh_pd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->f64[0] = dst->f64[1];
dst->f64[1] = src->f64[1];
}
void vec_movlh_ps128(NO_CPU, union xmm_reg *src, union xmm_reg *dst) {
dst->qw[1] = src->qw[0];
}

void vec_packss_w128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->u32[0] = (satsw(dst->u16[0]) << 0x00) | (satsw(dst->u16[1]) << 0x08) |
Expand Down Expand Up @@ -605,15 +585,8 @@ void vec_shuffle_d128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint
}

void vec_compare_eqb128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
#ifdef __ARM_NEON__
uint8x16_t neon_dst = vld1q_u8(dst->u8);
uint8x16_t neon_src = vld1q_u8(src->u8);
uint8x16_t neon_res = vceqq_u8(neon_dst, neon_src);
vst1q_u8(dst->u8, neon_res);
#else
for (unsigned i = 0; i < array_size(src->u8); i++)
dst->u8[i] = dst->u8[i] == src->u8[i] ? ~0 : 0;
#endif
}
void vec_compare_eqw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u16); i++)
Expand All @@ -624,16 +597,6 @@ void vec_compare_eqd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->u32[i] = dst->u32[i] == src->u32[i] ? ~0 : 0;
}

/*
* Neon algo: (only one part (64bits) is demonstrated, algo works the same for another part)
* z - is a bit which forms the mask, X - is not interesting bit.
* neon_src: zXXXXXXXzXXXXXXXzXXXXXXXzXXXXXXXzXXXXXXXzXXXXXXXzXXXXXXXzXXXXXXX...
* step1: 0000000z0000000z0000000z0000000z0000000z0000000z0000000z0000000z...
* step2: 00000000000000zz00000000000000zz00000000000000zz00000000000000zz...
* step3: 0000000000000000000000000000zzzz0000000000000000000000000000zzzz...
* step4: 00000000000000000000000000000000000000000000000000000000zzzzzzzz...
* After step4, 8 bits at the end of each 64bit lane are loaded into dst.
*/
void vec_compares_gtb128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
for (unsigned i = 0; i < array_size(src->u8); i++)
dst->u8[i] = (int8_t)dst->u8[i] > (int8_t)src->u8[i] ? ~0 : 0;
Expand All @@ -649,19 +612,10 @@ void vec_compares_gtd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {

void vec_movmask_b128(NO_CPU, const union xmm_reg *src, uint32_t *dst) {
*dst = 0;
#if defined(__ARM_NEON__) && defined(__LITTLE_ENDIAN__)
uint8x16_t neon_src = vld1q_u8(src->u8);
uint16x8_t step1 = vshrq_n_u8(neon_src, 7);
uint32x4_t step2 = vsraq_n_u16(step1, step1, 7);
uint64x2_t step3 = vsraq_n_u32(step2, step2, 14);
uint16x8_t step4 = vsraq_n_u64(step3, step3, 28);
*dst |= (vgetq_lane_u8(step4, 8) << 8) | (vgetq_lane_u8(step4, 0));
#else
for (unsigned i = 0; i < array_size(src->u8); i++) {
if (src->u8[i] & (1 << 7))
*dst |= 1 << i;
}
#endif
}

void vec_fmovmask_d128(NO_CPU, const union xmm_reg *src, uint32_t *dst) {
Expand All @@ -672,12 +626,18 @@ void vec_fmovmask_d128(NO_CPU, const union xmm_reg *src, uint32_t *dst) {
}
}

void vec_movl_pd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst) {
dst->qw[0] = src->qw[0];
void vec_movl_p64(NO_CPU, const uint64_t *src, union xmm_reg *dst) {
dst->qw[0] = *src;
}
void vec_movl_mem_pd128(NO_CPU, const union xmm_reg *src, uint64_t *dst) {
void vec_movl_pm64(NO_CPU, const union xmm_reg *src, uint64_t *dst) {
*dst = src->qw[0];
}
void vec_movh_p64(NO_CPU, const uint64_t *src, union xmm_reg *dst) {
dst->qw[1] = *src;
}
void vec_movh_pm64(NO_CPU, const union xmm_reg *src, uint64_t *dst) {
*dst = src->qw[1];
}

void vec_extract_w128(NO_CPU, const union xmm_reg *src, uint32_t *dst, uint8_t index) {
*dst = src->u16[index % 8];
Expand Down
7 changes: 6 additions & 1 deletion emu/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void vec_unpackh_d128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_unpackh_dq128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_unpackh_ps128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_unpackh_pd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_movlh_ps128(NO_CPU, union xmm_reg *src, union xmm_reg *dst);

void vec_shuffle_lw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding);
void vec_shuffle_hw128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding);
void vec_shuffle_d128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst, uint8_t encoding);
Expand All @@ -141,6 +141,11 @@ void vec_compares_gtd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);

void vec_movl_pd128(NO_CPU, const union xmm_reg *src, union xmm_reg *dst);
void vec_movl_mem_pd128(NO_CPU, const union xmm_reg *src, uint64_t *dst);
void vec_movl_p64(NO_CPU, const uint64_t *src, union xmm_reg *dst);
void vec_movl_pm64(NO_CPU, const union xmm_reg *src, uint64_t *dst);
void vec_movh_p64(NO_CPU, const uint64_t *src, union xmm_reg *dst);
void vec_movh_pm64(NO_CPU, const union xmm_reg *src, uint64_t *dst);

void vec_movmask_b128(NO_CPU, const union xmm_reg *src, uint32_t *dst);
void vec_fmovmask_d128(NO_CPU, const union xmm_reg *src, uint32_t *dst);
void vec_extract_w128(NO_CPU, const union xmm_reg *src, uint32_t *dst, uint8_t index);
Expand Down
4 changes: 2 additions & 2 deletions fs/fake.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ static void __attribute__((constructor)) init_fake_fdops() {

static int fakefs_mount(struct mount *mount) {
char db_path[PATH_MAX];
strcpy(db_path, mount->source);
strncpy(db_path, mount->source, PATH_MAX -1);
char *basename = strrchr(db_path, '/') + 1;
assert(strcmp(basename, "data") == 0);
strcpy(basename, "meta.db");
strncpy(basename, "meta.db", 8);

// do this now so rebuilding can use root_fd
int err = realfs.mount(mount);
Expand Down
9 changes: 5 additions & 4 deletions fs/proc/ish.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,18 @@ static int proc_ish_show_ips(struct proc_entry *UNUSED(entry), struct proc_data
char * int_ip = malloc(100);
char * int_dstaddr = malloc(100);
if(cursor->ifa_addr->sa_family == AF_INET) {
strcpy(type, "IF_INET");
strncpy(type, "IF_INET", 9);
} else {
strcpy(type, "IF_INET6");
strncpy(type, "IF_INET6", 9);
}
//cursor->ifa_addr->sa_family = AF_INET;
get_ip_str(cursor->ifa_addr, int_ip, 100);
char * mac = malloc(100);
if(cursor->ifa_dstaddr != NULL) {
if(cursor->ifa_dstaddr->sa_family == AF_INET) {
strcpy(type, "IF_INET");
strncpy(type, "IF_INET", 9);
} else {
strcpy(type, "IF_INET6");
strncpy(type, "IF_INET6", 9);
cursor->ifa_dstaddr->sa_family = AF_INET6;
}
get_ip_str(cursor->ifa_dstaddr, int_dstaddr, 100);
Expand All @@ -315,6 +315,7 @@ static int proc_ish_show_ips(struct proc_entry *UNUSED(entry), struct proc_data
);
free(int_ip);
free(int_flags);
free(int_dstaddr);
}
cursor = cursor->ifa_next;
}
Expand Down
Loading

0 comments on commit e9490b4

Please sign in to comment.