I wrote codes below and included asm/ptrace.h, compiled codes with GCC in linux, the compiler told
‘struct pt_regs’ has no member named ‘ARM_sp’
What can I do to solve this problem?
#include <asm/ptrace.h>
extern struct pt_regs saved_regs;
//...
uint32_t * inject_so_of(pid_t pid,const char *so_path)
{
struct pt_regs regs;
memcpy(®s,&saved_regs,sizeof(regs));
ptrace_readdata(pid,(void *)regs.ARM_sp,(void *)sbuf, sizeof(sbuf));
ptrace_writedata(pid,(void *)regs.ARM_sp,(void *)so_path,strlen(so_path));
uint32_t parameters[2];
parameters[0] = regs.ARM_sp;
parameters[1] = RTLD_NOW;
if(ptrace_call(pid,find_dlopen_addr(pid),parameters,2,®s) == -1)
{
DPRINTF("dlopen_error");
}
ptrace_getregs(pid,®s);
uint32_t r0 = regs.ARM_r0;
DPRINTF("[+2]\t");
ptrace_setregs(pid,&saved_regs);
ptrace_writedata(pid,(uint8_t *)saved_regs.ARM_sp,(uint8_t *) sbuf,sizeof(sbuf));
ptrace_detach(pid);
return (uint32_t *) r0;
}
//...
The definition of pt_regs in asm/ptrace.h is:
struct pt_regs
{
long uregs[18];
};
#define ARM_cpsr uregs[16]
#define ARM_pc uregs[15]
#define ARM_lr uregs[14]
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ARM_sp uregs[13]
#define ARM_ip uregs[12]
#define ARM_fp uregs[11]
#define ARM_r10 uregs[10]
I am getting the following errors:
AndroidInjectSo.c:149:38: error: ‘struct pt_regs’ has no member named ‘ARM_sp’
ptrace_writedata(pid,(void *)regs.ARM_sp,(void *)so_path,strlen(so_path));
^
AndroidInjectSo.c:151:25: error: ‘struct pt_regs’ has no member named ‘ARM_sp’
parameters[0] = regs.ARM_sp;
^
AndroidInjectSo.c:158:23: error: ‘struct pt_regs’ has no member named ‘ARM_r0’
uint32_t r0 = regs.ARM_r0;
^
AndroidInjectSo.c:161:47: error: ‘struct pt_regs’ has no member named ‘ARM_sp’
ptrace_writedata(pid,(uint8_t *)saved_regs.ARM_sp,(uint8_t *) sbuf,sizeof(sbuf));
Related
I like to know what is HISTOGRAMS in EBPF.
So for example below ebpf program creates histogram
Compiling it cause warning then bunch of errors udp.c:7:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int] BPF_HISTOGRAM(counter, u64);
SO in this tutorial about XDP it tells to create histogram I need to do BPF_HISTOGRAM(counter, u64); so where BPF_HISTOGRAM is #defined. Also what needed to be a type specifier in above waring so if I am doing BPF_HISTOGRAM(counter, u64); so I am assuming it wil be expended to something like u64 counter so if thats the case there here u go I have type specifier than what else is it complaining about in clang command root#fawad:/home/fawad/bpf# clang -I /usr/include/x86_64-linux-gnu/ -O2 -Wall -target bpf -c udp.c -o udp.o
How how to get rid of these errors and a warning if I try to compile with above command
Errors like : IPPROTO_UDP not found
use of undeclared u64
use of undeclared counter,(if I am assuming right in above question text why this warning and error about counter and histogram)
So I have this simple code
#define KBUILD_MODNAME "udp_counter"
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
#include <linux/udp.h>
BPF_HISTOGRAM(counter, u64);
int udp_counter(struct xdp_md *ctx)
{
void *data = (void *)(long)ctx->data;
void *data_end = (void *)(long)ctx->data_end;
struct ethhdr *eth = data;
if ((void *)eth + sizeof(*eth) <= data_end)
{
struct iphdr *ip = data + sizeof(*eth);
if ((void *)ip + sizeof(*ip) <= data_end)
{
if (ip->protocol == IPPROTO_UDP)
{
struct udphdr *udp = (void *)ip + sizeof(*ip);
if ((void *)udp + sizeof(*udp) <= data_end)
{
u64 value = htons(udp->dest);
counter.increment(value);
}
}
}
}
return XDP_PASS;
}
Throws error
udp.c:7:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
BPF_HISTOGRAM(counter, u64);
^
udp.c:7:15: error: a parameter list without types is only allowed in a function definition
BPF_HISTOGRAM(counter, u64);
^
udp.c:22:33: error: use of undeclared identifier 'IPPROTO_UDP'
if (ip->protocol == IPPROTO_UDP)
^
udp.c:28:21: error: use of undeclared identifier 'u64'
u64 value = htons(udp->dest);
^
udp.c:29:21: error: use of undeclared identifier 'counter'
counter.increment(value);
^
udp.c:29:39: error: use of undeclared identifier 'value'
counter.increment(value);
^
1 warning and 5 errors generated.
root#fawad:/home/fawad/bpf# gedit udp.c
(gedit:7386): Gtk-WARNING **: 13:24:34.572
https://dev.to/satrobit/absolute-beginner-s-guide-to-bcc-xdp-and-ebpf-47oi
I have two files(average.h, average.c). In the definition of a structure i have used #ifdef INTERNAL .
#ifndef AVERAGE_H_
#define AVERAGE_H_
typedef struct str_internal {
int i1;
int i2;
} internal;
typedef struct str_speed {
int lowest;
int highest;
#ifdef INTERNAL
internal i;
#endif
} speed;
extern double average(speed twoStroke);
#endif /* AVERAGE_H_ */
The contents of average.c are,
#include <stdio.h>
#include "average.h"
double average(speed twoStroke) {
double average = (twoStroke.highest + twoStroke.lowest) / 2.0;
#ifdef INTERNAL
average += twoStroke.internal.i1+twoStroke.internal.i2;
#endif
return average;
}
int main() {
speed twoStrokeEngine;
twoStrokeEngine.highest = 70;
twoStrokeEngine.lowest = 50;
#ifdef INTERNAL
twoStrokeEngine.internal.i1=20;
twoStrokeEngine.internal.i2=10;
#endif
double avg = average(twoStrokeEngine);
printf("Average speed of two stroke engine is: %f", avg);
return 0;
}
When i try to compile this code,
gcc -DINTERNAL -o average.exe average.c
i am getting the following error messages.
average.c:8:22: error: ‘speed {aka struct str_speed}’ has no member named ‘internal’
average += twoStroke.internal.i1+twoStroke.internal.i2;
^
average.c:8:44: error: ‘speed {aka struct str_speed}’ has no member named ‘internal’
average += twoStroke.internal.i1+twoStroke.internal.i2;
^
average.c: In function ‘main’:
average.c:20:17: error: ‘speed {aka struct str_speed}’ has no member named ‘internal’
twoStrokeEngine.internal.i1=20;
^
average.c:21:17: error: ‘speed {aka struct str_speed}’ has no member named ‘internal’
twoStrokeEngine.internal.i2=10;
The problem is with
twoStroke.internal.i1+twoStroke.internal.i2;
^^^ ^^^^
internal is a type, not a member that you can access. You need to access the member variables. The member variable, which is of type internal is i, so your statements should look something like
twoStroke.i.i1+twoStroke.i.i2;
Typo:
twoStrokeEngine.internal.i1=20;
ought to be
twoStrokeEngine.i.i1=20;
and so on. i is the member, not internal. The latter is the typedef for the struct.
I have this function:
void simul(char *new)
{
segment_table seg = malloc(sizeof(st));
segcode newcode = malloc(sizeof(sc));
int clen = 0;
seg -> segname = new;
clen = code_length(seg -> segname);
seg -> code = read_hexcode(seg -> segname, newcode, clen);
load_image(seg, clen-3);
if (strstr(new, "paper_boot-strap loader.hexcode") == NULL)
run(segment_offset(seg));
}
When I try to compile my program I get the following errors:
error: ‘st’ undeclared (first use in this function)
error: ‘sc’ undeclared (first use in this function)
error: invalid type argument of ‘->’ (have ‘segment_table’)
error: invalid type argument of ‘->’ (have ‘segment_table’)
error: invalid type argument of ‘->’ (have ‘segment_table’)
error: invalid type argument of ‘->’ (have ‘segment_table’)
What is it that I am doing wrong?
Header file, for example header.h:
// First an include guard (https://en.wikipedia.org/wiki/Include_guard)
#ifndef HEADER_
#define HEADER_
// Define the structures and their type-aliases
typedef struct st { ... } st;
typedef struct sc { ... } sc;
// Declare a couple of other type-aliases
// (Note that I personally recommend against declaring pointer type-aliases)
// (I personally recommend against using type-aliases for simple types
// like the above structures too)
typedef st *segment_table;
typedef sc *segcode;
// Declare a function prototype
void simul(char *new);
#endif // HEADER_
One source file
#include "header.h"
void simul(char *new)
{
...
}
Second source file
#include "header.h"
int main(void)
{
sumul("some string");
}
I want to pass a string > 1024 chars to my module (filesystem).
As kernel parameters are limited to 1024 chars, someone recommended to use sysfs instead.
I tried to include this example in my super.c class to create a string 'filename' & string 'code' entry in sysfs for my module.
static decl_subsys(myfs, NULL, NULL);
struct myfs_attr {
struct attribute attr;
char *value;
};
static struct myfs_attr fname = {
.attr.name="filename",
.attr.owner = THIS_MODULE,
.attr.mode = 0644,
.value = "/my/test/path",
};
static struct myfs_attr code = {
.attr.name="code",
.attr.owner = THIS_MODULE,
.attr.mode = 0644,
.value = "0101",
};
When compiling my module I get a lot of errors (line 41 is decl_subsys):
fs/myfs/super.c:41:26: error: expected ‘)’ before ‘(’ token
fs/myfs/super.c:50:2: error: unknown field ‘owner’ specified in initializer
fs/myfs/super.c:50:2: warning: initialization from incompatible pointer type [enabled by default]
fs/myfs/super.c:50:2: warning: (near initialization for ‘fname.attr.name’) [enabled by default]
...
fs/myfs/super.c: At top level:
fs/myfs/super.c:83:15: error: variable ‘myfsops’ has initializer but incomplete type
fs/myfs/super.c:84:2: error: unknown field ‘show’ specified in initializer
fs/myfs/super.c:84:2: warning: excess elements in struct initializer [enabled by default]
fs/myfs/super.c:84:2: warning: (near initialization for ‘myfsops’) [enabled by default]
fs/myfs/super.c:85:2: error: unknown field ‘store’ specified in initializer
fs/myfs/super.c:85:2: warning: excess elements in struct initializer [enabled by default]
fs/myfs/super.c:85:2: warning: (near initialization for ‘myfsops’) [enabled by default]
fs/myfs/super.c:89:2: error: unknown field ‘myfs_ops’ specified in initializer
fs/myfs/super.c:89:2: warning: initialization from incompatible pointer type [enabled by default]
fs/myfs/super.c:89:2: warning: (near initialization for ‘myfstype.release’) [enabled by default]
fs/myfs/super.c: In function ‘init_myfs_fs’:
fs/myfs/super.c:1554:2: error: implicit declaration of function ‘kobj_set_kset_s’ [-Werror=implicit-function-declaration]
fs/myfs/super.c:1554:19: error: ‘myfs_subsys’ undeclared (first use in this function)
fs/myfs/super.c:1554:19: note: each undeclared identifier is reported only once for each function it appears in
fs/myfs/super.c:1554:32: error: ‘fs_subsys’ undeclared (first use in this function)
fs/myfs/super.c:1557:2: error: implicit declaration of function ‘subsystem_register’ [-Werror=implicit-function-declaration]
fs/myfs/super.c: In function ‘exit_myfs_fs’:
fs/myfs/super.c:1579:2: error: implicit declaration of function ‘subsystem_unregister’ [-Werror=implicit-function-declaration]
fs/myfs/super.c:1579:24: error: ‘myfs_subsys’ undeclared (first use in this function)
Is this tutorial just outdated for my 3.5 kernel or am I missing something else?
How could I create 2 char string entries for my module in sysfs?
Here is the source code for transmitting data to a "param_buf" string. As requested, without read method. Only store.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <asm/string.h>
static struct kobject *register_kobj;
static char *param_buf;
// function for many symbol data enter
static ssize_t __used store_value(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count){
printk(KERN_ALERT "you entered %s\n", buf);
strncpy(param_buf, buf, PAGE_SIZE - 1);
return count;
}
// register function to attribute
static struct kobj_attribute store_val_attribute = __ATTR( put_parameters, 0220, NULL, store_value);
// put attribute to attribute group
static struct attribute *register_attrs[] = {
&store_val_attribute.attr,
NULL, /* NULL terminate the list*/
};
static struct attribute_group reg_attr_group = {
.attrs = register_attrs
};
static int hello_init(void){
param_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
// create sysfs object ( /sys/kernel/test_1025_sym directory )
register_kobj = kobject_create_and_add("test_1025_sym", kernel_kobj);
if (!register_kobj)
return -ENOMEM;
//create attributes (files)
if(sysfs_create_group(register_kobj, ®_attr_group)){
kobject_put(register_kobj);
return -ENOMEM;
}
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "last value was %s\n", param_buf);
kfree(param_buf);
kobject_put(register_kobj);
}
MODULE_LICENSE("Dual BSD/GPL");
module_init(hello_init);
module_exit(hello_exit);
You can test it in such a way:
cat /etc/fstab > /sys/kernel/test_1025_sym/put_parameters
For two string entries: copy a store_value function, register one more store_val_attribute and put it to attributes list.
I'm trying to compile a video driver on Ubuntu 10.04 LTS, here's the error:
**************************************************************************
* Building Techwell TW686x driver... *
* Type "make help" for a list of available targets. *
**************************************************************************
make -C /lib/modules/`uname -r`/build M="/home/v4/driver-686x-0.1.1" clean
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-43-generic'
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-43-generic'
make -C /lib/modules/`uname -r`/build M="/home/v4/driver-686x-0.1.1" modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-43-generic'
CC [M] /home/v4/driver-686x-0.1.1/tw686x-core.o
CC [M] /home/v4/driver-686x-0.1.1/tw686x-video.o
CC [M] /home/v4/driver-686x-0.1.1/tw686x-i2c.o
CC [M] /home/v4/driver-686x-0.1.1/tw686x-device.o
CC [M] /home/v4/driver-686x-0.1.1/i2c-sw.o
CC [M] /home/v4/driver-686x-0.1.1/tw686x-alsa.o
CC [M] /home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.o
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:341: warning: initialization from incompatible pointer type
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:343: warning: initialization from incompatible pointer type
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: error: unknown field ‘vaddr’ specified in initializer
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: warning: excess elements in struct initializer
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: warning: (near initialization for ‘qops’)
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c: In function ‘videobuf_queue_dma_contig_init_tw’:
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:357: warning: passing argument 2 of ‘videobuf_queue_core_init’ discards qualifiers from pointer target type
include/media/videobuf-core.h:197: note: expected ‘struct videobuf_queue_ops *’ but argument is of type ‘const struct videobuf_queue_ops *’
make[2]: *** [/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.o] Error 1
make[1]: *** [_module_/home/v4/driver-686x-0.1.1] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-43-generic'
make: *** [modules] Error 2
My kernel is 2.6.32-43. My C is very rusty, so I'm asking the gurus.
From what I can see, the problem refers to variable videobuf_queue_ops in file videobuf-core.h, which i found in these locations:
/usr/src/linux-headers-2.6.24-24/include/media/videobuf-core.h
/usr/src/linux-headers-2.6.32-43/include/media/videobuf-core.h
/usr/src/linux-headers-2.6.24-32/include/media/videobuf-core.h
Here's the offending file (extract) videobuf-dma-contig-tw.c:
static struct videobuf_qtype_ops qops = {
.magic = MAGIC_QTYPE_OPS,
.alloc = __videobuf_alloc,
.iolock = __videobuf_iolock,
.mmap_mapper = __videobuf_mmap_mapper,
.vaddr = __videobuf_to_vaddr,
};
The definition of videobuf_qtype_ops in the header file looks like this :
struct videobuf_queue_ops {
int (*buf_setup)(struct videobuf_queue *q,
unsigned int *count, unsigned int *size);
int (*buf_prepare)(struct videobuf_queue *q,
struct videobuf_buffer *vb,
enum v4l2_field field);
void (*buf_queue)(struct videobuf_queue *q,
struct videobuf_buffer *vb);
void (*buf_release)(struct videobuf_queue *q,
struct videobuf_buffer *vb);
};
#define MAGIC_QTYPE_OPS 0x12261003
/* Helper operations - device type dependent */
struct videobuf_qtype_ops {
u32 magic;
void *(*alloc) (size_t size);
void *(*vmalloc) (struct videobuf_buffer *buf);
int (*iolock) (struct videobuf_queue* q,
struct videobuf_buffer *vb,
struct v4l2_framebuffer *fbuf);
int (*mmap) (struct videobuf_queue *q,
unsigned int *count,
unsigned int *size,
enum v4l2_memory memory);
int (*sync) (struct videobuf_queue* q,
struct videobuf_buffer *buf);
int (*video_copy_to_user)(struct videobuf_queue *q,
char __user *data,
size_t count,
int nonblocking);
int (*copy_stream) (struct videobuf_queue *q,
char __user *data,
size_t count,
size_t pos,
int vbihack,
int nonblocking);
int (*mmap_free) (struct videobuf_queue *q);
int (*mmap_mapper) (struct videobuf_queue *q,
struct vm_area_struct *vma);
};
Should I change this header file? I'm not sure what the fix is, or whether I should even be changing Linux files - scary stuff!
Thanks for your help.
This part alone
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:343: warning: initialization from incompatible pointer type
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: error: unknown field ‘vaddr’ specified in initializer
/home/v4/driver-686x-0.1.1/videobuf-dma-contig-tw.c:344: warning: excess elements in struct initializer
tells us that the initializer and the struct are using different types, different field names, and different number of elements.
Definitely not the correct include file. :-)
You will have to figure out what version you should use, and make sure that one is in the include path (and not the others).
For some reason the compiler doesn't like this part:
static struct videobuf_qtype_ops qops = {
.magic = MAGIC_QTYPE_OPS,
.alloc = __videobuf_alloc,
.iolock = __videobuf_iolock,
.mmap_mapper = __videobuf_mmap_mapper,
.vaddr = __videobuf_to_vaddr,
};
The compiler told you the line number where the error had occurred:
videobuf-dma-contig-tw.c:344: error: unknown field ‘vaddr’ specified in initializer
Now the question is why there isn't a vaddr member in struct videobuf_qtype_ops. It could be under #if, but I don't know for sure. struct videobuf_qtype_ops isn't defined in this file.
You should've looked at this yourself. Posting lots of irrelevant code isn't a good use of people's time.