(linenum→info "unix/slp.c:2238")

NIIBE Yutaka

Bio:Free Software Hacker and Activist
URL:http://www.gniibe.org/
Location:Akihabara, Japan

2008-01-08

_ tree/1.5.1.1/tree.c:95-95

   95: } *gtable[256], *utable[256];

Should be static?

_ tree/1.5.1.1/tree.c:103-103

  103: } *itable[256];

Should be static?

_ tree/1.5.1.1/tree.c:112-138

  112: char colorize = FALSE, ansilines = FALSE;
  113: char *term, termmatch = FALSE, istty;
  114: char *leftcode = NULL, *rightcode = NULL, *endcode = NULL;
  115: 
  116: char *norm_flgs = NULL, *file_flgs = NULL, *dir_flgs = NULL, *link_flgs = NULL;
  117: char *fifo_flgs = NULL, *sock_flgs = NULL, *block_flgs = NULL, *char_flgs = NULL;
  118: char *exec_flgs = NULL, *orphan_flgs = NULL, *missing_flgs = NULL;
  119: 
  120: char *vgacolor[] = {
  121:   "black", "red", "green", "yellow", "blue", "fuchsia", "aqua", "white",
  122:   NULL, NULL,
  123:   "transparent", "red", "green", "yellow", "blue", "fuchsia", "aqua", "black"
  124: };
  125: 
  126: struct colortable {
  127:   char *term_flg, *CSS_name, *font_fg, *font_bg;
  128: } colortable[11];
  129: 
  130: struct extensions {
  131:   char *ext;
  132:   char *term_flg, *CSS_name, *web_fg, *web_bg, *web_extattr;
  133:   struct extensions *nxt;
  134: } *ext = NULL;
  135: 
  136: const struct linedraw {
  137:   const char **name, *vert, *vert_left, *corner, *copy;
  138: } *linedraw;

Should be static?

_ tree/1.5.1.1/tree.c:142-180

  142: /* Function prototypes: */
  143: int color(u_short, char *, char, char), cmd(char *), patmatch(char *, char *);
  144: int alnumsort(struct _info **, struct _info **);
  145: int reversealnumsort(struct _info **, struct _info **);
  146: int timesort(struct _info **, struct _info **);
  147: int dirsfirstsort(struct _info **, struct _info **);
  148: int findino(ino_t, dev_t);
  149: void *xmalloc(size_t), *xrealloc(void *, size_t);
  150: void listdir(char *, int *, int *, u_long, dev_t), usage(int);
  151: void parse_dir_colors(), printit(unsigned char *), free_dir(struct _info **), indent();
  152: void saveino(ino_t, dev_t);
  153: char **split(char *, char *, int *);
  154: char *gidtoname(int), *uidtoname(int), *do_date(time_t);
  155: char *gnu_getcwd();
  156: struct _info **read_dir(char *, int *);
  157: void html_encode(FILE *, char *), url_encode(FILE *, char *);
  158: const char *getcharset(void);
  159: void initlinedraw(int);
  160: void psize(char *buf, off_t size);
  161: #ifdef __EMX__
  162:   char *prot(long);
  163: #else
  164:   char *prot(u_short);
  165: #endif
  166: 
  167: /* Globals */
  168: int dflag, lflag, pflag, sflag, Fflag, aflag, fflag, uflag, gflag;
  169: int qflag, Nflag, Dflag, inodeflag, devflag, hflag;
  170: int noindent, force_color, nocolor, xdev, noreport, nolinks;
  171: char *pattern = NULL, *ipattern = NULL, *host = NULL, *title = "Directory Tree", *sp = " ";
  172: const char *charset=NULL;
  173: 
  174: int (*cmpfunc)() = alnumsort;
  175: 
  176: u_char Hflag, Rflag;
  177: int Level;
  178: char *sLevel, *curdir, *outfilename = NULL;
  179: FILE *outfile;
  180: int *dirs, maxdirs;

Most of them should be static?

