~ubuntu-branches/ubuntu/precise/ndiswrapper/precise

« back to all changes in this revision

Viewing changes to driver/ntoskernel.c

  • Committer: Package Import Robot
  • Author(s): Julian Andres Klode
  • Date: 2012-03-05 16:49:02 UTC
  • mfrom: (1.2.16) (2.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120305164902-xx82le3qjjzr6s4j
Tags: 1.57-1
* Imported Upstream version 1.57
  - Fixes build with kernel 3.2 (Closes: #655223, LP: #910597)
* Enable hardening build flags (Closes: #655249)
* patches/ndiswrapper-harden.patch: Use $(shell X) instead of `X`
* Update to Policy 3.9.3, copyright-format 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
struct workqueue_struct *ntos_wq;
88
88
 
89
89
#ifdef WRAP_PREEMPT
90
 
DEFINE_PER_CPU(irql_info_t, irql_info);
 
90
DEFINE_PER_CPU(struct irql_info, irql_info);
91
91
#endif
92
92
 
93
93
#if defined(CONFIG_X86_64)
94
94
static void update_user_shared_data_proc(unsigned long data)
95
95
{
96
96
        /* timer is supposed to be scheduled every 10ms, but bigger
97
 
         * intervals seem to work (tried upto 50ms) */
 
97
         * intervals seem to work (tried up to 50ms) */
98
98
        *((ULONG64 *)&kuser_shared_data.system_time) = ticks_1601();
99
99
        *((ULONG64 *)&kuser_shared_data.interrupt_time) =
100
100
                jiffies * TICKSPERSEC / HZ;
444
444
         * freed, so we use slack_kmalloc so it gets freed when driver
445
445
         * is unloaded */
446
446
        if (nmb)
447
 
                wrap_timer = kmalloc(sizeof(*wrap_timer), irql_gfp());
 
447
                wrap_timer = kzalloc(sizeof(*wrap_timer), irql_gfp());
448
448
        else
449
 
                wrap_timer = slack_kmalloc(sizeof(*wrap_timer));
 
449
                wrap_timer = slack_kzalloc(sizeof(*wrap_timer));
450
450
        if (!wrap_timer) {
451
451
                ERROR("couldn't allocate memory for timer");
452
452
                return;
453
453
        }
454
454
 
455
 
        memset(wrap_timer, 0, sizeof(*wrap_timer));
456
455
        init_timer(&wrap_timer->timer);
457
456
        wrap_timer->timer.data = (unsigned long)wrap_timer;
458
457
        wrap_timer->timer.function = timer_proc;
532
531
{
533
532
        unsigned long expires_hz, repeat_hz;
534
533
 
535
 
        TIMERENTER("%p, %Ld, %d", nt_timer, duetime_ticks, period_ms);
 
534
        TIMERENTER("%p, %lld, %d", nt_timer, duetime_ticks, period_ms);
536
535
        expires_hz = SYSTEM_TIME_TO_HZ(duetime_ticks);
537
536
        repeat_hz = MSEC_TO_HZ(period_ms);
538
537
        return wrap_set_timer(nt_timer, expires_hz, repeat_hz, kdpc);
542
541
        (struct nt_timer *nt_timer, LARGE_INTEGER duetime_ticks,
543
542
         struct kdpc *kdpc)
544
543
{
545
 
        TIMERENTER("%p, %Ld, %p", nt_timer, duetime_ticks, kdpc);
 
544
        TIMERENTER("%p, %lld, %p", nt_timer, duetime_ticks, kdpc);
546
545
        return KeSetTimerEx(nt_timer, duetime_ticks, 0, kdpc);
547
546
}
548
547
 
588
587
        ENTER3("%p, %p, %p", kdpc, func, ctx);
589
588
        memset(kdpc, 0, sizeof(*kdpc));
590
589
        kdpc->func = func;
591
 
        kdpc->ctx  = ctx;
 
590
        kdpc->ctx = ctx;
592
591
        InitializeListHead(&kdpc->list);
593
592
}
594
593
 
648
647
        }
649
648
        spin_unlock_irqrestore(&kdpc_list_lock, flags);
650
649
        if (ret == TRUE)
651
 
                schedule_ntos_work(&kdpc_work);
 
650
                queue_work(ntos_wq, &kdpc_work);
652
651
        WORKTRACE("%d", ret);
653
652
        return ret;
654
653
}
730
729
        spin_lock_bh(&ntos_work_lock);
731
730
        InsertTailList(&ntos_work_list, &ntos_work_item->list);
732
731
        spin_unlock_bh(&ntos_work_lock);
733
 
        schedule_ntos_work(&ntos_work);
 
732
        queue_work(ntos_wq, &ntos_work);
734
733
        WORKEXIT(return 0);
735
734
}
736
735
 
801
800
{
802
801
        void *addr;
803
802
 
804
 
        ENTER4("pool_type: %d, size: %lu, tag: 0x%x", pool_type, size, tag);
 
803
        ENTER4("pool_type: %d, size: %zu, tag: 0x%x", pool_type, size, tag);
805
804
        assert_irql(_irql_ <= DISPATCH_LEVEL);
806
805
        if (size < PAGE_SIZE)
807
806
                addr = kmalloc(size, irql_gfp());
809
808
                if (irql_gfp() & GFP_ATOMIC) {
810
809
                        addr = __vmalloc(size, GFP_ATOMIC | __GFP_HIGHMEM,
811
810
                                         PAGE_KERNEL);
812
 
                        TRACE1("%p, %lu", addr, size);
 
811
                        TRACE1("%p, %zu", addr, size);
813
812
                } else {
814
813
                        addr = vmalloc(size);
815
 
                        TRACE1("%p, %lu", addr, size);
 
814
                        TRACE1("%p, %zu", addr, size);
816
815
                }
817
816
        }
818
817
        DBG_BLOCK(1) {
819
818
                if (addr)
820
 
                        TRACE4("addr: %p, %lu", addr, size);
 
819
                        TRACE4("addr: %p, %zu", addr, size);
821
820
                else
822
 
                        TRACE1("failed: %lu", size);
 
821
                        TRACE1("failed: %zu", size);
823
822
        }
824
823
        return addr;
825
824
}
850
849
         LOOKASIDE_ALLOC_FUNC *alloc_func, LOOKASIDE_FREE_FUNC *free_func,
