[Android] Build goldfish kernel with NDK toolchain.

Domain/Android 2015.10.19 23:15

Here is the way to compile x86 goldfish and run on emulator


* AOSP Marshmallow + Goldfish 3.4

* ARCH=x86 (You don't need to set SUBARCH)

* Compiler version : gcc-4.8 (prebuilt x86 compiler from Android NDK)

  (Set CROSS_COMPILE environment variable)


$ make ARCH=x86 CC="${CROSS_COMPILE}gcc -mno-android" goldfish_defconfig

$ make ARCH=x86 CC="${CROSS_COMPILE}gcc -mno-android" -j40


And use 'arch/x86/boot/bzImage' as 'kernel-qemu' image


Please note that you SHOULD use '-mno-android' option to build linux kernel with NDK toolchains.
The reason is, '-mandroid' option is enabled by default at GCC in NDK(file name is something like *-*-android*)
Remember that NDK toolchain is used to build native executable or libraries run on Android devices.
And, in general, build environment of linux kernel is 'GCC' + 'GLIBC'.
(Note that, linux kernel binary even if it runs on Android device, it doesn't have any dependency on Android platform(ex. bionic or libc))
So, to build linux kernel, '-mandroid' option should be disabled by using '-mno-android' option.


Trackback 0 : Comment 0

[Java] Java main thread vs. user thread vs. daemon thread.

Language/Java 2015.10.19 23:01

StackOverlow 의 아래 답변을 참고하자.

http://stackoverflow.com/questions/2213340/what-is-daemon-thread-in-java


정리하면, JVM은 main thread가 끝나더라도, 아직 수행중인 다른 thread - non daemon thread(user thread) - 가 있다면, 중지되지 않는다.

즉, process가 계속해서 돈다.

C/C++ 처럼, main thread가 exit될 때 process를 종료시키려면, 모든 child thread 속성을 daemon thread로 설정해야 한다.


Thread t = new Thread(...)

t.setDaemon(true);


남아 있는 모든 thread가 Daemon thread일 경우, JVM은 중지된다.

다만, 이런식으로 thread가 급작스레 종료하는 것은 상당히 불안정한 결과를 가져 올 수 있으므로 주의해야 한다.


다시 말하면, 단 하나라도 종료되지 않은 user thread (non-daemon thread) 가 존재할 경우, JVM은 종료되지 않고, 모든 다른 thread (Daemon thraed 포함)역시 계속해도 수행된다.



Trackback 0 : Comment 0

[C/C++] Small tip - Argument passed to main() function.

Language/C&C++ 2015.10.19 22:56

In general, main function is used as below.


int main(int argc, const char *argv[]) {

}


But, it can be expanded like below


int main(int argc, const char *argv[], const char **envp) {

        while (*envp) {

                printf("%s\n", *envp++);

        }

}


By this way, we can use environment variables easily.

=> This matches parameters of execle() and execvpe() at Linux.



'Language > C&C++' 카테고리의 다른 글

[C/C++] Small tip - Argument passed to main() function.  (0) 2015.10.19
[C/C++] Template with value  (0) 2015.04.28
[C/C++] sizeof array  (0) 2015.03.19
[Macro] '##' macro operator  (0) 2015.02.11
'malloc' and 'Segmentation fault'  (0) 2014.07.25
[GCC] Initialize array...  (0) 2014.07.25
Trackback 0 : Comment 0