[Linux Kernel Exploit] C언어 배경지식..?

dandb3·2024년 4월 23일
0

linux kernel

목록 보기
2/21

__attribute__((packed))

구조체를 정의할 시 바이트 패딩을 통해서 구조체의 크기가 실제 구조체 멤버변수들의 크기의 합 보다 더 커지는 경우가 있다.

하지만 __attribute__((packed))를 선언하면 패딩 바이트가 없이 오직 멤버변수들로만 메모리가 구성된다.

예제 코드를 통해 보자.

#include <stdio.h>

struct s1
{
	unsigned long long a;
	char b;
	unsigned long long c;
};

struct s2
{
	unsigned long long a;
	char b;
	unsigned long long c;
} __attribute__((packed));

int main()
{
	printf(	"size of packed structure: %lu\n"	\
			"size of unpacked structure: %lu\n",	\
			sizeof(struct s2), sizeof(struct s1));
	return 0;
}

내부 구조는 동일한 struct s1, struct s2가 있다.
struct s2의 경우에만 __attribute__((packed))를 붙여주었다.

출력 결과는 다음과 같다.

넘어갑시다.

__attribute__((regparm(n)))

unsigned long __attribute__((regparm(3))) (*commit_creds)(unsigned long cred);

cdecl 함수 호출 규약에서는 함수의 인자를 넘길 때 stack을 이용해서 넘기게 된다.
하지만 regparm(n) 을 선언하면 n개의 인자를 넘길 때 만큼은 stack이 아닌, 레지스터를 통해서 넘기게 된다.

profile
공부 내용 저장소

0개의 댓글

관련 채용 정보