_ emacs/22.1/src/sysdep.c:2336-2509

 2336: /* init_system_name sets up the string for the Lisp function
 2337:    system-name to return. */
 2338: 
 2339: #ifdef BSD4_1
 2340: #include <whoami.h>
 2341: #endif
 2342: 
 2343: extern Lisp_Object Vsystem_name;
 2344: 
 2345: #ifndef BSD4_1
 2346: #ifndef VMS
 2347: #ifdef HAVE_SOCKETS
 2348: #include <sys/socket.h>
 2349: #include <netdb.h>
 2350: #endif /* HAVE_SOCKETS */
 2351: #endif /* not VMS */
 2352: #endif /* not BSD4_1 */
 2353: 
 2354: #ifdef TRY_AGAIN
 2355: #ifndef HAVE_H_ERRNO
 2356: extern int h_errno;
 2357: #endif
 2358: #endif /* TRY_AGAIN */
 2359: 
 2360: void
 2361: init_system_name ()
 2362: {
 2363: #ifdef BSD4_1
 2364:   Vsystem_name = build_string (sysname);
 2365: #else
 2366: #ifdef VMS
 2367:   char *sp, *end;
 2368:   if ((sp = egetenv ("SYS$NODE")) == 0)
 2369:     Vsystem_name = build_string ("vax-vms");
 2370:   else if ((end = index (sp, ':')) == 0)
 2371:     Vsystem_name = build_string (sp);
 2372:   else
 2373:     Vsystem_name = make_string (sp, end - sp);
 2374: #else
 2375: #ifndef HAVE_GETHOSTNAME
 2376:   struct utsname uts;
 2377:   uname (&uts);
 2378:   Vsystem_name = build_string (uts.nodename);
 2379: #else /* HAVE_GETHOSTNAME */
 2380:   unsigned int hostname_size = 256;
 2381:   char *hostname = (char *) alloca (hostname_size);
 2382: 
 2383:   /* Try to get the host name; if the buffer is too short, try
 2384:      again.  Apparently, the only indication gethostname gives of
 2385:      whether the buffer was large enough is the presence or absence
 2386:      of a '\0' in the string.  Eech.  */
 2387:   for (;;)
 2388:     {
 2389:       gethostname (hostname, hostname_size - 1);
 2390:       hostname[hostname_size - 1] = '\0';
 2391: 
 2392:       /* Was the buffer large enough for the '\0'?  */
 2393:       if (strlen (hostname) < hostname_size - 1)
 2394:         break;
 2395: 
 2396:       hostname_size <<= 1;
 2397:       hostname = (char *) alloca (hostname_size);
 2398:     }
 2399: #ifdef HAVE_SOCKETS
 2400:   /* Turn the hostname into the official, fully-qualified hostname.
 2401:      Don't do this if we're going to dump; this can confuse system
 2402:      libraries on some machines and make the dumped emacs core dump. */
 2403: #ifndef CANNOT_DUMP
 2404:   if (initialized)
 2405: #endif /* not CANNOT_DUMP */
 2406:     if (! index (hostname, '.'))
 2407:       {
 2408:         struct hostent *hp;
 2409:         int count;
 2410:         for (count = 0;; count++)
 2411:           {
 2412: #ifdef TRY_AGAIN
 2413:             h_errno = 0;
 2414: #endif
 2415:             hp = gethostbyname (hostname);
 2416: #ifdef TRY_AGAIN
 2417:             if (! (hp == 0 && h_errno == TRY_AGAIN))
 2418: #endif
 2419:               break;
 2420:             if (count >= 5)
 2421:               break;
 2422:             Fsleep_for (make_number (1), Qnil);
 2423:           }
 2424:         if (hp)
 2425:           {
 2426:             char *fqdn = (char *) hp->h_name;
 2427: #if 0
 2428:             char *p;
 2429: #endif
 2430: 
 2431:             if (!index (fqdn, '.'))
 2432:               {
 2433:                 /* We still don't have a fully qualified domain name.
 2434:                    Try to find one in the list of alternate names */
 2435:                 char **alias = hp->h_aliases;
 2436:                 while (*alias
 2437:                        && (!index (*alias, '.')
 2438:                            || !strcmp (*alias, "localhost.localdomain")))
 2439:                   alias++;
 2440:                 if (*alias)
 2441:                   fqdn = *alias;
 2442:               }
 2443:             hostname = fqdn;
 2444: #if 0
 2445:             /* Convert the host name to lower case.  */
 2446:             /* Using ctype.h here would introduce a possible locale
 2447:                dependence that is probably wrong for hostnames.  */
 2448:             p = hostname;
 2449:             while (*p)
 2450:               {
 2451:                 if (*p >= 'A' && *p <= 'Z')
 2452:                   *p += 'a' - 'A';
 2453:                 p++;
 2454:               }
 2455: #endif
 2456:           }
 2457:       }
 2458: #endif /* HAVE_SOCKETS */
 2459:   /* We used to try using getdomainname here,
 2460:      but NIIBE Yutaka <gniibe@etl.go.jp> says that
 2461:      getdomainname gets the NIS/YP domain which often is not the same
 2462:      as in Internet domain name.  */
 2463: #if 0 /* Turned off because sysinfo is not really likely to return the
 2464:          correct Internet domain.  */
 2465: #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
 2466:   if (! index (hostname, '.'))
 2467:     {
 2468:       /* The hostname is not fully qualified.  Append the domain name.  */
 2469: 
 2470:       int hostlen = strlen (hostname);
 2471:       int domain_size = 256;
 2472: 
 2473:       for (;;)
 2474:         {
 2475:           char *domain = (char *) alloca (domain_size + 1);
 2476:           char *fqdn = (char *) alloca (hostlen + 1 + domain_size + 1);
 2477:           int sys_domain_size = sysinfo (SI_SRPC_DOMAIN, domain, domain_size);
 2478:           if (sys_domain_size <= 0)
 2479:             break;
 2480:           if (domain_size < sys_domain_size)
 2481:             {
 2482:               domain_size = sys_domain_size;
 2483:               continue;
 2484:             }
 2485:           strcpy (fqdn, hostname);
 2486:           if (domain[0] == '.')
 2487:             strcpy (fqdn + hostlen, domain);
 2488:           else if (domain[0] != 0)
 2489:             {
 2490:               fqdn[hostlen] = '.';
 2491:               strcpy (fqdn + hostlen + 1, domain);
 2492:             }
 2493:           hostname = fqdn;
 2494:           break;
 2495:         }
 2496:     }
 2497: #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
 2498: #endif /* 0 */
 2499:   Vsystem_name = build_string (hostname);
 2500: #endif /* HAVE_GETHOSTNAME */
 2501: #endif /* VMS */
 2502: #endif /* BSD4_1 */
 2503:   {
 2504:     unsigned char *p;
 2505:     for (p = SDATA (Vsystem_name); *p; p++)
 2506:       if (*p == ' ' || *p == '\t')
 2507:         *p = '-';
 2508:   }
 2509: }

