[fpc-pascal] syscalls and fpc

Vincent Snijders vsnijders at quicknet.nl
Sat Feb 16 12:47:27 CET 2008

ik schreef:
> OK, so why don't you just say that you do not understand ?!

You don't understand.

> Let me start again. I never said that you, Micha, Daniel, Peter,
> Florian, or even the big bad wolf should implement all of the given
> syscall functions in the each platform in the world.
> The design of Do_SysCall at this time is hurting the usage of
> syscalls, for 3 reasons:
> 1. There is a support only for up to 6 parameters (plus the instruction itself).

Yes, and for i386 that is the limit, dictated by the hardware.

> 2. It support only integer base parameters, while you can not pass
> pointers, chars, array, record or floating point types.

Syscall pass registers, which are integers, so I don't see the problem.

> 3. Each OS changes/add/remove functions frequently, so assuming one of
> the above making the functions unusable for anything that is not an
> integer and up to 6 parameters.

Which syscall has more than 6 parameter or a parameter that does not fit 
in a register?

> (If you do not understand my points please ask, and I'll try to clear it up)

See above, I think I don't understand.

> Now one *example* (that caused me to notice this issues) is the following:
> extern int inotify_add_watch (int __fd, const char *__name, uint32_t __mask)

Is this a syscal with 3 parameters that fit in a register?
> So as you can see by the Do_SysCall function(s):
> function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult;
>  external name 'FPC_SYSCALL6';
> They unable to give you an answer to the above deceleration.
> So my questions are (still):
> 1. Is there a way to implement the above with array of const ?

Why? Not needed.

> 2. Is there a way to implement the above without using assembly, and
> if you must use assembly, then is there a way to use array of const
> inside the assembly, and if so, how ?

Why? Not needed.

> As you can see, I still haven't requested anyone to do it for me, I'm
> only trying to figure out how to achieve the above request with
> syscall using FPC !
> Here is a small way to do it btw, but it will be problematic with
> records (if you use assembly):
> function Do_SysCall(sysnr : TSysParam; const
> param1,param2,param3,param4,param5,param6) : TSysResult;  external
> name 'FPC_SYSCALL6';
> The problem is of course the number of bits that the registers can
> store in them (32 bit in i386 and 64 bit on x86_64).
> So when Micha mentioned the registers, I asked if my knowledge is
> valid, that you can do the following:
> push param1
> push param2
> push param3
> ...
> push param6

No, you cant't because the kernel expects the parameters in the 
registers and put them on the stack.

The rest *I* did not understand, so I snipped it.

For your example, I expect you to write a wrapper like (taken one at 
function fpugetrlimit(resource : cInt; rlim : PRLimit) : cInt;
   FpUGetRLimit := do_syscall(syscall_nr_ugetrlimit,
     TSysParam(resource), TSysParam(rlim));

Something like:
function fpinotify_add_watch (__fd: cint; __name: pchar; __mask: 
cuint32) : cint;
   fpinotify_add_watch := do_syscall(syscall_nr_inotify_add_watch, 
TSysParam(__fd), TSysParam(__name), TSysParam(__mask));


More information about the fpc-pascal mailing list