Arm Linux Kernel Hacks

rousalome.egloos.com

포토로그 Kernel Crash


통계 위젯 (화이트)

11105
637
415734


질문: current 매크로를 귀찮게(?) 두 번 캐스팅하는 이유 Question_Announcement

질문;

4.10.1절 중에
#define get_current() (current_thread_info()->task)
#define current get_current()
에서 왜 굳이 한줄로 사용할 수 있는 매크로를 두 줄로 정의하는 건가요? 

답신;

current 매크로를 귀찮게(?) 두 번 캐스팅하는 이유는,

#define get_current() (current_thread_info()->task)
#define current get_current()

current_thread_info()의 세부 구현부가 CPU 아키텍처 별로 다르기 때문입니다. 

예를 들어 32비트 기반의 Arm 아키텍처에서 current_thread_info 선언부는 다음과 같은데요.

https://elixir.bootlin.com/linux/v4.19.30/source/arch/arm/include/asm/thread_info.h#L86
static inline struct thread_info *current_thread_info(void) __attribute_const__;

static inline struct thread_info *current_thread_info(void)
{
return (struct thread_info *)
(current_stack_pointer & ~(THREAD_SIZE - 1));
}

64비트 기반의 Arm 아키텍처는 아래와 같습니다.

https://elixir.bootlin.com/linux/v4.19.30/source/include/linux/thread_info.h#L22
#define current_thread_info() ((struct thread_info *)current)

덧글

  • JohnLee 2023/01/23 19:04 # 삭제 답글

    답변감사합니다.
    그럼 첫번째 줄은 아키텍쳐에 맞는 current_thread_info()를 '미리' 캐스팅하는 것이고 (32비트면 32비트의. 64비트면 64비트의)
    두번째 줄이 실제로 가져오는 것일까요?
  • AustinKim 2023/01/26 22:47 #

    네, 맞습니다.
댓글 입력 영역