Following newer standard, I think that we should use getnameinfo.

2008-01-07

_ emacs/22.1/lisp/woman.el:563-563

  563: (defun woman-parse-man.conf ()

むむ。Emacs Lisp のシンボル名って、. (ドット)が入っていいのか。 Lisp的にはポータブルでないような。ハイライトまちがってるし。

_ linux/2.6.23/mm/mprotect.c:190-210

  190: success:
  191:         /*
  192:          * vm_flags and vm_page_prot are protected by the mmap_sem
  193:          * held in write mode.
  194:          */
  195:         vma->vm_flags = newflags;
  196:         vma->vm_page_prot = protection_map[newflags &
  197:                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
  198:         if (vma_wants_writenotify(vma)) {
  199:                 vma->vm_page_prot = protection_map[newflags &
  200:                         (VM_READ|VM_WRITE|VM_EXEC)];
  201:                 dirty_accountable = 1;
  202:         }
  203: 
  204:         if (is_vm_hugetlb_page(vma))
  205:                 hugetlb_change_protection(vma, start, end, vma->vm_page_prot);
  206:         else
  207:                 change_protection(vma, start, end, vma->vm_page_prot, dirty_accountable);
  208:         vm_stat_account(mm, oldflags, vma->vm_file, -nrpages);
  209:         vm_stat_account(mm, newflags, vma->vm_file, nrpages);
  210:         return 0;

BUG: Here, change_protection is called after the change of vma->vm_flags. This may cause a problem for CPU which requires cache coherency handling.

_ linux/2.6.23/mm/mprotect.c:121-121

  121:         flush_cache_range(vma, addr, end);

Here, flush_cache_range is called with new vma, which is problematic.

_ linux/2.6.23/include/asm-arm/cacheflush.h:331-337

  331: static inline void
  332: flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
  333: {
  334:         if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask))
  335:                 __cpuc_flush_user_range(start & PAGE_MASK, PAGE_ALIGN(end),
  336:                                         vma->vm_flags);
  337: }

