can't find the definition of __arm64_sys_ppoll function in linux source - linux-kernel

I'm trying to boot a development board containing arm64 core using busybox, u-boot and linux-5.10.0-rc5. The boot process is almost complete but when it enters the shell program, it stops shortly after(with no kernel panic). It doesn't even show the '#' prompt (but with qemu model, the image and busybox works ok with normal shell at the end). I could see that before it stops, there are some system calls from the busybox coming to the kernel, and when it stopped, it was processing system call 73.
(You can follow from arch/arm64/kernel/syscall.c, do_el0_svc () -> el0_svc_common -> invoke_syscall -> __invoke_syscall -> syscall_fn
By examining the files I could see syscall 73 is sys_ppoll. (in include/uapi/asm-generic/unistd.h). I found in include/uapi/asm-generic/unistd.h,
/* fs/select.c */
#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
#define __NR_pselect6 72
__SC_COMP_3264(__NR_pselect6, sys_pselect6_time32, sys_pselect6, compat_sys_pselect6_time32)
#define __NR_ppoll 73
__SC_COMP_3264(__NR_ppoll, sys_ppoll_time32, sys_ppoll, compat_sys_ppoll_time32)
#endif
The definition of __SC_COMP_3264 is at the first lines of the same file. To see what lines are selected and compiled by the #if/#endif macros, I tried adding a characters 'x' to cause compile error and I could see what lines are compiled. That is shown below.
#ifndef __SYSCALL
x <---- compile error, so compiled, and __SYSCALL(x,y) defined to be nothing?
#define __SYSCALL(x, y)
#endif
#if __BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT)
x <--------- no compile error, so not compiled
#define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _32)
#else
#define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _64)
#endif
#ifdef __SYSCALL_COMPAT
x <-------------- no compile error, so not compiled
#define __SC_COMP(_nr, _sys, _comp) __SYSCALL(_nr, _comp)
#define __SC_COMP_3264(_nr, _32, _64, _comp) __SYSCALL(_nr, _comp)
#else
#define __SC_COMP(_nr, _sys, _comp) __SYSCALL(_nr, _sys)
#define __SC_COMP_3264(_nr, _32, _64, _comp) __SC_3264(_nr, _32, _64)
#endif
So this means __SYSCALL(x, y) is defined to be doing nothing. But if that was true, all the other syscall would have done nothing and I figured __SYSCALL was defined previously and found in arch/arm64/kernel/sys.c
#undef __SYSCALL
#define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *);
#include <asm/unistd.h>
So the function definition becomes __arm64_sys_ppoll and I can see it in the System.map file.
But I couldn't find the definition of __arm64_sys_ppoll. Where can I find the source? My another question is, how can below line be compiled and make error when I do make -j28?
#ifndef __SYSCALL
x <---- compile error, so compiled, and __SYSCALL(x,y) defined to be nothing?
#define __SYSCALL(x, y)
#endif
By the way, this is what I see when I grep for sys_ppoll in the source(excluding all non-arm64 arch files).
./include/linux/compat.h:asmlinkage long compat_sys_ppoll_time32(struct pollfd __user *ufds,
./include/linux/compat.h:asmlinkage long compat_sys_ppoll_time64(struct pollfd __user *ufds,
./include/linux/syscalls.h:asmlinkage long sys_ppoll(struct pollfd __user *, unsigned int,
./include/linux/syscalls.h:asmlinkage long sys_ppoll_time32(struct pollfd __user *, unsigned int,
./include/uapi/asm-generic/unistd.h:__SC_COMP_3264(__NR_ppoll, sys_ppoll_time32, sys_ppoll, compat_sys_ppoll_time32)
./include/uapi/asm-generic/unistd.h:__SC_COMP(__NR_ppoll_time64, sys_ppoll, compat_sys_ppoll_time64)
./tools/include/uapi/asm-generic/unistd.h:__SC_COMP_3264(__NR_ppoll, sys_ppoll_time32, sys_ppoll, compat_sys_ppoll_time32)
./tools/include/uapi/asm-generic/unistd.h:__SC_COMP(__NR_ppoll_time64, sys_ppoll, compat_sys_ppoll_time64)
./arch/arm64/include/asm/unistd32.h:__SYSCALL(__NR_ppoll, compat_sys_ppoll_time32)
./arch/arm64/include/asm/unistd32.h:__SYSCALL(__NR_ppoll_time64, compat_sys_ppoll_time64)
Thanks for reading and sorry for the long question.

For SYSCALL_DEFINE0, ..., SYSCALL_DEFINE6, first see #Ian Abbott's comment to my original question.
In file include/uapi/asm-generic/unistd.h, you can see the syscall definitions.
For example if you want to see the source code for shmat, you can use grep to see in the file these lines,
/* ipc/shm.c */
#define __NR_shmget 194
__SYSCALL(__NR_shmget, sys_shmget)
#define __NR_shmctl 195
__SC_COMP(__NR_shmctl, sys_shmctl, compat_sys_shmctl)
#define __NR_shmat 196
__SC_COMP(__NR_shmat, sys_shmat, compat_sys_shmat)
#define __NR_shmdt 197
__SYSCALL(__NR_shmdt, sys_shmdt)
So it says the definition is in file ipc/shm.c. There you can see these lines.
SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)
{
unsigned long ret;
long err;
err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
if (err)
return err;
force_successful_syscall_return();
return (long)ret;
}
You can see the definition of shmat function with argments list.

Related

kernel code native_queued_spin_lock_slowpath function

In the kernel code, I cannot find the definition of the native_queued_spin_lock_slowpath function, __pv_queued_spin_lock_slowpath is the same, where are these functions defined? I searched all the kernel code, but in vain
The definition of native_queued_spin_lock_slowpath is in "kernel/locking/qspinlock.c", using a macro to change the name of queued_spin_lock_slowpath to native_queued_spin_lock_slowpath when CONFIG_PARAVIRT_SPINLOCKS is defined:
#ifdef CONFIG_PARAVIRT_SPINLOCKS
#define queued_spin_lock_slowpath native_queued_spin_lock_slowpath
#endif
…
void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
{
The definition of __pv_queued_spin_lock_slowpath is also in "kernel/locking/qspinlock.c" using the same renaming macro trick with a twist — The "qspinlock.c" file includes itself once more, using a guard macro _GEN_PV_LOCK_SLOWPATH to avoid infinite recursive inclusion:
#if !defined(_GEN_PV_LOCK_SLOWPATH) && defined(CONFIG_PARAVIRT_SPINLOCKS)
#define _GEN_PV_LOCK_SLOWPATH
…
#undef queued_spin_lock_slowpath
#define queued_spin_lock_slowpath __pv_queued_spin_lock_slowpath
#include "qspinlock_paravirt.h"
#include "qspinlock.c"
…
#endif

Warning C4091: ' __declspec(dllexport)'

I have the following code where I am trying to export a function called "Interface_API" out of my dll.
#ifdef INTERFACEDLL_EXPORTS
#define UserApp_API __declspec(dllexport);
#else
#define UserApp_API __declspec(dllimport);
#endif
UserApp_API int Interface_API(int *, int *, int *);
When I compile this code it gives the following warning and the function is not getting exported.
warning C4091: ' __declspec(dllexport)' : ignored on left of 'int' when no variable is declared
When I change the declaration as given below I don't get the warning and it exports properly.
__declspec(dllexport) int Interface_API(int *, int *, int *);
I am little confused because I have used it in different dll and it works fine. Any clue?
#define UserApp_API __declspec(dllimport);
^ Semicolon.

Error while compiling macro __COPYRIGHT with gcc

Here is the simple echo.c source code:
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT(
"#(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "#(#)echo.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: echo.c,v 1.7 1997/07/20 06:07:03 thorpej Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main __P((int, char *[]));
int
main(argc, argv)
int argc;
char *argv[];
{
/*
*main code with no error at all
*/
}
When compiling it with gcc 4.4.6, it report errors:
echo.c:4: error: expected declaration specifiers or â...â before string constant
echo.c:3: warning: data definition has no type or storage class
echo.c:12: error: expected declaration specifiers or â...â before string constant
echo.c:12: warning: data definition has no type or storage class
Line 3 and 4 is __COPYRIGHT macro.
Line 12 is __RCSID macro.
If I delete these two macro, it compiles successfully and runs correctly.
After some googling, I know that these two macros are defined in sys/cdefs.h and they are some kind of comment message.
But why it won't compile in gcc?
Well after going throuhg sys/cdefs.h (ubuntu 11.10), I found no __COPYRIGHT or __RCSID defination.
So I guess these two macros are defined in NetBSD sys/cdefs.h.
I added them in a new header file (I name it with "aeodefs.h") like the following:
#ifndef _AEODEFS_H_
#define _AEODEFS_H_
#include <sys/cdefs.h>
#define __IDSTRING(name,string) \
static const char name[] __attribute__((__unused__)) = string
#ifndef __RCSID
#define __RCSID(s) __IDSTRING(rcsid,s)
#endif
#ifndef __COPYRIGHT
#define __COPYRIGHT(s) __IDSTRING(copyright,s)
#endif
#endif /* !_AEODEFS_H_ */
Then change #include <sys/cdefs.h> to #include "aeodefs.h".
It's done!

bison parser compilation unkonwn errors

I am building a parser but I have some errors that I could not solve them, I am nuw to bison and flex, please help me solve them and understand why they are happening here is my errors that I get:
lexical.l:3:20: error: common.h: No such file or directory
In file included from lexical.l:5:
bison.tab.h:81: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âyylvalâ
bison.tab.c:1155: error: conflicting types for âyylvalâ
bison.tab.h:81: note: previous declaration of âyylvalâ was here
bison.y: In function âyyparseâ:
bison.y:96: error: incompatible types when assigning to type âSTYPEâ from type âNODEPTRâ
here is my parser file bison.y:
%{
#include <stdio.h>
#include "bison.tab.h"
#include "common.h"
//int yylex();
void yyerror (char const *);
typedef struct STYPE {
NODEPTR pointer;
} STYPE;
#define YYSTYPE STYPE
%}
/* Bison declarations. */
%token ELSE REAL INTEGER XWRITE WHILE END DO IF THEN XPROGRAM FUNCTION XRETURN XREAD VAR FOR XBEGIN CALL ID NUM
%token RELOP ADDOP MULOP ASSIGN AND OR NOT
%left '-' '+'
%left '*' '/'
%nonassoc LOWER_THAN_ELSE
%nonassoc ELSE
If you #define YYSTYPE in your bison file, you need to #define YYSTYPE also in your flex file, because bison doesn't put the #define into the generated header file. You need to do this before you #include the generated header file.
Bison doesn't put the #define in the generated header because it has no way of knowing whether you did, since you might do it in an included file. In fact, if you're going to #define YYSTYPE, you should do it in a common header file, and #include the common header file in both bison and flex programs (as above, before you include the bison-generated header file).
Also, when you're regenerating the generated code, remember to always generate the bison program first because the flex program depends on the generated header file. That's the opposite order to the way you are doing it.
Just to make all this a bit clearer, here's an example:
common.h:
struct MyType {
/* ... /
};
#define YYSTYPE struct MyType;
lexer.l:
%{
/* All your standard includes go here */
/* Must go in this order */
#include "common.h"
#include "bison.tab.h"
%}
bison.y:
%{
/* Whatever library includes you need */
#include "common.h"
/* Don't include bison.tab.h; it will get inserted automatically */
%}
To fix the yytext error add this to bison.y :-
extern char *yytext
To fix the yyerror error make your prototype at the top of bison.y match the defn below :-
int yyerror(const char *message);
Fixing the yylval error requires a little more work and I don't understand this well enough to help. I'd suggest trying a simple hello,world type lexer,parser and move forward from there.
Here is the common.h I used :-
typedef struct STYPE {
int pointer;
} STYPE;
And the header of lexer :-
%{
#include "common.h"
#define YYSTYPE STYPE
#include <stdio.h>
#include"bison.tab.h"
void showToken(char*);
%}
And the header of parser :-
%{
#include <stdio.h>
#include "common.h"
extern char *yytext;
#define YYSTYPE STYPE
%}
This gives me one error and a few warnings but those are due to the undefined functions. Note that I have moved the declaration of STYPE to the top of lexer and parser

chdir not declared, compilation error g++

I am trying to compile a relatively simple application that I obtained from the web..
When running make I get the following error:
In file included from main.cpp:2:0:
os.h: In function ‘void myOpenDir(const char*)’:
os.h:13:16: error: ‘chdir’ was not declared in this scope
The file os.h looks like this:
#ifndef OS_H
#define OS_H
#if defined(__GNUG__)
#define INT64 long long
#define UINT64 unsigned long long
#include <dirent.h>
#define SPRTR '/'
void myOpenDir(const char* dirpath)
{
chdir(dirpath);
}
#elif defined(_MSC_VER)
#define INT64 __int64
#define UINT64 unsigned __int64
#include <direct.h>
#define SPRTR '\\'
void myOpenDir(const char* dirpath)
{
_chdir(dirpath);
}
#else
#error "Platform not supported. Need to update source code"
#endif
#endif
Someone got an idea why it wont compile?
I also used a g++ compiler via g++-4.7.real -c main.cpp but so far no luck.
Add #include <unistd.h>, as per the chdir manual.

Resources