Mercurial > hg > xemacs-beta
annotate src/vdb-mach.c @ 5882:bbe4146603db
Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
lisp/ChangeLog addition:
2015-04-01 Aidan Kehoe <kehoea@parhasard.net>
When calling #'string-match with a REGEXP without regular
expression special characters, call #'search, #'mismatch, #'find,
etc. instead, making our code less likely to side-effect other
functions' match data and a little faster.
* apropos.el (apropos-command):
* apropos.el (apropos):
Call (position ?\n ...) rather than (string-match "\n" ...) here.
* buff-menu.el:
* buff-menu.el (buffers-menu-omit-invisible-buffers):
Don't fire up the regexp engine just to check if a string starts
with a space.
* buff-menu.el (select-buffers-tab-buffers-by-mode):
Don't fire up the regexp engine just to compare mode basenames.
* buff-menu.el (format-buffers-tab-line):
* buff-menu.el (build-buffers-tab-internal): Moved to being a
label within the following.
* buff-menu.el (buffers-tab-items): Use the label.
* bytecomp.el (byte-compile-log-1):
Don't fire up the regexp engine just to look for a newline.
* cus-edit.el (get):
Ditto.
* cus-edit.el (custom-variable-value-create):
Ditto, but for a colon.
* descr-text.el (describe-text-sexp):
Ditto.
* descr-text.el (describe-char-unicode-data):
Use #'split-string-by-char given that we're just looking for a
semicolon.
* descr-text.el (describe-char):
Don't fire up the regexp engine just to look for a newline.
* disass.el (disassemble-internal):
Ditto.
* files.el (file-name-sans-extension):
Implement this using #'position.
* files.el (file-name-extension):
Correct this function's docstring, implement it in terms of
#'position.
* files.el (insert-directory):
Don't fire up the regexp engine to split a string by space; don't
reverse the list of switches, this is actually a longstand bug as
far as I can see.
* gnuserv.el (gnuserv-process-filter):
Use #'position here, instead of consing inside #'split-string
needlessly.
* gtk-file-dialog.el (gtk-file-dialog-update-dropdown):
Use #'split-string-by-char here, don't fire up #'split-string for
directory-sep-char.
* gtk-font-menu.el (hack-font-truename):
Implement this more cheaply in terms of #'find,
#'split-string-by-char, #'equal, rather than #'string-match,
#'split-string, #'string-equal.
* hyper-apropos.el (hyper-apropos-grok-functions):
* hyper-apropos.el (hyper-apropos-grok-variables):
Look for a newline using #'position rather than #'string-match in
these functions.
* info.el (Info-insert-dir):
* info.el (Info-insert-file-contents):
* info.el (Info-follow-reference):
* info.el (Info-extract-menu-node-name):
* info.el (Info-menu):
Look for fixed strings using #'position or #'search as appropriate
in this file.
* ldap.el (ldap-decode-string):
* ldap.el (ldap-encode-string):
#'encode-coding-string, #'decode-coding-string are always
available, don't check if they're fboundp.
* ldap.el (ldap-decode-address):
* ldap.el (ldap-encode-address):
Use #'split-string-by-char in these functions.
* lisp-mnt.el (lm-creation-date):
* lisp-mnt.el (lm-last-modified-date):
Don't fire up the regexp engine just to look for spaces in this file.
* menubar-items.el (default-menubar):
Use (not (mismatch ...)) rather than #'string-match here, for
simple regexp.
Use (search "beta" ...) rather than (string-match "beta" ...)
* menubar-items.el (sort-buffers-menu-alphabetically):
* menubar-items.el (sort-buffers-menu-by-mode-then-alphabetically):
* menubar-items.el (group-buffers-menu-by-mode-then-alphabetically):
Don't fire up the regexp engine to check if a string starts with
a space or an asterisk.
Use the more fine-grained results of #'compare-strings; compare
case-insensitively for the buffer menu.
* menubar-items.el (list-all-buffers):
* menubar-items.el (tutorials-menu-filter):
Use #'equal rather than #'string-equal, which, in this context,
has the drawback of not having a bytecode, and no redeeming
features.
* minibuf.el:
* minibuf.el (un-substitute-in-file-name):
Use #'count, rather than counting the occurences of $ using the
regexp engine.
* minibuf.el (read-file-name-internal-1):
Don't fire up the regexp engine to search for ?=.
* mouse.el (mouse-eval-sexp):
Check for newline with #'find.
* msw-font-menu.el (mswindows-reset-device-font-menus):
Split a string by newline with #'split-string-by-char.
* mule/japanese.el:
* mule/japanese.el ("Japanese"):
Use #'search rather than #'string-match; canoncase before
comparing; fix a bug I had introduced where I had been making case
insensitive comparisons where the case mattered.
* mule/korea-util.el (default-korean-keyboard):
Look for ?3 using #'find, not #'string-march.
* mule/korea-util.el (quail-hangul-switch-hanja):
Search for a fixed string using #'search.
* mule/mule-cmds.el (set-locale-for-language-environment):
#'position, #'substitute rather than #'string-match,
#'replace-in-string.
* newcomment.el (comment-make-extra-lines):
Use #'search rather than #'string-match for a simple string.
* package-get.el (package-get-remote-filename):
Use #'position when looking for ?@
* process.el (setenv):
* process.el (read-envvar-name):
Use #'position when looking for ?=.
* replace.el (map-query-replace-regexp):
Use #'split-string-by-char instead of using an inline
implementation of it.
* select.el (select-convert-from-cf-text):
* select.el (select-convert-from-cf-unicodetext):
Use #'position rather than #'string-match in these functions.
* setup-paths.el (paths-emacs-data-root-p):
Use #'search when looking for simple string.
* sound.el (load-sound-file):
Use #'split-string-by-char rather than an inline reimplementation
of same.
* startup.el (splash-screen-window-body):
* startup.el (splash-screen-tty-body):
Search for simple strings using #'search.
* version.el (emacs-version):
Ditto.
* x-font-menu.el (hack-font-truename):
Implement this more cheaply in terms of #'find,
#'split-string-by-char, #'equal, rather than #'string-match,
#'split-string, #'string-equal.
* x-font-menu.el (x-reset-device-font-menus-core):
Use #'split-string-by-char here.
* x-init.el (x-initialize-keyboard):
Search for a simple string using #'search.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 01 Apr 2015 14:28:20 +0100 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
3092 | 1 /* Virtual diry bit implementation for XEmacs. |
2 Copyright (C) 2005 Marcus Crestani. | |
3 | |
4 This file is part of XEmacs. | |
5 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3092
diff
changeset
|
6 XEmacs is free software: you can redistribute it and/or modify it |
3092 | 7 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3092
diff
changeset
|
8 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3092
diff
changeset
|
9 option) any later version. |
3092 | 10 |
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
3092
diff
changeset
|
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
3092 | 18 |
19 /* Synched up with: Not in FSF. */ | |
20 | |
21 #include <config.h> | |
22 #include "lisp.h" | |
23 #include "gc.h" | |
24 #include "mc-alloc.h" | |
25 #include "vdb.h" | |
26 | |
27 #include <errno.h> | |
28 #include <signal.h> | |
29 #include <sys/mman.h> | |
30 #include <sys/time.h> | |
31 #include <sys/resource.h> | |
32 #include <unistd.h> | |
33 #include <mach/mach.h> | |
34 #include <mach/mach_error.h> | |
35 #include <architecture/ppc/cframe.h> | |
36 | |
37 | |
38 /* the structure of an exception msg and its reply */ | |
39 typedef struct rep_msg { | |
40 mach_msg_header_t head; | |
41 NDR_record_t NDR; | |
42 kern_return_t ret_code; | |
43 } mach_reply_msg_t; | |
44 | |
45 typedef struct exc_msg { | |
46 mach_msg_header_t head; | |
47 /* start of the kernel processed data */ | |
48 mach_msg_body_t msgh_body; | |
49 mach_msg_port_descriptor_t thread; | |
50 mach_msg_port_descriptor_t task; | |
51 /* end of the kernel processed data */ | |
52 NDR_record_t NDR; | |
53 exception_type_t exception; | |
54 mach_msg_type_number_t code_cnt; | |
55 exception_data_t code; | |
56 /* some padding */ | |
57 char pad[512]; | |
58 } mach_exc_msg_t; | |
59 | |
60 /* this is a neat little mach callback */ | |
61 extern boolean_t exc_server(mach_msg_header_t *in, mach_msg_header_t *out); | |
62 | |
63 /* these are the globals everyone needs */ | |
64 static size_t page_size = 16384; | |
65 static mach_port_t task_self = NULL; | |
66 static mach_port_t exc_port = NULL; | |
67 | |
68 /* these are some less neat mach callbacks */ | |
69 kern_return_t | |
70 catch_exception_raise_state | |
71 (mach_port_t UNUSED (port), | |
72 exception_type_t UNUSED (exception_type), | |
73 exception_data_t UNUSED (exception_data), | |
74 mach_msg_type_number_t UNUSED (data_cnt), | |
75 thread_state_flavor_t *UNUSED (flavor), | |
76 thread_state_t UNUSED (in_state), | |
77 mach_msg_type_number_t UNUSED (is_cnt), | |
78 thread_state_t UNUSED (out_state), | |
79 mach_msg_type_number_t UNUSED (os_cnt)) | |
80 { | |
81 return KERN_FAILURE; | |
82 } | |
83 | |
84 kern_return_t | |
85 catch_exception_raise_state_identitity | |
86 (mach_port_t UNUSED (port), | |
87 mach_port_t UNUSED (thread_port), | |
88 mach_port_t UNUSED (task_port), | |
89 exception_type_t UNUSED (exception_type), | |
90 exception_data_t UNUSED (exception_data), | |
91 mach_msg_type_number_t UNUSED (data_count), | |
92 thread_state_flavor_t *UNUSED (state_flavor), | |
93 thread_state_t UNUSED (in_state), | |
94 mach_msg_type_number_t UNUSED (in_state_count), | |
95 thread_state_t UNUSED (out_state), | |
96 mach_msg_type_number_t UNUSED (out_state_count)) | |
97 { | |
98 return KERN_FAILURE; | |
99 } | |
100 | |
101 kern_return_t | |
102 catch_exception_raise | |
103 (mach_port_t UNUSED (port), | |
104 mach_port_t UNUSED (thread_port), | |
105 mach_port_t UNUSED (task_port), | |
106 exception_type_t UNUSED (exception_type), | |
107 exception_data_t exception_data, | |
108 mach_msg_type_number_t UNUSED (data_count)) | |
109 { | |
110 /* kernel return value is in exception_data[0], faulting address in | |
111 exception_data[1] */ | |
112 if (write_barrier_enabled | |
113 && (fault_on_protected_page ((void *) exception_data[1])) | |
114 && exception_data[0] == KERN_PROTECTION_FAILURE) | |
115 { | |
116 vdb_designate_modified ((void *) exception_data[1]); | |
117 unprotect_page_and_mark_dirty ((void *) exception_data[1]); | |
118 return KERN_SUCCESS; | |
119 } | |
120 else /* default sigsegv handler */ | |
121 { | |
122 fprintf (stderr, "\n\nFatal Error: Received %s (%d) for address 0x%x\n", | |
123 "EXC_BAD_ACCESS", exception_data[0], (int) exception_data[1]); | |
124 return KERN_FAILURE; | |
125 } | |
126 } | |
127 | |
128 /* this is the thread which forwards of exceptions read from the exception | |
129 server off to our exception catchers and then back out to the other | |
130 thread */ | |
131 void | |
132 exception_thread(void) | |
133 { | |
134 mach_msg_header_t *message; | |
135 mach_msg_header_t *reply; | |
136 kern_return_t retval; | |
137 | |
138 /* allocate the space for the message and reply */ | |
139 message = (mach_msg_header_t *) malloc (sizeof (mach_exc_msg_t)); | |
140 reply = (mach_msg_header_t *) malloc (sizeof (mach_reply_msg_t)); | |
141 /* do this loop forever */ | |
142 while (1) | |
143 { | |
144 /* block until we get an exception message */ | |
145 retval = mach_msg (message, MACH_RCV_MSG, 0, sizeof (mach_exc_msg_t), | |
146 exc_port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); | |
147 /* forward off the handling of this message */ | |
148 if (!exc_server (message, reply)) | |
149 { | |
150 fprintf (stderr, "INTERNAL ERROR: exc_server() failed.\n"); | |
151 ABORT (); | |
152 } | |
153 /* send the message back out to the thread */ | |
154 retval = mach_msg (reply, MACH_SEND_MSG, sizeof (mach_reply_msg_t), 0, | |
155 MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, | |
156 MACH_PORT_NULL); | |
157 } | |
158 } | |
159 | |
160 /* this initializes the subsystem (sets the exception port, starts the | |
161 exception handling thread, etc) */ | |
162 void | |
163 vdb_install_signal_handler (void) | |
164 { | |
165 mach_port_t thread_self, exc_port_s, exc_thread; | |
166 ppc_thread_state_t *exc_thread_state; | |
167 mach_msg_type_name_t type; | |
168 void *subthread_stack; | |
169 kern_return_t retval; | |
170 | |
171 /* get ids for ourself */ | |
172 if (!task_self) | |
173 task_self = mach_task_self (); | |
174 thread_self = mach_thread_self (); | |
175 | |
176 /* allocate the port we're going to get exceptions on */ | |
177 retval = mach_port_allocate (task_self, MACH_PORT_RIGHT_RECEIVE, &exc_port); | |
178 if (retval != KERN_SUCCESS) | |
179 { | |
180 fprintf (stderr, "Couldn't allocate exception port: %s\n", | |
181 mach_error_string (retval)); | |
182 ABORT (); | |
183 } | |
184 | |
185 /* extract out the send rights for that port, which the OS needs */ | |
186 retval = mach_port_extract_right (task_self, exc_port, | |
187 MACH_MSG_TYPE_MAKE_SEND, | |
188 &exc_port_s, &type); | |
189 if(retval != KERN_SUCCESS) | |
190 { | |
191 fprintf (stderr, "Couldn't extract send rights: %s\n", | |
192 mach_error_string (retval)); | |
193 ABORT (); | |
194 } | |
195 | |
196 /* set the exception ports for this thread to the above */ | |
197 retval = thread_set_exception_ports(thread_self, EXC_MASK_BAD_ACCESS, | |
198 exc_port_s, EXCEPTION_DEFAULT, | |
199 PPC_THREAD_STATE); | |
200 if(retval != KERN_SUCCESS) | |
201 { | |
202 fprintf (stderr, "Couldn't set exception ports: %s\n", | |
203 mach_error_string (retval)); | |
204 ABORT (); | |
205 } | |
206 | |
207 /* set up the subthread */ | |
208 retval = thread_create(task_self, &exc_thread); | |
209 if(retval != KERN_SUCCESS) | |
210 { | |
211 fprintf (stderr , "Couldn't create exception thread: %s\n", | |
212 mach_error_string (retval)); | |
213 ABORT (); | |
214 } | |
215 subthread_stack = (void *) malloc (page_size); | |
216 subthread_stack = | |
217 (char *) subthread_stack + (page_size - C_ARGSAVE_LEN - C_RED_ZONE); | |
218 exc_thread_state = | |
219 (ppc_thread_state_t *) malloc (sizeof (ppc_thread_state_t)); | |
220 exc_thread_state->srr0 = (unsigned int) exception_thread; | |
221 exc_thread_state->r1 = (unsigned int) subthread_stack; | |
222 retval = thread_set_state (exc_thread, PPC_THREAD_STATE, | |
223 (thread_state_t) exc_thread_state, | |
224 PPC_THREAD_STATE_COUNT); | |
225 if (retval != KERN_SUCCESS) | |
226 { | |
227 fprintf (stderr, "Couldn't set subthread state: %s\n", | |
228 mach_error_string (retval)); | |
229 ABORT (); | |
230 } | |
231 retval = thread_resume (exc_thread); | |
232 if (retval != KERN_SUCCESS) | |
233 { | |
234 fprintf (stderr, "Couldn't resume subthread: %s\n", | |
235 mach_error_string (retval)); | |
236 ABORT (); | |
237 } | |
238 allow_incremental_gc = 1; | |
239 } | |
240 | |
241 void | |
242 vdb_protect (void *ptr, EMACS_INT len) | |
243 { | |
244 if (mprotect (ptr, len, PROT_READ)) | |
245 { | |
246 perror ("Couldn't mprotect"); | |
247 ABORT (); | |
248 } | |
249 } | |
250 | |
251 void | |
252 vdb_unprotect (void *ptr, EMACS_INT len) | |
253 { | |
254 if (mprotect (ptr, len, PROT_READ | PROT_WRITE)) | |
255 { | |
256 perror ("Couldn't mprotect"); | |
257 ABORT (); | |
258 } | |
259 } |