Skip to content

Instantly share code, notes, and snippets.

@nickdesaulniers
Created January 26, 2022 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdesaulniers/c2c37edcdbaf3a2deb914d2ea8011a96 to your computer and use it in GitHub Desktop.
Save nickdesaulniers/c2c37edcdbaf3a2deb914d2ea8011a96 to your computer and use it in GitHub Desktop.
typedef unsigned short __u16;
typedef __u16 u16;
enum { false, true };
typedef _Bool bool;
typedef struct qspinlock {
struct {
struct {
u16 tail;
};
};
} arch_spinlock_t;
typedef struct raw_spinlock {
arch_spinlock_t raw_lock;
} raw_spinlock_t;
typedef struct spinlock {
struct {
struct raw_spinlock rlock;
};
} spinlock_t;
struct bug_entry {};
void __attribute__(())
_raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags);
static inline __attribute__(()) __attribute__(()) __attribute__(())
__attribute__(()) void
spin_unlock_irqrestore(spinlock_t *lock)
{
do
_raw_spin_unlock_irqrestore(&lock->rlock, 0);
while (0);
}
struct wait_queue_head {
spinlock_t lock;
};
typedef struct wait_queue_head wait_queue_head_t;
typedef struct refcount_struct {
} refcount_t;
struct kref {
refcount_t refcount;
};
static inline __attribute__(()) __attribute__(()) __attribute__(()) int
kref_put(struct kref *kref, void (*release)())
{
if (refcount_dec_and_test(&kref->refcount))
release(kref);
}
enum media_request_state {
MEDIA_REQUEST_STATE_QUEUED,
};
struct media_request {
struct media_device *mdev;
struct kref kref;
enum media_request_state state;
unsigned int num_incomplete_objects;
wait_queue_head_t poll_wait;
spinlock_t lock;
};
struct media_request_object {
struct media_request req;
};
extern void media_request_release();
struct media_request_object *media_request_object_complete_obj;
void media_request_object_complete(void)
{
struct media_request *req = &media_request_object_complete_obj->req;
bool completed = false;
if (({
int __ret_warn_on = !!(!req->num_incomplete_objects);
if (__builtin_expect(!!(__ret_warn_on), 0))
do {
asm(".byte 0x0f, 0x0b");
asm(".Lreachable%=:\n\t"
".pushsection .discard.reachable\n\t"
".long .Lreachable%= - .\n\t"
".popsection\n\t" ::
: "memory");
} while (0);
__builtin_expect(!!(__ret_warn_on), 0);
}) ||
({
int __ret_warn_on =
!!(req->state != MEDIA_REQUEST_STATE_QUEUED);
if (__builtin_expect(!!(__ret_warn_on), 0))
do {
asm(".byte 0x0f, 0x0b" ::"i"(
sizeof(struct bug_entry)));
asm(".Lreachable%=:\n\t"
".pushsection .discard.reachable\n\t"
".long .Lreachable%= - .\n\t"
".popsection\n\t" ::
: "memory");
} while (0);
__builtin_expect(!!(__ret_warn_on), 0);
}))
goto unlock;
if (!--req->num_incomplete_objects) {
__wake_up(&req->poll_wait, 0x0001, 0, 0);
completed = true;
}
unlock:
spin_unlock_irqrestore(&req->lock);
if (completed)
kref_put(&req->kref, media_request_release);
}
.file "mc-request.i"
.text
.p2align 4
.globl media_request_object_complete
.type media_request_object_complete, @function
media_request_object_complete:
.LFB2:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
pushq %rbx
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
subq $8, %rsp
.cfi_def_cfa_offset 32
movq media_request_object_complete_obj(%rip), %rbx
movl 12(%rbx), %eax
leaq 18(%rbx), %rbp
testl %eax, %eax
je .L16
movl 8(%rbx), %edx
testl %edx, %edx
jne .L17
subl $1, %eax
movl %eax, 12(%rbx)
je .L18
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
movq %rbp, %rdi
xorl %esi, %esi
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
jmp _raw_spin_unlock_irqrestore
.p2align 4,,10
.p2align 3
.L18:
.cfi_restore_state
xorl %ecx, %ecx
xorl %edx, %edx
leaq 16(%rbx), %rdi
movl $1, %esi
xorl %eax, %eax
call __wake_up
movq %rbp, %rdi
xorl %esi, %esi
leaq 8(%rbx), %rbp
call _raw_spin_unlock_irqrestore
xorl %eax, %eax
movq %rbp, %rdi
call refcount_dec_and_test
testl %eax, %eax
je .L19
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
movq %rbp, %rdi
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
jmp media_request_release
.p2align 4,,10
.p2align 3
.L19:
.cfi_restore_state
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L16:
.cfi_restore_state
#APP
# 72 "mc-request.i" 1
.byte 0x0f, 0x0b
# 0 "" 2
#NO_APP
.L13:
#APP
# 88 "mc-request.i" 1
.Lreachable90:
.pushsection .discard.reachable
.long .Lreachable90 - .
.popsection
# 0 "" 2
#NO_APP
addq $8, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 24
movq %rbp, %rdi
xorl %esi, %esi
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
jmp _raw_spin_unlock_irqrestore
.p2align 4,,10
.p2align 3
.L17:
.cfi_restore_state
#APP
# 86 "mc-request.i" 1
.byte 0x0f, 0x0b
# 0 "" 2
#NO_APP
jmp .L13
.cfi_endproc
.LFE2:
.size media_request_object_complete, .-media_request_object_complete
.globl media_request_object_complete_obj
.bss
.align 8
.type media_request_object_complete_obj, @object
.size media_request_object_complete_obj, 8
media_request_object_complete_obj:
.zero 8
.ident "GCC: (Debian 11.2.0-12) 11.2.0"
.section .note.GNU-stack,"",@progbits
gcc -fno-PIE -O2 -c -o mc-request.o mc-request.i -w
tools/objtool/objtool orc generate --module --no-fp --retpoline --uaccess mc-request.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment