]>
git.saurik.com Git - apple/xnu.git/blob - libsyscall/create-syscalls.pl
3 # Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
5 # @APPLE_OSREFERENCE_LICENSE_HEADER_START@
7 # This file contains Original Code and/or Modifications of Original Code
8 # as defined in and that are subject to the Apple Public Source License
9 # Version 2.0 (the 'License'). You may not use this file except in
10 # compliance with the License. Please obtain a copy of the License at
11 # http://www.opensource.apple.com/apsl/ and read it before using this
14 # The Original Code and all software distributed under the License are
15 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 # Please see the License for the specific language governing rights and
20 # limitations under the License.
22 # @APPLE_OSREFERENCE_LICENSE_HEADER_END@
24 ##########################################################################
26 # % create-syscalls.pl syscalls.master custom-directory out-directory
28 # This script fills the the out-directory with a Makefile.inc and *.s
29 # files to create the double-underbar syscall stubs. It reads the
30 # syscall.master file to get the symbol names and number of arguments,
31 # and whether Libsystem should automatically create the (non-double-underbar)
32 # stubs if Libc doesn't provide a wrapper. Which system calls will get
33 # the automatic treatment is writen to the libsyscall.list file, also
34 # written to the out-directory.
36 # The custom-directory contains:
37 # 1. SYS.h - used by the automatically created *.s and custom files
38 # 2. custom.s - contains architecture specific additional system calls and
39 # auxilliary routines (like cerror)
40 # 3. special case double-underbar stub files - which are copied into
43 # The BSDmakefile copies /usr/include/architecture/ppc/emode_independent_asm.h
44 # and /usr/include/architecture/i386/asm_help.h to $(OBJDIR)/include,
45 # replacing .globl with .private_extern. These headers, along with SYS.h
46 # make the double-underbar syscall stub private_extern, so that then become
47 # static in the resulting libSystem.dylib.
49 ##########################################################################
52 use File
::Basename
();
57 my $MyName = File
::Basename
::basename
($0);
59 my @CustomSrc = qw(custom.s);
61 my @Copy = (qw(SYS.h), @CustomSrc);
66 quota
=> [4, 0], # unimplemented
67 setquota
=> [2, 0], # unimplemented
68 syscall => [0, 0], # custom/__syscall.s will be used
70 my $StubFile = 'libsyscall.list';
71 # size in bytes of known types (only used for i386)
83 'mach_port_name_t' => 4,
104 ##########################################################################
105 # Make a __xxx.s file: if it exists in the $CustomDir, just copy it, otherwise
106 # create one. We define the macro __SYSCALL_32BIT_ARG_BYTES so that SYS.h could
107 # use that to define __SYSCALL dependent on the arguments' total size.
108 ##########################################################################
110 my($name, $args, $bytes) = @_;
113 $pseudo = '__' . $pseudo unless $pseudo =~ /^__/;
114 my $file = $pseudo . '.s';
115 my $custom = File
::Spec-
>join($CustomDir, $file);
116 my $path = File
::Spec-
>join($OutDir, $file);
118 File
::Copy
::copy
($custom, $path) || die "$MyName: copy($custom, $path): $!\n";
119 print "Copying $path\n";
121 my $f = IO
::File-
>new($path, 'w');
122 die "$MyName: $path: $!\n" unless defined($f);
123 print $f "#define __SYSCALL_32BIT_ARG_BYTES $bytes\n\n";
124 print $f "#include \"SYS.h\"\n\n";
125 print $f "__SYSCALL($pseudo, $name, $args)\n";
126 print "Creating $path\n";
132 die "Usage: $MyName syscalls.master custom-directory out-directory\n";
135 ##########################################################################
136 # Read the syscall.master file and collect the system call names and number
137 # of arguments. It looks for the NO_SYSCALL_STUB quailifier following the
138 # prototype to determine if no automatic stub should be created by Libsystem.
139 # System call name that are already prefixed with double-underbar are set as
140 # if the NO_SYSCALL_STUB qualifier were specified (whether it is or not).
142 # For the #if lines in syscall.master, all macros are assumed to be defined,
143 # except COMPAT_GETFSSTAT (assumed undefined).
144 ##########################################################################
148 my $f = IO
::File-
>new($file, 'r');
149 die "$MyName: $file: $!\n" unless defined($f);
163 if(/^#\s*if\s+(\S+)$/) {
164 $skip = ($1 eq 'COMPAT_GETFSSTAT') ? -1 : 1;
171 die "$MyName: no function prototype on line $line\n" unless length($_) > 0 && /;$/;
172 my $no_syscall_stub = /\)\s*NO_SYSCALL_STUB\s*;/;
173 my($name, $args) = /\s(\S+)\s*\(([^)]*)\)/;
174 next if $name =~ /e?nosys/;
179 if($args ne '' && $args ne 'void') {
180 my @a = split(',', $args);
182 # Calculate the size of all the arguments (only used for i386)
184 $type =~ s/\s*\w+$//; # remove the argument name
186 $argbytes += 4; # a pointer type
188 $type =~ s/^.*\s//; # remove any type qualifier, like unsigned
189 my $b = $TypeBytes{$type};
190 die "$MyName: $name: unknown type '$type'\n" unless defined($b);
195 if($no_syscall_stub || $name =~ /^__/) {
196 $NoStub{$name} = [$nargs, $argbytes];
198 $Stub{$name} = [$nargs, $argbytes];
203 usage
() unless scalar(@ARGV) == 3;
204 $CustomDir = $ARGV[1];
205 die "$MyName: $CustomDir: No such directory\n" unless -d
$CustomDir;
207 die "$MyName: $OutDir: No such directory\n" unless -d
$OutDir;
209 readmaster
($ARGV[0]);
211 ##########################################################################
212 # copy the files specified in @Copy from the $CustomDir to $OutDir
213 ##########################################################################
215 my $custom = File
::Spec-
>join($CustomDir, $_);
216 my $path = File
::Spec-
>join($OutDir, $_);
217 File
::Copy
::copy
($custom, $path) || die "$MyName: copy($custom, $path): $!\n";
220 ##########################################################################
221 # make all the *.s files
222 ##########################################################################
225 while(($k, $v) = each(%Stub)) {
226 push(@src, make_s
($k, @$v));
228 while(($k, $v) = each(%NoStub)) {
229 push(@src, make_s
($k, @$v));
232 ##########################################################################
233 # create the Makefile.inc file from the list for files in @src and @CustomSrc
234 ##########################################################################
235 my $path = File
::Spec-
>join($OutDir, 'Makefile.inc');
236 my $f = IO
::File-
>new($path, 'w');
237 die "$MyName: $path: $!\n" unless defined($f);
238 print $f ".PATH: $OutDir\n\n";
239 print $f "SYSCALLSRCS= " . join(" \\\n\t", sort(@src, @CustomSrc)) . "\n\n";
240 print $f "MDSRCS+= \$(SYSCALLSRCS)\n\n";
241 print $f ".for S in \$(SYSCALLSRCS)\n";
242 print $f "PRECFLAGS-\$(S)+= -I\$(OBJROOT)/include\n";
243 print $f ".endfor\n";
246 ##########################################################################
247 # create the libsyscall.list file for Libsystem to use. For the one that
248 # should not have auto-generated stubs, the line begins with #.
249 ##########################################################################
250 $path = File
::Spec-
>join($OutDir, $StubFile);
251 $f = IO
::File-
>new($path, 'w');
252 die "$MyName: $path: $!\n" unless defined($f);
253 # Add the %NoStub entries to %Stub, appending '#' to the name, so we can sort
254 while(($k, $v) = each(%NoStub)) {
258 for(sort(keys(%Stub))) {
261 printf $f "#___%s\t%s\n", $k, $Stub{$_}->[0];
263 printf $f "___%s\t%s\n", $_, $Stub{$_}->[0];