I tried to add tidy-html5 library in my projects. To start I just create a file named "clean.c" with only two includes :
#include <tidy.h>
#include <tidybuffio.h>
I used libtidys.a file and I copied it into libs directory in my project.
So I compiled the file that way :
$ gcc -ansi -pedantic -std=c99 -c -W -Wall -O -I/foo/bar/inc -I/usr/include/libxml2 -I/foo/bar/dependencies/tidy-html5/include -L/foo/bar/libs -ltidys clean.c -o clean.o
And here is the results :
In file included from /foo/bar/dependencies/tidy-html5/include/tidy.h:65:0,
from clean.c:1:
/foo/bar/dependencies/tidy-html5/include/tidyplatform.h:547:9: error: unknown type name 'uint'
typedef uint tchar; /* single, full character */
^
In file included from clean.c:1:0:
/foo/bar/dependencies/tidy-html5/include/tidy.h:368:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyErrorCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:371:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyWarningCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:374:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyAccessWarningCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:377:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyConfigErrorCount( TidyDoc tdoc );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:469:13: error: unknown type name 'ulong'
TIDY_EXPORT ulong TIDY_CALL tidyOptGetDefaultInt( TidyOption opt );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:487:13: error: unknown type name 'ulong'
TIDY_EXPORT ulong TIDY_CALL tidyOptGetInt( TidyDoc tdoc, TidyOptionId optId );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:489:86: error: unknown type name 'ulong'
TIDY_EXPORT Bool TIDY_CALL tidyOptSetInt( TidyDoc tdoc, TidyOptionId optId, ulong val );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:594:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyGetByte( TidyInputSource* source );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:597:68: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyUngetByte( TidyInputSource* source, uint byteValue );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:631:63: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyPutByte( TidyOutputSink* sink, uint byteValue );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:643:44: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:643:55: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:646:44: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:646:55: error: unknown type name 'uint'
uint line, uint col, ctmbstr mssg, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:649:49: error: unknown type name 'uint'
uint line, uint col, ctmbstr code, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:649:60: error: unknown type name 'uint'
uint line, uint col, ctmbstr code, va_list args );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:653:51: error: unknown type name 'TidyReportFilter'
TidyReportFilter filtCallback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:656:51: error: unknown type name 'TidyReportFilter2'
TidyReportFilter2 filtCallback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:659:56: error: unknown type name 'TidyReportFilter3'
TidyReportFilter3 filtCallback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:675:57: error: unknown type name 'uint'
typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:675:68: error: unknown type name 'uint'
typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:675:78: error: unknown type name 'uint'
typedef void (TIDY_CALL *TidyPPProgress)( TidyDoc tdoc, uint line, uint col, uint destLine );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:678:51: error: unknown type name 'TidyPPProgress'
TidyPPProgress callback );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:756:65: error: unknown type name 'uint'
tmbstr buffer, uint* buflen );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:908:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyNodeLine( TidyNode tnod );
^
/foo/bar/dependencies/tidy-html5/include/tidy.h:909:13: error: unknown type name 'uint'
TIDY_EXPORT uint TIDY_CALL tidyNodeColumn( TidyNode tnod );
^
In file included from clean.c:2:0:
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:27:5: error: unknown type name 'uint'
uint size; /**< # bytes currently in use */
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:28:5: error: unknown type name 'uint'
uint allocated; /**< # bytes allocated */
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:29:5: error: unknown type name 'uint'
uint next; /**< Offset of current input position */
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:40:59: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyBufAlloc( TidyBuffer* buf, uint allocSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:46:55: error: unknown type name 'uint'
uint allocSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:52:47: error: unknown type name 'uint'
uint allocSize, uint chunkSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:52:63: error: unknown type name 'uint'
uint allocSize, uint chunkSize );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:61:70: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyBufAttach( TidyBuffer* buf, byte* bp, uint size );
^
/foo/bar/dependencies/tidy-html5/include/tidybuffio.h:68:70: error: unknown type name 'uint'
TIDY_EXPORT void TIDY_CALL tidyBufAppend( TidyBuffer* buf, void* vp, uint size );
^
Makefile:16: recipe for target 'clean.o' failed
make[1]: *** [clean.o] Error 1
Makefile:26: recipe for target 'all' failed
make: *** [all] Error 1
So I've made a quick check and I noticed tidy.h file include "tidyplatform.h" which contains that :
#if defined(BE_OS) || defined(SOLARIS_OS) || defined(BSD_BASED_OS) || defined(OSF_OS) || defined(IRIX_OS) || defined(AIX_OS)
#include <sys/types.h>
#endif
#if !defined(HPUX_OS) && !defined(CYGWIN_OS) && !defined(MAC_OS_X) && !defined(BE_OS) && !defined(SOLARIS_OS) && !defined(BSD_BASED_OS) && !defined(OSF_OS) && !defined(IRIX_OS) && !defined(AIX_OS) && !defined(LINUX_OS)
# undef uint
typedef unsigned int uint;
#endif
#if defined(HPUX_OS) || defined(CYGWIN_OS) || defined(MAC_OS) || defined(BSD_BASED_OS) || defined(_WIN32)
# undef ulong
typedef unsigned long ulong;
#endif
I'm on GNU/Linux. So I think I can fix that by adding "defined(LINUX_OS)" in the first preprocessor instructions (I didn't try). But, thats strange because this library is heavily used so...did I miss something ?
Cheers
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've got this error always when i'm using the below code ,
so please could anyone tell me where is my mistake??
the code is:
#ifndef OSAPI_H
#define OSAPI_H
void sdk_os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg);
void sdk_os_timer_arm(ETSTimer *ptimer, uint32_t milliseconds, bool repeat_flag);
void sdk_os_timer_disarm(ETSTimer *ptimer);
#endif
errors i've got:
1- :4:25: error: unknown type name 'ETSTimer' 2- :4:43: error: unknown
type name 'ETSTimerFunc' 3- :5:23: error: unknown type name 'ETSTimer'
4- :6:26: error: unknown type name 'ETSTimer'
thanks for everyone for the help
I am trying to call a function that is declared as a function ptr I believe? Compiler Gives error: expected ‘)’ before ‘,’ token
static void map_start(struct map_reduce *mr){
map_fn(mr, mr->infile, mr->id , mr->threadNum);
}
static void reduce_start(struct map_reduce *mr){
reduce_fn(mr, mr->outfile,(mr->threadNum));
}
//map_fn and reduce_fn is defined as these
typedef int (*map_fn)(struct map_reduce *mr, int infd, int id, int nmaps);
typedef int (*reduce_fn)(struct map_reduce *mr, int outfd, int nmaps);
errors are:
mapreduce.c: In function ‘map_start’:
mapreduce.c:87: error: expected ‘)’ before ‘,’ token
mapreduce.c: In function ‘reduce_start’:
mapreduce.c:92: error: expected ‘)’ before ‘,’ token
make: *** [mapreduce.o] Error 1
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));
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.