]>
git.saurik.com Git - apple/xnu.git/blob - libsyscall/create-syscalls.pl
f54f344ed8d1462ebba06466ff057fa1566945ea
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)
103 ##########################################################################
104 # Make a __xxx.s file: if it exists in the $CustomDir, just copy it, otherwise
105 # create one. We define the macro __SYSCALL_I386_ARG_BYTES so that SYS.h could
106 # use that to define __SYSCALL dependent on the arguments' total size.
107 ##########################################################################
109 my($name, $args, $bytes) = @_;
112 $pseudo = '__' . $pseudo unless $pseudo =~ /^__/;
113 my $file = $pseudo . '.s';
114 my $custom = File
::Spec-
>join($CustomDir, $file);
115 my $path = File
::Spec-
>join($OutDir, $file);
117 File
::Copy
::copy
($custom, $path) || die "$MyName: copy($custom, $path): $!\n";
118 print "Copying $path\n";
120 my $f = IO
::File-
>new($path, 'w');
121 die "$MyName: $path: $!\n" unless defined($f);
122 print $f "#define __SYSCALL_I386_ARG_BYTES $bytes\n\n";
123 print $f "#include \"SYS.h\"\n\n";
124 print $f "__SYSCALL($pseudo, $name, $args)\n";
125 print "Creating $path\n";
131 die "Usage: $MyName syscalls.master custom-directory out-directory\n";
134 ##########################################################################
135 # Read the syscall.master file and collect the system call names and number
136 # of arguments. It looks for the NO_SYSCALL_STUB quailifier following the
137 # prototype to determine if no automatic stub should be created by Libsystem.
138 # System call name that are already prefixed with double-underbar are set as
139 # if the NO_SYSCALL_STUB qualifier were specified (whether it is or not).
141 # For the #if lines in syscall.master, all macros are assumed to be defined,
142 # except COMPAT_GETFSSTAT (assumed undefined).
143 ##########################################################################
147 my $f = IO
::File-
>new($file, 'r');
148 die "$MyName: $file: $!\n" unless defined($f);
162 if(/^#\s*if\s+(\S+)$/) {
163 $skip = ($1 eq 'COMPAT_GETFSSTAT') ? -1 : 1;
170 die "$MyName: no function prototype on line $line\n" unless length($_) > 0 && /;$/;
171 my $no_syscall_stub = /\)\s*NO_SYSCALL_STUB\s*;/;
172 my($name, $args) = /\s(\S+)\s*\(([^)]*)\)/;
173 next if $name =~ /e?nosys/;
178 if($args ne '' && $args ne 'void') {
179 my @a = split(',', $args);
181 # Calculate the size of all the arguments (only used for i386)
183 $type =~ s/\s*\w+$//; # remove the argument name
185 $argbytes += 4; # a pointer type
187 $type =~ s/^.*\s//; # remove any type qualifier, like unsigned
188 my $b = $TypeBytes{$type};
189 die "$MyName: $name: unknown type '$type'\n" unless defined($b);
194 if($no_syscall_stub || $name =~ /^__/) {
195 $NoStub{$name} = [$nargs, $argbytes];
197 $Stub{$name} = [$nargs, $argbytes];
202 usage
() unless scalar(@ARGV) == 3;
203 $CustomDir = $ARGV[1];
204 die "$MyName: $CustomDir: No such directory\n" unless -d
$CustomDir;
206 die "$MyName: $OutDir: No such directory\n" unless -d
$OutDir;
208 readmaster
($ARGV[0]);
210 ##########################################################################
211 # copy the files specified in @Copy from the $CustomDir to $OutDir
212 ##########################################################################
214 my $custom = File
::Spec-
>join($CustomDir, $_);
215 my $path = File
::Spec-
>join($OutDir, $_);
216 File
::Copy
::copy
($custom, $path) || die "$MyName: copy($custom, $path): $!\n";
219 ##########################################################################
220 # make all the *.s files
221 ##########################################################################
224 while(($k, $v) = each(%Stub)) {
225 push(@src, make_s
($k, @$v));
227 while(($k, $v) = each(%NoStub)) {
228 push(@src, make_s
($k, @$v));
231 ##########################################################################
232 # create the Makefile.inc file from the list for files in @src and @CustomSrc
233 ##########################################################################
234 my $path = File
::Spec-
>join($OutDir, 'Makefile.inc');
235 my $f = IO
::File-
>new($path, 'w');
236 die "$MyName: $path: $!\n" unless defined($f);
237 print $f ".PATH: $OutDir\n\n";
238 print $f "SYSCALLSRCS= " . join(" \\\n\t", sort(@src, @CustomSrc)) . "\n\n";
239 print $f "MDSRCS+= \$(SYSCALLSRCS)\n\n";
240 print $f ".for S in \$(SYSCALLSRCS)\n";
241 print $f "PRECFLAGS-\$(S)+= -I\$(OBJROOT)/include\n";
242 print $f ".endfor\n";
245 ##########################################################################
246 # create the libsyscall.list file for Libsystem to use. For the one that
247 # should not have auto-generated stubs, the line begins with #.
248 ##########################################################################
249 $path = File
::Spec-
>join($OutDir, $StubFile);
250 $f = IO
::File-
>new($path, 'w');
251 die "$MyName: $path: $!\n" unless defined($f);
252 # Add the %NoStub entries to %Stub, appending '#' to the name, so we can sort
253 while(($k, $v) = each(%NoStub)) {
257 for(sort(keys(%Stub))) {
260 printf $f "#___%s\t%s\n", $k, $Stub{$_}->[0];
262 printf $f "___%s\t%s\n", $_, $Stub{$_}->[0];