1 diff -up ./mozilla/security/nss/lib/freebl/Makefile.prelink ./mozilla/security/nss/lib/freebl/Makefile
2 --- ./mozilla/security/nss/lib/freebl/Makefile.prelink 2010-09-04 14:13:58.846327263 -0700
3 +++ ./mozilla/security/nss/lib/freebl/Makefile 2010-09-04 14:15:11.544326993 -0700
4 @@ -82,6 +82,12 @@ ifeq ($(FREEBL_NO_DEPEND),1)
6 MAPFILE_SOURCE = freebl.def
8 +ifdef FREEBL_USE_PRELINK
9 + DEFINES += -DFREEBL_USE_PRELINK
11 +ifdef FREEBL_PRELINK_COMMAND
12 + DEFINES +=-DFREEBL_PRELINK_COMMAND=\"$(FREEBL_PRELINK_COMMAND)\"
14 # NSS_X86 means the target is a 32-bits x86 CPU architecture
15 # NSS_X64 means the target is a 64-bits x64 CPU architecture
16 # NSS_X86_OR_X64 means the target is either x86 or x64
17 diff -up ./mozilla/security/nss/lib/freebl/shvfy.c.prelink ./mozilla/security/nss/lib/freebl/shvfy.c
18 --- ./mozilla/security/nss/lib/freebl/shvfy.c.prelink 2010-09-04 14:16:01.518326988 -0700
19 +++ ./mozilla/security/nss/lib/freebl/shvfy.c 2010-09-04 14:25:44.770326384 -0700
24 +#ifdef FREEBL_USE_PRELINK
25 +#ifndef FREELB_PRELINK_COMMAND
26 +#define FREEBL_PRELINK_COMMAND "/usr/sbin/prelink -u -o -"
28 +#include "private/pprio.h"
33 +#include <sys/wait.h>
34 +#include <sys/stat.h>
37 +bl_OpenUnPrelink(const char *shName, int *pid)
39 + char *command= strdup(FREEBL_PRELINK_COMMAND);
40 + char *argString = NULL;
42 + char *shNameArg = NULL;
45 + int argc = 0, argNext = 0;
46 + struct stat statBuf;
47 + int pipefd[2] = {-1,-1};
52 + /* make sure the prelink command exists first. If not, fall back to
53 + * just reading the file */
54 + for (cp = command; *cp ; cp++) {
61 + memset (&statBuf, 0, sizeof(statBuf));
62 + /* stat the file, follow the link */
63 + ret = stat(command, &statBuf);
66 + return PR_Open(shName, PR_RDONLY, 0);
68 + /* file exits, make sure it's an executable */
69 + if (!S_ISREG(statBuf.st_mode) ||
70 + ((statBuf.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) == 0)) {
72 + return PR_Open(shName, PR_RDONLY, 0);
75 + /* OK, the prelink command exists and looks correct, use it */
76 + /* build the arglist while we can still malloc */
77 + /* count the args if any */
78 + if (argString && *argString) {
79 + /* argString may have leading spaces, strip them off*/
80 + for (cp = argString; *cp && *cp == ' '; cp++);
83 + /* there is at least one arg.. */
87 + /* count the rest: Note there is no provision for escaped
89 + for (cp = argString; *cp ; cp++) {
91 + while (*cp && *cp == ' ') cp++;
97 + /* add the additional args: argv[0] (command), shName, NULL*/
99 + argv = PORT_NewArray(char *, argc);
100 + if (argv == NULL) {
104 + /* fill in the arglist */
105 + argv[argNext++] = command;
106 + if (argString && *argString) {
107 + argv[argNext++] = argString;
108 + for (cp = argString; *cp; cp++) {
111 + while (*cp && *cp == ' ') cp++;
112 + if (*cp) argv[argNext++] = cp;
116 + /* exec doesn't advertise taking const char **argv, do the paranoid
118 + shNameArg = strdup(shName);
119 + if (shNameArg == NULL) {
122 + argv[argNext++] = shNameArg;
123 + argv[argNext++] = 0;
125 + ret = pipe(pipefd);
130 + /* use vfork() so we don't trigger the pthread_at_fork() handlers */
132 + if (child < 0) goto loser;
134 + /* set up the file descriptors */
136 + /* associate pipefd[1] with stdout */
137 + if (pipefd[1] != 1) dup2(pipefd[1], 1);
140 + /* should probably close the other file descriptors? */
143 + execv(command, argv);
144 + /* avoid at_exit() handlers */
145 + _exit(1); /* shouldn't reach here except on an error */
150 + /* this is safe because either vfork() as full fork() semantics, and thus
151 + * already has it's own address space, or because vfork() has paused
152 + * the parent util the exec or exit */
159 + return PR_ImportPipe(pipefd[0]);
162 + if (pipefd[0] != -1) {
165 + if (pipefd[1] != -1) {
176 +bl_CloseUnPrelink( PRFileDesc *file, int pid)
178 + /* close the file descriptor */
180 + /* reap the child */
182 + waitpid(pid, NULL, 0);
187 /* #define DEBUG_SHVERIFY 1 */
189 @@ -117,6 +279,9 @@ BLAPI_SHVerify(const char *name, PRFuncP
193 +#ifdef FREEBL_USE_PRELINK
197 PRBool result = PR_FALSE; /* if anything goes wrong,
198 * the signature does not verify */
199 @@ -197,7 +362,11 @@ BLAPI_SHVerify(const char *name, PRFuncP
202 /* open our library file */
203 +#ifdef FREEBL_USE_PRELINK
204 + shFD = bl_OpenUnPrelink(shName,&pid);
206 shFD = PR_Open(shName, PR_RDONLY, 0);
209 #ifdef DEBUG_SHVERIFY
210 fprintf(stderr, "Failed to open the library file %s: (%d, %d)\n",
211 @@ -218,7 +387,11 @@ BLAPI_SHVerify(const char *name, PRFuncP
212 SHA1_Update(hashcx, buf, bytesRead);
215 +#ifdef FREEBL_USE_PRELINK
216 + bl_CloseUnPrelink(shFD, pid);
222 SHA1_End(hashcx, hash.data, &hash.len, hash.len);
223 diff -up ./mozilla/security/nss/lib/freebl/stubs.c.prelink ./mozilla/security/nss/lib/freebl/stubs.c
224 --- ./mozilla/security/nss/lib/freebl/stubs.c.prelink 2010-09-04 14:26:27.454327120 -0700
225 +++ ./mozilla/security/nss/lib/freebl/stubs.c 2010-09-04 14:31:56.778327428 -0700
230 +#include <private/pprio.h>
232 #define FREEBL_NO_WEAK 1
234 @@ -157,6 +158,8 @@ STUB_DECLARE(void,PR_Lock,(PRLock *lock)
235 STUB_DECLARE(PRLock *,PR_NewLock,(void));
236 STUB_DECLARE(PRFileDesc *,PR_Open,(const char *name, PRIntn flags,
238 +STUB_DECLARE(PRFileDesc *,PR_ImportFile,(PROsfd osfd));
239 +STUB_DECLARE(PRFileDesc *,PR_ImportPipe,(PROsfd osfd));
240 STUB_DECLARE(PRInt32,PR_Read,(PRFileDesc *fd, void *buf, PRInt32 amount));
241 STUB_DECLARE(PROffset32,PR_Seek,(PRFileDesc *fd, PROffset32 offset,
242 PRSeekWhence whence));
243 @@ -295,6 +298,34 @@ PR_Open_stub(const char *name, PRIntn fl
244 return (PRFileDesc *)lfd;
248 +PR_ImportFile_stub(PROsfd fd)
252 + STUB_SAFE_CALL1(PR_ImportFile, fd);
254 + lfd = PORT_New_stub(int);
258 + return (PRFileDesc *)lfd;
262 +PR_ImportPipe_stub(PROsfd fd)
266 + STUB_SAFE_CALL1(PR_ImportPipe, fd);
268 + lfd = PORT_New_stub(int);
272 + return (PRFileDesc *)lfd;
276 PR_Close_stub(PRFileDesc *fd)
278 @@ -492,6 +523,8 @@ freebl_InitNSPR(void *lib)
280 STUB_FETCH_FUNCTION(PR_Free);
281 STUB_FETCH_FUNCTION(PR_Open);
282 + STUB_FETCH_FUNCTION(PR_ImportFile);
283 + STUB_FETCH_FUNCTION(PR_ImportPipe);
284 STUB_FETCH_FUNCTION(PR_Close);
285 STUB_FETCH_FUNCTION(PR_Read);
286 STUB_FETCH_FUNCTION(PR_Seek);
287 diff -up ./mozilla/security/nss/lib/freebl/stubs.h.prelink ./mozilla/security/nss/lib/freebl/stubs.h
288 --- ./mozilla/security/nss/lib/freebl/stubs.h.prelink 2010-09-04 14:26:41.822327256 -0700
289 +++ ./mozilla/security/nss/lib/freebl/stubs.h 2010-09-04 14:32:53.498540767 -0700
291 #define PR_Lock PR_Lock_stub
292 #define PR_NewLock PR_NewLock_stub
293 #define PR_Open PR_Open_stub
294 +#define PR_ImportFile PR_ImportFile_stub
295 +#define PR_ImportPipe PR_ImportPipe_stub
296 #define PR_Read PR_Read_stub
297 #define PR_Seek PR_Seek_stub
298 #define PR_Sleep PR_Sleep_stub