另外: http://hamer-blog.logdown.com/posts/174690-android-find-kernel-headers-the-source-needs

http://blog.csdn.net/heqiangflytosky/article/details/8941466


http://www.eoeandroid.com/thread-4668-1-1.html

http://blog.chinaunix.net/uid-9078996-id-2010323.html

http://blog.csdn.net/andyhuabing/article/details/7183369

1、Syscall stub:

每个系统调用函数都由一个小的汇编代码段实现(称为”syscall stub”),这是由tools/gensyscalls.py工具自动生成的,它从SYSCALL.TXT中取得输入参数。
SYSCALLS.TXT包含了一份要生成的系统调用块列表,和相应的系统调用数字标识符(ARM和X86不一样),以及它的签署。
如果你要修改这个文件,你可能要使用tools/checksyscalls.py工具,检查它里面是否包含官方linux核心头文件,如果有不合法的syscall ids,它会报告错误。
有时,C库函数其实就是一个包装,它内部调用相应的syscall名称,例如,exit函数由C库提供,它调用了_exit()这个syscall stub.
详细内容请参考SYSCALLS.TXT文件。

2、比如要增加消息队列的函数:
(1). 修改 SYSCALL.TXT
增加:
long ipc(unsigned int call, int first, unsigned long second, unsigned long third, void __user *ptr, long fifth) 117
(2). 执行 tools/gensyscalls.py
(3). 以下内容会由 tools/gensyscalls.py 自动产生:

bionic/libc/arch-mips/syscalls.mk
----------------------------------------------------------------------------------------------------------------------------
syscall_src += arch-mips/syscalls/ipc.S
----------------------------------------------------------------------------------------------------------------------------

bionic/libc/include/sys/linux-syscalls.h
----------------------------------------------------------------------------------------------------------------------------
#define _NR_ipc (_NR_SYSCALL_BASE + 117)
----------------------------------------------------------------------------------------------------------------------------

bionic/libc/include/sys/linux-unistd.h
----------------------------------------------------------------------------------------------------------------------------
int ipc (unsigned int call, int first, int second, int third, void* ptr, long fifth);
----------------------------------------------------------------------------------------------------------------------------

(4). 手动编写
bionic/libc/Android.mk
----------------------------------------------------------------------------------------------------------------------------
ifeq ($(TARGET_ARCH),mips)
libc_common_src_files += \
arch-mips/bionic/sys_ipc.c \

----------------------------------------------------------------------------------------------------------------------------
bionic/libc/arch-mips/bionic/sys_ipc.c
----------------------------------------------------------------------------------------------------------------------------
[cpp] view plain copy
  1. #include<stdarg.h>
  2. #include<sys/msg.h>
  3. externintipc(unsignedintcall,intfirst,intsecond,intthird,void*ptr,longfifth);
  4. intsemget(key_tkey,intnsems,intsemflg)
  5. {
  6. returnipc(SEMGET,key,nsems,semflg,(void*)NULL,(long)NULL);
  7. }
  8. intsemop(intsemid,structsembuf*sops,size_tnsops)
  9. {
  10. returnipc(SEMOP,semid,(int)nsops,0,sops,(long)NULL);
  11. }
  12. void*shmat(intshmid,constvoid*shmaddr,intshmflg)
  13. {
  14. intrval;
  15. unsignedlongraddr;
  16. rval=ipc(SHMAT,shmid,shmflg,(int)&raddr,(void*)shmaddr,(long)NULL);
  17. if(rval<0)
  18. return(char*)rval;
  19. return(char*)raddr;
  20. }
  21. intshmctl(intshmid,intcmd,structshmid_ds*buf)
  22. {
  23. returnipc(SHMCTL,shmid,cmd,0,buf,(long)NULL);
  24. }
  25. intshmget(key_tkey,size_tsize,intshmflg)
  26. {
  27. returnipc(SHMGET,key,size,shmflg,(void*)NULL,(long)NULL);
  28. }
  29. intmsgctl(intmsqid,intcmd,structmsqid_ds*buf)
  30. {
  31. returnipc(MSGCTL,msqid,cmd,0,buf,(long)NULL);
  32. }
  33. intshmdt(constvoid*shmaddr)
  34. {
  35. returnipc(SHMDT,0,0,0,(void*)shmaddr,(long)NULL);
  36. }
  37. intmsgget(key_tkey,intmsgflg)
  38. {
  39. returnipc(MSGGET,key,msgflg,0,NULL,(long)NULL);
  40. }
  41. ssize_tmsgrcv(intmsqid,void*msgp,size_tmsgsz,longintmsgtyp,intmsgflg)
  42. {
  43. structipc_kludgetmp;
  44. tmp.msgp=msgp;
  45. tmp.msgtyp=msgtyp;
  46. returnipc(MSGRCV,msqid,msgsz,msgflg,&tmp,(long)NULL);
  47. }
  48. intmsgsnd(intmsqid,constvoid*msgp,size_tmsgsz,intmsgflg)
  49. {
  50. returnipc(MSGSND,msqid,msgsz,msgflg,(void*)msgp,(long)NULL);
  51. }



bionic/libc/arch-mips/syscalls/ipc.S
----------------------------------------------------------------------------------------------------------------------------
/* autogenerated by gensyscalls.py */
#include <sys/linux-syscalls.h>
.text
.globl ipc
.align 4
.ent ipc

