PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

CE 4.0 source?

MS released a goodly sized chunk of the CE 3.0 source a few years ago. Have they followed suite with 4.0 yet?

Dan East
Dan East wrote:MS released a goodly sized chunk of the CE 3.0 source a few years ago. Have they followed suite with 4.0 yet?

Dan East

If I remember correctly, it works as follows:

In general, the sources are included in platform builder. In order to gain access to the sources you can obtain an evaluation license for platform builder, and then keep the sources which are under their 'shared source' license. I believe there is an FAQ around this somewhere on the MS site.

- HM
We were able to access the source directly before:

http://www.pocketmatrix.com/forums/viewtopic.php?t=890

Dan East
Dan East wrote:We were able to access the source directly before:

http://www.pocketmatrix.com/forums/viewtopic.php?t=890

Dan East

I know. Anyway, here's the official link (for 5.0):
http://www.microsoft.com/resources/sharedsource/Licensing/WindowsCE.mspx

Section "Fulfillment".

And:
http://msdn.microsoft.com/embedded/usewinemb/ce/sharedsrccode/obtain/default.aspx


Couldn't find the 4.2 reference anymore, though.

- HM
Okay, does anyone have the 4.0 kernel.h lying around? Or at least the Thread struct definition contained within?

Dan East
Here is Thread structure from WinCE 4.2

Code:

#define PRIORITY_LEVELS_HASHSIZE 32
/* Thread data structures */

typedef struct CLEANEVENT {
struct CLEANEVENT *ceptr;
LPVOID base;
DWORD size;
DWORD op;
} CLEANEVENT, *LPCLEANEVENT;

typedef struct THREADTIME {
struct THREADTIME *pnext;
HANDLE hTh;
FILETIME CreationTime;
FILETIME ExitTime;
FILETIME KernelTime;
FILETIME UserTime;
} THREADTIME, *LPTHREADTIME;

typedef struct CRIT *LPCRIT;

typedef _CONTEXT CPUCONTEXT;

#define RUNSTATE_RUNNING 0 // must be 0
#define RUNSTATE_RUNNABLE 1
#define RUNSTATE_BLOCKED 2
#define RUNSTATE_NEEDSRUN 3 // on way to being runnable

#define WAITSTATE_SIGNALLED 0
#define WAITSTATE_PROCESSING 1
#define WAITSTATE_BLOCKED 2

#define TIMEMODE_USER 0
#define TIMEMODE_KERNEL 1

#define RUNSTATE_SHIFT 0 // 2 bits
#define DYING_SHIFT 2 // 1 bit
#define DEAD_SHIFT 3 // 1 bit
#define BURIED_SHIFT 4 // 1 bit
#define SLEEPING_SHIFT 5 // 1 bit
#define TIMEMODE_SHIFT 6 // 1 bit
#define NEEDDBG_SHIFT 7 // 1 bit
#define STACKFAULT_SHIFT 8 // 1 bit
#define DEBUGBLK_SHIFT 9 // 1 bit
#define NOPRIOCALC_SHIFT 10 // 1 bit
#define DEBUGWAIT_SHIFT 11 // 1 bit
#define USERBLOCK_SHIFT 12 // 1 bit
#ifdef DEBUG
#define DEBUG_LOOPCNT_SHIFT 13 // 1 bit - only in debug
#endif
#define NEEDSLEEP_SHIFT 14 // 1 bit
#define PROFILE_SHIFT 15 // 1 bit, must be 15! Used by assembly code!

#define GET_BPRIO(T) ((WORD)((T)->bBPrio)) /* base priority */
#define GET_CPRIO(T) ((WORD)((T)->bCPrio)) /* current priority */
#define SET_BPRIO(T,S) ((T)->bBPrio = (BYTE)(S))
#define SET_CPRIO(T,S) ((T)->bCPrio = (BYTE)(S))

