Re: System calls parameter restrictions



On 26 Oct 2006 01:54:12 -0700
"David Schwartz" <davids@xxxxxxxxxxxxx> wrote:

Obviously, nobody would design a system that had a system call that
required a parameter you couldn't pass the value for. You can always
pass pointers, otherwise 'read' and 'write' wouldn't work. A struct
would be passed by address.

Obviously you can pass pretty much anything through a pointer, but what
I didn't understand was whether you could pass a struct by value or not.

Mine doesn't cast the parameter to a long. It looks like this:

#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{\
return syscall(__NR_##name, arg1);\
}

And 'syscall' takes the number of the system call and then '...'.

Hum. What's your kernel version? On linux 2.6.18.1 (i386 code) it goes
like this:
#define _syscall1(type,name,type1,arg1) \
type name(type1 arg1) \
{ \
long __res; \
__asm__ volatile ("int $0x80" \
: "=a" (__res) \
: "0" (__NR_##name),"b" ((long)(arg1))); \
__syscall_return(type,__res); \
}
So you can see from that that passing a struct (and not a pointer to a
struct) as a parameter is going to fail.

I believe structs and unions are never passed by value, but I'm not
sure.
Yeah, I couldn't find any system call that gets a struct as a parameter.
That's why I thought it was a restriction on the possible parameter
types. And I want to know the reason of that restriction. Not because I
want to pass a struct as a parameter so bad, but because I want to learn
what I'm missing that would make passing a struct by value a bad idea.
.



Relevant Pages

  • Re: Another spinoza challenge
    ... You should test against the int type's limits: ... typedef struct complex ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: how to store list of varying types
    ... represent that with those in the struct definitions? ... pointer null, and the second one the CString object. ... then have to finish constructing the packet by copying the two data objects ... start with an upper-case letter (so, I would use DataElement ...
    (microsoft.public.vc.mfc)
  • Re: N1298 - try/finally for C
    ... Do you mean that "struct throwInfo" should be optional? ... that exception handling would be supported only on implementations ... If the standard mandates an integer as throw argument, ... should be an integer wide enough to encode a pointer if necessary. ...
    (comp.std.c)
  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • Re: [RFC][PATCH 1/4] cgroup: support per cgroup subsys state ID (CSS ID)
    ... Patch for Per-CSS(Cgroup Subsys State) ID and private hierarchy code. ... This patch attaches unique ID to each css and provides following. ... returns pointer to struct cgroup_subysys_state of id. ... using a pointer introduces no such restriction. ...
    (Linux-Kernel)