ipc:
.set noreorder
.cpload $t9
li $v0, __NR_ipc
syscall
bnez $a3, 1f
move $a0, $v0
j $ra
nop
1:
la $t9,__set_errno
j $t9
nop
.set reorder
.end ipc

----------------------------------------------------------------------------------------------------------------------------
bionic/libc/include/sys/msg.h
----------------------------------------------------------------------------------------------------------------------------

[cpp] view plain copy
  1. #ifndef_SYS_MSG_H
  2. #define_SYS_MSG_H
  3. #include<features.h>
  4. #define__need_size_t
  5. #include<stddef.h>
  6. /*GetcommondefinitionofSystemVstyleIPC.*/
  7. #include<sys/ipc.h>
  8. /*Getsystemdependentdefinitionof`structmsqid_ds'andmore.*/
  9. #include<msq.h>
  10. /*Definetypesrequiredbythestandard.*/
  11. #define__need_time_t
  12. #include<time.h>
  13. #ifndef__pid_t_defined
  14. typedef__pid_tpid_t;
  15. #define__pid_t_defined
  16. #endif
  17. #ifndef__ssize_t_defined
  18. typedef__ssize_tssize_t;
  19. #define__ssize_t_defined
  20. #endif
  21. #defineSEMOP1
  22. #defineSEMGET2
  23. #defineSEMCTL3
  24. #defineSEMTIMEDOP4
  25. #defineMSGSND11
  26. #defineMSGRCV12
  27. #defineMSGGET13
  28. #defineMSGCTL14
  29. #defineSHMAT21
  30. #defineSHMDT22
  31. #defineSHMGET23
  32. #defineSHMCTL24
  33. /*ThefollowingSystemVstyleIPCfunctionsimplementamessagequeue
  34. system.ThedefinitionisfoundinXPG2.*/
  35. #ifdef__USE_GNU
  36. /*Templateforstructtobeusedasargumentfor`msgsnd'and`msgrcv'.*/
  37. structmsgbuf
  38. {
  39. longintmtype;/*typeofreceived/sentmessage*/
  40. charmtext[1];/*textofthemessage*/
  41. };
  42. #endif
  43. structipc_kludge{
  44. structmsgbuf__user*msgp;
  45. longmsgtyp;
  46. };
  47. __BEGIN_DECLS
  48. /*Messagequeuecontroloperation.*/
  49. externintmsgctl(int__msqid,int__cmd,structmsqid_ds*__buf);
  50. /*Getmessagesqueue.*/
  51. externintmsgget(key_t__key,int__msgflg);
  52. /*Receivemessagefrommessagequeue.
  53. Thisfunctionisacancellationpointandthereforenotmarkedwith
  54. __THROW.*/
  55. externssize_tmsgrcv(int__msqid,void*__msgp,size_t__msgsz,longint__msgtyp,int__msgflg);
  56. /*Sendmessagetomessagequeue.
  57. Thisfunctionisacancellationpointandthereforenotmarkedwith
  58. __THROW.*/
  59. externintmsgsnd(int__msqid,__constvoid*__msgp,size_t__msgsz,int__msgflg);
  60. __END_DECLS
  61. #endif/*sys/msg.h*/


----------------------------------------------------------------------------------------------------------------------------
Create bionic/libc/include/msq.h

[cpp] view plain copy
  1. #ifndef_SYS_MSG_H
  2. #error"Neveruse<msq.h>directly;include<sys/msg.h>instead."
  3. #endif
  4. #include<sys/types.h>
  5. /*Defineoptionsformessagequeuefunctions.*/
  6. #defineMSG_NOERROR010000/*noerrorifmessageistoobig*/
  7. /*Typesusedinthestructuredefinition.*/
  8. typedefunsignedshortintmsgqnum_t;
  9. typedefunsignedshortintmsglen_t;
  10. /*Structureofrecordforonemessageinsidethekernel.
  11. Thetype`struct__msg'isopaque.*/
  12. structmsqid_ds
  13. {
  14. structipc_permmsg_perm;/*structuredescribingoperationpermission*/
  15. __time_tmsg_stime;/*timeoflastmsgsndcommand*/
  16. __time_tmsg_rtime;/*timeoflastmsgrcvcommand*/
  17. __time_tmsg_ctime;/*timeoflastchange*/
  18. msgqnum_tmsg_qnum;/*numberofmessagescurrentlyonqueue*/
  19. msglen_tmsg_qbytes;/*maxnumberofbytesallowedonqueue*/
  20. __pid_tmsg_lspid;/*pidoflastmsgsnd()*/
  21. __pid_tmsg_lrpid;/*pidoflastmsgrcv()*/
  22. };

更多相关文章

  1. android,webview增加自定义JS对象,调用过程追踪。
  2. 【黑马Android】(03)学生管理系统/动态刷新界面
  3. Java中,使用HTTP Basic进行验证
  4. 接收系统广播监听网络变化
  5. android、webService 天气预报demo
  6. OKhttp上传头像,调用相机相册进行裁剪
  7. Android调用邮件客户端
  8. Android(安卓)打开资源raw文件
  9. 模拟按键操作的几种方式

随机推荐

  1. android上gl纹理资源路径的问题
  2. android的图标资源及其巧用
  3. 采用CakePHP框架为Android应用快速搭建We
  4. Android中代码混淆和打包
  5. Android小说阅读器
  6. Android原生网络库HttpURLConnection分析
  7. Android(安卓)改变窗口标题栏的布局
  8. 一起学android之微信登录(18)
  9. 提高Android应用程序的速度四大原则
  10. Android4.4的init进程