#define GET_TIMEMODE(T) (((T)->wInfo >> TIMEMODE_SHIFT)&0x1) /* What timemode are we in */
#define GET_RUNSTATE(T) (((T)->wInfo >> RUNSTATE_SHIFT)&0x3) /* Is thread runnable */
#define GET_BURIED(T) (((T)->wInfo >> BURIED_SHIFT)&0x1) /* Is thread 6 feet under */
#define GET_SLEEPING(T) (((T)->wInfo >> SLEEPING_SHIFT)&0x1) /* Is thread sleeping */
#define GET_DEBUGBLK(T) (((T)->wInfo >> DEBUGBLK_SHIFT)&0x1) /* Has DebugActive suspended thread */
#define GET_DYING(T) (((T)->wInfo >> DYING_SHIFT)&0x1) /* Has been set to die */
#define TEST_STACKFAULT(T) ((T)->wInfo & (1<<STACKFAULT_SHIFT))
#define GET_DEAD(T) (((T)->wInfo >> DEAD_SHIFT)&0x1)
#define GET_NEEDDBG(T) (((T)->wInfo >> NEEDDBG_SHIFT)&0x1)
#define GET_PROFILE(T) (((T)->wInfo >> PROFILE_SHIFT)&0x1) /* montecarlo profiling */
#define GET_NOPRIOCALC(T) (((T)->wInfo >> NOPRIOCALC_SHIFT)&0x1)
#define GET_DEBUGWAIT(T) (((T)->wInfo >> DEBUGWAIT_SHIFT)&0x1)
#define GET_USERBLOCK(T) (((T)->wInfo >> USERBLOCK_SHIFT)&0x1) /* did thread voluntarily block? */
#define GET_NEEDSLEEP(T) (((T)->wInfo >> NEEDSLEEP_SHIFT)&0x1) /* should the thread put back to sleepq? */

#define SET_RUNSTATE(T,S) ((T)->wInfo = (WORD)(((T)->wInfo & ~(3<<RUNSTATE_SHIFT)) | ((S)<<RUNSTATE_SHIFT)))
#define SET_BURIED(T) ((T)->wInfo |= (1<<BURIED_SHIFT))
#define SET_SLEEPING(T) ((T)->wInfo |= (1<<SLEEPING_SHIFT))
#define CLEAR_SLEEPING(T) ((T)->wInfo &= ~(1<<SLEEPING_SHIFT))
#define SET_DEBUGBLK(T) ((T)->wInfo |= (1<<DEBUGBLK_SHIFT))
#define CLEAR_DEBUGBLK(T) ((T)->wInfo &= ~(1<<DEBUGBLK_SHIFT))
#define SET_DYING(T) ((T)->wInfo |= (1<<DYING_SHIFT))
#define SET_STACKFAULT(T) ((T)->wInfo |= (1<<STACKFAULT_SHIFT))
#define CLEAR_STACKFAULT(T) ((T)->wInfo &= ~(1<<STACKFAULT_SHIFT))
#define SET_DEAD(T) ((T)->wInfo |= (1<<DEAD_SHIFT))
#define SET_TIMEUSER(T) ((T)->wInfo &= ~(1<<TIMEMODE_SHIFT))
#define SET_TIMEKERN(T) ((T)->wInfo |= (1<<TIMEMODE_SHIFT))
#define SET_NEEDDBG(T) ((T)->wInfo |= (1<<NEEDDBG_SHIFT))
#define CLEAR_NEEDDBG(T) ((T)->wInfo &= ~(1<<NEEDDBG_SHIFT))
#define SET_PROFILE(T) ((T)->wInfo |= (1<<PROFILE_SHIFT))
#define CLEAR_PROFILE(T) ((T)->wInfo &= ~(1<<PROFILE_SHIFT))
#define SET_NOPRIOCALC(T) ((T)->wInfo |= (1<<NOPRIOCALC_SHIFT))
#define CLEAR_NOPRIOCALC(T) ((T)->wInfo &= ~(1<<NOPRIOCALC_SHIFT))
#define SET_DEBUGWAIT(T) ((T)->wInfo |= (1<<DEBUGWAIT_SHIFT))
#define CLEAR_DEBUGWAIT(T) ((T)->wInfo &= ~(1<<DEBUGWAIT_SHIFT))
#define SET_USERBLOCK(T) ((T)->wInfo |= (1<<USERBLOCK_SHIFT))
#define CLEAR_USERBLOCK(T) ((T)->wInfo &= ~(1<<USERBLOCK_SHIFT))
#define SET_NEEDSLEEP(T) ((T)->wInfo |= (1<<NEEDSLEEP_SHIFT))
#define CLEAR_NEEDSLEEP(T) ((T)->wInfo &= ~(1<<NEEDSLEEP_SHIFT))