851
850
         ULONG flags, SIZE_T size, ULONG tag, USHORT depth)
852
851
{
853
 
        ENTER3("lookaside: %p, size: %lu, flags: %u, head: %p, "
 
852
        ENTER3("lookaside: %p, size: %zu, flags: %u, head: %p, "
854
853
               "alloc: %p, free: %p", lookaside, size, flags,
855
854
               lookaside, alloc_func, free_func);
856
855
 
1044
1043
        typeof(jiffies) wait_hz = 0;
1045
1044
        struct wait_block *wb, wb_array[THREAD_WAIT_OBJECTS];
1046
1045
        struct dispatcher_header *dh;
 
1046
        KIRQL irql = current_irql();
1047
1047
 
1048
1048
        EVENTENTER("%p, %d, %u, %p", current, count, wait_type, timeout);
1049
1049
 
1115
1115
        else
1116
1116
                wait_hz = SYSTEM_TIME_TO_HZ(*timeout);
1117
1117
 
1118
 
        DBG_BLOCK(2) {
1119
 
                KIRQL irql = current_irql();
1120
 
                if (irql >= DISPATCH_LEVEL) {
1121
 
                        TRACE2("wait in atomic context: %lu, %d, %ld",
1122
 
                               wait_hz, in_atomic(), in_interrupt());
1123
 
                }
 
1118
        if (irql >= DISPATCH_LEVEL) {
 
1119
                WARNING("attempt to wait with irql %d", irql);
 
1120
                EVENTEXIT(return STATUS_INVALID_PARAMETER);
1124
1121
        }
1125
 
        assert_irql(_irql_ < DISPATCH_LEVEL);
1126
1122
        EVENTTRACE("%p: sleep for %ld on %p", current, wait_hz, &wait_done);
1127
1123
        /* we don't honor 'alertable' - according to description for
1128
1124
         * this, even if waiting in non-alertable state, thread may be
1342
1338
                ERROR("invalid wait_mode %d", wait_mode);
1343
1339
 
1344
1340
        timeout = SYSTEM_TIME_TO_HZ(*interval);
1345
 
        EVENTTRACE("%p, %Ld, %ld", current, *interval, timeout);
 
1341
        EVENTTRACE("%p, %lld, %ld", current, *interval, timeout);
1346
1342
        if (timeout <= 0)
1347
1343
                EVENTEXIT(return STATUS_SUCCESS);
1348
1344
 
1375
1371
        (LARGE_INTEGER *time)
1376
1372
{
1377
1373
        *time = ticks_1601();
1378
 
        TRACE5("%Lu, %lu", *time, jiffies);
 
1374
        TRACE5("%llu, %lu", *time, jiffies);
1379
1375
}
1380
1376
 
1381
1377
wstdcall void WIN_FUNC(KeQueryTickCount,1)
1695
1691
        void *addr;
1696
1692
        gfp_t flags;
1697
1693
 
1698
 
        ENTER2("%lu, 0x%lx, 0x%lx, 0x%lx, %d", size, (long)lowest,
1699
 
               (long)highest, (long)boundary, cache_type);
 
1694
        ENTER2("%zu, 0x%llx, 0x%llx, 0x%llx, %d", size, lowest,
 
1695
               highest, boundary, cache_type);
1700
1696
        flags = irql_gfp();
1701
1697
        addr = wrap_get_free_pages(flags, size);
1702
 
        TRACE2("%p, %lu, 0x%x", addr, size, flags);
 
1698
        TRACE2("%p, %zu, 0x%x", addr, size, flags);
1703
1699
        if (addr && ((virt_to_phys(addr) + size) <= highest))
1704
1700
                EXIT2(return addr);
1705
1701
#ifdef CONFIG_X86_64
1715
1711
        else if (highest > DMA_BIT_MASK(30))
1716
1712
                flags |= __GFP_HIGHMEM;
1717
1713
#endif
 
1714
        if (addr)
 
1715
                free_pages((unsigned long)addr, get_order(size));
1718
1716
        addr = wrap_get_free_pages(flags, size);
1719
 
        TRACE2("%p, %lu, 0x%x", addr, size, flags);
 
1717
        TRACE2("%p, %zu, 0x%x", addr, size, flags);
1720
1718
        return addr;
1721
1719
}
1722
1720
 
1723
1721
wstdcall void WIN_FUNC(MmFreeContiguousMemorySpecifyCache,3)
1724
1722
        (void *base, SIZE_T size, enum memory_caching_type cache_type)
1725
1723
{
1726
 
        TRACE2("%p, %lu", base, size);
 
1724
        TRACE2("%p, %zu", base, size);
1727
1725
        free_pages((unsigned long)base, get_order(size));
1728
1726
}
1729
1727
 
1752
1750
                virt = ioremap(phys_addr, size);
1753
1751
        else
1754
1752
                virt = ioremap_nocache(phys_addr, size);
1755
 
        TRACE1("%Lx, %lu, %p", phys_addr, size, virt);
 
1753
        TRACE1("%llx, %zu, %p", phys_addr, size, virt);
1756
1754
        return virt;
1757
1755
}
1758
1756
 
1759
1757
wstdcall void WIN_FUNC(MmUnmapIoSpace,2)
1760
1758
        (void __iomem *addr, SIZE_T size)
1761
1759
{
1762
 
        ENTER1("%p, %lu", addr, size);
 
1760
        ENTER1("%p, %zu", addr, size);
1763
1761
        iounmap(addr);
1764
1762
        return;
1765
1763
}
2156
2154
        else
2157
2155
                offset = fo->current_byte_offset;
2158
2156
        if (length + offset > file->size) {
2159
 
                WARNING("%lu, %u", length + offset, (unsigned int)file->size);
 
2157
                WARNING("%lu, %zu", length + offset, file->size);
2160
2158
                /* TODO: implement writing past end of current size */
2161
2159
                iosb->status = STATUS_FAILURE;
2162
2160
                iosb->info = 0;
2264
2262
 
2265
2263
wstdcall NTSTATUS WIN_FUNC(ZwMapViewOfSection,10)
2266
2264
        (void *secn_handle, void *process_handle, void **base_address,
2267
 
         ULONG zero_bits, LARGE_INTEGER *secn_offset, SIZE_T *view_size,
2268
 
         enum section_inherit inherit, ULONG alloc_type, ULONG protect)
 
2265
         ULONG zero_bits, SIZE_T commit_size, LARGE_INTEGER *secn_offset,
 
2266
         SIZE_T *view_size, enum section_inherit inherit, ULONG alloc_type,
 
2267
         ULONG protect)
2269
2268
{
2270
2269
        INFO("%p, %p, %p", secn_handle, process_handle, base_address);
2271
2270
        TODO();
2345
2344
        return STATUS_SUCCESS;
2346
2345
}
2347
2346
 
2348
 
wstdcall NTSTATUS WIN_FUNC(ZwPowerInformation,4)
 
2347
wstdcall NTSTATUS WIN_FUNC(ZwPowerInformation,5)
2349
2348
        (INT info_level, void *in_buf, ULONG in_buf_len, void *out_buf,
2350
2349
         ULONG out_buf_len)
2351
2350
{
2502
2501
 
2503
2502
        nt_spin_lock_init(&nt_list_lock);
2504
2503
 
2505
 
        initialize_work(&kdpc_work, kdpc_worker);
2506
 
        initialize_work(&ntos_work, ntos_work_worker);
 
2504
        INIT_WORK(&kdpc_work, kdpc_worker);
 
2505
        INIT_WORK(&ntos_work, ntos_work_worker);
2507
2506
        wrap_timer_slist.next = NULL;
2508
2507
 
2509
2508
        do_gettimeofday(&now);
2511
2510
        wrap_ticks_to_boot += (u64)now.tv_sec * TICKSPERSEC;
2512
2511
        wrap_ticks_to_boot += now.tv_usec * 10;
2513
2512
        wrap_ticks_to_boot -= jiffies * TICKSPERJIFFY;
2514
 
        TRACE2("%Lu", wrap_ticks_to_boot);
 
2513
        TRACE2("%llu", wrap_ticks_to_boot);
2515
2514
 
2516
2515
        cpu_count = num_online_cpus();
2517
2516
 
2519
2518
        do {
2520
2519
                int cpu;
2521
2520
                for_each_possible_cpu(cpu) {
2522
 
                        irql_info_t *info;
 
2521
                        struct irql_info *info;
2523
2522
                        info = &per_cpu(irql_info, cpu);
2524
2523
                        mutex_init(&(info->lock));
2525
2524
                        info->task = NULL;
2526
2525
                        info->count = 0;
 
2526
#ifdef CONFIG_SMP
 
2527
                        cpumask_setall(&info->cpus_allowed);
 
2528
#endif
2527
2529
                }
2528
2530
        } while (0);
2529
2531
#endif
2559
2561
        *((ULONG64 *)&kuser_shared_data.system_time) = ticks_1601();
2560
2562
        init_timer(&shared_data_timer);
2561
2563
        shared_data_timer.function = update_user_shared_data_proc;
2562
 
        shared_data_timer.data = (unsigned long)0;
 
2564
        shared_data_timer.data = 0;
2563
2565
#endif
2564
2566
        return 0;
2565
2567
}