Finishing off the kernel method conversion.

This commit is contained in:
Ben Vanik 2013-05-26 23:06:09 -07:00
parent 64eb2aa2b3
commit fe6df31280
3 changed files with 142 additions and 61 deletions

View File

@ -58,8 +58,13 @@ namespace xboxkrnl {
// } // }
SHIM_CALL ExCreateThread_shim( X_STATUS xeExCreateThread(
xe_ppc_state_t* ppc_state, KernelState* state) { uint32_t* handle_ptr, uint32_t stack_size, uint32_t* thread_id_ptr,
uint32_t xapi_thread_startup,
uint32_t start_address, uint32_t start_context, uint32_t creation_flags) {
KernelState* state = shared_kernel_state_;
XEASSERTNOTNULL(state);
// DWORD // DWORD
// LPHANDLE Handle, // LPHANDLE Handle,
// DWORD StackSize, // DWORD StackSize,
@ -69,6 +74,30 @@ SHIM_CALL ExCreateThread_shim(
// LPVOID StartContext, // LPVOID StartContext,
// DWORD CreationFlags // 0x80? // DWORD CreationFlags // 0x80?
XThread* thread = new XThread(
state, stack_size, xapi_thread_startup, start_address, start_context,
creation_flags);
X_STATUS result_code = thread->Create();
if (XFAILED(result_code)) {
// Failed!
thread->Release();
XELOGE("Thread creation failed: %.8X", result_code);
return result_code;
}
if (handle_ptr) {
*handle_ptr = thread->handle();
}
if (thread_id_ptr) {
*thread_id_ptr = thread->thread_id();
}
return result_code;
}
SHIM_CALL ExCreateThread_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
uint32_t handle_ptr = SHIM_GET_ARG_32(0); uint32_t handle_ptr = SHIM_GET_ARG_32(0);
uint32_t stack_size = SHIM_GET_ARG_32(1); uint32_t stack_size = SHIM_GET_ARG_32(1);
uint32_t thread_id_ptr = SHIM_GET_ARG_32(2); uint32_t thread_id_ptr = SHIM_GET_ARG_32(2);
@ -87,37 +116,44 @@ SHIM_CALL ExCreateThread_shim(
start_context, start_context,
creation_flags); creation_flags);
XThread* thread = new XThread( uint32_t handle;
state, stack_size, xapi_thread_startup, start_address, start_context, uint32_t thread_id;
creation_flags); X_STATUS result = xeExCreateThread(
&handle, stack_size, &thread_id, xapi_thread_startup,
X_STATUS result_code = thread->Create(); start_address, start_context, creation_flags);
if (XFAILED(result_code)) {
// Failed!
thread->Release();
XELOGE("Thread creation failed: %.8X", result_code);
SHIM_SET_RETURN(result_code);
return;
}
if (XSUCCEEDED(result)) {
if (handle_ptr) { if (handle_ptr) {
SHIM_SET_MEM_32(handle_ptr, thread->handle()); SHIM_SET_MEM_32(handle_ptr, handle);
} }
if (thread_id_ptr) { if (thread_id_ptr) {
SHIM_SET_MEM_32(thread_id_ptr, thread->thread_id()); SHIM_SET_MEM_32(thread_id_ptr, thread_id);
} }
SHIM_SET_RETURN(result_code); }
SHIM_SET_RETURN(result);
} }
SHIM_CALL KeGetCurrentProcessType_shim( uint32_t xeKeGetCurrentProcessType() {
xe_ppc_state_t* ppc_state, KernelState* state) { KernelState* state = shared_kernel_state_;
XEASSERTNOTNULL(state);
// DWORD // DWORD
XELOGD( XELOGD(
"KeGetCurrentProcessType()"); "KeGetCurrentProcessType()");
SHIM_SET_RETURN(X_PROCTYPE_USER); return X_PROCTYPE_USER;
}
SHIM_CALL KeGetCurrentProcessType_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
XELOGD(
"KeGetCurrentProcessType()");
int result = xeKeGetCurrentProcessType();
SHIM_SET_RETURN(result);
} }
@ -128,12 +164,11 @@ SHIM_CALL KeGetCurrentProcessType_shim(
// http://msdn.microsoft.com/en-us/library/ms686801 // http://msdn.microsoft.com/en-us/library/ms686801
SHIM_CALL KeTlsAlloc_shim( uint32_t xeKeTlsAlloc() {
xe_ppc_state_t* ppc_state, KernelState* state) { KernelState* state = shared_kernel_state_;
// DWORD XEASSERTNOTNULL(state);
XELOGD( // DWORD
"KeTlsAlloc()");
uint32_t tls_index; uint32_t tls_index;
@ -148,25 +183,30 @@ SHIM_CALL KeTlsAlloc_shim(
} }
#endif // WIN32 #endif // WIN32
SHIM_SET_RETURN(tls_index); return tls_index;
}
SHIM_CALL KeTlsAlloc_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
XELOGD(
"KeTlsAlloc()");
uint32_t result = xeKeTlsAlloc();
SHIM_SET_RETURN(result);
} }
// http://msdn.microsoft.com/en-us/library/ms686804 // http://msdn.microsoft.com/en-us/library/ms686804
SHIM_CALL KeTlsFree_shim( int KeTlsFree(uint32_t tls_index) {
xe_ppc_state_t* ppc_state, KernelState* state) { KernelState* state = shared_kernel_state_;
XEASSERTNOTNULL(state);
// BOOL // BOOL
// _In_ DWORD dwTlsIndex // _In_ DWORD dwTlsIndex
uint32_t tls_index = SHIM_GET_ARG_32(0);
XELOGD(
"KeTlsFree(%.8X)",
tls_index);
if (tls_index == X_TLS_OUT_OF_INDEXES) { if (tls_index == X_TLS_OUT_OF_INDEXES) {
SHIM_SET_RETURN(0); return 0;
return;
} }
int result_code = 0; int result_code = 0;
@ -177,22 +217,31 @@ SHIM_CALL KeTlsFree_shim(
result_code = pthread_key_delete(tls_index) == 0; result_code = pthread_key_delete(tls_index) == 0;
#endif // WIN32 #endif // WIN32
SHIM_SET_RETURN(result_code); return result_code;
}
SHIM_CALL KeTlsFree_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
uint32_t tls_index = SHIM_GET_ARG_32(0);
XELOGD(
"KeTlsFree(%.8X)",
tls_index);
int result = xeKeTlsAlloc();
SHIM_SET_RETURN(result);
} }
// http://msdn.microsoft.com/en-us/library/ms686812 // http://msdn.microsoft.com/en-us/library/ms686812
SHIM_CALL KeTlsGetValue_shim( uint32_t xeKeTlsGetValue(uint32_t tls_index) {
xe_ppc_state_t* ppc_state, KernelState* state) { KernelState* state = shared_kernel_state_;
XEASSERTNOTNULL(state);
// LPVOID // LPVOID
// _In_ DWORD dwTlsIndex // _In_ DWORD dwTlsIndex
uint32_t tls_index = SHIM_GET_ARG_32(0);
XELOGD(
"KeTlsGetValue(%.8X)",
tls_index);
uint32_t value = 0; uint32_t value = 0;
#if XE_PLATFORM(WIN32) #if XE_PLATFORM(WIN32)
@ -206,24 +255,32 @@ SHIM_CALL KeTlsGetValue_shim(
// TODO(benvanik): SetLastError // TODO(benvanik): SetLastError
} }
SHIM_SET_RETURN(value); return value;
}
SHIM_CALL KeTlsGetValue_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
uint32_t tls_index = SHIM_GET_ARG_32(0);
XELOGD(
"KeTlsGetValue(%.8X)",
tls_index);
uint32_t result = xeKeTlsGetValue(tls_index);
SHIM_SET_RETURN(result);
} }
// http://msdn.microsoft.com/en-us/library/ms686818 // http://msdn.microsoft.com/en-us/library/ms686818
SHIM_CALL KeTlsSetValue_shim( int xeKeTlsSetValue(uint32_t tls_index, uint32_t tls_value) {
xe_ppc_state_t* ppc_state, KernelState* state) { KernelState* state = shared_kernel_state_;
XEASSERTNOTNULL(state);
// BOOL // BOOL
// _In_ DWORD dwTlsIndex, // _In_ DWORD dwTlsIndex,
// _In_opt_ LPVOID lpTlsValue // _In_opt_ LPVOID lpTlsValue
uint32_t tls_index = SHIM_GET_ARG_32(0);
uint32_t tls_value = SHIM_GET_ARG_32(1);
XELOGD(
"KeTlsSetValue(%.8X, %.8X)",
tls_index, tls_value);
int result_code = 0; int result_code = 0;
#if XE_PLATFORM(WIN32) #if XE_PLATFORM(WIN32)
@ -232,7 +289,21 @@ SHIM_CALL KeTlsSetValue_shim(
result_code = pthread_setspecific(tls_index, (void*)tls_value) == 0; result_code = pthread_setspecific(tls_index, (void*)tls_value) == 0;
#endif // WIN32 #endif // WIN32
SHIM_SET_RETURN(result_code); return result_code;
}
SHIM_CALL KeTlsSetValue_shim(
xe_ppc_state_t* ppc_state, KernelState* state) {
uint32_t tls_index = SHIM_GET_ARG_32(0);
uint32_t tls_value = SHIM_GET_ARG_32(1);
XELOGD(
"KeTlsSetValue(%.8X, %.8X)",
tls_index, tls_value);
int result = xeKeTlsSetValue(tls_index, tls_value);
SHIM_SET_RETURN(result);
} }

View File

@ -21,7 +21,17 @@ namespace kernel {
namespace xboxkrnl { namespace xboxkrnl {
X_STATUS xeExCreateThread(
uint32_t* handle_ptr, uint32_t stack_size, uint32_t* thread_id_ptr,
uint32_t xapi_thread_startup,
uint32_t start_address, uint32_t start_context, uint32_t creation_flags);
uint32_t xeKeGetCurrentProcessType();
uint32_t xeKeTlsAlloc();
int KeTlsFree(uint32_t tls_index);
uint32_t xeKeTlsGetValue(uint32_t tls_index);
int xeKeTlsSetValue(uint32_t tls_index, uint32_t tls_value);
} // namespace xboxkrnl } // namespace xboxkrnl

View File

@ -30,7 +30,7 @@ namespace kernel {
(xe_kernel_export_shim_fn)export_name##_shim, \ (xe_kernel_export_shim_fn)export_name##_shim, \
NULL); NULL);
#define SHIM_MEM_ADDR(a) (a==NULL?NULL:(ppc_state->membase + a)) #define SHIM_MEM_ADDR(a) (a ? (ppc_state->membase + a) : NULL)
#define SHIM_MEM_16(a) (uint16_t)XEGETUINT16BE(SHIM_MEM_ADDR(a)); #define SHIM_MEM_16(a) (uint16_t)XEGETUINT16BE(SHIM_MEM_ADDR(a));
#define SHIM_MEM_32(a) (uint32_t)XEGETUINT32BE(SHIM_MEM_ADDR(a)); #define SHIM_MEM_32(a) (uint32_t)XEGETUINT32BE(SHIM_MEM_ADDR(a));
@ -47,7 +47,7 @@ namespace kernel {
#define SHIM_SET_RETURN(v) SHIM_SET_GPR_64(3, v) #define SHIM_SET_RETURN(v) SHIM_SET_GPR_64(3, v)
#define IMPL_MEM_ADDR(a) (a==0?NULL:xe_memory_addr(state->memory(), a)) #define IMPL_MEM_ADDR(a) (a ? xe_memory_addr(state->memory(), a) : NULL)
#define IMPL_MEM_16(a) (uint16_t)XEGETUINT16BE(IMPL_MEM_ADDR(a)); #define IMPL_MEM_16(a) (uint16_t)XEGETUINT16BE(IMPL_MEM_ADDR(a));
#define IMPL_MEM_32(a) (uint32_t)XEGETUINT32BE(IMPL_MEM_ADDR(a)); #define IMPL_MEM_32(a) (uint32_t)XEGETUINT32BE(IMPL_MEM_ADDR(a));