발표자 : 오동권님(www.flowdas.com)




발표 내용
  • 안드로이드 RPC 메카니즘의 이해
  1. 바인더의 탄생
  2. 바인더 IPC
  3. 바인더의 데이터 전달
  4. 서비스 관리자
  5. 바인더의 한계와 전망

+ 생략된 강의 내용
Flat Binder Object 로 IBinder 외에 File Descriptor를 전달할 수 있습니다.
One-way Call이 존재한다는 사실을 알리지 않았습니다.
Reference Counting 과 관련된 일체의 내용을 생략했습니다.
Thread Priority 와 관련된 내용을 다루지 않았습니다.
Death Notification 을 생략했습니다.
/proc 로 노출되는 데이터들에 관한 설명을 생략했습니다.
Activity Manager 와 관련된 모든 것들을 생략했음은 발표 때 이미 설명 드렸습니다.

Binder는 Linker와 하는 일이 비슷
Linker - 오브젝트 간에 심볼을 연결
Binder - Process 간에 함수의 심볼을 연결

Dannie Hackborn
  • OpenBinder
BeOS의 Project로 시작 -> PalmOS 6 Cobalt에 처음 구현 -> Linux 구현이 오픈 소스로 공개
2005년 개발 중단(Google로 이직)
  • Android Binder
OpenBinder(C++) -> Android Binder(C++/JAVA)
Kernel Module은 OpenBinder 코드 재사용
OpenBinder와 설계 철학을 공유
Android Binder Document는 존재하지 않아서 Source Code를 보고 직접 확인

Thread Model
  • stub는 어떤 thread에서 수행 되는가?
callee가 결정 해야함
여러개의 caller가 호출하게 되면 callee가 알아서 Thread를 만들어 줘야함
service 제작시 유의사항
  • thread looper를 직접 디자인
  • service manager의 경우는 모든 요청을 단일 Thread로 동작
  • stub()의 수행이 짧음

  • return value는 어떻게 caller에게 돌아가는가?
Binder Diver가 History를 기억

  • stub의 내부에서 callback 함수가 수행되면 누가 보장해주냐?
Transparent Recursion - Android Binder만의 Unique한 특징
stub에서 callback함수를 호출하게 되면 caller에게 BC_TRANSACTION으로 caller의 callback함수를 사용
caller에서는 자신에게 온게 BR_REPLY가 아닌 BR_TRANSACTION임을 확인하고 callee에서 callback함수를 호출 한 것임을 알아야 함
때의 Thread는 원래의 caller thread를 이용하게 됨

  • caller는 LPC와 RPC의 차이를 구분하지 못하도록 하자!
timing를 제외한 나머지는 동일하게 작업된다.

/dev/binder
Binder의 IPC의 단 하나의 기능을 제외한 모든 기능을 넣어둠
  • 단 하나의 기능 : share memory -> ashmem을 사용
Protocol Version 7


BINDER_WRITE_READ
struct binde_write_read {
long write_size;
long write_consumed;
unsigned long write_buffer;
long read_size;
long read_consumed;
unsigned long read_buffer;
}

  • read_size가 0이 아니면 계속 return을 기다림
  • consumed -> 진척 상황을 보여줌

Binder Transaction

binder.



  • Target Method
handle : Remote Interface
ptr & cookie : Local Interface
code : Method ID -> 호출 하고자 하는 Method ID(함수 선언 순서)

  • Parcel - Input/Output Parameters
data.ptr.buffer
data_size

  • Object Reference Management
data.ptr.offsets
offsets_size
  • Security
sender_pid
sender_euid
binder 드라이버가 caller의 uid와 pid를 넣어줌
callee가 알아서 Security Model을 결정
Service Manager
  • System이 외에는 모두 무시

  • Transaction GUID
누구에게 return을 해야 하는지 알려줌
Android Binder에는 없음

Standard Parcel
Android의 대부분에서 사용되어 지는 Parcel
BC_TRANSACTION
  • Interface의 이름 -> String16 : full name이 들어가기 때문에 overhead를 예상
  • Input Parameters
BC_REPLY
  • Return Value
  • Output Parameters

Object Reference Management

트랙백 주소 :: http://www.mirwing.com/177/trackback/
옵션
댓글 달기