Re: System calls parameter restrictions



On Fri, 27 Oct 2006 16:54:36 -0300 Rafael Almeida <rafaelc@xxxxxxxxxxx> wrote:
| 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.

C is capable of passing a struct by value. But in the past it was not,
and thus traditional Unix system calls would pass a struct by pointer.
In cases where the struct might be changed and the called needs to see
those changes, then either passing by pointer is needed or the syscall
would need to return the struct value.

I've never heard of any syscall that passes or returns a struct by value.
That doesn't mean there couldn't be one in the future.


| 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.

It's not that bad of an idea for application programs. I've done it many
times. As for passing to and from a kernel, that might be another issue.
Passing by value is actually a kind of abstraction, anyway. Literally,
the struct is copied or loaded in registers, depending on architecture.
The register starved i386 is probably going to have to copy.

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2006-10-27-1704@xxxxxxxx |
|------------------------------------/-------------------------------------|
.



Relevant Pages

  • Re: [uml-devel] [RFC] PATCH 3/4 - Time virtualization : PTRACE_SYSCALL_MASK
    ... so we'd pack them in a struct and pass its address). ... We could either make two new PTRACE_* operations (I don't like ... You need this treatment anyway - above we're passing a pointer to a bitstring, ... somewhere an "extended error code" saying which is the last allowed syscall ...
    (Linux-Kernel)
  • Re: is this a bug of elf_core_dump
    ... The fact that it is passing in the address of a ... more or less it is looking up the struct page pointer for the user address ... passed in and returning it to the calling function via &page... ...
    (Linux-Kernel)
  • Re: Passing by ref or by value
    ... > PARAFORMAT2 is a structure that SendMessage will return stuff in. ... > Suppose I was passing data rather then receiving it, ... "A struct type is a value type..." ... then passing by value (no ref) will work fine. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: call by address vs. call by value
    ... > reference (or pointer)? ... he's talking about the total number of memory references including ... For every access to a member of the struct passed by a pointer, ... exceed the time required to copy the struct for passing by value. ...
    (comp.lang.c)
  • Re: Passing structs by value
    ... > does passing a struct by value cause undefined behavior if that struct ... > has as a member a pointer that has been passed to free? ...
    (comp.lang.c)