1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2020, Oracle and/or its affiliates. 3 4 #include "vmlinux.h" 5 #include <bpf/bpf_helpers.h> 6 #include <bpf/bpf_tracing.h> 7 #include "bpf_misc.h" 8 9 char _license[] SEC("license") = "GPL"; 10 11 int trace_printk_ret = 0; 12 int trace_printk_ran = 0; 13 int trace_printk_invalid_spec_ret = 0; 14 int trace_printk_utf8_ret = 0; 15 int trace_printk_utf8_ran = 0; 16 17 const char fmt[] = "Testing,testing %d\n"; 18 static const char utf8_fmt[] = "中文,测试 %d\n"; 19 /* Non-ASCII bytes after '%' must still be rejected. */ 20 static const char invalid_spec_fmt[] = "%\x80\n"; 21 22 SEC("fentry/" SYS_PREFIX "sys_nanosleep") 23 int sys_enter(void *ctx) 24 { 25 trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt), 26 ++trace_printk_ran); 27 trace_printk_utf8_ret = bpf_trace_printk(utf8_fmt, sizeof(utf8_fmt), 28 ++trace_printk_utf8_ran); 29 trace_printk_invalid_spec_ret = bpf_trace_printk(invalid_spec_fmt, 30 sizeof(invalid_spec_fmt)); 31 return 0; 32 } 33