2013-12-30
xbionic - ntdll.dll (Windows Native APIs)
1. [ntdll.dll] Header and Code from the scratch
For implementing the system-call of Linux, Windows Native APIs will be used.
And the API-set will be re-written from the scrach.
[WinDDK] has the useful package to start, but that is too complicate.
So, the structures and functions are extracted one by one whenever it is used.
2. Current Codes
The porting process is on the stable stage, so the file system is almost fixed.
See the below files :
- Main Headers
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/ntstatus.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/nttypes.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/ntdll.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/ntsock.h
- Supporting Headers
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/poppack.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/pshpack1.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/pshpack2.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/pshpack4.h
https://github.com/webos21/xbionic/blob/master/lib/mingw32/include/pshpack8.h
- Implementing Source
https://github.com/webos21/xbionic/blob/master/xbionic/libc/arch-win/_nt_imp/ntdll.c
https://github.com/webos21/xbionic/blob/master/xbionic/libc/arch-win/_nt_imp/ntsock.c
xbionic - bionic libc for windows
1. What is [xbionic]
1-1. Bionic Libc
Android has the own standard c library, Bionic Libc.
It is just for the Linux OS, more precisely the Linux Kernel.
The implementation is very dependent on the System Call of Linux.
Because it stands for providing the light-weight standard c library, so it is natural.
Android version 4.4 (codename KitKat) has began to support the 64-bit CPU.
So, the Bionic Libc is evolving to support it.
1-2. Cygwin & MinGW for Developing on Windows
Cygwin(or MinGW) is the best choice to develop on Windows OS.
But, there is some missing features. For example, [the Group Source on Multicast],
[Getting the list of Ethernet Interfaces], [Socket Options], [Signal] and so on.
Inspite of these missing features, it is quite useful.
1-3. Bionic Libc for Windows
For overcome the missing features of Cygwin(or MinGW) and getting more flexible
standard c library, it is started the porting Bionic Libc on Windows 7.
[xbionic] is that project. And, it is also the begining of Android Platform for Windows.
That means running the Android Apps directly on Windows without QEMU.
2. the Way to port the Bionic Libc on Windows
2-1. only use the [ntdll.dll]
[ntdll.dll] has the Windows Native API. It is not documented by Microsoft.
But, [WinDDK] has small piece of reference code and documents,
and the undocumented project of NTinternal - http://undocumented.ntinternals.net/ -
has the good API documents. Also, the ReactOS Project has the good usage.
On the source tree of Bionic Libc, libc/arch-x86 is the base directory
to fork the [arch-win].
And the implementation of linux system-call is re-written by Windows Native APIs.
2-2. Building System
Same as any other android libraries, bionic libc has android building system
- [Android.mk].
But, I need the independent building system, so the Make and ANT is used
for compiling and linking the project.
2-3. VCS - GitHub
The project is started on GitHub. https://github.com/webos21/xbionic.git
Anyone can participate and help.
2013-06-22
Designing 64-bit compatible library
[Compiler : 64-bit data model]
First of all, you must check the 64-bit data model of your compiler.
In case of 64-bit supporting compiler,
there is the 64-bit data model(about the length of the c primitive types).
When you search about the 64-bit programming,
you can see the many articles such as LLP64 / LP64 / ILP64(Integer, Long, Pointer).
- LLP64 : only pointer type is 64-bit. (MSVC)
- LP64 : long & pointer types are 64-bit (GCC)
- ILP64 : int & long & pointer types are 64-bit (just few case)
* You can find the detail information on http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models.
I learned that the INTEGER type follows the size of CPU generic register,
in the time of changing from 16-bit to 32-bit.
But, in this time that information is wrong.
I guess that the gurus decide to avoid the huge modification of legacy codes
by changing the size of INTEGER.
(Maybe, the Microsoft decides to retain the length of LONG type because of this reason.)
[Important types : size_t / ssize_t / offset_t]
The 64-bit system can handle the large amount of memory and storage
with these types.
You can see that these types are defined as LONG
in the header files of Linux. (LP system)
Of cause the 32-bit system must be able to handle the large storage,
so there is "off64_t" when you use the "_LAGEFILE64_SOURCE" or "_FILE_OFFSET_BITS=64" in compile time.
We have to understand of these type for designing the compatible library both 32-bit and 64-bit.
The system calls those we frequently use "read", "memcpy", "strncpy"
are defined as below:
ssize_t read(int fd, void *buf, size_t count);
void *memcpy(void *dest, const void *src, size_t n);
char *strncpy(char *dest, const char *src, size_t n);
MSVC also has similar types such as "SIZE_T", "SSIZE_T",
and the size of those is changed from 32-bit system to 64-bit.
[Use the : intptr_t / uintptr_t]
In case of the "pthread" API,
"pthread_t" type to be used as the thread handle is LONG.
It looks like a decimal value, but the real value is the pointer address.
In windows programming, the "WPARAM" and "LPARAM" to be used in event loop
are cast to the pointer value frequently.
It is vary useful to cast between INTEGER and POINTER
for hiding the structure and eliminating the dependency.
But, in the LP data model, the size of INTEGER is still 32-bit,
and the size of POINTER is 64-bit.
This difference can cause the bugs and system fault.
For solving this problem, there is "intptr_t" type in the C99 specification.
The standard header file "stdint.h" is
introduced for converting a pointer to integer exactly.
So, you can be free just using the "intptr_t" in that case.
[Examples]
You can see the custom type definition
in "glib" or "APR(Apache Portable Runtime)".
It is used for overcoming the differences of systems or compilers.
So, those custom definitions are like as below :
/************************************************
* Primitive Types Definition
* ----------------------------------------------
* References the inttypes.h
* Both Win32 and Linux are equal.
************************************************/
typedef void xvoid; ///< define the type : void to xvoid
#ifdef __cplusplus
typedef bool xbool; ///< define the type : bool to xbool
#else // !__cplusplus
typedef unsigned char xbool; ///< define the type : unsigned char to xbool
#endif // __cplusplus
typedef char xchar; ///< define the type : char to xchar
typedef char xint8; ///< define the type : char to xint8
typedef unsigned char xuint8; ///< define the type : unsigned char to xuint8
typedef short xint16; ///< define the type : short to xint16
typedef unsigned short xuint16; ///< define the type : unsigned short to xuint16
typedef int xint32; ///< define the type : int to xint32
typedef unsigned int xuint32; ///< define the type : unsigned int to xuint32
typedef long long xint64; ///< define the type : long long to xint64
typedef unsigned long long xuint64; ///< define the type : unsigned long long to xuint64
typedef float xfloat32; ///< define the type : float to xfloat32
typedef double xfloat64; ///< define the type : double to xfloat64
/************************************************
* Pointer Type Definition
* ----------------------------------------------
* for both 32-bit and 64-bit (LP Architecture)
************************************************/
#ifdef _WIN32
# ifdef _WIN64
typedef __int64 xintptr; ///< define the long to integer-pointer
typedef unsigned __int64 xuintptr; ///< define the unsigned long to unsigned integer-pointer
# else // !_WIN64
typedef long xintptr; ///< define the long to integer-pointer
typedef unsigned long xuintptr; ///< define the unsigned long to unsigned integer-pointer
# endif // _WIN64
#else // !_WIN32
typedef long xintptr; ///< define the long to integer-pointer
typedef unsigned long xuintptr; ///< define the unsigned long to unsigned integer-pointer
#endif // _WIN32
/************************************************
* Size and Offset Type Definition
* ----------------------------------------------
* for both 32-bit and 64-bit (LP Architecture)
************************************************/
#if defined(__x86_64) || defined(__amd64)
typedef long unsigned int xsize;
typedef long xoff64; ///< define the off64 to long (64bit)
#else // !(define(__x86_64) || define(__amd64))
typedef unsigned int xsize;
typedef long long xoff64; ///< define the off64 to long long (64bit)
#endif // define(__x86_64) || define(__amd64)
/**
* Copies len bytes from memory area src to memory area dest.
* The memory areas should not overlap.
*
* @param dest The destination pointer to be copied
* @param src The source pointer to be copied
* @param len The length to be copied
* @return Same pointer as the destination pointer
*/
xvoid *xi_mem_copy(xvoid *dest, const xvoid *src, xsize len);
MSI GT60 - Atheros Killer E2200 Ethernet Driver (alx) in Ubuntu
I use the GT60 notebook of MSI.
But, the device driver - Qualcomm Atheros Killer E2200 - is not working on Ubuntu.
After the long web searching,
I found the solution of this problem, finally,
* Cause of Problem
- Ubuntu Distribution has no driver for Qualcomm Atheros Killer E2200.
- You can get the (alx) driver for this chip in compat-drivers package.
But it is not working, because of non-matching Device ID.
* Solution
1. Ubuntu 12.10 and before
- Follow the operation on http://ubuntuforums.org/showthread.php?t=2008332
- You must apply the two patch files.
- compat-patch.txt --> for adding device id
- tty.c.patch.txt --> for fixing the definition of TTY functions
2. Ubuntu 13.04 and after
- Install the compiler tool-chain and the header files of linux kernel
sudo apt-get install build-essential linux-headers
- Download the compat-drivers package
- Extract the tar ball
tar xvjf compat-drivers-2013-03-04-u.tar.bz2
- Fix the codes (Adding Device ID of MSI's)
vim drivers/net/ethernet/atheros/alx/alx_reg.h
--> #define ALX_DEV_ID_AR8172 0x10A0 // add below codes
#define ALX_DEV_ID_MINE 0xe091
vim drivers/net/ethernet/atheros/alx/alx_main.c
--> ALX_ETHER_DEVICE(ALX_DEV_ID_AR8172), // add below codes
ALX_ETHER_DEVICE(ALX_DEV_ID_MINE),
- Set the target driver [alx] in compat-drivers build tree
./scripts/driver-select alx
- Build the compat-drivers and Install the target kernel module [alx]
sudo make all install
- Load the kernel module of [alx] driver, and Check the network interfaces
sudo modprobe alx
ifconfig
- After rebooting, check the final status
lsmod | grep alx
ifconfig
Subscribe to:
Posts (Atom)