struct Thread {
WORD wInfo; /* 00: various info about thread, see above */
BYTE bSuspendCnt;/* 02: thread suspend count */
BYTE bWaitState; /* 03: state of waiting loop */
LPPROXY pProxList; /* 04: list of proxies to threads blocked on this thread */
PTHREAD pNextInProc;/* 08: next thread in this process */
PPROCESS pProc; /* 0C: pointer to current process */
PPROCESS pOwnerProc; /* 10: pointer to owner process */
ACCESSKEY aky; /* 14: keys used by thread to access memory & handles */
PCALLSTACK pcstkTop; /* 18: current api call info */
DWORD dwOrigBase; /* 1C: Original stack base */
DWORD dwOrigStkSize; /* 20: Size of the original thread stack */
LPDWORD tlsPtr; /* 24: tls pointer */
DWORD dwWakeupTime; /* 28: sleep count, also pending sleepcnt on waitmult */
LPDWORD tlsSecure; /* 2c: TLS for secure stack */
LPDWORD tlsNonSecure; /* 30: TLS for non-secure stack */
LPPROXY lpProxy; /* 34: first proxy this thread is blocked on */
DWORD dwLastError;/* 38: last error */
HANDLE hTh; /* 3C: Handle to this thread, needed by NextThread */
BYTE bBPrio; /* 40: base priority */
BYTE bCPrio; /* 41: curr priority */
WORD wCount; /* 42: nonce for blocking lists */
PTHREAD pPrevInProc;/* 44: previous thread in this process */
LPTHRDDBG pThrdDbg; /* 48: pointer to thread debug structure, if any */
LPBYTE pSwapStack; /* 4c */
FILETIME ftCreate; /* 50: time thread is created */
CLEANEVENT *lpce; /* 58: cleanevent for unqueueing blocking lists */
DWORD dwStartAddr; /* 5c: thread PC at creation, used to get thread name */
CPUCONTEXT ctx; /* 60: thread's cpu context information */
PTHREAD pNextSleepRun; /* ??: next sleeping thread, if sleeping, else next on runq if runnable */
PTHREAD pPrevSleepRun; /* ??: back pointer if sleeping or runnable */
PTHREAD pUpRun; /* ??: up run pointer (circulaar) */
PTHREAD pDownRun; /* ??: down run pointer (circular) */
PTHREAD pUpSleep; /* ??: up sleep pointer (null terminated) */
PTHREAD pDownSleep; /* ??: down sleep pointer (null terminated) */
LPCRIT pOwnedList; /* ??: list of crits and mutexes for priority inversion */
LPCRIT pOwnedHash[PRIORITY_LEVELS_HASHSIZE];
DWORD dwQuantum; /* ??: thread quantum */
DWORD dwQuantLeft;/* ??: quantum left */
LPPROXY lpCritProxy;/* ??: proxy from last critical section block, in case stolen back */
LPPROXY lpPendProxy;/* ??: pending proxies for queueing */
DWORD dwPendReturn;/* ??: return value from pended wait */
DWORD dwPendTime; /* ??: timeout value of wait operation */
PTHREAD pCrabPth;
WORD wCrabCount;
WORD wCrabDir;
DWORD dwPendWakeup;/* ??: pending timeout */
WORD wCount2; /* ??: nonce for SleepList */
BYTE bPendSusp; /* ??: pending suspend count */
BYTE bDbgCnt; /* ??: recurse level in debug message */
HANDLE hLastCrit; /* ??: Last crit taken, cleared by nextthread */
//DWORD dwCrabTime;
CALLSTACK IntrStk;
DWORD dwKernTime; /* ??: elapsed kernel time */
DWORD dwUserTime; /* ??: elapsed user time */
}; /* Thread */

#define THREAD_CONTEXT_OFFSET 0x60
Thanks! It seems that dwUserTime / dwKernTime is not used with the newer kernel - those values are always 0. However I see a new struct THREADTIME, which must be the new mechanism they are using to keep track of CPU usage per-thread. Would you be able to email kernel.h to info@dex-plor.com?

Thanks again.

Dan East
sent it
Thanks!

Dan East
here is a link for 4.2
http://www.microsoft.com/downloads/deta ... layLang=en

ps: this version comes without a key but . . .
the 5.0 key works great 8)
get it here
http://www.microsoft.com/downloads/deta ... laylang=en

have fun
inteks
Thanks for the links.

Dan East