This is the implementation of flush_cache_range.

_ linux/2.6.23/include/asm-arm/cacheflush.h:216-216

  216: #define __cpuc_flush_user_range         cpu_cache.flush_user_range

This is the definition. Let's see flush_user_range.

_ linux/2.6.23/arch/arm/mm/proc-arm926.S:302-311

  302: ENTRY(arm926_cache_fns)
  303:         .long  arm926_flush_kern_cache_all
  304:         .long  arm926_flush_user_cache_all
  305:         .long  arm926_flush_user_cache_range
  306:         .long  arm926_coherent_kern_range
  307:         .long  arm926_coherent_user_range
  308:         .long  arm926_flush_kern_dcache_page
  309:         .long  arm926_dma_inv_range
  310:         .long  arm926_dma_clean_range
  311:         .long  arm926_dma_flush_range

This is the function table.

_ linux/2.6.23/arch/arm/mm/proc-arm926.S:141-177

  141: 
  142: /*
  143:  *      flush_user_cache_range(start, end, flags)
  144:  *
  145:  *      Clean and invalidate a range of cache entries in the
  146:  *      specified address range.
  147:  *
  148:  *      - start      - start address (inclusive)
  149:  *      - end        - end address (exclusive)
  150:  *      - flags      - vm_flags describing address space
  151:  */
  152: ENTRY(arm926_flush_user_cache_range)
  153:         mov    ip, #0
  154:         sub    r3, r1, r0                 @ calculate total size
  155:         cmp    r3, #CACHE_DLIMIT
  156:         bgt    __flush_whole_cache
  157: 1:      tst  r2, #VM_EXEC
  158: #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
  159:         mcr    p15, 0, r0, c7, c6, 1              @ invalidate D entry
  160:         mcrne  p15, 0, r0, c7, c5, 1            @ invalidate I entry
  161:         add    r0, r0, #CACHE_DLINESIZE
  162:         mcr    p15, 0, r0, c7, c6, 1              @ invalidate D entry
  163:         mcrne  p15, 0, r0, c7, c5, 1            @ invalidate I entry
  164:         add    r0, r0, #CACHE_DLINESIZE
  165: #else
  166:         mcr    p15, 0, r0, c7, c14, 1             @ clean and invalidate D entry
  167:         mcrne  p15, 0, r0, c7, c5, 1            @ invalidate I entry
  168:         add    r0, r0, #CACHE_DLINESIZE
  169:         mcr    p15, 0, r0, c7, c14, 1             @ clean and invalidate D entry
  170:         mcrne  p15, 0, r0, c7, c5, 1            @ invalidate I entry
  171:         add    r0, r0, #CACHE_DLINESIZE
  172: #endif
  173:         cmp    r0, r1
  174:         blo    1b
  175:         tst    r2, #VM_EXEC
  176:         mcrne  p15, 0, ip, c7, c10, 4           @ drain WB
  177:         mov    pc, lr

Here, it checks the flag if it's executable or not. This should be old flag when the control reaches through sys_mprotect.