jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.3KB

  1. #include "../../IAndroidShm.h"
  2. #include <binder/MemoryHeapBase.h>
  3. #include <binder/IServiceManager.h>
  4. #include "../../../common/shm.h"
  5. namespace android {
  6. static sp<IMemoryHeap> receiverMemBase;
  7. #define MAX_SHARED_MEMORY_COUNT 257
  8. sp<IAndroidShm> getAndroidShmService() {
  9. sp<IAndroidShm> shm = 0;
  10. /* Get the buffer service */
  11. if (shm == NULL) {
  12. sp<IServiceManager> sm = defaultServiceManager();
  13. sp<IBinder> binder;
  14. binder = sm->getService(String16("com.samsung.android.jam.IAndroidShm"));
  15. if (binder != 0) {
  16. shm = IAndroidShm::asInterface(binder);
  17. //shm = interface_cast<IAndroidShm>(binder);
  18. }
  19. }
  20. return shm;
  21. }
  22. unsigned int * getBufferMemPointer(int index)
  23. {
  24. sp<IAndroidShm> shm = getAndroidShmService();
  25. if (shm == NULL) {
  26. printf("The EneaBufferServer is not published\n");
  27. return (unsigned int *)-1; /* return an errorcode... */
  28. } else {
  29. receiverMemBase = shm->getBuffer(index);
  30. if(receiverMemBase != NULL)
  31. return (unsigned int *) receiverMemBase->getBase();
  32. else
  33. return (unsigned int*)-1;
  34. }
  35. }
  36. }
  37. using namespace android;
  38. void showStatus() {
  39. sp<IAndroidShm> shm = getAndroidShmService();
  40. if(shm == NULL) {
  41. printf("shm service is not available\n");
  42. return;
  43. }
  44. printf("<<<<<<<<<<< dump memory allocation status >>>>>>>>>>\n");
  45. for(int i = 256; i >= 0; i--) {
  46. if(shm->isAllocated(i) == 1) {
  47. printf("Mem[%3d] == 0x%x\n", i, (unsigned int)getBufferMemPointer(i));
  48. } else {
  49. printf("Mem[%3d] == NULL\n", i);
  50. }
  51. }
  52. }
  53. void showRegistryIndex() {
  54. sp<IAndroidShm> shm = getAndroidShmService();
  55. if(shm == NULL) {
  56. printf("shm service is not available\n");
  57. return;
  58. }
  59. printf("<<<<<<<<<<< show registry index >>>>>>>>>>\n");
  60. printf("index [%3d]\n",shm->getRegistryIndex());
  61. }
  62. void showHeader() {
  63. sp<IAndroidShm> shm = getAndroidShmService();
  64. if(shm == NULL) {
  65. printf("shm service is not available\n");
  66. return;
  67. }
  68. if(shm->getRegistryIndex() > 256) {
  69. printf("don't have a registry header\n");
  70. return;
  71. }
  72. unsigned int* buffer = getBufferMemPointer(shm->getRegistryIndex());
  73. if(buffer) {
  74. jack_shm_header_t * header = (jack_shm_header_t*)buffer;
  75. printf("<<<<<<<<<< register header value >>>>>>>>>>\n");
  76. printf("memory address 0x%x 0x%x\n", (unsigned int)(header), (unsigned int)buffer);
  77. printf("magic = %d\n", header->magic);
  78. printf("protocol = %d\n", header->protocol);
  79. printf("type = %d\n", header->type);
  80. printf("size = %d\n", header->size);
  81. printf("hdr_len = %d\n", header->hdr_len);
  82. printf("entry_len = %d\n", header->entry_len);
  83. for(int j = 0; j < MAX_SERVERS; j++) {
  84. //char name[256];
  85. //memset(name, '\0', 256);
  86. //strncpy(name, header->server[j].name, 10);
  87. printf("server[%d] pid = %d, name = %s\n", j, header->server[j].pid, header->server[j].name);
  88. }
  89. }
  90. }
  91. void showBody() {
  92. sp<IAndroidShm> shm = getAndroidShmService();
  93. if(shm == NULL) {
  94. printf("shm service is not available\n");
  95. return;
  96. }
  97. if(shm->getRegistryIndex() > 256) {
  98. printf("don't have a registry body\n");
  99. return;
  100. }
  101. unsigned int* buffer = getBufferMemPointer(shm->getRegistryIndex());
  102. if(buffer) {
  103. jack_shm_header_t * header = (jack_shm_header_t*)buffer;
  104. printf("<<<<<<<<<< registry body value >>>>>>>>>>\n");
  105. jack_shm_registry_t * registry = (jack_shm_registry_t *) (header + 1);
  106. for(int k = 255; k >= 0; k--) {
  107. printf("registry[%3d] index[%3d],allocator[%3d],size[%6d],id[%10s],fd[%3d]\n", k,
  108. registry[k].index, registry[k].allocator, registry[k].size,
  109. registry[k].id,
  110. registry[k].fd);
  111. }
  112. }
  113. }
  114. void showSemaphore() {
  115. sp<IAndroidShm> shm = getAndroidShmService();
  116. if(shm == NULL) {
  117. printf("shm service is not available\n");
  118. return;
  119. }
  120. shm->sendCommand("semaphore");
  121. printf("log will be shown in the logcat log\n");
  122. }
  123. int main(int argc, char** argv) {
  124. // base could be on same address as Servers base but this
  125. // is purely by luck do NEVER rely on this. Linux memory
  126. // management may put it wherever it likes.
  127. if(argc < 2) {
  128. printf("usage\n shmservicedump [status|header|body|index|semaphore]\n");
  129. printf(" status: show the shared memory allocation status\n");
  130. printf(" header: show the registry header infomations if the registry exist\n");
  131. printf(" body: show the registry body infomations if the registry exist\n");
  132. printf(" index: show the index of array that is allocated registry shared memory\n");
  133. printf(" semaphore: show the memory array about semaphore simulation\n");
  134. return 0;
  135. }
  136. if(strcmp(argv[1], "semaphore") == 0) {
  137. showSemaphore();
  138. } else if(strcmp(argv[1], "index") == 0) {
  139. showRegistryIndex();
  140. } else if(strcmp(argv[1], "status") == 0) {
  141. showStatus();
  142. } else if(strcmp(argv[1], "header") == 0) {
  143. showHeader();
  144. } else if(strcmp(argv[1], "body") == 0) {
  145. showBody();
  146. } else {
  147. printf("%s is invalid parameter\n", argv[1]);
  148. }
  149. return 0;
  150. }