Skip to content

Commit

Permalink
FIXME: Workarounds for __builtin_return_address and _THIS_IP_
Browse files Browse the repository at this point in the history
  • Loading branch information
okuoku committed Oct 10, 2023
1 parent a2d87b5 commit 0cb256b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/xfs/xfs_buf.h
Expand Up @@ -247,8 +247,13 @@ xfs_buf_read(
{
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);

#ifndef __wasm__
return xfs_buf_read_map(target, &map, 1, flags, bpp, ops,
__builtin_return_address(0));
#else
return xfs_buf_read_map(target, &map, 1, flags, bpp, ops,
(void*)0xdeadcafe);
#endif
}

static inline void
Expand Down
8 changes: 8 additions & 0 deletions fs/xfs/xfs_linux.h
Expand Up @@ -123,14 +123,22 @@ typedef __u32 xfs_nlink_t;
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
#define EFSBADCRC EBADMSG /* Bad CRC detected */

#ifndef __wasm__
#define __return_address __builtin_return_address(0)
#else
#define __return_address (void*)0xdeadcafe
#endif

/*
* Return the address of a label. Use barrier() so that the optimizer
* won't reorder code to refactor the error jumpouts into a single
* return, which throws off the reported address.
*/
#ifndef __wasm__
#define __this_address ({ __label__ __here; __here: barrier(); &&__here; })
#else
#define __this_address (void*)0xdeadcafe
#endif

#define XFS_PROJID_DEFAULT 0

Expand Down
9 changes: 9 additions & 0 deletions include/linux/instruction_pointer.h
Expand Up @@ -2,7 +2,16 @@
#ifndef _LINUX_INSTRUCTION_POINTER_H
#define _LINUX_INSTRUCTION_POINTER_H

#ifndef __wasm__
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
#else
#define _RET_IP_ (unsigned long)0xdeadcafe
#endif

#ifndef __wasm__
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
#else
#define _THIS_IP_ (unsigned long)0xdeadcafe
#endif

#endif /* _LINUX_INSTRUCTION_POINTER_H */
14 changes: 14 additions & 0 deletions kernel/panic.c
Expand Up @@ -641,14 +641,23 @@ void warn_slowpath_fmt(const char *file, int line, unsigned taint,
pr_warn(CUT_HERE);

if (!fmt) {
#ifndef __wasm__
__warn(file, line, __builtin_return_address(0), taint,
NULL, NULL);
#else
__warn(file, line, (void*)0xdeadcafe, taint,
NULL, NULL);
#endif
return;
}

args.fmt = fmt;
va_start(args.args, fmt);
#ifndef __wasm__
__warn(file, line, __builtin_return_address(0), taint, NULL, &args);
#else
__warn(file, line, (void*)0xdeadcafe, taint, NULL, &args);
#endif
va_end(args.args);
}
EXPORT_SYMBOL(warn_slowpath_fmt);
Expand Down Expand Up @@ -700,8 +709,13 @@ device_initcall(register_warn_debugfs);
__visible noinstr void __stack_chk_fail(void)
{
instrumentation_begin();
#ifndef __wasm__
panic("stack-protector: Kernel stack is corrupted in: %pB",
__builtin_return_address(0));
#else
panic("stack-protector: Kernel stack is corrupted in: %pB",
(void*)0xdeadcafe);
#endif
instrumentation_end();
}
EXPORT_SYMBOL(__stack_chk_fail);
Expand Down
6 changes: 6 additions & 0 deletions mm/util.c
Expand Up @@ -603,9 +603,15 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
* about the resulting pointer, and cannot play
* protection games.
*/
#ifndef __wasm__
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
node, __builtin_return_address(0));
#else
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
flags, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
node, (void*)0xdeadcafe);
#endif
}
EXPORT_SYMBOL(kvmalloc_node);

Expand Down
12 changes: 12 additions & 0 deletions net/core/skbuff.c
Expand Up @@ -887,7 +887,11 @@ kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)

DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);

#ifndef __wasm__
trace_kfree_skb(skb, __builtin_return_address(0), reason);
#else
trace_kfree_skb(skb, (void*)0xdeadcafe, reason);
#endif
__kfree_skb(skb);
}
EXPORT_SYMBOL(kfree_skb_reason);
Expand Down Expand Up @@ -2149,7 +2153,11 @@ void *skb_put(struct sk_buff *skb, unsigned int len)
skb->tail += len;
skb->len += len;
if (unlikely(skb->tail > skb->end))
#ifndef __wasm__
skb_over_panic(skb, len, __builtin_return_address(0));
#else
skb_over_panic(skb, len, (void*)0xdeadcafe);
#endif
return tmp;
}
EXPORT_SYMBOL(skb_put);
Expand All @@ -2168,7 +2176,11 @@ void *skb_push(struct sk_buff *skb, unsigned int len)
skb->data -= len;
skb->len += len;
if (unlikely(skb->data < skb->head))
#ifndef __wasm__
skb_under_panic(skb, len, __builtin_return_address(0));
#else
skb_under_panic(skb, len, (void*)0xdeadcafe);
#endif
return skb->data;
}
EXPORT_SYMBOL(skb_push);
Expand Down
4 changes: 4 additions & 0 deletions tools/include/linux/kernel.h
Expand Up @@ -15,7 +15,11 @@
#define UINT_MAX (~0U)
#endif

#ifndef __wasm__
#define _RET_IP_ ((unsigned long)__builtin_return_address(0))
#else
#define _RET_IP_ ((unsigned long)0xdeadcafe)
#endif

#define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
#define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
Expand Down

0 comments on commit 0cb256b

Please sign in to comment.